我在MacOS上有一个MetalKit项目,除深度模板外,其他一切都按预期工作。
因为我只能找到iOS深度模板的示例,所以我关注这些示例。创建渲染管道后立即调用下面的代码段,但是newDepthStencilStateWithDescriptor的返回值似乎无效(设备和标签均为null)。
我可能将MTKView设置错误,但是我不确定,因为没有使用MTKView和MacOS的深度模板的例子。
如果任何人都可以解释这是怎么发生的,我该如何调试它,或者如果我有可以与之比较的示例代码,那将是很好的。
desc := MTLDepthStencilDescriptor.alloc.init.autorelease;
desc.setDepthCompareFunction(MTLCompareFunctionLess);
desc.setDepthWriteEnabled(true);
desc.setLabel(NSSTR('MY DEPTH STENCIL'));
depthStencilState := device.newDepthStencilStateWithDescriptor(desc);
<MTLDepthStencilDescriptorInternal: 0x1003153a0>
label = MY DEPTH STENCIL
depthCompareFunction = MTLCompareFunctionLess
depthWriteEnabled = 1
frontFace:
stencilCompareFunction = MTLCompareFunctionAlways
stencilFailOperation = MTLStencilOperationKeep
stencilPassDepthFailOperation = MTLStencilOperationKeep
stencilPassDepthPassOperation = MTLStencilOperationKeep
stencilReadMask = 0xffffffff
stencilWriteMask = 0xffffffff
backFace:
stencilCompareFunction = MTLCompareFunctionAlways
stencilFailOperation = MTLStencilOperationKeep
stencilPassDepthFailOperation = MTLStencilOperationKeep
stencilPassDepthPassOperation = MTLStencilOperationKeep
stencilReadMask = 0xffffffff
stencilWriteMask = 0xffffffff
<MTLIGDepthStencilState: 0x1003241d0>
label = <none>
device = <null>
请注意深度模具无法正常工作,并且片段绘制顺序错误。
答案 0 :(得分:0)
我得到不一致的输出的原因是因为在我测试过的金属验证的Xcode项目中启用了,但是在我的项目中却没有。如果启用验证,则值是一致的。
启用验证后,相同的代码将返回:
<MTLDebugDepthStencilState: 0x100758d40> -> <MTLIGDepthStencilState: 0x1007582a0>
label = <none>
device = <null><MTLDepthStencilDescriptorInternal: 0x100758e20>
label = MY DEPTH STENCIL
depthCompareFunction = MTLCompareFunctionLess
depthWriteEnabled = 1
frontFace: <MTLStencilDescriptorInternal: 0x100758f60>
stencilCompareFunction = MTLCompareFunctionAlways
stencilFailureOperation = MTLStencilOperationKeep
stencilPassDepthFailOperation = MTLStencilOperationKeep
stencilPassDepthPassOperation = MTLStencilOperationKeep
stencilReadMask = 0xffffffff
stencilWriteMask = 0xffffffff
backFace: <MTLStencilDescriptorInternal: 0x100758f90>
stencilCompareFunction = MTLCompareFunctionAlways
stencilFailureOperation = MTLStencilOperationKeep
stencilPassDepthFailOperation = MTLStencilOperationKeep
stencilPassDepthPassOperation = MTLStencilOperationKeep
stencilReadMask = 0xffffffff
stencilWriteMask = 0xffffffff
所以整个问题毕竟是鲱鱼。深度模具仍然无法使用,因此问题可能出在我的着色器或顶点数据中。