44
55#include <inttypes.h>
66
7+ static int isGpuNameEqual (const FFGPUResult * gpu , const FFstrbuf * name )
8+ {
9+ return ffStrbufEqual (& gpu -> name , name );
10+ }
11+
712const char * ffDetectGPUImpl (FFlist * gpus , FF_MAYBE_UNUSED const FFinstance * instance )
813{
914 DISPLAY_DEVICEW displayDevice = { .cb = sizeof (displayDevice ) };
@@ -16,7 +21,16 @@ const char* ffDetectGPUImpl(FFlist* gpus, FF_MAYBE_UNUSED const FFinstance* inst
1621 if (displayDevice .StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER ) continue ;
1722
1823 const uint32_t deviceKeyLength = (uint32_t ) wcslen (displayDevice .DeviceKey );
19- if (deviceKeyLength != 100 || wmemcmp (& displayDevice .DeviceKey [deviceKeyLength - 4 ], L"0000" , 4 ) != 0 ) continue ;
24+ if (__builtin_expect (deviceKeyLength == 100 , true))
25+ {
26+ if (wmemcmp (& displayDevice .DeviceKey [deviceKeyLength - 4 ], L"0000" , 4 ) != 0 ) continue ;
27+ }
28+ else
29+ {
30+ // DeviceKey can be empty. See #484
31+ FF_STRBUF_AUTO_DESTROY gpuName = ffStrbufCreateWS (displayDevice .DeviceString );
32+ if (ffListFirstIndexComp (gpus , & gpuName , (void * ) isGpuNameEqual ) != gpus -> length ) continue ;
33+ }
2034
2135 FFGPUResult * gpu = (FFGPUResult * )ffListAdd (gpus );
2236 ffStrbufInit (& gpu -> vendor );
@@ -27,7 +41,7 @@ const char* ffDetectGPUImpl(FFlist* gpus, FF_MAYBE_UNUSED const FFinstance* inst
2741 gpu -> type = FF_GPU_TYPE_UNKNOWN ;
2842 gpu -> dedicated .total = gpu -> dedicated .used = gpu -> shared .total = gpu -> shared .used = FF_GPU_VMEM_SIZE_UNSET ;
2943
30- if (displayDevice .DeviceKey [deviceKeyPrefixLength - 1 ] == '{' )
44+ if (deviceKeyLength == 100 && displayDevice .DeviceKey [deviceKeyPrefixLength - 1 ] == '{' )
3145 {
3246 wmemcpy (regKey + regKeyPrefixLength , displayDevice .DeviceKey + deviceKeyPrefixLength , 100 - regKeyPrefixLength + 1 );
3347 FF_HKEY_AUTO_DESTROY hKey = NULL ;
0 commit comments