From 1974b2a344e3472ba5e96561877216926ffa9e13 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Wed, 13 Jan 2021 00:01:25 +0100 Subject: [PATCH] [rs] Exposed get_texture_format_features on adapter --- wgpu/src/backend/direct.rs | 13 +++++++++++++ wgpu/src/backend/web.rs | 8 ++++++++ wgpu/src/lib.rs | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 6387b84c23..e8cad6b193 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -710,6 +710,19 @@ impl crate::Context for Context { } } + fn adapter_get_texture_format_features( + &self, + adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + let global = &self.0; + match wgc::gfx_select!(*adapter => global.adapter_get_texture_format_features(*adapter, format)) + { + Ok(info) => info, + Err(err) => self.handle_error_fatal(err, "Adapter::get_texture_format_features"), + } + } + fn device_features(&self, device: &Self::DeviceId) -> Features { let global = &self.0; match wgc::gfx_select!(device.id => global.device_features(device.id)) { diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 753d7555b2..8d056413bb 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -984,6 +984,14 @@ impl crate::Context for Context { } } + fn adapter_get_texture_format_features( + &self, + _adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + format.describe().guaranteed_format_features + } + fn device_features(&self, _device: &Self::DeviceId) -> wgt::Features { // TODO: web-sys has no way of getting extensions on devices wgt::Features::empty() diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index c2ee1d38fe..7691ff41f6 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -197,6 +197,11 @@ trait Context: Debug + Send + Sized + Sync { fn adapter_features(&self, adapter: &Self::AdapterId) -> Features; fn adapter_limits(&self, adapter: &Self::AdapterId) -> Limits; fn adapter_get_info(&self, adapter: &Self::AdapterId) -> AdapterInfo; + fn adapter_get_texture_format_features( + &self, + adapter: &Self::AdapterId, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures; fn device_features(&self, device: &Self::DeviceId) -> Features; fn device_limits(&self, device: &Self::DeviceId) -> Limits; @@ -1413,6 +1418,17 @@ impl Adapter { pub fn get_info(&self) -> AdapterInfo { Context::adapter_get_info(&*self.context, &self.id) } + + /// Returns the features supported for a given texture format by this adapter. + /// + /// Note that the WebGPU spec further restricts the available usages/features. + /// To disable these restrictions on a device, request the [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] feature. + pub fn get_texture_format_features( + &self, + format: wgt::TextureFormat, + ) -> wgt::TextureFormatFeatures { + Context::adapter_get_texture_format_features(&*self.context, &self.id, format) + } } impl Device {