diff --git a/CHANGELOG.md b/CHANGELOG.md index 880c8cf73a..7821c8349b 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 350e85017c..676158e83f 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 977f175b4e..a033c45115 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 ee10030dab..57f3f19488 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 8b1fb2b4a7..2fc6167a62 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 fc85b09c17..a5823a38f5 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -1025,6 +1025,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 4a3bd00668..044efd5afb 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -132,6 +132,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,