【问题标题】:Debugging Metal compute shaders with Xcode使用 Xcode 调试 Metal 计算着色器
【发布时间】:2020-09-27 17:13:00
【问题描述】:

在 Apple 的 2018 年 WWDC 会议“Metal Shader 调试和分析”中,演讲者详细介绍了当时新的 Metal 调试工作流程。然而,他们在演示中并没有对计算着色器走得太远,只是简单地提到了调试计算内核时会出现的选项,并专注于顶点和片段着色器的调试。

当我们只将工作发送到 GPU 一次而不是每一帧时,我们如何调试计算着色器? 请指导我参加您推荐的其他 WWDC 会议,涵盖此主题并使用 MTLCaptureManager。

【问题讨论】:

    标签: swift xcode metal compute-shader


    【解决方案1】:

    要调试您的 Metal Compute Kernel 函数,您需要创建一个CaptureScope。

    您不自己分配范围,而是从MTLCaptureManager 中检索它:

    let sharedCapturer = MTLCaptureManager.shared()
    let customScope = sharedCapturer.makeCaptureScope(device: device)
    // Add a label if you want to capture it from XCode's debug bar
    customScope.label = "Pls debug me"
    // If you want to set this scope as the default debug scope, assign it to MTLCaptureManager's defaultCaptureScope
    sharedCapturer.defaultCaptureScope = customScope
    

    使自定义范围起作用的关键步骤:

    • 在计算循环之外创建范围。
    • 当作用域处于活动状态时,您需要保持对它的强引用。

    我上面说的,但在代码中:

    customScope?.begin()
    let commandBuffer = commandQueue.makeCommandBuffer()!
    // Perform your metal computing here
    commandBuffer.commit()
    customScope?.end()
    

    一些相关的 WWDC:

    WWDC 2019 - Delivering Optimized Metal Apps and Games

    更多信息:

    Developer Guide - Frame Capture Debugging Tools

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 2019-01-24
      • 2018-05-24
      相关资源
      最近更新 更多