GPU: adds unified ffGPUFillVendorByDeviceName

This commit is contained in:
Carter Li
2026-06-12 16:08:07 +08:00
committed by 李通洲
parent 01e7503263
commit fc303c58db
5 changed files with 41 additions and 57 deletions
+30
View File
@@ -206,3 +206,33 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result) {
FF_DEBUG("GPU detection failed in all enabled backends");
return "GPU detection failed";
}
bool ffGPUFillVendorByDeviceName(FFGPUResult* gpu) {
if (gpu->type == FF_GPU_TYPE_UNKNOWN) {
return true;
}
FF_DEBUG("Using fallback GPU type detection");
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT ")) { gpu->type = FF_GPU_TYPE_DISCRETE; }
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) {
// 0000:00:02.0 is reserved for Intel integrated graphics
gpu->type = gpu->deviceId == ffGPUPciAddr2Id(0, 0, 2, 0) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_VMWARE || gpu->vendor.chars == FF_GPU_VENDOR_NAME_PARALLELS) {
// Virtualized GPUs
gpu->type = FF_GPU_TYPE_INTEGRATED;
}
if (gpu->type != FF_GPU_TYPE_UNKNOWN) {
FF_DEBUG("Determined GPU type based on vendor (%s) and name: %u", gpu->vendor.chars, gpu->type);
return true;
}
return false;
}
+2
View File
@@ -87,3 +87,5 @@ static inline uint64_t ffGPUGeneral2Id(uint64_t originalId) {
// Note: originalId may already have the MSB set
return (1ULL << 63) | originalId;
}
bool ffGPUFillVendorByDeviceName(FFGPUResult* gpu);
+6 -25
View File
@@ -11,31 +11,12 @@
#include <bus/pci/pcireg.h> // DragonFly
#endif
static void fillGPUTypeGeneric(FFGPUResult* gpu) {
if (gpu->type == FF_GPU_TYPE_UNKNOWN) {
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT ")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) {
// 0000:00:02.0 is reserved for Intel integrated graphics
gpu->type = gpu->deviceId == ffGPUPciAddr2Id(0, 0, 2, 0) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
}
}
}
#if FF_HAVE_DRM
#include "common/library.h"
#include "common/strutil.h"
#include <drm.h>
// https://github.com/freebsd/drm-kmod/blob/8fea1f06b3ac3fa24217e24ba7b2133abad705a9/include/uapi/drm/drm.h#L1095
struct drm_pciinfo {
uint16_t domain;
@@ -86,14 +67,14 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus) {
// dev.drm.drm_debug_persist: 0
// dev.drm.skip_ddb: 0
// dev.drm.__drm_debug: 0
// hw.dri.timestamp_precision: 20
// hw.dri.vblank_offdelay: 5000
// hw.dri.0.modesetting: 1
// hw.dri.0.busid: pci:0000:01:00.0
// hw.dri.0.vblank:
// hw.dri.0.vblank:
// crtc ref count last enabled inmodeset
// hw.dri.0.clients:
// hw.dri.0.clients:
// a dev pid uid magic ioctls
// y drm/128 101655 0 0 0
// n drm/128 101655 0 0 0
@@ -180,7 +161,7 @@ static const char* detectByDrm(const FFGPUOptions* options, FFlist* gpus) {
}
}
fillGPUTypeGeneric(gpu);
ffGPUFillVendorByDeviceName(gpu);
}
return NULL;
@@ -252,7 +233,7 @@ static const char* detectByPci(const FFGPUOptions* options, FFlist* gpus) {
}
}
fillGPUTypeGeneric(gpu);
ffGPUFillVendorByDeviceName(gpu);
}
return NULL;
+1 -13
View File
@@ -478,19 +478,7 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf
ffGPUFillVendorAndName(subclassId, (uint16_t) vendorId, (uint16_t) deviceId, gpu);
}
if (gpu->type == FF_GPU_TYPE_UNKNOWN) {
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT ")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
}
}
ffGPUFillVendorByDeviceName(gpu);
return NULL;
}
+2 -19
View File
@@ -553,25 +553,8 @@ ffGPUDetectWsl2
}
if (gpu->type == FF_GPU_TYPE_UNKNOWN) {
FF_DEBUG("Using fallback GPU type detection");
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "GeForce") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Quadro") ||
ffStrbufStartsWithIgnCaseS(&gpu->name, "Tesla")) {
gpu->type = FF_GPU_TYPE_DISCRETE;
}
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_MTHREADS) {
if (ffStrbufStartsWithIgnCaseS(&gpu->name, "MTT ")) { gpu->type = FF_GPU_TYPE_DISCRETE; }
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) {
// 0000:00:02.0 is reserved for Intel integrated graphics
gpu->type = gpu->deviceId == ffGPUPciAddr2Id(0, 0, 2, 0) ? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
} else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_VMWARE || gpu->vendor.chars == FF_GPU_VENDOR_NAME_PARALLELS) {
// Virtualized GPUs
gpu->type = FF_GPU_TYPE_INTEGRATED;
}
if (gpu->type != FF_GPU_TYPE_UNKNOWN) {
FF_DEBUG("Determined GPU type based on vendor (%s) and name: %u", gpu->vendor.chars, gpu->type);
if (ffGPUFillVendorByDeviceName(gpu)) {
// OK
}
#if _WIN32
else if (ffIsWindows10OrGreater()) {