如何识别iPhone或Mac中带有metal的可用计算设备

4

请问有没有人能提供一个示例来说明如何使用Metal识别可用的计算设备,例如CPU和GPU?非常感谢。

1个回答

5

Metal仅适用于GPU。不过,有一个名为MTLCopyAllDevices()的函数,它返回系统上所有GPU。下面是我在OS X playground中运行此功能以查看我系统拥有的兼容设备的快速示例。

enter image description here

编辑:

Objective-C中,这看起来很相似。只需首先导入<Metal/Metal.h>

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSArray *devices = MTLCopyAllDevices(); for (id device in devices) { NSLog(@"%@", [device name]); } }
@end

谢谢@Marius。不过,它能用Objective-C实现吗?我是Metal的新手。 - Pony
我使用了谷歌的 MLTCopyAllDevices,但是没有得到有价值的结果。 - Pony
2
文档在这里:MTLCopyAllDevices。此函数仅适用于OS X。在iOS上,只有一个设备,您可以通过调用MTLCreateSystemDefaultDevice来获取它。 - warrenm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接