From 25e84decffd7ae4079aa9017fdf5b89392e7d46f Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 30 Oct 2025 11:01:06 +0800 Subject: [PATCH] GPU: unifies non-pci GPU device ID formatting across platforms --- src/detection/gpu/gpu.h | 6 ++++++ src/detection/gpu/gpu_drm.c | 2 +- src/detection/gpu/gpu_windows.c | 2 +- src/detection/gpu/gpu_wsl.cpp | 7 +++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index b8d469341..6acbd63cd 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -78,3 +78,9 @@ static inline uint64_t ffGPUPciAddr2Id(uint64_t domain, uint64_t bus, uint64_t d { return (domain << 16) | (bus << 8) | (device << 3) | function; } + +static inline uint64_t ffGPUGeneral2Id(uint64_t originalId) +{ + // Note: originalId may already have the MSB set + return (1ULL << 63) | originalId; +} diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index a1c9cd0c3..aee70ca4a 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -313,7 +313,7 @@ const char* ffDrmDetectAsahi(FFGPUResult* gpu, int fd) // They removed `unstable_uabi_version` from the struct. Hopefully they won't introduce new ABI changes. gpu->coreCount = (int32_t) (paramsGlobal.num_clusters_total * paramsGlobal.num_cores_per_cluster); gpu->frequency = paramsGlobal.max_frequency_khz / 1000; - gpu->deviceId = paramsGlobal.chip_id; + gpu->deviceId = ffGPUGeneral2Id(paramsGlobal.chip_id); if (!gpu->name.length) { diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 19c3418e4..1cde2376d 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -182,7 +182,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if (ffRegReadUint64(hDirectxKey, L"AdapterLuid", &adapterLuid, NULL)) { FF_DEBUG("Found adapter LUID: %llu", adapterLuid); - if (!gpu->deviceId) gpu->deviceId = adapterLuid; + if (!gpu->deviceId) gpu->deviceId = ffGPUGeneral2Id(adapterLuid); } uint32_t featureLevel = 0; diff --git a/src/detection/gpu/gpu_wsl.cpp b/src/detection/gpu/gpu_wsl.cpp index 1ab5bb27d..738a02546 100644 --- a/src/detection/gpu/gpu_wsl.cpp +++ b/src/detection/gpu/gpu_wsl.cpp @@ -79,6 +79,13 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF gpu->deviceId = 0; ffStrbufInitStatic(&gpu->platformApi, "DXCore"); + LUID luid; + if (SUCCEEDED(adapter->GetProperty(DXCoreAdapterProperty::InstanceLuid, sizeof(luid), &luid))) + { + static_assert(sizeof(luid) == sizeof(uint64_t), "LUID size mismatch"); + gpu->deviceId = ffGPUGeneral2Id(*(uint64_t*)&luid); + } + ffStrbufInit(&gpu->driver); uint64_t value = 0; if (SUCCEEDED(adapter->GetProperty(DXCoreAdapterProperty::DriverVersion, sizeof(value), &value)))