From 981ae6bdd143aae22fa41c73fd18a64923ef8c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 6 Jan 2026 20:21:03 +0800 Subject: [PATCH] GPU: improves error handling and add case-insensitive PCI ID parsing --- src/detection/gpu/gpu_windows.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index abaf843c7..c114a16ce 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -47,14 +47,12 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* DEVINST devInst = 0; + if (CM_Locate_DevNodeW(&devInst, devId, CM_LOCATE_DEVNODE_NORMAL) != CR_SUCCESS) { - if (CM_Locate_DevNodeW(&devInst, devId, CM_LOCATE_DEVNODE_NORMAL) != CR_SUCCESS) - { - FF_DEBUG("Failed to get device instance ID or locate device node"); - continue; - } - FF_DEBUG("Device instance ID: %lu", devInst); + FF_DEBUG("Failed to get device instance ID or locate device node"); + continue; } + FF_DEBUG("Device instance ID: %lu", devInst); FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus); deviceCount++; @@ -75,7 +73,10 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->frequency = FF_GPU_FREQUENCY_UNSET; unsigned vendorId = 0, deviceId = 0, subSystemId = 0, revId = 0; - if (swscanf(devId, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x", &vendorId, &deviceId, &subSystemId, &revId) == 4) + if ( + (*devId == 'P' && swscanf(devId, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x", &vendorId, &deviceId, &subSystemId, &revId) == 4) || + (*devId == 'p' && swscanf(devId, L"pci\\ven_%x&dev_%x&subsys_%x&rev_%x", &vendorId, &deviceId, &subSystemId, &revId) == 4) // Windows 7 + ) { FF_DEBUG("Parsed PCI IDs - Vendor: 0x%x, Device: 0x%x, SubSystem: 0x%x, Rev: 0x%x", vendorId, deviceId, subSystemId, revId); ffStrbufSetStatic(&gpu->vendor, ffGPUGetVendorString(vendorId)); @@ -224,9 +225,9 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* FF_DEBUG("Failed to open device node registry key"); } - if (gpu->vendor.length == 0 || gpu->name.length == 0) + if (gpu->vendor.length == 0 || gpu->name.length == 0 || gpu->driver.length == 0 || gpu->dedicated.total == FF_GPU_VMEM_SIZE_UNSET) { - FF_DEBUG("Trying fallback registry method for vendor/name"); + FF_DEBUG("Trying fallback registry method for vendor/name etc."); bufferLen = sizeof(buffer); if (CM_Get_DevNode_Registry_PropertyW(devInst, CM_DRP_DRIVER, NULL, buffer, &bufferLen, 0) == CR_SUCCESS && bufferLen == (FF_GUID_STRLEN + strlen("\\0000") + 1) * 2)