From 51cc87e0db559a5889760e6bae6a3a7a5b0f8979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 9 Feb 2023 00:17:13 +0800 Subject: [PATCH] GPU (Windows): keep WMI query as a slow operation for accurate results --- src/detection/gpu/gpu_windows.cpp | 38 ++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/detection/gpu/gpu_windows.cpp b/src/detection/gpu/gpu_windows.cpp index 49d0b3e7e..4146fc53e 100644 --- a/src/detection/gpu/gpu_windows.cpp +++ b/src/detection/gpu/gpu_windows.cpp @@ -3,6 +3,7 @@ extern "C" { #include "util/windows/unicode.h" #include "util/windows/registry.h" } +#include "util/windows/wmi.hpp" #include #include @@ -111,10 +112,45 @@ static const char* detectWithDxgi(FFlist* gpus) return nullptr; } +static const char* detectWithWmi(FFlist* gpus) +{ + FFWmiQuery query(L"SELECT Name, AdapterCompatibility, DriverVersion FROM Win32_VideoController", nullptr); + if(!query) + return "Query WMI service failed"; + + while(FFWmiRecord record = query.next()) + { + FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); + + gpu->type = FF_GPU_TYPE_UNKNOWN; + + ffStrbufInit(&gpu->vendor); + record.getString(L"AdapterCompatibility", &gpu->vendor); + if(ffStrbufStartsWithS(&gpu->vendor, "Intel ")) + { + //Intel returns "Intel Corporation", not sure about AMD + ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL); + } + + ffStrbufInit(&gpu->name); + record.getString(L"Name", &gpu->name); + + ffStrbufInit(&gpu->driver); + record.getString(L"DriverVersion", &gpu->driver); + + gpu->temperature = FF_GPU_TEMP_UNSET; + gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; + } + + return nullptr; +} + extern "C" const char* ffDetectGPUImpl(FFlist* gpus, FF_MAYBE_UNUSED const FFinstance* instance) { - if (!detectWithRegistry(gpus)) + if (instance->config.allowSlowOperations) + detectWithWmi(gpus); + else if (!detectWithRegistry(gpus)) return nullptr; return detectWithDxgi(gpus); }