Skip to content

Commit 408d939

Browse files
committed
GPU (Windows/WSL): adds basic GPU type detection code
1 parent 9b10617 commit 408d939

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

src/detection/gpu/gpu_windows.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,34 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
486486
if (gpu->type == FF_GPU_TYPE_UNKNOWN)
487487
{
488488
FF_DEBUG("Using fallback GPU type detection");
489-
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
489+
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
490490
{
491+
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
492+
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
493+
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla"))
494+
gpu->type = FF_GPU_TYPE_DISCRETE;
495+
}
496+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS)
497+
{
498+
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT "))
499+
gpu->type = FF_GPU_TYPE_DISCRETE;
500+
}
501+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
502+
{
503+
// 0000:00:02.0 is reserved for Intel integrated graphics
491504
gpu->type = gpu->deviceId == ffGPUPciAddr2Id(0, 0, 2, 0) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
492-
FF_DEBUG("Intel GPU type determined: %s", gpu->type == FF_GPU_TYPE_INTEGRATED ? "Integrated" : "Discrete");
493505
}
506+
507+
if (gpu->type != FF_GPU_TYPE_UNKNOWN)
508+
FF_DEBUG("Determined GPU type based on vendor (%s) and name: %u", gpu->vendor.chars, gpu->type);
494509
else if (ffIsWindows10OrGreater())
495510
{
496511
const char* ffGPUDetectTypeWithDXCore(LUID adapterLuid, FFGPUResult* gpu);
497512
FF_MAYBE_UNUSED const char* error = ffGPUDetectTypeWithDXCore(*(LUID*)&adapterLuid, gpu);
498513
FF_DEBUG("DXCore GPU type detection result: %s", error ?: "Success");
499514
}
500515
else
501-
FF_DEBUG("Unable to determine GPU type");
516+
FF_DEBUG("Unable to determine GPU type by any method for this adapter");
502517
}
503518

504519
FF_DEBUG("Completed processing GPU #%d - Vendor: %s, Name: %s, Type: %d", deviceCount, gpu->vendor.chars, gpu->name.chars, gpu->type);

src/detection/gpu/gpu_wsl.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,27 @@ const char* ffGPUDetectWsl2(const FFGPUOptions* options, FFlist* gpus)
335335
FF_DEBUG("Failed to query temperature for adapter #%u: %s", i, strerror(errno));
336336
}
337337

338+
if (gpu->type == FF_GPU_TYPE_UNKNOWN)
339+
{
340+
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA)
341+
{
342+
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
343+
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
344+
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla"))
345+
gpu->type = FF_GPU_TYPE_DISCRETE;
346+
}
347+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS)
348+
{
349+
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT "))
350+
gpu->type = FF_GPU_TYPE_DISCRETE;
351+
}
352+
else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL)
353+
{
354+
// 0000:00:02.0 is reserved for Intel integrated graphics
355+
gpu->type = gpu->deviceId == ffGPUPciAddr2Id(0, 0, 2, 0) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
356+
}
357+
}
358+
338359
FF_DEBUG("Adapter #%u summary: name='%s', vendor='%s', type=%u, deviceId=%lu",
339360
i,
340361
gpu->name.length ? gpu->name.chars : "unknown",

0 commit comments

Comments
 (0)