Skip to content

Commit 1166617

Browse files
authored
expose adapter info on device (#8807)
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent 0a007b3 commit 1166617

7 files changed

Lines changed: 43 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Bottom level categories:
4444
### New Features
4545

4646
- Added support for cooperative load/store operations in shaders. Currently only WGSL on the input and SPIR-V, METAL, and WGSL on the output are supported. By @kvark in [#8251](https://github.com/gfx-rs/wgpu/issues/8251).
47+
- Added support for obtaining `AdapterInfo` from `Device`. By @sagudev in [#8807](https://github.com/gfx-rs/wgpu/pull/8807).
4748

4849
### Bug Fixes
4950

examples/standalone/custom_backend/src/custom.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ impl DeviceInterface for CustomDevice {
128128
unimplemented!()
129129
}
130130

131+
fn adapter_info(&self) -> wgpu::AdapterInfo {
132+
unimplemented!()
133+
}
134+
131135
fn create_shader_module(
132136
&self,
133137
desc: wgpu::ShaderModuleDescriptor<'_>,

wgpu-core/src/device/global.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ impl Global {
8787
device.limits.clone()
8888
}
8989

90+
pub fn device_adapter_info(&self, device_id: DeviceId) -> wgt::AdapterInfo {
91+
let device = self.hub.devices.get(device_id);
92+
device.adapter.get_info()
93+
}
94+
9095
pub fn device_downlevel_properties(&self, device_id: DeviceId) -> wgt::DownlevelCapabilities {
9196
let device = self.hub.devices.get(device_id);
9297
device.downlevel.clone()

wgpu/src/api/device.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ impl Device {
116116
self.inner.limits()
117117
}
118118

119+
/// Get info about the adapter that this device was created from.
120+
pub fn adapter_info(&self) -> AdapterInfo {
121+
self.inner.adapter_info()
122+
}
123+
119124
/// Creates a shader module.
120125
///
121126
/// <div class="warning">

wgpu/src/backend/webgpu.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,23 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits {
850850
}
851851
}
852852

853+
fn map_adapter_info(adapter_info: &webgpu_sys::GpuAdapterInfo) -> wgt::AdapterInfo {
854+
// TODO(https://github.com/gfx-rs/wgpu/issues/8819): populate more fields if/when possible
855+
wgt::AdapterInfo {
856+
name: adapter_info.description().to_string(),
857+
vendor: 0,
858+
device: 0,
859+
device_type: wgt::DeviceType::Other,
860+
device_pci_bus_id: String::new(),
861+
driver: String::new(),
862+
driver_info: String::new(),
863+
backend: wgt::Backend::BrowserWebGpu,
864+
subgroup_min_size: wgt::MINIMUM_SUBGROUP_MIN_SIZE,
865+
subgroup_max_size: wgt::MAXIMUM_SUBGROUP_MAX_SIZE,
866+
transient_saves_memory: false,
867+
}
868+
}
869+
853870
fn map_js_sys_limits(limits: &wgt::Limits) -> js_sys::Object {
854871
let object = js_sys::Object::new();
855872

@@ -1716,7 +1733,7 @@ impl dispatch::AdapterInterface for WebAdapter {
17161733
}
17171734

17181735
fn get_info(&self) -> crate::AdapterInfo {
1719-
// TODO: web-sys has no way of getting information on adapters
1736+
// TODO(https://github.com/gfx-rs/wgpu/issues/8818): web-sys has no way of getting information on adapters
17201737
wgt::AdapterInfo {
17211738
name: String::new(),
17221739
vendor: 0,
@@ -1762,6 +1779,10 @@ impl dispatch::DeviceInterface for WebDevice {
17621779
map_wgt_limits(self.inner.limits())
17631780
}
17641781

1782+
fn adapter_info(&self) -> crate::AdapterInfo {
1783+
map_adapter_info(&self.inner.adapter_info())
1784+
}
1785+
17651786
fn create_shader_module(
17661787
&self,
17671788
desc: crate::ShaderModuleDescriptor<'_>,
@@ -2560,6 +2581,7 @@ impl dispatch::DeviceInterface for WebDevice {
25602581
self.inner.destroy();
25612582
}
25622583
}
2584+
25632585
impl Drop for WebDevice {
25642586
fn drop(&mut self) {
25652587
// no-op

wgpu/src/backend/wgpu_core.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,10 @@ impl dispatch::DeviceInterface for CoreDevice {
10071007
self.context.0.device_limits(self.id)
10081008
}
10091009

1010+
fn adapter_info(&self) -> crate::AdapterInfo {
1011+
self.context.0.device_adapter_info(self.id)
1012+
}
1013+
10101014
// If we have no way to create a shader module, we can't return one, and so most of the function is unreachable.
10111015
#[cfg_attr(
10121016
not(any(

wgpu/src/dispatch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ pub trait AdapterInterface: CommonTraits {
131131
pub trait DeviceInterface: CommonTraits {
132132
fn features(&self) -> crate::Features;
133133
fn limits(&self) -> crate::Limits;
134+
fn adapter_info(&self) -> crate::AdapterInfo;
134135

135136
fn create_shader_module(
136137
&self,

0 commit comments

Comments
 (0)