我正在尝试使用 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
. 我偶然发现
MTLCaptureManager
如果有 Info.plist
也可以使用在与命令行应用程序相同的目录中。这个 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/