Skip to content

Commit 061e04b

Browse files
expose driver info in AdapterInfo (#3037)
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
1 parent cdf6ee0 commit 061e04b

File tree

9 files changed

+52
-1
lines changed

9 files changed

+52
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ SurfaceConfiguration {
7373

7474
- Add `Buffer::size()` and `Buffer::usage()`; by @kpreid in [#2923](https://github.com/gfx-rs/wgpu/pull/2923)
7575
- Expose `alpha_mode` on SurfaceConfiguration, by @jinleili in [#2836](https://github.com/gfx-rs/wgpu/pull/2836)
76+
- Introduce fields for driver name and info in `AdapterInfo`, by @i509VCB in [#3037](https://github.com/gfx-rs/wgpu/pull/3037)
7677

7778
### Bug Fixes
7879

wgpu-hal/src/dx11/adapter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ impl super::Adapter {
243243
1 => wgt::DeviceType::IntegratedGpu,
244244
_ => unreachable!(),
245245
},
246+
driver: String::new(),
247+
driver_info: String::new(),
246248
backend: wgt::Backend::Dx11,
247249
};
248250

wgpu-hal/src/dx12/adapter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ impl super::Adapter {
122122
} else {
123123
wgt::DeviceType::DiscreteGpu
124124
},
125+
driver: String::new(),
126+
driver_info: String::new(),
125127
};
126128

127129
let mut options: d3d12::D3D12_FEATURE_DATA_D3D12_OPTIONS = unsafe { mem::zeroed() };

wgpu-hal/src/gles/adapter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ impl super::Adapter {
173173
vendor: vendor_id as usize,
174174
device: 0,
175175
device_type: inferred_device_type,
176+
driver: String::new(),
177+
driver_info: String::new(),
176178
backend: wgt::Backend::Gl,
177179
}
178180
}

wgpu-hal/src/metal/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ impl crate::Instance<Api> for Instance {
116116
vendor: 0,
117117
device: 0,
118118
device_type: shared.private_caps.device_type(),
119+
driver: String::new(),
120+
driver_info: String::new(),
119121
backend: wgt::Backend::Metal,
120122
},
121123
features: shared.private_caps.features(),

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ pub struct PhysicalDeviceCapabilities {
511511
supported_extensions: Vec<vk::ExtensionProperties>,
512512
properties: vk::PhysicalDeviceProperties,
513513
descriptor_indexing: Option<vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
514+
driver: Option<vk::PhysicalDeviceDriverPropertiesKHR>,
514515
/// The effective driver api version supported by the physical device.
515516
///
516517
/// The Vulkan specification states the following in the documentation for VkPhysicalDeviceProperties:
@@ -572,6 +573,11 @@ impl PhysicalDeviceCapabilities {
572573
extensions.push(vk::KhrImageFormatListFn::name()); // Required for `KhrImagelessFramebufferFn`
573574
}
574575

576+
// This extension is core in Vulkan 1.2
577+
if self.supports_extension(vk::KhrDriverPropertiesFn::name()) {
578+
extensions.push(vk::KhrDriverPropertiesFn::name());
579+
}
580+
575581
extensions.push(vk::ExtSamplerFilterMinmaxFn::name());
576582
extensions.push(vk::KhrTimelineSemaphoreFn::name());
577583

@@ -747,9 +753,12 @@ impl super::InstanceShared {
747753
capabilities.properties = if let Some(ref get_device_properties) =
748754
self.get_physical_device_properties
749755
{
750-
// Get this now to avoid borrowing conflicts later
756+
// Get these now to avoid borrowing conflicts later
751757
let supports_descriptor_indexing =
752758
capabilities.supports_extension(vk::ExtDescriptorIndexingFn::name());
759+
let supports_driver_properties = capabilities.properties.api_version
760+
>= vk::API_VERSION_1_2
761+
|| capabilities.supports_extension(vk::KhrDriverPropertiesFn::name());
753762

754763
let mut builder = vk::PhysicalDeviceProperties2::builder();
755764

@@ -760,6 +769,13 @@ impl super::InstanceShared {
760769
builder = builder.push_next(next);
761770
}
762771

772+
if supports_driver_properties {
773+
let next = capabilities
774+
.driver
775+
.insert(vk::PhysicalDeviceDriverPropertiesKHR::default());
776+
builder = builder.push_next(next);
777+
}
778+
763779
let mut properties2 = builder.build();
764780
unsafe {
765781
get_device_properties.get_physical_device_properties2(phd, &mut properties2);
@@ -889,6 +905,24 @@ impl super::Instance {
889905
ash::vk::PhysicalDeviceType::CPU => wgt::DeviceType::Cpu,
890906
_ => wgt::DeviceType::Other,
891907
},
908+
driver: unsafe {
909+
let driver_name = if let Some(driver) = phd_capabilities.driver {
910+
CStr::from_ptr(driver.driver_name.as_ptr()).to_str().ok()
911+
} else {
912+
None
913+
};
914+
915+
driver_name.unwrap_or("?").to_owned()
916+
},
917+
driver_info: unsafe {
918+
let driver_info = if let Some(driver) = phd_capabilities.driver {
919+
CStr::from_ptr(driver.driver_info.as_ptr()).to_str().ok()
920+
} else {
921+
None
922+
};
923+
924+
driver_info.unwrap_or("?").to_owned()
925+
},
892926
backend: wgt::Backend::Vulkan,
893927
};
894928

wgpu-info/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ mod inner {
139139
println!("\t VendorID: {:?}", info.vendor);
140140
println!("\t DeviceID: {:?}", info.device);
141141
println!("\t Type: {:?}", info.device_type);
142+
println!("\t Driver: {:?}", info.driver);
143+
println!("\tDriverInfo: {:?}", info.driver);
142144
println!("\t Compliant: {:?}", downlevel.is_webgpu_compliant());
143145
println!("\tFeatures:");
144146
for i in 0..(size_of::<wgpu::Features>() * 8) {

wgpu-types/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,10 @@ pub struct AdapterInfo {
11481148
pub device: usize,
11491149
/// Type of device
11501150
pub device_type: DeviceType,
1151+
/// Driver name
1152+
pub driver: String,
1153+
/// Driver info
1154+
pub driver_info: String,
11511155
/// Backend used for device
11521156
pub backend: Backend,
11531157
}

wgpu/src/backend/web.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,8 @@ impl crate::Context for Context {
11991199
vendor: 0,
12001200
device: 0,
12011201
device_type: wgt::DeviceType::Other,
1202+
driver: String::new(),
1203+
driver_info: String::new(),
12021204
backend: wgt::Backend::BrowserWebGpu,
12031205
}
12041206
}

0 commit comments

Comments
 (0)