Skip to content

Commit

Permalink
expose driver info in AdapterInfo (gfx-rs#3037)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
i509VCB and cwfitzgerald authored Sep 21, 2022
1 parent cdf6ee0 commit 061e04b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/dx11/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ impl super::Adapter {
1 => wgt::DeviceType::IntegratedGpu,
_ => unreachable!(),
},
driver: String::new(),
driver_info: String::new(),
backend: wgt::Backend::Dx11,
};

Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() };
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ impl crate::Instance<Api> 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(),
Expand Down
36 changes: 35 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ pub struct PhysicalDeviceCapabilities {
supported_extensions: Vec<vk::ExtensionProperties>,
properties: vk::PhysicalDeviceProperties,
descriptor_indexing: Option<vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
driver: Option<vk::PhysicalDeviceDriverPropertiesKHR>,
/// The effective driver api version supported by the physical device.
///
/// The Vulkan specification states the following in the documentation for VkPhysicalDeviceProperties:
Expand Down Expand Up @@ -572,6 +573,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());

Expand Down Expand Up @@ -747,9 +753,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();

Expand All @@ -760,6 +769,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);
Expand Down Expand Up @@ -889,6 +905,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,
};

Expand Down
2 changes: 2 additions & 0 deletions wgpu-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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::<wgpu::Features>() * 8) {
Expand Down
4 changes: 4 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,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,
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,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,
}
}
Expand Down

0 comments on commit 061e04b

Please sign in to comment.