From 5d63362163de329d32862b90b8ea958ed55b346c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Wed, 1 Oct 2025 19:05:54 -0700 Subject: [PATCH 1/5] Add support for device uuid and pci bus id to AdapterInfo. --- wgpu-core/src/pipeline_cache.rs | 2 ++ wgpu-hal/src/metal/mod.rs | 2 ++ wgpu-hal/src/noop/mod.rs | 2 ++ wgpu-hal/src/vulkan/adapter.rs | 53 +++++++++++++++++++++++++++++++++ wgpu-types/src/lib.rs | 13 ++++++++ 5 files changed, 72 insertions(+) diff --git a/wgpu-core/src/pipeline_cache.rs b/wgpu-core/src/pipeline_cache.rs index 8f4e65cfed1..fddde4dcd76 100644 --- a/wgpu-core/src/pipeline_cache.rs +++ b/wgpu-core/src/pipeline_cache.rs @@ -319,6 +319,8 @@ mod tests { vendor: 0x0002_FEED, device: 0xFEFE_FEFE, device_type: wgt::DeviceType::Other, + device_pci_bus_id: None, + device_uuid: None, driver: String::new(), driver_info: String::new(), backend: wgt::Backend::Vulkan, diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index 00223b2f778..fdfbe48a00d 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -156,6 +156,8 @@ impl crate::Instance for Instance { vendor: 0, device: 0, device_type: shared.private_caps.device_type(), + device_pci_bus_id: None, + device_uuid: None, driver: String::new(), driver_info: String::new(), backend: wgt::Backend::Metal, diff --git a/wgpu-hal/src/noop/mod.rs b/wgpu-hal/src/noop/mod.rs index abd7c628a98..e5f6ef5ccb8 100644 --- a/wgpu-hal/src/noop/mod.rs +++ b/wgpu-hal/src/noop/mod.rs @@ -137,6 +137,8 @@ pub fn adapter_info() -> wgt::AdapterInfo { vendor: 0, device: 0, device_type: wgt::DeviceType::Cpu, + device_pci_bus_id: None, + device_uuid: None, driver: String::from("wgpu"), driver_info: String::new(), backend: wgt::Backend::Noop, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 0ebf1fec9a4..6693ca93de6 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -958,6 +958,14 @@ pub struct PhysicalDeviceProperties { /// `VK_EXT_mesh_shader` extension. mesh_shader: Option>, + /// Additional `vk::PhysicalDevice` properties from the + /// `VK_EXT_pci_bus_info` extension. + pci_bus_info: Option>, + + /// Additional `vk::PhysicalDevice` properties from the + /// `VK_EXT_physical_device_id` extension. + device_id: Option>, + /// The device API version. /// /// Which is the version of Vulkan supported for device-level functionality. @@ -1388,6 +1396,9 @@ impl super::InstanceShared { >= vk::API_VERSION_1_3 || capabilities.supports_extension(ext::subgroup_size_control::NAME); let supports_robustness2 = capabilities.supports_extension(ext::robustness2::NAME); + let supports_pci_bus_info = + capabilities.supports_extension(ext::pci_bus_info::NAME); + let supports_device_id = capabilities.device_api_version >= vk::API_VERSION_1_1; let supports_acceleration_structure = capabilities.supports_extension(khr::acceleration_structure::NAME); @@ -1444,6 +1455,20 @@ impl super::InstanceShared { properties2 = properties2.push_next(next); } + if supports_pci_bus_info { + let next = capabilities + .pci_bus_info + .insert(vk::PhysicalDevicePCIBusInfoPropertiesEXT::default()); + properties2 = properties2.push_next(next); + } + + if supports_device_id { + let next = capabilities + .device_id + .insert(vk::PhysicalDeviceIDProperties::default()); + properties2 = properties2.push_next(next); + } + if supports_mesh_shader { let next = capabilities .mesh_shader @@ -1658,6 +1683,34 @@ impl super::Instance { vk::PhysicalDeviceType::CPU => wgt::DeviceType::Cpu, _ => wgt::DeviceType::Other, }, + device_pci_bus_id: phd_capabilities.pci_bus_info.and_then(|info| { + if info.pci_bus != 0 || info.pci_device != 0 { + Some(format!( + "{:04x}:{:02x}:{:02x}.{}", + info.pci_domain, + info.pci_bus, + info.pci_device, + info.pci_function + )) + } else { + None + } + }), + device_uuid: phd_capabilities.device_id.and_then(|id| { + if id.device_uuid != [0u8; 16] { + let uuid = id.device_uuid; + Some(format!( + "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + )) + } else { + None + } + }), driver: { phd_capabilities .driver diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 7674c0a95d8..a007d427f70 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1408,6 +1408,19 @@ pub struct AdapterInfo { pub device: u32, /// Type of device pub device_type: DeviceType, + /// [`Backend`]-specific PCI bus ID of the adapter. + /// + /// * For [`Backend::Vulkan`], [`VkPhysicalDevicePCIBusInfoPropertiesEXT`] is used, + /// if available, in the form `bus:device.function`, e.g. `0000:01:00.0`. + /// + /// [`VkPhysicalDevicePCIBusInfoPropertiesEXT`]: https://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDevicePCIBusInfoPropertiesEXT.html + pub device_pci_bus_id: Option, + /// [`Backend`]-specific unique device identifier of the adapter. + /// + /// * For [`Backend::Vulkan`], [`VkPhysicalDeviceIDProperties`] is used, if available. + /// + /// [`VkPhysicalDeviceIDProperties`]: hhttps://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDeviceIDProperties.html + pub device_uuid: Option, /// Driver name pub driver: String, /// Driver info From ec98dbca467c23f02c24e3337ff1cb371652d995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Wed, 1 Oct 2025 20:28:28 -0700 Subject: [PATCH 2/5] Gles. --- wgpu-hal/src/gles/adapter.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 806f5567ba2..b2f2cbe3e84 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -187,6 +187,8 @@ impl super::Adapter { device: 0, device_type: inferred_device_type, driver: "".to_owned(), + device_pci_bus_id: None, + device_uuid: None, driver_info: version, backend: wgt::Backend::Gl, } From 1f042e9eb6e355d17492353a24952bf1c23f130c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Wed, 1 Oct 2025 20:50:47 -0700 Subject: [PATCH 3/5] Option -> String. --- wgpu-core/src/pipeline_cache.rs | 4 ++-- wgpu-hal/src/gles/adapter.rs | 4 ++-- wgpu-hal/src/metal/mod.rs | 4 ++-- wgpu-hal/src/noop/mod.rs | 4 ++-- wgpu-info/src/human.rs | 3 +++ wgpu-types/src/lib.rs | 4 ++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/wgpu-core/src/pipeline_cache.rs b/wgpu-core/src/pipeline_cache.rs index fddde4dcd76..ae495c9e0c7 100644 --- a/wgpu-core/src/pipeline_cache.rs +++ b/wgpu-core/src/pipeline_cache.rs @@ -319,8 +319,8 @@ mod tests { vendor: 0x0002_FEED, device: 0xFEFE_FEFE, device_type: wgt::DeviceType::Other, - device_pci_bus_id: None, - device_uuid: None, + device_pci_bus_id: String::new(), + device_uuid: String::new(), driver: String::new(), driver_info: String::new(), backend: wgt::Backend::Vulkan, diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index b2f2cbe3e84..066bc124f9d 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -187,8 +187,8 @@ impl super::Adapter { device: 0, device_type: inferred_device_type, driver: "".to_owned(), - device_pci_bus_id: None, - device_uuid: None, + device_pci_bus_id: String::new(), + device_uuid: String::new(), driver_info: version, backend: wgt::Backend::Gl, } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index fdfbe48a00d..fe9f39c4218 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -156,8 +156,8 @@ impl crate::Instance for Instance { vendor: 0, device: 0, device_type: shared.private_caps.device_type(), - device_pci_bus_id: None, - device_uuid: None, + device_pci_bus_id: String::new(), + device_uuid: String::new(), driver: String::new(), driver_info: String::new(), backend: wgt::Backend::Metal, diff --git a/wgpu-hal/src/noop/mod.rs b/wgpu-hal/src/noop/mod.rs index e5f6ef5ccb8..201633059be 100644 --- a/wgpu-hal/src/noop/mod.rs +++ b/wgpu-hal/src/noop/mod.rs @@ -137,8 +137,8 @@ pub fn adapter_info() -> wgt::AdapterInfo { vendor: 0, device: 0, device_type: wgt::DeviceType::Cpu, - device_pci_bus_id: None, - device_uuid: None, + device_pci_bus_id: String::new(), + device_uuid: String::new(), driver: String::from("wgpu"), driver_info: String::new(), backend: wgt::Backend::Noop, diff --git a/wgpu-info/src/human.rs b/wgpu-info/src/human.rs index f0930bd0212..f9ec1859228 100644 --- a/wgpu-info/src/human.rs +++ b/wgpu-info/src/human.rs @@ -99,6 +99,9 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize writeln!(output, "\t Name: {}", info.name)?; writeln!(output, "\t VendorID: {:#X?}", info.vendor)?; writeln!(output, "\t DeviceID: {:#X?}", info.device)?; + writeln!(output, "\t DeviceUUID: {}", print_empty_string(&info.device_uuid))?; + writeln!(output, "\t DevicePCIBusId: {}", print_empty_string(&info.device_pci_bus_id))?; + writeln!(output, "\t DriverUUID: {}", print_empty_string(&info.driver))?; writeln!(output, "\t Type: {:?}", info.device_type)?; writeln!(output, "\t Driver: {}", print_empty_string(&info.driver))?; writeln!(output, "\t DriverInfo: {}", print_empty_string(&info.driver_info))?; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a007d427f70..eded8ba62b5 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1414,13 +1414,13 @@ pub struct AdapterInfo { /// if available, in the form `bus:device.function`, e.g. `0000:01:00.0`. /// /// [`VkPhysicalDevicePCIBusInfoPropertiesEXT`]: https://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDevicePCIBusInfoPropertiesEXT.html - pub device_pci_bus_id: Option, + pub device_pci_bus_id: String, /// [`Backend`]-specific unique device identifier of the adapter. /// /// * For [`Backend::Vulkan`], [`VkPhysicalDeviceIDProperties`] is used, if available. /// /// [`VkPhysicalDeviceIDProperties`]: hhttps://registry.khronos.org/vulkan/specs/latest/man/html/VkPhysicalDeviceIDProperties.html - pub device_uuid: Option, + pub device_uuid: String, /// Driver name pub driver: String, /// Driver info From 3d6087cbd8e1cc115748d328de2bc994e4814597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Wed, 1 Oct 2025 20:53:51 -0700 Subject: [PATCH 4/5] Fix vulkan. --- wgpu-hal/src/vulkan/adapter.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 6693ca93de6..a957e281574 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1695,7 +1695,8 @@ impl super::Instance { } else { None } - }), + }) + .unwrap_or("".to_owned()), device_uuid: phd_capabilities.device_id.and_then(|id| { if id.device_uuid != [0u8; 16] { let uuid = id.device_uuid; @@ -1710,7 +1711,9 @@ impl super::Instance { } else { None } - }), + }) + .unwrap_or("".to_owned()) + , driver: { phd_capabilities .driver From 9f1caeaaae89112ed9cd8aeaf9e191dd51c17fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?charlotte=20=F0=9F=8C=B8?= Date: Wed, 1 Oct 2025 20:56:33 -0700 Subject: [PATCH 5/5] User iter methods. --- wgpu-hal/src/vulkan/adapter.rs | 50 ++++++++++++++-------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index a957e281574..31394e9ef93 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1683,37 +1683,27 @@ impl super::Instance { vk::PhysicalDeviceType::CPU => wgt::DeviceType::Cpu, _ => wgt::DeviceType::Other, }, - device_pci_bus_id: phd_capabilities.pci_bus_info.and_then(|info| { - if info.pci_bus != 0 || info.pci_device != 0 { - Some(format!( - "{:04x}:{:02x}:{:02x}.{}", - info.pci_domain, - info.pci_bus, - info.pci_device, - info.pci_function - )) - } else { - None - } - }) - .unwrap_or("".to_owned()), - device_uuid: phd_capabilities.device_id.and_then(|id| { - if id.device_uuid != [0u8; 16] { - let uuid = id.device_uuid; - Some(format!( + device_pci_bus_id: phd_capabilities.pci_bus_info + .filter(|info| info.pci_bus != 0 || info.pci_device != 0) + .map(|info| format!( + "{:04x}:{:02x}:{:02x}.{}", + info.pci_domain, + info.pci_bus, + info.pci_device, + info.pci_function + )) + .unwrap_or_default(), + device_uuid: phd_capabilities.device_id + .filter(|id| id.device_uuid != [0u8; 16]) + .map(|id| { + let u = id.device_uuid; + format!( "{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] - )) - } else { - None - } - }) - .unwrap_or("".to_owned()) - , + u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], + u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15] + ) + }) + .unwrap_or_default(), driver: { phd_capabilities .driver