Skip to content

Commit d00fca2

Browse files
committed
GPU (Windows): clean up
1 parent 23e4d1c commit d00fca2

1 file changed

Lines changed: 44 additions & 36 deletions

File tree

src/detection/gpu/gpu_windows.c

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
9494
if(ffRegReadUint(hDirectxKey, L"VendorId", &vendorId, NULL) && vendorId)
9595
ffStrbufSetStatic(&gpu->vendor, ffGPUGetVendorString(vendorId));
9696

97-
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
98-
gpu->type = gpu->deviceId == 20 ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
99-
10097
ffRegReadUint64(hDirectxKey, L"DedicatedVideoMemory", &gpu->dedicated.total, NULL);
101-
ffRegReadUint64(hDirectxKey, L"DedicatedSystemMemory", &gpu->shared.total, NULL);
98+
if (ffRegReadUint64(hDirectxKey, L"DedicatedSystemMemory", &gpu->shared.total, NULL))
99+
{
100+
uint64_t sharedSystemMemory = 0;
101+
if (ffRegReadUint64(hDirectxKey, L"SharedSystemMemory", &sharedSystemMemory, NULL))
102+
gpu->shared.total += sharedSystemMemory;
103+
}
102104

103105
if (ffRegReadUint64(hDirectxKey, L"AdapterLuid", &adapterLuid, NULL))
104106
{
@@ -125,36 +127,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
125127
}
126128
}
127129

128-
if (adapterLuid > 0)
129-
{
130-
HMODULE hgdi32 = GetModuleHandleW(L"gdi32.dll");
131-
if (hgdi32)
132-
{
133-
FF_LIBRARY_LOAD_SYMBOL_LAZY(hgdi32, D3DKMTOpenAdapterFromLuid);
134-
if (ffD3DKMTOpenAdapterFromLuid) // Windows 8 and later
135-
{
136-
D3DKMT_OPENADAPTERFROMLUID openAdapterFromLuid = { .AdapterLuid = *(LUID*)&adapterLuid };
137-
if (NT_SUCCESS(ffD3DKMTOpenAdapterFromLuid(&openAdapterFromLuid)))
138-
{
139-
D3DKMT_ADAPTERTYPE adapterType = {};
140-
D3DKMT_QUERYADAPTERINFO queryAdapterInfo = {
141-
.hAdapter = openAdapterFromLuid.hAdapter,
142-
.Type = KMTQAITYPE_ADAPTERTYPE,
143-
.pPrivateDriverData = &adapterType,
144-
.PrivateDriverDataSize = sizeof(adapterType),
145-
};
146-
if (NT_SUCCESS(D3DKMTQueryAdapterInfo(&queryAdapterInfo))) // Vista and later
147-
{
148-
if (adapterType.HybridDiscrete)
149-
gpu->type = FF_GPU_TYPE_DISCRETE;
150-
else if (adapterType.HybridIntegrated)
151-
gpu->type = FF_GPU_TYPE_INTEGRATED;
152-
}
153-
}
154-
}
155-
}
156-
}
157-
158130
if (gpu->vendor.length == 0)
159131
{
160132
bufferLen = sizeof(buffer);
@@ -243,8 +215,44 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
243215
if (CM_Get_DevNode_Registry_PropertyW(devInst, CM_DRP_DEVICEDESC, NULL, buffer, &bufferLen, 0) == CR_SUCCESS)
244216
ffStrbufSetWS(&gpu->name, buffer);
245217
}
246-
if (gpu->type == FF_GPU_TYPE_UNKNOWN && gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
247-
gpu->type = gpu->dedicated.total >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
218+
219+
if (gpu->type == FF_GPU_TYPE_UNKNOWN && adapterLuid > 0)
220+
{
221+
HMODULE hgdi32 = GetModuleHandleW(L"gdi32.dll");
222+
if (hgdi32)
223+
{
224+
FF_LIBRARY_LOAD_SYMBOL_LAZY(hgdi32, D3DKMTOpenAdapterFromLuid);
225+
if (ffD3DKMTOpenAdapterFromLuid) // Windows 8 and later
226+
{
227+
D3DKMT_OPENADAPTERFROMLUID openAdapterFromLuid = { .AdapterLuid = *(LUID*)&adapterLuid };
228+
if (NT_SUCCESS(ffD3DKMTOpenAdapterFromLuid(&openAdapterFromLuid)))
229+
{
230+
D3DKMT_ADAPTERTYPE adapterType = {};
231+
D3DKMT_QUERYADAPTERINFO queryAdapterInfo = {
232+
.hAdapter = openAdapterFromLuid.hAdapter,
233+
.Type = KMTQAITYPE_ADAPTERTYPE,
234+
.pPrivateDriverData = &adapterType,
235+
.PrivateDriverDataSize = sizeof(adapterType),
236+
};
237+
if (NT_SUCCESS(D3DKMTQueryAdapterInfo(&queryAdapterInfo))) // Vista and later
238+
{
239+
if (adapterType.HybridDiscrete)
240+
gpu->type = FF_GPU_TYPE_DISCRETE;
241+
else if (adapterType.HybridIntegrated)
242+
gpu->type = FF_GPU_TYPE_INTEGRATED;
243+
}
244+
}
245+
}
246+
}
247+
}
248+
249+
if (gpu->type == FF_GPU_TYPE_UNKNOWN)
250+
{
251+
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
252+
gpu->type = gpu->deviceId == 20 ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
253+
else if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
254+
gpu->type = gpu->dedicated.total >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
255+
}
248256
}
249257

250258
return NULL;

0 commit comments

Comments
 (0)