From d00fca26c59c89fe9883560e96797b147b1307bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 8 Jul 2025 01:06:14 +0800 Subject: [PATCH] GPU (Windows): clean up --- src/detection/gpu/gpu_windows.c | 80 ++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 34be31958..457fd6488 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -94,11 +94,13 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if(ffRegReadUint(hDirectxKey, L"VendorId", &vendorId, NULL) && vendorId) ffStrbufSetStatic(&gpu->vendor, ffGPUGetVendorString(vendorId)); - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) - gpu->type = gpu->deviceId == 20 ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; - ffRegReadUint64(hDirectxKey, L"DedicatedVideoMemory", &gpu->dedicated.total, NULL); - ffRegReadUint64(hDirectxKey, L"DedicatedSystemMemory", &gpu->shared.total, NULL); + if (ffRegReadUint64(hDirectxKey, L"DedicatedSystemMemory", &gpu->shared.total, NULL)) + { + uint64_t sharedSystemMemory = 0; + if (ffRegReadUint64(hDirectxKey, L"SharedSystemMemory", &sharedSystemMemory, NULL)) + gpu->shared.total += sharedSystemMemory; + } if (ffRegReadUint64(hDirectxKey, L"AdapterLuid", &adapterLuid, NULL)) { @@ -125,36 +127,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* } } - if (adapterLuid > 0) - { - HMODULE hgdi32 = GetModuleHandleW(L"gdi32.dll"); - if (hgdi32) - { - FF_LIBRARY_LOAD_SYMBOL_LAZY(hgdi32, D3DKMTOpenAdapterFromLuid); - if (ffD3DKMTOpenAdapterFromLuid) // Windows 8 and later - { - D3DKMT_OPENADAPTERFROMLUID openAdapterFromLuid = { .AdapterLuid = *(LUID*)&adapterLuid }; - if (NT_SUCCESS(ffD3DKMTOpenAdapterFromLuid(&openAdapterFromLuid))) - { - D3DKMT_ADAPTERTYPE adapterType = {}; - D3DKMT_QUERYADAPTERINFO queryAdapterInfo = { - .hAdapter = openAdapterFromLuid.hAdapter, - .Type = KMTQAITYPE_ADAPTERTYPE, - .pPrivateDriverData = &adapterType, - .PrivateDriverDataSize = sizeof(adapterType), - }; - if (NT_SUCCESS(D3DKMTQueryAdapterInfo(&queryAdapterInfo))) // Vista and later - { - if (adapterType.HybridDiscrete) - gpu->type = FF_GPU_TYPE_DISCRETE; - else if (adapterType.HybridIntegrated) - gpu->type = FF_GPU_TYPE_INTEGRATED; - } - } - } - } - } - if (gpu->vendor.length == 0) { bufferLen = sizeof(buffer); @@ -243,8 +215,44 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if (CM_Get_DevNode_Registry_PropertyW(devInst, CM_DRP_DEVICEDESC, NULL, buffer, &bufferLen, 0) == CR_SUCCESS) ffStrbufSetWS(&gpu->name, buffer); } - if (gpu->type == FF_GPU_TYPE_UNKNOWN && gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) - gpu->type = gpu->dedicated.total >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + + if (gpu->type == FF_GPU_TYPE_UNKNOWN && adapterLuid > 0) + { + HMODULE hgdi32 = GetModuleHandleW(L"gdi32.dll"); + if (hgdi32) + { + FF_LIBRARY_LOAD_SYMBOL_LAZY(hgdi32, D3DKMTOpenAdapterFromLuid); + if (ffD3DKMTOpenAdapterFromLuid) // Windows 8 and later + { + D3DKMT_OPENADAPTERFROMLUID openAdapterFromLuid = { .AdapterLuid = *(LUID*)&adapterLuid }; + if (NT_SUCCESS(ffD3DKMTOpenAdapterFromLuid(&openAdapterFromLuid))) + { + D3DKMT_ADAPTERTYPE adapterType = {}; + D3DKMT_QUERYADAPTERINFO queryAdapterInfo = { + .hAdapter = openAdapterFromLuid.hAdapter, + .Type = KMTQAITYPE_ADAPTERTYPE, + .pPrivateDriverData = &adapterType, + .PrivateDriverDataSize = sizeof(adapterType), + }; + if (NT_SUCCESS(D3DKMTQueryAdapterInfo(&queryAdapterInfo))) // Vista and later + { + if (adapterType.HybridDiscrete) + gpu->type = FF_GPU_TYPE_DISCRETE; + else if (adapterType.HybridIntegrated) + gpu->type = FF_GPU_TYPE_INTEGRATED; + } + } + } + } + } + + if (gpu->type == FF_GPU_TYPE_UNKNOWN) + { + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) + gpu->type = gpu->deviceId == 20 ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE; + else if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) + gpu->type = gpu->dedicated.total >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + } } return NULL;