From 960df10add522cba5441933ae14d9453229d51c8 Mon Sep 17 00:00:00 2001 From: i509VCB Date: Mon, 19 Sep 2022 20:42:48 -0500 Subject: [PATCH] expose driver info in AdapterInfo This is a native only feature and has been implemented for Vulkan so far. --- CHANGELOG.md | 1 + wgpu-hal/src/dx11/adapter.rs | 2 ++ wgpu-hal/src/dx12/adapter.rs | 2 ++ wgpu-hal/src/gles/adapter.rs | 2 ++ wgpu-hal/src/metal/mod.rs | 2 ++ wgpu-hal/src/vulkan/adapter.rs | 36 +++++++++++++++++++++++++++++++++- wgpu-info/src/main.rs | 2 ++ wgpu-types/src/lib.rs | 4 ++++ wgpu/src/backend/web.rs | 2 ++ 9 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd1493c315..4e8f449caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ SurfaceConfiguration { - Add `Buffer::size()` and `Buffer::usage()`; by @kpreid in [#2923](https://github.com/gfx-rs/wgpu/pull/2923) - Expose `alpha_mode` on SurfaceConfiguration, by @jinleili in [#2836](https://github.com/gfx-rs/wgpu/pull/2836) +- Introduce fields for driver name and info in `AdapterInfo`, by @i509VCB in [#3037](https://github.com/gfx-rs/wgpu/pull/3037) ### Bug Fixes diff --git a/wgpu-hal/src/dx11/adapter.rs b/wgpu-hal/src/dx11/adapter.rs index bfae7b2030..327f585a69 100644 --- a/wgpu-hal/src/dx11/adapter.rs +++ b/wgpu-hal/src/dx11/adapter.rs @@ -243,6 +243,8 @@ impl super::Adapter { 1 => wgt::DeviceType::IntegratedGpu, _ => unreachable!(), }, + driver: String::new(), + driver_info: String::new(), backend: wgt::Backend::Dx11, }; diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 55e3602c33..ddd021341e 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -122,6 +122,8 @@ impl super::Adapter { } else { wgt::DeviceType::DiscreteGpu }, + driver: String::new(), + driver_info: String::new(), }; let mut options: d3d12::D3D12_FEATURE_DATA_D3D12_OPTIONS = unsafe { mem::zeroed() }; diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 66709a424f..8ac4543493 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -169,6 +169,8 @@ impl super::Adapter { vendor: vendor_id as usize, device: 0, device_type: inferred_device_type, + driver: String::new(), + driver_info: String::new(), backend: wgt::Backend::Gl, } } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index d4ba2d14cf..82cb2a889b 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -116,6 +116,8 @@ impl crate::Instance for Instance { vendor: 0, device: 0, device_type: shared.private_caps.device_type(), + driver: String::new(), + driver_info: String::new(), backend: wgt::Backend::Metal, }, features: shared.private_caps.features(), diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 0a3afb690e..b87a5e2c81 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -511,6 +511,7 @@ pub struct PhysicalDeviceCapabilities { supported_extensions: Vec, properties: vk::PhysicalDeviceProperties, descriptor_indexing: Option, + driver: Option, } // This is safe because the structs have `p_next: *mut c_void`, which we null out/never read. @@ -558,6 +559,11 @@ impl PhysicalDeviceCapabilities { extensions.push(vk::KhrImageFormatListFn::name()); // Required for `KhrImagelessFramebufferFn` } + // This extension is core in Vulkan 1.2 + if self.supports_extension(vk::KhrDriverPropertiesFn::name()) { + extensions.push(vk::KhrDriverPropertiesFn::name()); + } + extensions.push(vk::ExtSamplerFilterMinmaxFn::name()); extensions.push(vk::KhrTimelineSemaphoreFn::name()); @@ -733,9 +739,12 @@ impl super::InstanceShared { capabilities.properties = if let Some(ref get_device_properties) = self.get_physical_device_properties { - // Get this now to avoid borrowing conflicts later + // Get these now to avoid borrowing conflicts later let supports_descriptor_indexing = capabilities.supports_extension(vk::ExtDescriptorIndexingFn::name()); + let supports_driver_properties = capabilities.properties.api_version + >= vk::API_VERSION_1_2 + || capabilities.supports_extension(vk::KhrDriverPropertiesFn::name()); let mut builder = vk::PhysicalDeviceProperties2::builder(); @@ -746,6 +755,13 @@ impl super::InstanceShared { builder = builder.push_next(next); } + if supports_driver_properties { + let next = capabilities + .driver + .insert(vk::PhysicalDeviceDriverPropertiesKHR::default()); + builder = builder.push_next(next); + } + let mut properties2 = builder.build(); unsafe { get_device_properties.get_physical_device_properties2(phd, &mut properties2); @@ -871,6 +887,24 @@ impl super::Instance { ash::vk::PhysicalDeviceType::CPU => wgt::DeviceType::Cpu, _ => wgt::DeviceType::Other, }, + driver: unsafe { + let driver_name = if let Some(driver) = phd_capabilities.driver { + CStr::from_ptr(driver.driver_name.as_ptr()).to_str().ok() + } else { + None + }; + + driver_name.unwrap_or("?").to_owned() + }, + driver_info: unsafe { + let driver_info = if let Some(driver) = phd_capabilities.driver { + CStr::from_ptr(driver.driver_info.as_ptr()).to_str().ok() + } else { + None + }; + + driver_info.unwrap_or("?").to_owned() + }, backend: wgt::Backend::Vulkan, }; diff --git a/wgpu-info/src/main.rs b/wgpu-info/src/main.rs index 34260e10c2..902dc32496 100644 --- a/wgpu-info/src/main.rs +++ b/wgpu-info/src/main.rs @@ -138,6 +138,8 @@ mod inner { println!("\t VendorID: {:?}", info.vendor); println!("\t DeviceID: {:?}", info.device); println!("\t Type: {:?}", info.device_type); + println!("\t Driver: {:?}", info.driver); + println!("\tDriverInfo: {:?}", info.driver); println!("\t Compliant: {:?}", downlevel.is_webgpu_compliant()); println!("\tFeatures:"); for i in 0..(size_of::() * 8) { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 1b698bd9d4..ae66f9c637 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1145,6 +1145,10 @@ pub struct AdapterInfo { pub device: usize, /// Type of device pub device_type: DeviceType, + /// Driver name + pub driver: String, + /// Driver info + pub driver_info: String, /// Backend used for device pub backend: Backend, } diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 3a9c58fb65..6be6747ee0 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1189,6 +1189,8 @@ impl crate::Context for Context { vendor: 0, device: 0, device_type: wgt::DeviceType::Other, + driver: String::new(), + driver_info: String::new(), backend: wgt::Backend::BrowserWebGpu, } }