2022-09-05 17:42:42 +02:00
|
|
|
#include "gpu.h"
|
2023-02-14 17:50:53 +08:00
|
|
|
#include "detection/vulkan/vulkan.h"
|
2024-06-20 14:05:38 +08:00
|
|
|
#include "detection/opencl/opencl.h"
|
2023-12-26 10:53:43 +08:00
|
|
|
#include "detection/opengl/opengl.h"
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2023-02-06 11:07:49 +08:00
|
|
|
const char* FF_GPU_VENDOR_NAME_APPLE = "Apple";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_AMD = "AMD";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_INTEL = "Intel";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_NVIDIA = "NVIDIA";
|
2024-08-02 16:00:54 +08:00
|
|
|
const char* FF_GPU_VENDOR_NAME_MTHREADS = "Moore Threads";
|
2024-01-29 21:48:33 +08:00
|
|
|
const char* FF_GPU_VENDOR_NAME_QUALCOMM = "Qualcomm";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_MTK = "MTK";
|
2023-10-21 17:36:13 +08:00
|
|
|
const char* FF_GPU_VENDOR_NAME_VMWARE = "VMware";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_PARALLEL = "Parallel";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_MICROSOFT = "Microsoft";
|
2023-10-31 15:11:22 +08:00
|
|
|
const char* FF_GPU_VENDOR_NAME_REDHAT = "RedHat";
|
|
|
|
|
const char* FF_GPU_VENDOR_NAME_ORACLE = "Oracle";
|
2023-02-06 11:07:49 +08:00
|
|
|
|
2024-12-28 15:26:17 +08:00
|
|
|
const char* ffGPUGetVendorString(unsigned vendorId)
|
2023-02-06 11:07:49 +08:00
|
|
|
{
|
2023-10-31 15:11:22 +08:00
|
|
|
// https://devicehunt.com/all-pci-vendors
|
2024-05-13 19:33:31 +08:00
|
|
|
switch (vendorId)
|
|
|
|
|
{
|
|
|
|
|
case 0x106b: return FF_GPU_VENDOR_NAME_APPLE;
|
|
|
|
|
case 0x1002: case 0x1022: return FF_GPU_VENDOR_NAME_AMD;
|
|
|
|
|
case 0x8086: case 0x8087: case 0x03e7: return FF_GPU_VENDOR_NAME_INTEL;
|
|
|
|
|
case 0x0955: case 0x10de: case 0x12d2: return FF_GPU_VENDOR_NAME_NVIDIA;
|
2024-08-02 16:00:54 +08:00
|
|
|
case 0x1ed5: return FF_GPU_VENDOR_NAME_MTHREADS;
|
2024-05-13 19:33:31 +08:00
|
|
|
case 0x5143: return FF_GPU_VENDOR_NAME_QUALCOMM;
|
|
|
|
|
case 0x14c3: return FF_GPU_VENDOR_NAME_MTK;
|
|
|
|
|
case 0x15ad: return FF_GPU_VENDOR_NAME_VMWARE;
|
|
|
|
|
case 0x1af4: return FF_GPU_VENDOR_NAME_REDHAT;
|
|
|
|
|
case 0x1ab8: return FF_GPU_VENDOR_NAME_PARALLEL;
|
|
|
|
|
case 0x1414: return FF_GPU_VENDOR_NAME_MICROSOFT;
|
|
|
|
|
case 0x108e: return FF_GPU_VENDOR_NAME_ORACLE;
|
|
|
|
|
default: return NULL;
|
|
|
|
|
}
|
2023-02-06 11:07:49 +08:00
|
|
|
}
|
2022-09-05 17:42:42 +02:00
|
|
|
|
2023-12-26 10:53:43 +08:00
|
|
|
const char* detectByOpenGL(FFlist* gpus)
|
|
|
|
|
{
|
|
|
|
|
FFOpenGLResult result;
|
|
|
|
|
ffStrbufInit(&result.version);
|
|
|
|
|
ffStrbufInit(&result.renderer);
|
|
|
|
|
ffStrbufInit(&result.vendor);
|
|
|
|
|
ffStrbufInit(&result.slv);
|
2024-07-09 20:39:15 +08:00
|
|
|
ffStrbufInit(&result.library);
|
|
|
|
|
|
2023-12-26 10:53:43 +08:00
|
|
|
const char* error = ffDetectOpenGL(&instance.config.modules.openGL, &result);
|
|
|
|
|
if (!error)
|
|
|
|
|
{
|
|
|
|
|
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
|
|
|
|
|
gpu->type = FF_GPU_TYPE_UNKNOWN;
|
2025-01-10 08:48:29 +08:00
|
|
|
ffStrbufInitMove(&gpu->vendor, &result.vendor);
|
2023-12-26 10:53:43 +08:00
|
|
|
ffStrbufInitMove(&gpu->name, &result.renderer);
|
2025-01-10 08:48:29 +08:00
|
|
|
ffStrbufInit(&gpu->driver);
|
2023-12-29 15:12:41 +08:00
|
|
|
ffStrbufInitF(&gpu->platformApi, "OpenGL %s", result.version.chars);
|
2024-09-19 15:22:09 +08:00
|
|
|
gpu->index = FF_GPU_INDEX_UNSET;
|
2023-12-26 10:53:43 +08:00
|
|
|
gpu->temperature = FF_GPU_TEMP_UNSET;
|
|
|
|
|
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
|
|
|
|
|
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
|
2024-08-01 13:54:03 +08:00
|
|
|
gpu->coreUsage = FF_GPU_CORE_USAGE_UNSET;
|
2023-12-26 10:53:43 +08:00
|
|
|
gpu->dedicated = gpu->shared = (FFGPUMemory){0, 0};
|
|
|
|
|
gpu->deviceId = 0;
|
|
|
|
|
|
2024-05-20 16:45:23 +08:00
|
|
|
if (ffStrbufContainS(&gpu->name, "Apple"))
|
2023-12-26 10:53:43 +08:00
|
|
|
{
|
2024-05-20 16:45:23 +08:00
|
|
|
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
|
2024-01-04 10:29:02 +08:00
|
|
|
gpu->type = FF_GPU_TYPE_INTEGRATED;
|
2024-05-20 16:45:23 +08:00
|
|
|
}
|
|
|
|
|
else if (ffStrbufContainS(&gpu->name, "Intel"))
|
|
|
|
|
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
|
|
|
|
|
else if (ffStrbufContainS(&gpu->name, "AMD") || ffStrbufContainS(&gpu->name, "ATI"))
|
|
|
|
|
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
|
|
|
|
|
else if (ffStrbufContainS(&gpu->name, "NVIDIA"))
|
|
|
|
|
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
|
2024-08-02 16:00:54 +08:00
|
|
|
else if (ffStrbufContainS(&gpu->name, "MTT"))
|
|
|
|
|
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_MTHREADS);
|
2024-05-20 16:45:23 +08:00
|
|
|
|
2023-12-26 10:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&result.version);
|
|
|
|
|
ffStrbufDestroy(&result.renderer);
|
|
|
|
|
ffStrbufDestroy(&result.vendor);
|
|
|
|
|
ffStrbufDestroy(&result.slv);
|
2024-07-09 20:39:15 +08:00
|
|
|
ffStrbufDestroy(&result.library);
|
2023-12-26 10:53:43 +08:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
|
2022-09-05 17:42:42 +02:00
|
|
|
{
|
2024-05-20 16:45:23 +08:00
|
|
|
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_PCI)
|
2023-06-12 11:30:18 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* error = ffDetectGPUImpl(options, result);
|
2023-12-26 10:53:43 +08:00
|
|
|
if (!error && result->length > 0) return NULL;
|
2023-06-12 11:30:18 +08:00
|
|
|
}
|
2024-05-20 16:45:23 +08:00
|
|
|
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_VULKAN)
|
|
|
|
|
{
|
|
|
|
|
FFVulkanResult* vulkan = ffDetectVulkan();
|
|
|
|
|
if (!vulkan->error && vulkan->gpus.length > 0)
|
|
|
|
|
{
|
|
|
|
|
ffListDestroy(result);
|
|
|
|
|
ffListInitMove(result, &vulkan->gpus);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-20 14:05:38 +08:00
|
|
|
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_OPENCL)
|
|
|
|
|
{
|
|
|
|
|
FFOpenCLResult* opencl = ffDetectOpenCL();
|
|
|
|
|
if (!opencl->error && opencl->gpus.length > 0)
|
|
|
|
|
{
|
|
|
|
|
ffListDestroy(result);
|
|
|
|
|
ffListInitMove(result, &opencl->gpus);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-20 16:45:23 +08:00
|
|
|
if (options->detectionMethod <= FF_GPU_DETECTION_METHOD_OPENGL)
|
2023-12-26 10:53:43 +08:00
|
|
|
{
|
2024-05-20 16:45:23 +08:00
|
|
|
if (detectByOpenGL(result) == NULL)
|
|
|
|
|
return NULL;
|
2023-12-26 10:53:43 +08:00
|
|
|
}
|
2023-06-12 11:30:18 +08:00
|
|
|
|
2023-12-26 10:53:43 +08:00
|
|
|
return "GPU detection failed";
|
2022-09-05 17:42:42 +02:00
|
|
|
}
|