GPU: correct detection of Apple M1 GPU

Don't cheat
This commit is contained in:
李通洲
2022-09-16 18:11:39 +08:00
committed by Carter Li
parent 413d126bcc
commit 09f3bd5a79
7 changed files with 43 additions and 52 deletions
+14 -34
View File
@@ -1,33 +1,18 @@
#include "gpu.h"
#include "common/library.h"
#include "detection/cpu/cpu.h"
#include "util/apple/cfdict_helpers.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/graphics/IOGraphicsLib.h>
void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
const char* ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
{
FF_UNUSED(instance);
const FFCPUResult* cpu = ffDetectCPU();
if(ffStrbufStartsWithIgnCaseS(&cpu->name, "Apple M"))
{
FFGPUResult* gpu = ffListAdd(gpus);
ffStrbufInit(&gpu->vendor);
ffStrbufAppendS(&gpu->vendor, "Apple");
ffStrbufInit(&gpu->name);
ffStrbufAppendS(&gpu->name, cpu->name.chars + 6); //Cut "Apple "
ffStrbufInitA(&gpu->driver, 0);
gpu->temperature = FF_GPU_TEMP_UNSET;
}
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
CFMutableDictionaryRef matchDict = IOServiceMatching(kIOAcceleratorClassName);
io_iterator_t iterator;
if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
return;
return "IOServiceGetMatchingServices() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
@@ -39,25 +24,19 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
continue;
}
CFStringRef key = CFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, kCFAllocatorNull);
CFStringRef model = CFDictionaryGetValue(properties, key);
if(model == NULL || CFGetTypeID(model) != CFDataGetTypeID())
{
CFRelease(properties);
IOObjectRelease(registryEntry);
continue;
}
FFGPUResult* gpu = ffListAdd(gpus);
uint32_t modelLength = (uint32_t) CFStringGetLength(model);
ffStrbufInitA(&gpu->name, modelLength + 1);
CFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
gpu->name.length = modelLength;
gpu->name.chars[gpu->name.length] = '\0';
ffStrbufInit(&gpu->name);
ffCfDictGetString(properties, "model", &gpu->name);
if (!ffCfDictGetInt(properties, "gpu-core-count", &gpu->coreCount))
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
ffStrbufInitA(&gpu->vendor, 0);
ffStrbufInitA(&gpu->driver, 0);
ffStrbufInit(&gpu->driver);
ffCfDictGetString(properties, "CFBundleIdentifier", &gpu->driver);
gpu->temperature = FF_GPU_TEMP_UNSET;
CFRelease(properties);
@@ -65,4 +44,5 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
}
IOObjectRelease(iterator);
return NULL;
}