ohmu
·
2026-10-15
1#pragma once
2
3#include "gpu.h"
4
5typedef enum FFGpuDriverConditionType: uint8_t {
6 FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID = 1 << 0,
7 FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID = 1 << 1,
8 FF_GPU_DRIVER_CONDITION_TYPE_LUID = 1 << 2,
9} FFGpuDriverConditionType;
10
11typedef struct FFGpuDriverPciDeviceId {
12 uint32_t deviceId;
13 uint32_t vendorId;
14 uint32_t subSystemId;
15 uint32_t revId;
16} FFGpuDriverPciDeviceId;
17
18// Use pciBusId if not nullptr; use pciDeviceId otherwise
19typedef struct FFGpuDriverCondition {
20 FFGpuDriverConditionType type;
21 FFGpuDriverPciBusId pciBusId;
22 FFGpuDriverPciDeviceId pciDeviceId;
23 uint64_t luid;
24} FFGpuDriverCondition;
25
26// detect x if not nullptr
27typedef struct FFGpuDriverResult {
28 uint32_t* index;
29 double* temp;
30 FFGPUMemory* memory;
31 FFstrbuf* memoryType;
32 FFGPUMemory* sharedMemory;
33 uint32_t* coreCount;
34 double* coreUsage;
35 FFGPUType* type;
36 uint32_t* frequency;
37 FFstrbuf* name;
38 FFGPUPcieSpeed* psMax;
39 FFGPUPcieSpeed* psCurr;
40} FFGpuDriverResult;
41
42const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
43const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
44const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
45const char* ffDetectMthreadsGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
46
47#ifndef FF_GPU_DRIVER_DLLNAME_PATH_PREFIX
48 #define FF_GPU_DRIVER_DLLNAME_PATH_PREFIX
49#endif
50
51[[maybe_unused]] static inline bool getDriverSpecificDetectionFn(const char* vendor, typeof(&ffDetectNvidiaGpuInfo)* pDetectFn, const char** pDllName) {
52 if (vendor == FF_GPU_VENDOR_NAME_NVIDIA) {
53 *pDetectFn = ffDetectNvidiaGpuInfo;
54#ifdef _WIN32
55 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "nvml.dll";
56#else
57 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "libnvidia-ml.so";
58#endif
59 } else if (vendor == FF_GPU_VENDOR_NAME_MTHREADS) {
60 *pDetectFn = ffDetectMthreadsGpuInfo;
61#ifdef _WIN32
62 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "mtml.dll";
63#else
64 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "libmtml.so";
65#endif
66 }
67#ifdef _WIN32
68 else if (vendor == FF_GPU_VENDOR_NAME_INTEL) {
69 *pDetectFn = ffDetectIntelGpuInfo;
70 #ifdef _WIN64
71 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "ControlLib.dll";
72 #else
73 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "ControlLib32.dll";
74 #endif
75 } else if (vendor == FF_GPU_VENDOR_NAME_AMD) {
76 *pDetectFn = ffDetectAmdGpuInfo;
77 #ifdef _WIN64
78 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "atiadlxx.dll";
79 #else
80 *pDllName = FF_GPU_DRIVER_DLLNAME_PATH_PREFIX "atiadlxy.dll";
81 #endif
82 }
83#endif
84 else {
85 *pDetectFn = nullptr;
86 *pDllName = nullptr;
87 return false;
88 }
89
90 return true;
91}