From 10973dd9d15c287f2ae9a5786368522605d979a5 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 6 Sep 2022 02:28:32 -0700 Subject: [PATCH] Better MacOS GPU support --- src/detection/gpu/gpu_apple.c | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/detection/gpu/gpu_apple.c b/src/detection/gpu/gpu_apple.c index 77a76c32c..baab518be 100644 --- a/src/detection/gpu/gpu_apple.c +++ b/src/detection/gpu/gpu_apple.c @@ -16,7 +16,15 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceGetMatchingServices, ) FF_LIBRARY_LOAD_SYMBOL(iokit, kIOMasterPortDefault, ) FF_LIBRARY_LOAD_SYMBOL(iokit, IOIteratorNext, ) - FF_LIBRARY_LOAD_SYMBOL(iokit, IORegistryEntryGetName, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, IORegistryEntryCreateCFProperties, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorDefault, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFDictionaryGetValue, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFGetTypeID, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringCreateWithCStringNoCopy, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetLength, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetCString, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFRelease, ) + FF_LIBRARY_LOAD_SYMBOL(iokit, CFDataGetTypeID, ) FF_LIBRARY_LOAD_SYMBOL(iokit, IOObjectRelease, ) CFMutableDictionaryRef matchDict = ffIOServiceMatching(kIOAcceleratorClassName); @@ -30,21 +38,33 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance) io_registry_entry_t registryEntry; while((registryEntry = ffIOIteratorNext(iterator)) != 0) { - io_name_t deviceName; - kern_return_t ret = ffIORegistryEntryGetName(registryEntry, deviceName); - ffIOObjectRelease(registryEntry); - - if(ret != KERN_SUCCESS) + CFMutableDictionaryRef properties; + if(ffIORegistryEntryCreateCFProperties(registryEntry, &properties, *ffkCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) + { + ffIOObjectRelease(registryEntry); continue; + } + + CFStringRef key = ffCFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingUTF8, NULL); + CFStringRef model = ffCFDictionaryGetValue(properties, key); + if(model == NULL || ffCFGetTypeID(model) != ffCFDataGetTypeID()) + { + ffCFRelease(properties); + ffIOObjectRelease(registryEntry); + continue; + } FFGPUResult* gpu = ffListAdd(gpus); - ffStrbufInit(&gpu->name); - ffStrbufAppendS(&gpu->name, deviceName); + ffStrbufInitA(&gpu->name, (uint32_t) (ffCFStringGetLength(model) + 1)); + ffCFStringGetCString(model, gpu->name.chars, ffStrbufGetFree(&gpu->name), kCFStringEncodingUTF8); ffStrbufInitA(&gpu->vendor, 0); ffStrbufInitA(&gpu->driver, 0); gpu->temperature = FF_GPU_TEMP_UNSET; + + ffCFRelease(properties); + ffIOObjectRelease(registryEntry); } ffIOObjectRelease(iterator);