The following code:-
#import <Metal/Metal.h>
#import <simd/simd.h>
#import <MetalKit/MetalKit.h>
#import <Foundation/Foundation.h>
int main(int argc, char** argv)
{
id <MTLDevice> device;
device = MTLCreateSystemDefaultDevice();
if (!device) {
printf("no default device\n");
} else {
printf("default device: %s\n", [[device name] cStringUsingEncoding:NSISOLatin1StringEncoding]);
}
NSArray *devices = MTLCopyAllDevices();
for (device in devices) {
NSString *s = [device name];
printf("all devices: %s\n", [s cStringUsingEncoding:NSISOLatin1StringEncoding]);
}
}
clang -framework Metal -framework Foundation objc.m -o objc
./objc # gives
no default device
all devices: AMD Radeon Pro 5500 XT
The equivalent swift
cat mtl.sw
#!/usr/bin/swift
import Foundation
import Cocoa // AppKit, CoreData, Foundation
let device = MTLCreateSystemDefaultDevice()!
let name = device.name;
print("Default: name: " + name);
./mtl.sw # gives
Default: name: AMD Radeon Pro 5500 XT
My question is why does objective see return null from the call to MTLCreateSystemDefaultDevice() but Swift does not.
I am running this on an iMac 27-inch 2020, i7 model.