如何在 macOS 中检查 MTKView 是否支持 display-P3 像素格式?

How to check a MTKView supports display-P3 pixel formats in macOS?

提问人:endavid 提问时间:11/7/2023 最后编辑:endavid 更新时间:11/7/2023 访问量:25

问:

我有一个内置于 SwiftUI 的 macOS 应用程序,其中我有一个带有 .我将像素格式设置为:MTKView

let metalView = MTKView()
metalView.colorPixelFormat = .bgra10_xr_srgb

这适用于运行 macOS Sonoma 和 Xcode 15 的 M1 Mac mini。

但是,当我在 macOS Ventura(相同的 Xcode 15)上的 2017 Intel MacBook Pro 上运行相同的代码时,出现运行时错误,视图无法初始化。

日志:

unsupported extended range format
(
    0   CoreFoundation                      0x00007ff80611218a __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff805c3842b objc_exception_throw + 48
    2   CoreFoundation                      0x00007ff806111ff0 +[NSException raise:format:] + 214
    3   QuartzCore                          0x00007ff80d94e5f5 -[CAMetalLayer setPixelFormat:] + 339
    4   MetalKit                            0x00007ff8173dd17a -[MTKView setColorPixelFormat:atIndex:] + 112
...

因此,它表示不支持扩展范围像素格式(XR)。但是我该如何检查情况呢?

bgra10_xr_srgb文档没有提到任何关于崩溃的内容。它说,如果设备不支持更宽的范围,颜色就会被夹住,仅此而已。

macOS Metal 金属套件

评论


答:

1赞 Spo1ler 11/7/2023 #1

XR 格式不适用于 GPU 系列和更高版本以外的任何格式。Apple3

如果转到 Metal Feature Set Table 并滚动到 ,您将看到它仅在 on 及更高版本上受支持。Extended range and wide color pixel formatsApple3

因此,若要检查设备是否支持 XR 像素格式,可以使用MTLDevicesupportsFamily:MTLGPUFamilyApple3