Skip to content

Commit

Permalink
expose driver info in AdapterInfo
Browse files Browse the repository at this point in the history
This is a native only feature and has been implemented for Vulkan so far.
  • Loading branch information
i509VCB committed Sep 20, 2022
1 parent 6f2c393 commit d4c4ab7
Show file tree
Hide file tree
Showing 8 changed files with 47 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 @@ -169,6 +169,8 @@ impl super::Adapter {
vendor: vendor_id as usize,
device: 0,
device_type: inferred_device_type,
driver: String::from("?"),
driver_info: String::from("?"),
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
33 changes: 32 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>,
}

// This is safe because the structs have `p_next: *mut c_void`, which we null out/never read.
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -733,9 +739,11 @@ 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 @@ -746,6 +754,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 @@ -871,6 +886,22 @@ impl super::Instance {
ash::vk::PhysicalDeviceType::CPU => wgt::DeviceType::Cpu,
_ => wgt::DeviceType::Other,
},
driver: unsafe {
phd_capabilities.driver
.map(|props| CStr::from_ptr(props.driver_name.as_ptr()))
.map(CStr::to_str)
.and_then(Result::ok)
.unwrap_or("?")
.to_owned()
},
driver_info: unsafe {
phd_capabilities.driver
.map(|props| CStr::from_ptr(props.driver_info.as_ptr()))
.map(CStr::to_str)
.and_then(Result::ok)
.unwrap_or("?")
.to_owned()
},
backend: wgt::Backend::Vulkan,
};

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 @@ -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,
}
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 @@ -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,
}
}
Expand Down

0 comments on commit d4c4ab7

Please sign in to comment.