MacOS Metal : Failing to capture GPU Frame from command line app

标签 macos metal

我正在尝试使用 MTLCaptureManager 以编程方式捕获 GPU 帧在命令行应用程序中。
至此,抓包管理器不支持 MTLCaptureDestinationGPUTraceDocument目的地。
我尝试使用 XCode 创建一个非常小的重现案例:

#import <Foundation/Foundation.h>
#import <Metal/Metal.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {

      id<MTLDevice> device = MTLCreateSystemDefaultDevice();
      
      MTLCaptureManager* captureManager = [MTLCaptureManager sharedCaptureManager];
      if (![captureManager supportsDestination:MTLCaptureDestinationGPUTraceDocument])
      {
        NSLog(@"********** captureManager does not support MTLCaptureDestinationGPUTraceDocument ************");
      }
      else
      {
        NSLog(@"captureManager support is fine");
      }
  }
  return 0;
}
当使用 XCode 运行时,它似乎愿意工作:输出是:
2020-09-02 16:25:59.712217+0200 testMetalCapture[20095:416447] Metal GPU Frame Capture Enabled
2020-09-02 16:25:59.712503+0200 testMetalCapture[20095:416447] Metal API Validation Enabled
2020-09-02 16:26:00.669092+0200 testMetalCapture[20095:416447] captureManager support is fine
Program ended with exit code: 0
但是当我存档构建结果并从终端运行时,它失败了:
2020-09-02 16:32:57.607 testMetalCapture[20126:419837] ********** captureManager does not support MTLCaptureDestinationGPUTraceDocument ************
是否有任何我可以在终端中重现的运行时环境来获取 MTLCaptureManager在职的 ?
(环境为 XCode 11.6 + MacOS 10.15 Catalina)

最佳答案

据我了解(我找不到任何官方文档):

  • MTLCaptureManager需要Info.plist的授权: MetalCaptureEnabled应该设置为 YES .
  • 正确的方法是将命令行应用程序与这样的 plist 捆绑在一起
  • 这是相当复杂的,例如参见Building OSX App Bundle


  • 我偶然发现MTLCaptureManager如果有 Info.plist 也可以使用在与命令行应用程序相同的目录中。
    enter image description here
    这个 Info.plist 几乎可以是空的,像这样:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>MetalCaptureEnabled</key>
        <true/>
    </dict>
    </plist>
    
    通过这个简单的设置,我可以运行我的测试程序(也可以运行我的真实程序)
    % ./testMetalCapture
    2020-10-02 15:53:08.507 testMetalCapture[28559:686864] Metal GPU Frame Capture Enabled
    2020-10-02 15:53:08.523 testMetalCapture[28559:686864] captureManager support is fine
    
    (我目前使用的是 MacOSX 10.15.6,将来可能会崩溃)

    关于MacOS Metal : Failing to capture GPU Frame from command line app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63707866/

    相关文章:

    macos - Mountain Lion 的听写应用程序的命令行界面/工具?

    c++ - Mac OSX 下 Eclipse CDT 与 Qt 交叉编译

    Cocoa:如何在执行后台任务时运行模式窗口?

    metal - 从内核检索结果

    ios - 在 iOS 上将 ARKit 与 Metal 结合使用时如何过滤掉模糊图像?

    ios - 此代码是在点级别还是像素级别绘制的?如何绘制视网膜像素?

    macos - Apple 语音问题的可访问性与字段集图例

    python - 如何在 osx 10.6.8 上安装 python 库 Pyexiv2 和 Gexiv2?

    swift - Metal 计算内核中的 Mipmap 采样器(不是顶点或片段着色器)

    ios - 在 Metal 计算着色器中排序