2023-12-20 14:45:27 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "gpu.h"
|
|
|
|
|
|
2024-11-14 10:04:57 +08:00
|
|
|
typedef enum __attribute__((__packed__)) FFGpuDriverConditionType
|
2023-12-20 14:45:27 +08:00
|
|
|
{
|
|
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID = 1 << 0,
|
|
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID = 1 << 1,
|
|
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_LUID = 1 << 2,
|
2024-11-14 10:04:57 +08:00
|
|
|
FF_GPU_DRIVER_CONDITION_TYPE_FORCE_UNSIGNED = UINT8_MAX,
|
2023-12-20 14:45:27 +08:00
|
|
|
} FFGpuDriverConditionType;
|
|
|
|
|
|
|
|
|
|
typedef struct FFGpuDriverPciBusId
|
|
|
|
|
{
|
|
|
|
|
uint32_t domain;
|
|
|
|
|
uint32_t bus;
|
|
|
|
|
uint32_t device;
|
|
|
|
|
uint32_t func;
|
|
|
|
|
} FFGpuDriverPciBusId;
|
|
|
|
|
|
|
|
|
|
typedef struct FFGpuDriverPciDeviceId
|
|
|
|
|
{
|
|
|
|
|
uint32_t deviceId;
|
|
|
|
|
uint32_t vendorId;
|
|
|
|
|
uint32_t subSystemId;
|
|
|
|
|
uint32_t revId;
|
|
|
|
|
} FFGpuDriverPciDeviceId;
|
|
|
|
|
|
|
|
|
|
// Use pciBusId if not NULL; use pciDeviceId otherwise
|
|
|
|
|
typedef struct FFGpuDriverCondition
|
|
|
|
|
{
|
|
|
|
|
FFGpuDriverConditionType type;
|
|
|
|
|
FFGpuDriverPciBusId pciBusId;
|
|
|
|
|
FFGpuDriverPciDeviceId pciDeviceId;
|
|
|
|
|
uint64_t luid;
|
|
|
|
|
} FFGpuDriverCondition;
|
|
|
|
|
|
|
|
|
|
// detect x if not NULL
|
|
|
|
|
typedef struct FFGpuDriverResult
|
|
|
|
|
{
|
2024-09-19 15:38:43 +08:00
|
|
|
uint32_t* index;
|
2023-12-20 14:45:27 +08:00
|
|
|
double* temp;
|
|
|
|
|
FFGPUMemory* memory;
|
|
|
|
|
uint32_t* coreCount;
|
2024-08-01 14:10:07 +08:00
|
|
|
double* coreUsage;
|
2023-12-20 14:45:27 +08:00
|
|
|
FFGPUType* type;
|
2024-07-17 14:52:35 +08:00
|
|
|
uint32_t* frequency;
|
2024-08-02 15:21:42 +08:00
|
|
|
FFstrbuf* name;
|
2023-12-20 14:45:27 +08:00
|
|
|
} FFGpuDriverResult;
|
|
|
|
|
|
|
|
|
|
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
|
|
|
|
const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2023-12-21 14:53:35 +08:00
|
|
|
const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2024-08-02 16:00:54 +08:00
|
|
|
const char* ffDetectMthreadsGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
|
2024-08-02 16:29:23 +08:00
|
|
|
|
|
|
|
|
FF_MAYBE_UNUSED static inline bool getDriverSpecificDetectionFn(const char* vendor, __typeof__(&ffDetectNvidiaGpuInfo)* pDetectFn, const char** pDllName)
|
|
|
|
|
{
|
|
|
|
|
if (vendor == FF_GPU_VENDOR_NAME_NVIDIA)
|
|
|
|
|
{
|
|
|
|
|
*pDetectFn = ffDetectNvidiaGpuInfo;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
*pDllName = "nvml.dll";
|
|
|
|
|
#else
|
|
|
|
|
*pDllName = "libnvidia-ml.so";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (vendor == FF_GPU_VENDOR_NAME_MTHREADS)
|
|
|
|
|
{
|
|
|
|
|
*pDetectFn = ffDetectMthreadsGpuInfo;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
*pDllName = "mtml.dll";
|
|
|
|
|
#else
|
|
|
|
|
*pDllName = "libmtml.so";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
else if (vendor == FF_GPU_VENDOR_NAME_INTEL)
|
|
|
|
|
{
|
|
|
|
|
*pDetectFn = ffDetectIntelGpuInfo;
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
|
*pDllName = "ControlLib.dll";
|
|
|
|
|
#else
|
|
|
|
|
*pDllName = "ControlLib32.dll";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (vendor == FF_GPU_VENDOR_NAME_AMD)
|
|
|
|
|
{
|
|
|
|
|
*pDetectFn = ffDetectAmdGpuInfo;
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
|
*pDllName = "amd_ags_x64.dll";
|
|
|
|
|
#else
|
|
|
|
|
*pDllName = "amd_ags_x86.dll";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*pDetectFn = NULL;
|
|
|
|
|
*pDllName = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|