@@ -15,7 +15,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev)
1515}
1616
1717#define FF_EMPTY_GUID_STR L"{00000000-0000-0000-0000-000000000000}"
18- #define FF_GUID_STRLEN ( sizeof(FF_EMPTY_GUID_STR) / sizeof(wchar_t) - 1)
18+ enum { FF_GUID_STRLEN = sizeof (FF_EMPTY_GUID_STR ) / sizeof (wchar_t ) - 1 };
1919
2020const char * ffDetectGPUImpl (FF_MAYBE_UNUSED const FFGPUOptions * options , FFlist * gpus )
2121{
@@ -37,7 +37,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
3737 ffStrbufInit (& gpu -> vendor );
3838 ffStrbufInit (& gpu -> name );
3939 ffStrbufInit (& gpu -> driver );
40- ffStrbufInitStatic (& gpu -> platformApi , "Direct3D " );
40+ ffStrbufInitStatic (& gpu -> platformApi , "SetupAPI " );
4141 gpu -> temperature = FF_GPU_TEMP_UNSET ;
4242 gpu -> coreCount = FF_GPU_CORE_COUNT_UNSET ;
4343 gpu -> coreUsage = FF_GPU_CORE_USAGE_UNSET ;
@@ -46,34 +46,31 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
4646 gpu -> deviceId = 0 ;
4747 gpu -> frequency = FF_GPU_FREQUENCY_UNSET ;
4848
49- wchar_t name [256 ];
50- if (SetupDiGetDeviceRegistryPropertyW (hdev , & did , SPDRP_DEVICEDESC , NULL , (PBYTE ) name , sizeof (name ), NULL ))
51- ffStrbufSetWS (& gpu -> name , name );
49+ wchar_t buffer [256 ];
50+ if (SetupDiGetDeviceRegistryPropertyW (hdev , & did , SPDRP_DEVICEDESC , NULL , (PBYTE ) buffer , sizeof (buffer ), NULL ))
51+ ffStrbufSetWS (& gpu -> name , buffer );
5252
53- wchar_t hardwareId [256 ];
54- if (!SetupDiGetDeviceRegistryPropertyW (hdev , & did , SPDRP_HARDWAREID , NULL , (PBYTE ) hardwareId , sizeof (hardwareId ), NULL ))
53+ if (!SetupDiGetDeviceRegistryPropertyW (hdev , & did , SPDRP_HARDWAREID , NULL , (PBYTE ) buffer , sizeof (buffer ), NULL ))
5554 continue ;
5655
5756 unsigned vendorId = 0 , deviceId = 0 , subSystemId = 0 , revId = 0 ;
58- swscanf (hardwareId , L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x" , & vendorId , & deviceId , & subSystemId , & revId );
57+ swscanf (buffer , L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x" , & vendorId , & deviceId , & subSystemId , & revId );
5958 ffStrbufSetStatic (& gpu -> vendor , ffGetGPUVendorString (vendorId ));
6059
61- wchar_t videoId [39 ];
62- {
63- FF_HKEY_AUTO_DESTROY hKey = SetupDiOpenDevRegKey (hdev , & did , DICS_FLAG_GLOBAL , 0 , DIREG_DEV , KEY_QUERY_VALUE );
64- if (!hKey ) continue ;
65- DWORD videoIdLength = sizeof (videoId );
66- if (RegGetValueW (hKey , NULL , L"VideoID" , RRF_RT_REG_SZ , NULL , videoId , & videoIdLength ) != ERROR_SUCCESS || videoIdLength != (FF_GUID_STRLEN + 1 ) * sizeof (wchar_t ))
67- continue ;
68- }
60+ FF_HKEY_AUTO_DESTROY hVideoIdKey = SetupDiOpenDevRegKey (hdev , & did , DICS_FLAG_GLOBAL , 0 , DIREG_DEV , KEY_QUERY_VALUE );
61+ if (!hVideoIdKey ) continue ;
62+ DWORD videoIdLength = sizeof (buffer );
63+ if (RegGetValueW (hVideoIdKey , NULL , L"VideoID" , RRF_RT_REG_SZ , NULL , buffer , & videoIdLength ) != ERROR_SUCCESS )
64+ continue ;
6965
70- wmemcpy (regControlVideoKey + regControlVideoKeyPrefixLength , videoId , FF_GUID_STRLEN );
71- FF_HKEY_AUTO_DESTROY hKey = NULL ;
72- if (!ffRegOpenKeyForRead (HKEY_LOCAL_MACHINE , regControlVideoKey , & hKey , NULL )) continue ;
66+ if (videoIdLength != (FF_GUID_STRLEN + 1 ) * sizeof (wchar_t ))
67+ continue ; // Should not happen
7368
74- ffRegReadStrbuf (hKey , L"DriverVersion" , & gpu -> driver , NULL );
69+ wmemcpy (regControlVideoKey + regControlVideoKeyPrefixLength , buffer , FF_GUID_STRLEN );
70+ FF_HKEY_AUTO_DESTROY hRegControlVideoKey = NULL ;
71+ if (!ffRegOpenKeyForRead (HKEY_LOCAL_MACHINE , regControlVideoKey , & hRegControlVideoKey , NULL )) continue ;
7572
76- wmemcpy (regDirectxKey + regDirectxKeyPrefixLength , videoId , FF_GUID_STRLEN );
73+ wmemcpy (regDirectxKey + regDirectxKeyPrefixLength , buffer , FF_GUID_STRLEN );
7774 FF_HKEY_AUTO_DESTROY hDirectxKey = NULL ;
7875 if (ffRegOpenKeyForRead (HKEY_LOCAL_MACHINE , regDirectxKey , & hDirectxKey , NULL ))
7976 {
@@ -97,17 +94,17 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
9794 else if (ffRegReadUint (hDirectxKey , L"MaxD3D11FeatureLevel" , & featureLevel , NULL ) && featureLevel )
9895 ffStrbufSetF (& gpu -> platformApi , "Direct3D 11.%u" , (featureLevel & 0x0F00 ) >> 8 );
9996 }
100- else if (!ffRegReadUint64 (hKey , L"HardwareInformation.qwMemorySize" , & gpu -> dedicated .total , NULL ))
97+ else if (!ffRegReadUint64 (hRegControlVideoKey , L"HardwareInformation.qwMemorySize" , & gpu -> dedicated .total , NULL ))
10198 {
10299 uint32_t vmem = 0 ;
103- if (ffRegReadUint (hKey , L"HardwareInformation.MemorySize" , & vmem , NULL ))
100+ if (ffRegReadUint (hRegControlVideoKey , L"HardwareInformation.MemorySize" , & vmem , NULL ))
104101 gpu -> dedicated .total = vmem ;
105102 gpu -> type = gpu -> dedicated .total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED ;
106103 }
107104
108105 if (gpu -> vendor .length == 0 )
109106 {
110- ffRegReadStrbuf (hKey , L"ProviderName" , & gpu -> vendor , NULL );
107+ ffRegReadStrbuf (hRegControlVideoKey , L"ProviderName" , & gpu -> vendor , NULL );
111108 if (ffStrbufContainS (& gpu -> vendor , "Intel" ))
112109 ffStrbufSetStatic (& gpu -> vendor , FF_GPU_VENDOR_NAME_INTEL );
113110 else if (ffStrbufContainS (& gpu -> vendor , "NVIDIA" ))
0 commit comments