GPU (macOS): fix code smell

This commit is contained in:
李通洲
2025-03-25 09:19:32 +08:00
parent 7b5dc58140
commit 0a0c1745b3
3 changed files with 14 additions and 12 deletions
+12 -11
View File
@@ -18,11 +18,12 @@ static double detectGpuTemp(const FFstrbuf* gpuName)
{
switch (strtol(gpuName->chars + strlen("Apple M"), NULL, 10))
{
case 0: error = "Invalid Apple Silicon GPU"; break;
case 1: error = ffDetectSmcTemps(FF_TEMP_GPU_M1X, &result); break;
case 2: error = ffDetectSmcTemps(FF_TEMP_GPU_M2X, &result); break;
case 3: error = ffDetectSmcTemps(FF_TEMP_GPU_M3X, &result); break;
case 4: error = ffDetectSmcTemps(FF_TEMP_GPU_M4X, &result); break;
default: error = "Unsupported Apple Silicon GPU";
default: error = "Unsupported Apple Silicon GPU"; break;
}
}
else if (ffStrbufStartsWithS(gpuName, "Intel"))
@@ -102,7 +103,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
}
FFGPUResult* gpu = ffListAdd(gpus);
gpu->index = FF_GPU_INDEX_UNSET;
ffStrbufInit(&gpu->memoryType);
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
@@ -113,7 +114,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
ffStrbufInit(&gpu->driver); // Ok for both Apple and Intel
ffCfDictGetString(properties, CFSTR("CFBundleIdentifier"), &gpu->driver);
if(ffCfDictGetInt(properties, CFSTR("gpu-core-count"), &gpu->coreCount)) // For Apple
if(ffCfDictGetInt(properties, CFSTR("gpu-core-count"), &gpu->coreCount) != NULL) // For Apple
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
@@ -132,9 +133,9 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
if (ffCfDictGetInt64(perfStatistics, CFSTR("In use system memory"), (int64_t*) &vramUsed) != NULL)
vramTotal = 0;
}
else if (ffCfDictGetInt64(perfStatistics, CFSTR("vramUsedBytes"), (int64_t*) &vramTotal) == NULL)
else if (ffCfDictGetInt64(perfStatistics, CFSTR("vramFreeBytes"), (int64_t*) &vramTotal) == NULL)
{
if (ffCfDictGetInt64(perfStatistics, CFSTR("vramFreeBytes"), (int64_t*) &vramUsed) == NULL)
if (ffCfDictGetInt64(perfStatistics, CFSTR("vramUsedBytes"), (int64_t*) &vramUsed) == NULL)
vramTotal += vramUsed;
else
vramTotal = 0;
@@ -144,15 +145,15 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
ffStrbufInit(&gpu->name);
//IOAccelerator returns model / vendor-id properties for Apple Silicon, but not for Intel Iris GPUs.
//Still needs testing for AMD's
if(ffCfDictGetString(properties, CFSTR("model"), &gpu->name))
if(ffCfDictGetString(properties, CFSTR("model"), &gpu->name) != NULL)
{
CFRelease(properties);
properties = NULL;
io_registry_entry_t parentEntry;
IORegistryEntryGetParentEntry(registryEntry, kIOServicePlane, &parentEntry);
if(IORegistryEntryCreateCFProperties(parentEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t parentEntry = 0;
if(IORegistryEntryGetParentEntry(registryEntry, kIOServicePlane, &parentEntry) != kIOReturnSuccess ||
IORegistryEntryCreateCFProperties(parentEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
{
IOObjectRelease(parentEntry);
IOObjectRelease(registryEntry);
continue;
}
@@ -180,7 +181,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
gpu->shared.total = vramTotal;
gpu->shared.used = vramUsed;
}
else
else if (gpu->type == FF_GPU_TYPE_DISCRETE)
{
gpu->dedicated.total = vramTotal;
gpu->dedicated.used = vramUsed;
+1
View File
@@ -29,6 +29,7 @@ const char* ffGpuDetectDriverVersion(FFlist* gpus)
ffStrbufAppendS(&x->driver, version.UTF8String);
}
}
return NULL;
}
return "Unsupported macOS version";
}
+1 -1
View File
@@ -28,7 +28,7 @@ static inline void cfReleaseWrapper(void* type)
#define FF_CFTYPE_AUTO_RELEASE __attribute__((__cleanup__(cfReleaseWrapper)))
static inline void wrapIoObjectRelease(io_service_t* service)
static inline void wrapIoObjectRelease(io_object_t* service)
{
assert(service);
if (*service)