2022-09-05 17:42:42 +02:00
|
|
|
#include "gpu.h"
|
2022-09-05 13:41:05 -07:00
|
|
|
#include "common/library.h"
|
2022-09-09 05:40:27 -07:00
|
|
|
#include "detection/cpu/cpu.h"
|
2022-09-05 13:41:05 -07:00
|
|
|
|
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
#include <IOKit/graphics/IOGraphicsLib.h>
|
2022-09-05 17:42:42 +02:00
|
|
|
|
|
|
|
|
void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
|
|
|
|
{
|
2022-09-05 13:41:05 -07:00
|
|
|
FF_UNUSED(instance);
|
|
|
|
|
|
2022-09-09 05:40:27 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:55:28 +02:00
|
|
|
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
|
2022-09-05 13:41:05 -07:00
|
|
|
io_iterator_t iterator;
|
2022-09-14 14:55:28 +02:00
|
|
|
if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
|
2022-09-05 13:41:05 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
io_registry_entry_t registryEntry;
|
2022-09-14 14:55:28 +02:00
|
|
|
while((registryEntry = IOIteratorNext(iterator)) != 0)
|
2022-09-05 13:41:05 -07:00
|
|
|
{
|
2022-09-06 02:28:32 -07:00
|
|
|
CFMutableDictionaryRef properties;
|
2022-09-14 14:55:28 +02:00
|
|
|
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
|
2022-09-06 02:28:32 -07:00
|
|
|
{
|
2022-09-14 14:55:28 +02:00
|
|
|
IOObjectRelease(registryEntry);
|
2022-09-06 02:28:32 -07:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-09-05 13:41:05 -07:00
|
|
|
|
2022-09-14 14:55:28 +02:00
|
|
|
CFStringRef key = CFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, kCFAllocatorNull);
|
|
|
|
|
CFStringRef model = CFDictionaryGetValue(properties, key);
|
|
|
|
|
if(model == NULL || CFGetTypeID(model) != CFDataGetTypeID())
|
2022-09-06 02:28:32 -07:00
|
|
|
{
|
2022-09-14 14:55:28 +02:00
|
|
|
CFRelease(properties);
|
|
|
|
|
IOObjectRelease(registryEntry);
|
2022-09-05 13:41:05 -07:00
|
|
|
continue;
|
2022-09-06 02:28:32 -07:00
|
|
|
}
|
2022-09-05 13:41:05 -07:00
|
|
|
|
|
|
|
|
FFGPUResult* gpu = ffListAdd(gpus);
|
|
|
|
|
|
2022-09-14 14:55:28 +02:00
|
|
|
uint32_t modelLength = (uint32_t) CFStringGetLength(model);
|
2022-09-07 06:37:35 -07:00
|
|
|
ffStrbufInitA(&gpu->name, modelLength + 1);
|
2022-09-14 14:55:28 +02:00
|
|
|
CFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
|
2022-09-07 06:40:47 -07:00
|
|
|
gpu->name.length = modelLength;
|
|
|
|
|
gpu->name.chars[gpu->name.length] = '\0';
|
2022-09-05 13:41:05 -07:00
|
|
|
|
|
|
|
|
ffStrbufInitA(&gpu->vendor, 0);
|
|
|
|
|
ffStrbufInitA(&gpu->driver, 0);
|
|
|
|
|
gpu->temperature = FF_GPU_TEMP_UNSET;
|
2022-09-06 02:28:32 -07:00
|
|
|
|
2022-09-14 14:55:28 +02:00
|
|
|
CFRelease(properties);
|
|
|
|
|
IOObjectRelease(registryEntry);
|
2022-09-05 13:41:05 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-14 14:55:28 +02:00
|
|
|
IOObjectRelease(iterator);
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|