如何解决使用Xcode调试Metal计算着色器
在Apple的2018年WWDC会议“ Metal Shader Debugging and Profiling”中,演讲者详细介绍了当时新的Metal调试工作流程。但是,他们在演示中对计算着色器的使用并没有走太远,仅简要提到了调试计算内核并着重于顶点和片段着色器调试时会出现的选项。
当仅将工作发送到GPU一次而不是每帧一次时,如何调试计算着色器?
请引导我参加您建议涵盖此主题和使用MTLCaptureManager
的其他WWDC会议。
解决方法
要调试 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
更多信息:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。