Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose driver info in AdapterInfo #3037

Merged
merged 2 commits into from Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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
Expand Up @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/metal/mod.rs
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
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,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 @@ -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);
Expand Down Expand Up @@ -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,
};

Expand Down
2 changes: 2 additions & 0 deletions wgpu-info/src/main.rs
Expand Up @@ -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::<wgpu::Features>() * 8) {
Expand Down
4 changes: 4 additions & 0 deletions wgpu-types/src/lib.rs
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
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