1

我在 MacOS 上有一个 MetalKit 项目,除了深度模板外,一切都按预期工作。

因为我只能找到 iOS 深度模板的示例,所以我正在关注这些示例。在创建渲染管道后立即调用下面的代码片段,但 newDepthStencilStateWithDescriptor 的返回值似乎无效(设备和标签均为空)。

我可能错误地设置了 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>

请注意深度模板不工作和以错误顺序绘制的片段。

在此处输入图像描述

4

1 回答 1

0

我得到不一致输出的原因是因为在我测试的 Xcode 项目中启用了 Metal Validation,但在我的项目中却没有。如果我启用验证,则值是一致的。

启用验证后,相同的代码返回:

<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

所以整个问题毕竟是一个红鲱鱼。深度模板仍然不起作用,所以问题可能出在我的着色器或顶点数据中。

于 2018-07-03T20:46:42.470 回答