2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2018-2019 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "RenderPipelineMTL.h"
|
|
|
|
#include "DeviceMTL.h"
|
2020-09-21 22:10:50 +08:00
|
|
|
#include "RenderTargetMTL.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "ShaderModuleMTL.h"
|
|
|
|
#include "DepthStencilStateMTL.h"
|
2020-09-11 00:10:44 +08:00
|
|
|
#include "UtilsMTL.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
#include "ProgramMTL.h"
|
|
|
|
#include "xxhash.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
MTLVertexStepFunction toMTLVertexStepFunction(VertexStepMode vertexStepMode)
|
|
|
|
{
|
|
|
|
if (VertexStepMode::VERTEX == vertexStepMode)
|
|
|
|
return MTLVertexStepFunctionPerVertex;
|
|
|
|
else
|
|
|
|
return MTLVertexStepFunctionPerInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTLVertexFormat toMTLVertexFormat(VertexFormat vertexFormat, bool needNormalize)
|
|
|
|
{
|
|
|
|
MTLVertexFormat ret = MTLVertexFormatFloat4;
|
|
|
|
switch (vertexFormat)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
case VertexFormat::FLOAT4:
|
|
|
|
ret = MTLVertexFormatFloat4;
|
|
|
|
break;
|
|
|
|
case VertexFormat::FLOAT3:
|
|
|
|
ret = MTLVertexFormatFloat3;
|
|
|
|
break;
|
|
|
|
case VertexFormat::FLOAT2:
|
|
|
|
ret = MTLVertexFormatFloat2;
|
|
|
|
break;
|
|
|
|
case VertexFormat::FLOAT:
|
|
|
|
ret = MTLVertexFormatFloat;
|
|
|
|
break;
|
|
|
|
case VertexFormat::INT4:
|
|
|
|
ret = MTLVertexFormatInt4;
|
|
|
|
break;
|
|
|
|
case VertexFormat::INT3:
|
|
|
|
ret = MTLVertexFormatInt3;
|
|
|
|
break;
|
|
|
|
case VertexFormat::INT2:
|
|
|
|
ret = MTLVertexFormatInt2;
|
|
|
|
break;
|
|
|
|
case VertexFormat::INT:
|
|
|
|
ret = MTLVertexFormatInt;
|
|
|
|
break;
|
|
|
|
case VertexFormat::USHORT4:
|
|
|
|
ret = MTLVertexFormatUShort4;
|
|
|
|
break;
|
|
|
|
case VertexFormat::USHORT2:
|
|
|
|
ret = MTLVertexFormatUShort2;
|
|
|
|
break;
|
|
|
|
case VertexFormat::UBYTE4:
|
|
|
|
if (needNormalize)
|
|
|
|
ret = MTLVertexFormatUChar4Normalized;
|
2019-11-23 20:27:39 +08:00
|
|
|
else
|
2021-12-31 12:12:40 +08:00
|
|
|
ret = MTLVertexFormatUChar4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
break;
|
2021-12-28 11:07:12 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
MTLColorWriteMask toMTLColorWriteMask(ColorWriteMask mask)
|
|
|
|
{
|
|
|
|
switch (mask)
|
2021-12-28 21:27:32 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
case ColorWriteMask::NONE:
|
|
|
|
return MTLColorWriteMaskNone;
|
|
|
|
case ColorWriteMask::RED:
|
|
|
|
return MTLColorWriteMaskRed;
|
|
|
|
case ColorWriteMask::GREEN:
|
|
|
|
return MTLColorWriteMaskGreen;
|
|
|
|
case ColorWriteMask::BLUE:
|
|
|
|
return MTLColorWriteMaskBlue;
|
|
|
|
case ColorWriteMask::ALPHA:
|
|
|
|
return MTLColorWriteMaskAlpha;
|
|
|
|
case ColorWriteMask::ALL:
|
|
|
|
return MTLColorWriteMaskAll;
|
2021-12-31 11:00:35 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MTLBlendFactor toMTLBlendFactor(BlendFactor factor)
|
|
|
|
{
|
|
|
|
switch (factor)
|
2021-12-31 11:00:35 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
case BlendFactor::ZERO:
|
|
|
|
return MTLBlendFactorZero;
|
|
|
|
case BlendFactor::ONE:
|
|
|
|
return MTLBlendFactorOne;
|
|
|
|
case BlendFactor::SRC_COLOR:
|
|
|
|
return MTLBlendFactorSourceColor;
|
|
|
|
case BlendFactor::ONE_MINUS_SRC_COLOR:
|
|
|
|
return MTLBlendFactorOneMinusSourceColor;
|
|
|
|
case BlendFactor::SRC_ALPHA:
|
|
|
|
return MTLBlendFactorSourceAlpha;
|
|
|
|
case BlendFactor::ONE_MINUS_SRC_ALPHA:
|
|
|
|
return MTLBlendFactorOneMinusSourceAlpha;
|
|
|
|
case BlendFactor::DST_COLOR:
|
|
|
|
return MTLBlendFactorDestinationColor;
|
|
|
|
case BlendFactor::ONE_MINUS_DST_COLOR:
|
|
|
|
return MTLBlendFactorOneMinusDestinationColor;
|
|
|
|
case BlendFactor::DST_ALPHA:
|
|
|
|
return MTLBlendFactorDestinationAlpha;
|
|
|
|
case BlendFactor::ONE_MINUS_DST_ALPHA:
|
|
|
|
return MTLBlendFactorOneMinusDestinationAlpha;
|
|
|
|
case BlendFactor::SRC_ALPHA_SATURATE:
|
|
|
|
return MTLBlendFactorSourceAlphaSaturated;
|
|
|
|
case BlendFactor::BLEND_CLOLOR:
|
|
|
|
return MTLBlendFactorBlendColor;
|
|
|
|
default:
|
|
|
|
return MTLBlendFactorZero;
|
2021-12-28 21:27:32 +08:00
|
|
|
}
|
2021-12-28 21:00:45 +08:00
|
|
|
}
|
2021-12-28 11:07:12 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
MTLBlendOperation toMTLBlendOperation(BlendOperation operation)
|
2021-12-31 11:00:35 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case BlendOperation::ADD:
|
|
|
|
return MTLBlendOperationAdd;
|
|
|
|
case BlendOperation::SUBTRACT:
|
|
|
|
return MTLBlendOperationSubtract;
|
|
|
|
case BlendOperation::RESERVE_SUBTRACT:
|
|
|
|
return MTLBlendOperationReverseSubtract;
|
|
|
|
default:
|
|
|
|
return MTLBlendOperationAdd;
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 11:00:35 +08:00
|
|
|
}
|
2021-12-28 21:27:32 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
RenderPipelineMTL::RenderPipelineMTL(id<MTLDevice> mtlDevice) : _mtlDevice(mtlDevice) {}
|
|
|
|
|
|
|
|
void RenderPipelineMTL::update(const RenderTarget* renderTarget, const PipelineDescriptor& pipelineDescirptor)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2019-11-27 15:39:41 +08:00
|
|
|
size_t vertexShaderHash;
|
|
|
|
size_t fragmentShaderHash;
|
2019-11-23 20:27:39 +08:00
|
|
|
unsigned int vertexLayoutInfo[32];
|
2020-09-21 22:10:50 +08:00
|
|
|
backend::PixelFormat colorAttachment[MAX_COLOR_ATTCHMENT];
|
2019-11-23 20:27:39 +08:00
|
|
|
backend::PixelFormat depthAttachment;
|
|
|
|
backend::PixelFormat stencilAttachment;
|
|
|
|
bool blendEnabled;
|
|
|
|
unsigned int writeMask;
|
|
|
|
unsigned int rgbBlendOperation;
|
|
|
|
unsigned int alphaBlendOperation;
|
|
|
|
unsigned int sourceRGBBlendFactor;
|
|
|
|
unsigned int destinationRGBBlendFactor;
|
|
|
|
unsigned int sourceAlphaBlendFactor;
|
|
|
|
unsigned int destinationAlphaBlendFactor;
|
2021-12-31 12:12:40 +08:00
|
|
|
} hashMe;
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
memset(&hashMe, 0, sizeof(hashMe));
|
|
|
|
const auto& blendDescriptor = pipelineDescirptor.blendDescriptor;
|
2020-11-08 13:12:06 +08:00
|
|
|
chooseAttachmentFormat(renderTarget, _colorAttachmentsFormat, _depthAttachmentFormat, _stencilAttachmentFormat);
|
2021-12-31 12:12:40 +08:00
|
|
|
auto program = static_cast<ProgramMTL*>(pipelineDescirptor.programState->getProgram());
|
|
|
|
hashMe.vertexShaderHash = program->getVertexShader()->getHashValue();
|
2019-11-27 15:39:41 +08:00
|
|
|
hashMe.fragmentShaderHash = program->getFragmentShader()->getHashValue();
|
2020-09-21 22:10:50 +08:00
|
|
|
memcpy(&hashMe.colorAttachment, &_colorAttachmentsFormat, sizeof(_colorAttachmentsFormat));
|
2021-12-31 12:12:40 +08:00
|
|
|
hashMe.depthAttachment = _depthAttachmentFormat;
|
|
|
|
hashMe.stencilAttachment = _stencilAttachmentFormat;
|
|
|
|
hashMe.blendEnabled = blendDescriptor.blendEnabled;
|
|
|
|
hashMe.writeMask = (unsigned int)blendDescriptor.writeMask;
|
|
|
|
hashMe.rgbBlendOperation = (unsigned int)blendDescriptor.rgbBlendOperation;
|
|
|
|
hashMe.alphaBlendOperation = (unsigned int)blendDescriptor.alphaBlendOperation;
|
|
|
|
hashMe.sourceRGBBlendFactor = (unsigned int)blendDescriptor.sourceRGBBlendFactor;
|
|
|
|
hashMe.destinationRGBBlendFactor = (unsigned int)blendDescriptor.destinationRGBBlendFactor;
|
|
|
|
hashMe.sourceAlphaBlendFactor = (unsigned int)blendDescriptor.sourceAlphaBlendFactor;
|
2019-11-23 20:27:39 +08:00
|
|
|
hashMe.destinationAlphaBlendFactor = (unsigned int)blendDescriptor.destinationAlphaBlendFactor;
|
2021-12-31 12:12:40 +08:00
|
|
|
int index = 0;
|
|
|
|
auto vertexLayout = pipelineDescirptor.programState->getVertexLayout();
|
|
|
|
const auto& attributes = vertexLayout->getAttributes();
|
2019-11-23 20:27:39 +08:00
|
|
|
for (const auto& it : attributes)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
auto& attribute = it.second;
|
2019-11-23 20:27:39 +08:00
|
|
|
/*
|
|
|
|
stepFunction:1 stride:15 offest:10 format:5 needNormalized:1
|
|
|
|
bit31 bit30 ~ bit16 bit15 ~ bit6 bit5 ~ bit1 bit0
|
|
|
|
*/
|
|
|
|
hashMe.vertexLayoutInfo[index++] =
|
2021-12-31 12:12:40 +08:00
|
|
|
((unsigned int)vertexLayout->getVertexStepMode() & 0x1) << 31 |
|
|
|
|
((unsigned int)(vertexLayout->getStride() & 0x7FFF)) << 16 | ((unsigned int)attribute.offset & 0x3FF) << 6 |
|
|
|
|
((unsigned int)attribute.format & 0x1F) << 1 | ((unsigned int)attribute.needToBeNormallized & 0x1);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-27 15:39:41 +08:00
|
|
|
unsigned int hash = XXH32((const void*)&hashMe, sizeof(hashMe), 0);
|
2021-12-31 12:12:40 +08:00
|
|
|
auto it = _mtlStateCache.find(hash);
|
|
|
|
if (it != _mtlStateCache.end())
|
|
|
|
{
|
2020-09-22 16:32:17 +08:00
|
|
|
_mtlRenderPipelineState = it->second;
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
_mtlRenderPipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
setShaderModules(pipelineDescirptor);
|
|
|
|
setVertexLayout(_mtlRenderPipelineDescriptor, pipelineDescirptor);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2020-09-21 22:10:50 +08:00
|
|
|
setBlendStateAndFormat(pipelineDescirptor.blendDescriptor);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
|
|
|
NSError* error = nil;
|
|
|
|
_mtlRenderPipelineState = [_mtlDevice newRenderPipelineStateWithDescriptor:_mtlRenderPipelineDescriptor
|
|
|
|
error:&error];
|
2019-11-23 20:27:39 +08:00
|
|
|
if (error)
|
|
|
|
NSLog(@"Can not create renderpipeline state: %@", error);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
[_mtlRenderPipelineDescriptor release];
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2020-09-22 16:32:17 +08:00
|
|
|
_mtlStateCache.emplace(hash, _mtlRenderPipelineState);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderPipelineMTL::~RenderPipelineMTL()
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
for (auto& item : _mtlStateCache)
|
2020-09-22 16:32:17 +08:00
|
|
|
[item.second release];
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void RenderPipelineMTL::setVertexLayout(MTLRenderPipelineDescriptor* mtlDescriptor,
|
|
|
|
const PipelineDescriptor& descriptor)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2023-07-19 21:12:25 +08:00
|
|
|
int vertexIndex = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
auto vertexLayout = descriptor.programState->getVertexLayout();
|
|
|
|
if (!vertexLayout->isValid())
|
|
|
|
return;
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2023-07-19 21:12:25 +08:00
|
|
|
mtlDescriptor.vertexDescriptor.layouts[vertexIndex].stride = vertexLayout->getStride();
|
|
|
|
mtlDescriptor.vertexDescriptor.layouts[vertexIndex].stepFunction =
|
2021-12-31 12:12:40 +08:00
|
|
|
toMTLVertexStepFunction(vertexLayout->getVertexStepMode());
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
const auto& attributes = vertexLayout->getAttributes();
|
|
|
|
for (const auto& it : attributes)
|
|
|
|
{
|
|
|
|
auto attribute = it.second;
|
2023-07-19 21:12:25 +08:00
|
|
|
mtlDescriptor.vertexDescriptor.attributes[attribute.index].format =
|
2021-12-31 12:12:40 +08:00
|
|
|
toMTLVertexFormat(attribute.format, attribute.needToBeNormallized);
|
2023-07-19 21:12:25 +08:00
|
|
|
mtlDescriptor.vertexDescriptor.attributes[attribute.index].offset = attribute.offset;
|
2019-11-23 20:27:39 +08:00
|
|
|
// Buffer index will always be 0;
|
2023-07-19 21:12:25 +08:00
|
|
|
mtlDescriptor.vertexDescriptor.attributes[attribute.index].bufferIndex = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderPipelineMTL::setBlendState(MTLRenderPipelineColorAttachmentDescriptor* colorAttachmentDescriptor,
|
|
|
|
const BlendDescriptor& blendDescriptor)
|
|
|
|
{
|
|
|
|
colorAttachmentDescriptor.blendingEnabled = blendDescriptor.blendEnabled;
|
2021-12-31 12:12:40 +08:00
|
|
|
colorAttachmentDescriptor.writeMask = toMTLColorWriteMask(blendDescriptor.writeMask);
|
|
|
|
|
|
|
|
colorAttachmentDescriptor.rgbBlendOperation = toMTLBlendOperation(blendDescriptor.rgbBlendOperation);
|
2019-11-23 20:27:39 +08:00
|
|
|
colorAttachmentDescriptor.alphaBlendOperation = toMTLBlendOperation(blendDescriptor.alphaBlendOperation);
|
2021-12-31 12:12:40 +08:00
|
|
|
|
|
|
|
colorAttachmentDescriptor.sourceRGBBlendFactor = toMTLBlendFactor(blendDescriptor.sourceRGBBlendFactor);
|
2019-11-23 20:27:39 +08:00
|
|
|
colorAttachmentDescriptor.destinationRGBBlendFactor = toMTLBlendFactor(blendDescriptor.destinationRGBBlendFactor);
|
2021-12-31 12:12:40 +08:00
|
|
|
colorAttachmentDescriptor.sourceAlphaBlendFactor = toMTLBlendFactor(blendDescriptor.sourceAlphaBlendFactor);
|
|
|
|
colorAttachmentDescriptor.destinationAlphaBlendFactor =
|
|
|
|
toMTLBlendFactor(blendDescriptor.destinationAlphaBlendFactor);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderPipelineMTL::setShaderModules(const PipelineDescriptor& descriptor)
|
|
|
|
{
|
|
|
|
auto vertexShaderModule = static_cast<ProgramMTL*>(descriptor.programState->getProgram())->getVertexShader();
|
|
|
|
_mtlRenderPipelineDescriptor.vertexFunction = vertexShaderModule->getMTLFunction();
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
auto fragShaderModule = static_cast<ProgramMTL*>(descriptor.programState->getProgram())->getFragmentShader();
|
|
|
|
_mtlRenderPipelineDescriptor.fragmentFunction = fragShaderModule->getMTLFunction();
|
|
|
|
}
|
|
|
|
|
2020-11-08 13:12:06 +08:00
|
|
|
void RenderPipelineMTL::chooseAttachmentFormat(const RenderTarget* renderTarget,
|
2021-12-31 12:12:40 +08:00
|
|
|
PixelFormat colorAttachmentsFormat[MAX_COLOR_ATTCHMENT],
|
|
|
|
PixelFormat& depthFormat,
|
|
|
|
PixelFormat& stencilFormat)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-04-22 22:01:47 +08:00
|
|
|
// Choose color attachment format
|
2021-12-31 12:12:40 +08:00
|
|
|
auto rtMTL = static_cast<const RenderTargetMTL*>(renderTarget);
|
2020-09-21 22:10:50 +08:00
|
|
|
auto rtflags = rtMTL->getTargetFlags();
|
2021-12-31 12:12:40 +08:00
|
|
|
for (auto i = 0; i < MAX_COLOR_ATTCHMENT; ++i)
|
|
|
|
{
|
|
|
|
colorAttachmentsFormat[i] =
|
|
|
|
bitmask::any(rtflags, getMRTColorFlag(i)) ? rtMTL->getColorAttachmentPixelFormat(i) : PixelFormat::NONE;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
2021-04-22 22:01:47 +08:00
|
|
|
if (bitmask::any(rtflags, RenderTargetFlag::DEPTH_AND_STENCIL))
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
depthFormat = rtMTL->getDepthAttachmentPixelFormat();
|
|
|
|
stencilFormat = rtMTL->getStencilAttachmentPixelFormat();
|
2021-04-22 22:01:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
depthFormat = stencilFormat = PixelFormat::NONE;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2020-09-21 22:10:50 +08:00
|
|
|
void RenderPipelineMTL::setBlendStateAndFormat(const BlendDescriptor& blendDescriptor)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
for (int i = 0; i < MAX_COLOR_ATTCHMENT; ++i)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
if (PixelFormat::NONE == _colorAttachmentsFormat[i])
|
|
|
|
{
|
2020-09-21 22:10:50 +08:00
|
|
|
_mtlRenderPipelineDescriptor.colorAttachments[i].pixelFormat = MTLPixelFormat::MTLPixelFormatInvalid;
|
2019-11-23 20:27:39 +08:00
|
|
|
continue;
|
2020-09-21 22:10:50 +08:00
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
|
|
|
|
_mtlRenderPipelineDescriptor.colorAttachments[i].pixelFormat =
|
|
|
|
UtilsMTL::toMTLPixelFormat(_colorAttachmentsFormat[i]);
|
2019-11-23 20:27:39 +08:00
|
|
|
setBlendState(_mtlRenderPipelineDescriptor.colorAttachments[i], blendDescriptor);
|
|
|
|
}
|
2021-12-31 12:12:40 +08:00
|
|
|
_mtlRenderPipelineDescriptor.depthAttachmentPixelFormat = UtilsMTL::toMTLPixelFormat(_depthAttachmentFormat);
|
2020-09-11 00:10:44 +08:00
|
|
|
_mtlRenderPipelineDescriptor.stencilAttachmentPixelFormat = UtilsMTL::toMTLPixelFormat(_stencilAttachmentFormat);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BACKEND_END
|