From 11666170b4fb63e9f2e1dcc600789fe287359cb2 Mon Sep 17 00:00:00 2001 From: Sam <16504129+sagudev@users.noreply.github.com> Date: Fri, 9 Jan 2026 21:50:49 +0100 Subject: [PATCH] expose adapter info on device (#8807) Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- CHANGELOG.md | 1 + .../standalone/custom_backend/src/custom.rs | 4 ++++ wgpu-core/src/device/global.rs | 5 ++++ wgpu/src/api/device.rs | 5 ++++ wgpu/src/backend/webgpu.rs | 24 ++++++++++++++++++- wgpu/src/backend/wgpu_core.rs | 4 ++++ wgpu/src/dispatch.rs | 1 + 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25771ea3c..23dd99986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Bottom level categories: ### New Features - 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). +- Added support for obtaining `AdapterInfo` from `Device`. By @sagudev in [#8807](https://github.com/gfx-rs/wgpu/pull/8807). ### Bug Fixes diff --git a/examples/standalone/custom_backend/src/custom.rs b/examples/standalone/custom_backend/src/custom.rs index 350e85017..676158e83 100644 --- a/examples/standalone/custom_backend/src/custom.rs +++ b/examples/standalone/custom_backend/src/custom.rs @@ -128,6 +128,10 @@ impl DeviceInterface for CustomDevice { unimplemented!() } + fn adapter_info(&self) -> wgpu::AdapterInfo { + unimplemented!() + } + fn create_shader_module( &self, desc: wgpu::ShaderModuleDescriptor<'_>, diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index fa8140c64..035d8df29 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -87,6 +87,11 @@ impl Global { device.limits.clone() } + pub fn device_adapter_info(&self, device_id: DeviceId) -> wgt::AdapterInfo { + let device = self.hub.devices.get(device_id); + device.adapter.get_info() + } + pub fn device_downlevel_properties(&self, device_id: DeviceId) -> wgt::DownlevelCapabilities { let device = self.hub.devices.get(device_id); device.downlevel.clone() diff --git a/wgpu/src/api/device.rs b/wgpu/src/api/device.rs index ee10030da..57f3f1948 100644 --- a/wgpu/src/api/device.rs +++ b/wgpu/src/api/device.rs @@ -116,6 +116,11 @@ impl Device { self.inner.limits() } + /// Get info about the adapter that this device was created from. + pub fn adapter_info(&self) -> AdapterInfo { + self.inner.adapter_info() + } + /// Creates a shader module. /// ///
diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 8b1fb2b4a..2fc6167a6 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -850,6 +850,23 @@ fn map_wgt_limits(limits: webgpu_sys::GpuSupportedLimits) -> wgt::Limits { } } +fn map_adapter_info(adapter_info: &webgpu_sys::GpuAdapterInfo) -> wgt::AdapterInfo { + // TODO(https://github.com/gfx-rs/wgpu/issues/8819): populate more fields if/when possible + wgt::AdapterInfo { + name: adapter_info.description().to_string(), + vendor: 0, + device: 0, + device_type: wgt::DeviceType::Other, + device_pci_bus_id: String::new(), + driver: String::new(), + driver_info: String::new(), + backend: wgt::Backend::BrowserWebGpu, + subgroup_min_size: wgt::MINIMUM_SUBGROUP_MIN_SIZE, + subgroup_max_size: wgt::MAXIMUM_SUBGROUP_MAX_SIZE, + transient_saves_memory: false, + } +} + fn map_js_sys_limits(limits: &wgt::Limits) -> js_sys::Object { let object = js_sys::Object::new(); @@ -1716,7 +1733,7 @@ impl dispatch::AdapterInterface for WebAdapter { } fn get_info(&self) -> crate::AdapterInfo { - // TODO: web-sys has no way of getting information on adapters + // TODO(https://github.com/gfx-rs/wgpu/issues/8818): web-sys has no way of getting information on adapters wgt::AdapterInfo { name: String::new(), vendor: 0, @@ -1762,6 +1779,10 @@ impl dispatch::DeviceInterface for WebDevice { map_wgt_limits(self.inner.limits()) } + fn adapter_info(&self) -> crate::AdapterInfo { + map_adapter_info(&self.inner.adapter_info()) + } + fn create_shader_module( &self, desc: crate::ShaderModuleDescriptor<'_>, @@ -2560,6 +2581,7 @@ impl dispatch::DeviceInterface for WebDevice { self.inner.destroy(); } } + impl Drop for WebDevice { fn drop(&mut self) { // no-op diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index a6c593d0a..ab6bb185a 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -1007,6 +1007,10 @@ impl dispatch::DeviceInterface for CoreDevice { self.context.0.device_limits(self.id) } + fn adapter_info(&self) -> crate::AdapterInfo { + self.context.0.device_adapter_info(self.id) + } + // If we have no way to create a shader module, we can't return one, and so most of the function is unreachable. #[cfg_attr( not(any( diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index 9e88b5706..21f30d010 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -131,6 +131,7 @@ pub trait AdapterInterface: CommonTraits { pub trait DeviceInterface: CommonTraits { fn features(&self) -> crate::Features; fn limits(&self) -> crate::Limits; + fn adapter_info(&self) -> crate::AdapterInfo; fn create_shader_module( &self,