fix(host): dedupe repeated Vulkan GPUs by DeviceUUID and integrated PCI ID (#177)

This commit is contained in:
千川白浪 authored and GitHub committed 2026-12-04 23:25:36 +08:00
1 parent fc3f35f6af
commit b3b66c9306
4 files changed
+106 -26

No files matched your search

+2 -2
View File
@@ -2,6 +2,6 @@
"group": "fixes",
"order": 0,
"authors": ["Nwflower"],
"zh": "修复宿主机存在多份 Vulkan ICD 驱动清单时,内核页重复显示同一块显卡且缺失驱动版本号的问题。",
"en": "Deduplicate repeated Vulkan physical device entries on the Runtime page when multiple ICD manifests are registered for the same GPU."
"zh": "修复宿主机存在多份 Vulkan ICD 驱动清单或重复枚举同一张显卡时,内核页与虚拟机设置页重复显示同一块显卡且缺失驱动版本号的问题。",
"en": "Deduplicate repeated Vulkan physical device entries on the Runtime and VM settings pages when the same GPU is enumerated multiple times."
}
+44 -18
View File
@@ -24,6 +24,7 @@ type VulkanDeviceProbe struct {
DeviceType uint32 // VkPhysicalDeviceType: 1=integrated, 2=discrete, 3=virtual, 4=cpu
APIVersion uint32
Extensions map[string]bool
DeviceUUID string // optional physical device UUID from VkPhysicalDeviceIDProperties
DeviceLUID string // optional adapter LUID:nodeMask from VkPhysicalDeviceIDProperties
}
@@ -223,11 +224,26 @@ func betterVulkanProbe(a, b VulkanDeviceProbe) bool {
return ae > be
}
func sameVulkanDuplicate(a, b VulkanDeviceProbe) bool {
if a.DeviceLUID != "" && b.DeviceLUID != "" {
return a.DeviceLUID == b.DeviceLUID
func sameStrongVulkanIdentity(a, b VulkanDeviceProbe) bool {
if a.DeviceUUID != "" && b.DeviceUUID != "" && a.DeviceUUID == b.DeviceUUID {
return true
}
if a.DeviceLUID != "" || b.DeviceLUID != "" {
if a.DeviceLUID != "" && b.DeviceLUID != "" && a.DeviceLUID == b.DeviceLUID {
return true
}
return a.DeviceType == 1 && b.DeviceType == 1 &&
a.VendorID != 0 && a.DeviceID != 0 &&
a.VendorID == b.VendorID && a.DeviceID == b.DeviceID
}
func sameVulkanDuplicate(a, b VulkanDeviceProbe) bool {
if sameStrongVulkanIdentity(a, b) {
return true
}
if a.DeviceUUID != "" && b.DeviceUUID != "" && a.DeviceUUID != b.DeviceUUID {
return false
}
if a.DeviceLUID != "" && b.DeviceLUID != "" && a.DeviceLUID != b.DeviceLUID {
return false
}
return a.VendorID != 0 && a.DeviceID != 0 &&
@@ -235,7 +251,7 @@ func sameVulkanDuplicate(a, b VulkanDeviceProbe) bool {
strings.EqualFold(strings.TrimSpace(a.Name), strings.TrimSpace(b.Name))
}
func probeMatchesExistingGPU(p VulkanDeviceProbe, out []GPUInfo, outLUIDs []string) bool {
func probeMatchesExistingGPU(p VulkanDeviceProbe, out []GPUInfo, outUUIDs, outLUIDs []string) bool {
pVen, pDev := "", ""
if p.VendorID != 0 {
pVen = fmt.Sprintf("%04x", p.VendorID)
@@ -245,16 +261,24 @@ func probeMatchesExistingGPU(p VulkanDeviceProbe, out []GPUInfo, outLUIDs []stri
}
pName := strings.ToLower(strings.TrimSpace(p.Name))
for i, existing := range out {
if p.DeviceLUID != "" && outLUIDs[i] != "" {
if p.DeviceLUID == outLUIDs[i] {
return true
}
continue
if p.DeviceUUID != "" && outUUIDs[i] != "" && p.DeviceUUID == outUUIDs[i] {
return true
}
if p.DeviceLUID != "" && outLUIDs[i] != "" && p.DeviceLUID == outLUIDs[i] {
return true
}
eVen := strings.ToLower(strings.TrimSpace(existing.VendorID))
eDev := strings.ToLower(strings.TrimSpace(existing.DeviceID))
samePCI := pVen != "" && pDev != "" && eVen != "" && eDev != "" && pVen == eVen && pDev == eDev
if samePCI && (p.DeviceType == 1 || existing.Kind == GPUIntegrated) {
return true
}
if (p.DeviceUUID != "" && outUUIDs[i] != "" && p.DeviceUUID != outUUIDs[i]) ||
(p.DeviceLUID != "" && outLUIDs[i] != "" && p.DeviceLUID != outLUIDs[i]) {
continue
}
if pVen != "" && pDev != "" && eVen != "" && eDev != "" {
if pVen == eVen && pDev == eDev {
if samePCI {
return true
}
continue
@@ -274,11 +298,9 @@ func MergeRegistryAndVulkanGPUs(regGPUs []GPUInfo, vkProbes []VulkanDeviceProbe)
used := make([]bool, len(vkProbes))
markUsed := func(idx int) {
used[idx] = true
if luid := vkProbes[idx].DeviceLUID; luid != "" {
for j := range vkProbes {
if vkProbes[j].DeviceLUID == luid {
used[j] = true
}
for j := range vkProbes {
if !used[j] && sameStrongVulkanIdentity(vkProbes[idx], vkProbes[j]) {
used[j] = true
}
}
}
@@ -330,13 +352,16 @@ func MergeRegistryAndVulkanGPUs(regGPUs []GPUInfo, vkProbes []VulkanDeviceProbe)
}
out := make([]GPUInfo, 0, len(regGPUs)+len(vkProbes))
outUUIDs := make([]string, 0, len(regGPUs)+len(vkProbes))
outLUIDs := make([]string, 0, len(regGPUs)+len(vkProbes))
for _, g := range regGPUs {
p := matchProbe(g)
out = append(out, EvaluateGPUCompat(g, p))
if p != nil {
outUUIDs = append(outUUIDs, p.DeviceUUID)
outLUIDs = append(outLUIDs, p.DeviceLUID)
} else {
outUUIDs = append(outUUIDs, "")
outLUIDs = append(outLUIDs, "")
}
}
@@ -344,13 +369,13 @@ func MergeRegistryAndVulkanGPUs(regGPUs []GPUInfo, vkProbes []VulkanDeviceProbe)
// Include any non-CPU Vulkan GPU enumerated by vulkan-1.dll that wasn't
// listed under the display-class registry, skipping duplicate ICD entries
// for a physical device already present in out while keeping distinct
// identical-model GPUs (different DeviceLUIDs) separate.
// identical-model discrete GPUs (different DeviceUUID/DeviceLUID) separate.
for i := range vkProbes {
if used[i] || vkProbes[i].DeviceType == 4 {
continue
}
p := vkProbes[i]
if probeMatchesExistingGPU(p, out, outLUIDs) {
if probeMatchesExistingGPU(p, out, outUUIDs, outLUIDs) {
continue
}
for j := i + 1; j < len(vkProbes); j++ {
@@ -369,6 +394,7 @@ func MergeRegistryAndVulkanGPUs(regGPUs []GPUInfo, vkProbes []VulkanDeviceProbe)
Kind: ClassifyGPU(p.Name),
}
out = append(out, EvaluateGPUCompat(base, &p))
outUUIDs = append(outUUIDs, p.DeviceUUID)
outLUIDs = append(outLUIDs, p.DeviceLUID)
}
return out
+48
View File
@@ -231,6 +231,54 @@ func TestGPUCompatibilityGradingAndRecommendation(t *testing.T) {
if dualLUID[0].VulkanVersion != "1.4.303" || dualLUID[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected both LUID-distinct GPUs to pick best Vulkan version, got %+v", dualLUID)
}
// Repeated integrated GPU probes (e.g. Intel Arc 140T enumerated 5x with identical
// DeviceUUID or distinct adapter LUIDs) must collapse to one entry whether or not
// the iGPU was also present in the display-class registry.
const intelUUID = "8680517d030000000002000000000000"
intelDupes := []VulkanDeviceProbe{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VendorID: 0x10de, DeviceID: 0x2d18, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceUUID: "e666906384a109aef5e564050a6038c8", DeviceLUID: "0000000000000010:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v13, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000021:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000022:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000023:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000024:1"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VendorID: 0x8086, DeviceID: 0x7d51, DeviceType: 1, APIVersion: v14, Extensions: allReqExts, DeviceUUID: intelUUID, DeviceLUID: "0000000000000025:1"},
}
withReg := MergeRegistryAndVulkanGPUs(
[]GPUInfo{
{Name: "NVIDIA GeForce RTX 5070 Laptop GPU", VulkanICD: `C:\nv-vk64.json`, VendorID: "10de", DeviceID: "2d18", DriverVersion: "32.0.15.9174"},
{Name: "Intel(R) Arc(TM) 140T GPU (16GB)", VulkanICD: `C:\igvk64.json`, VendorID: "8086", DeviceID: "7d51", DriverVersion: "32.0.101.6554"},
},
intelDupes,
)
if len(withReg) != 2 {
t.Fatalf("expected 2 GPUs when iGPU has identical DeviceUUID / distinct LUIDs (with registry), got %d: %+v", len(withReg), withReg)
}
if withReg[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected Intel iGPU to pick best Vulkan version, got %+v", withReg[1])
}
vkOnly := MergeRegistryAndVulkanGPUs(nil, intelDupes)
if len(vkOnly) != 2 {
t.Fatalf("expected 2 GPUs when iGPU has identical DeviceUUID / distinct LUIDs (Vulkan-only), got %d: %+v", len(vkOnly), vkOnly)
}
// Mixed LUID (one probe reports LUID, duplicate omits it) and discrete GPU sharing
// DeviceUUID across distinct LUIDs must both collapse to one entry.
mixedDupes := MergeRegistryAndVulkanGPUs(
nil,
[]VulkanDeviceProbe{
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceLUID: "0000000000000031:1"},
{Name: "AMD Radeon RX 7900 XTX", VendorID: 0x1002, DeviceID: 0x744c, DeviceType: 2, APIVersion: v14, Extensions: allReqExts},
{Name: "NVIDIA GeForce RTX 5080", VendorID: 0x10de, DeviceID: 0x2c02, DeviceType: 2, APIVersion: v13, Extensions: allReqExts, DeviceUUID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeviceLUID: "0000000000000041:1"},
{Name: "NVIDIA GeForce RTX 5080", VendorID: 0x10de, DeviceID: 0x2c02, DeviceType: 2, APIVersion: v14, Extensions: allReqExts, DeviceUUID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", DeviceLUID: "0000000000000042:1"},
},
)
if len(mixedDupes) != 2 {
t.Fatalf("expected 2 deduplicated discrete GPUs, got %d: %+v", len(mixedDupes), mixedDupes)
}
if mixedDupes[0].VulkanVersion != "1.4.303" || mixedDupes[1].VulkanVersion != "1.4.303" {
t.Fatalf("expected deduplicated discrete GPUs to pick best Vulkan version, got %+v", mixedDupes)
}
}
func TestAffinityMaskHelpers(t *testing.T) {
+12 -6
View File
@@ -160,8 +160,8 @@ func probeVulkanDevices() ([]VulkanDeviceProbe, error) {
DeviceType: binary.LittleEndian.Uint32(propsBuf[16:20]),
Name: cstrFromBytes(propsBuf[20:276]),
Extensions: probeVulkanDeviceExtensions(pEnumExts, pd),
DeviceLUID: probeVulkanDeviceLUID(pGetProps2, pd, appInfo.apiVersion, apiVersion),
}
probe.DeviceUUID, probe.DeviceLUID = probeVulkanDeviceIDs(pGetProps2, pd, appInfo.apiVersion, apiVersion)
out = append(out, probe)
}
return out, nil
@@ -174,9 +174,9 @@ func vulkanResultError(call string, result int32) error {
return fmt.Errorf("%s: VkResult %d", call, result)
}
func probeVulkanDeviceLUID(pGetProps2 *syscall.LazyProc, pd uintptr, instanceAPIVersion, deviceAPIVersion uint32) string {
func probeVulkanDeviceIDs(pGetProps2 *syscall.LazyProc, pd uintptr, instanceAPIVersion, deviceAPIVersion uint32) (uuid, luid string) {
if pGetProps2 == nil || instanceAPIVersion < vkAPIVersion11 || deviceAPIVersion < vkAPIVersion11 {
return ""
return "", ""
}
idProps := vkPhysicalDeviceIDProperties{
sType: vkStructureTypePhysicalDeviceIDProps,
@@ -185,10 +185,16 @@ func probeVulkanDeviceLUID(pGetProps2 *syscall.LazyProc, pd uintptr, instanceAPI
binary.LittleEndian.PutUint32(props2Buf[0:4], vkStructureTypePhysicalDeviceProps2)
binary.LittleEndian.PutUint64(props2Buf[8:16], uint64(uintptr(unsafe.Pointer(&idProps))))
pGetProps2.Call(pd, uintptr(unsafe.Pointer(&props2Buf[0])))
if idProps.deviceLUIDValid == 0 {
return ""
for _, b := range idProps.deviceUUID {
if b != 0 {
uuid = fmt.Sprintf("%x", idProps.deviceUUID)
break
}
}
return fmt.Sprintf("%x:%x", idProps.deviceLUID, idProps.deviceNodeMask)
if idProps.deviceLUIDValid != 0 {
luid = fmt.Sprintf("%x:%x", idProps.deviceLUID, idProps.deviceNodeMask)
}
return uuid, luid
}
func probeVulkanDeviceExtensions(pEnumExts *syscall.LazyProc, pd uintptr) map[string]bool {