Skip to content

Commit

Permalink
GPU (macOS): detect GPU driver version
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Sep 26, 2024
1 parent fc05d72 commit af63e6e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/detection/gpu/gpu_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <IOKit/graphics/IOGraphicsLib.h>

const char* ffGpuDetectMetal(FFlist* gpus);
const char* ffGpuDetectDriverVersion(FFlist* gpus);

static double detectGpuTemp(const FFstrbuf* gpuName)
{
Expand Down Expand Up @@ -185,5 +186,7 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
}

ffGpuDetectMetal(gpus);
if (instance.config.general.detectVersion)
ffGpuDetectDriverVersion(gpus);
return NULL;
}
23 changes: 23 additions & 0 deletions src/detection/gpu/gpu_apple.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gpu.h"

#import <Metal/MTLDevice.h>
#import <IOKit/kext/KextManager.h>

#ifndef MAC_OS_VERSION_13_0
#define MTLGPUFamilyMetal3 ((MTLGPUFamily) 5001)
Expand All @@ -10,6 +11,28 @@
#define MTLFeatureSet_macOS_GPUFamily2_v1 ((MTLFeatureSet) 10005)
#endif

const char* ffGpuDetectDriverVersion(FFlist* gpus)
{
if (@available(macOS 10.7, *))
{
NSMutableArray* arr = NSMutableArray.new;
FF_LIST_FOR_EACH(FFGPUResult, x, *gpus)
[arr addObject:@(x->driver.chars)];

NSDictionary* dict = CFBridgingRelease(KextManagerCopyLoadedKextInfo((__bridge CFArrayRef)arr, (__bridge CFArrayRef)@[@"CFBundleVersion"]));
FF_LIST_FOR_EACH(FFGPUResult, x, *gpus)
{
NSString* version = dict[@(x->driver.chars)][@"CFBundleVersion"];
if (version)
{
ffStrbufAppendC(&x->driver, ' ');
ffStrbufAppendS(&x->driver, version.UTF8String);
}
}
}
return "Unsupported macOS version";
}

const char* ffGpuDetectMetal(FFlist* gpus)
{
if (@available(macOS 10.13, *))
Expand Down

0 comments on commit af63e6e

Please sign in to comment.