diff --git a/deno_webgpu/02_idl_types.js b/deno_webgpu/02_idl_types.js index bb50c852da..7bc3cc22a3 100644 --- a/deno_webgpu/02_idl_types.js +++ b/deno_webgpu/02_idl_types.js @@ -114,6 +114,7 @@ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter( "texture-compression-bc", "texture-compression-etc2", "texture-compression-astc", + "rg11b10ufloat-renderable", // extended from spec diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 46b9d8d14f..2f73c4bef9 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -186,6 +186,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> { if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) { return_features.push("texture-compression-astc"); } + if features.contains(wgpu_types::Features::RG11B10UFLOAT_RENDERABLE) { + return_features.push("rg11b10ufloat-renderable"); + } // extended from spec @@ -404,6 +407,10 @@ impl From for wgpu_types::Features { wgpu_types::Features::TEXTURE_COMPRESSION_ASTC, required_features.0.contains("texture-compression-astc"), ); + features.set( + wgpu_types::Features::RG11B10UFLOAT_RENDERABLE, + required_features.0.contains("rg11b10ufloat-renderable"), + ); // extended from spec diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index cb7fdc9aeb..e1afd4ca68 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -99,6 +99,7 @@ enum GPUFeatureName { "texture-compression-bc", "texture-compression-etc2", "texture-compression-astc", + "rg11b10ufloat-renderable", // extended from spec diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index c8ef8632ad..7c2a33a8b8 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -880,7 +880,10 @@ impl Device { let missing_allowed_usages = desc.usage - format_features.allowed_usages; if !missing_allowed_usages.is_empty() { // detect downlevel incompatibilities - let wgpu_allowed_usages = desc.format.guaranteed_format_features().allowed_usages; + let wgpu_allowed_usages = desc + .format + .guaranteed_format_features(self.features) + .allowed_usages; let wgpu_missing_usages = desc.usage - wgpu_allowed_usages; return Err(CreateTextureError::InvalidFormatUsages( missing_allowed_usages, @@ -3252,7 +3255,7 @@ impl Device { if using_device_features || downlevel { Ok(adapter.get_texture_format_features(format)) } else { - Ok(format.guaranteed_format_features()) + Ok(format.guaranteed_format_features(self.features)) } } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index a77484c301..fd7f2f926c 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -223,7 +223,8 @@ impl super::Adapter { | wgt::Features::CLEAR_TEXTURE | wgt::Features::TEXTURE_FORMAT_16BIT_NORM | wgt::Features::PUSH_CONSTANTS - | wgt::Features::SHADER_PRIMITIVE_INDEX; + | wgt::Features::SHADER_PRIMITIVE_INDEX + | wgt::Features::RG11B10UFLOAT_RENDERABLE; //TODO: in order to expose this, we need to run a compute shader // that extract the necessary statistics out of the D3D12 result. // Alternatively, we could allocate a buffer for the query set, diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 4a747327e6..e5c3de3417 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -800,6 +800,8 @@ impl super::PrivateCapabilities { ); features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true); + features.set(F::RG11B10UFLOAT_RENDERABLE, self.format_rg11b10_all); + features } diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index ab07b7f854..5aed876d18 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -526,6 +526,16 @@ impl PhysicalDeviceFeatures { features.set(F::DEPTH32FLOAT_STENCIL8, texture_d32_s8); + let rg11b10ufloat_renderable = supports_format( + instance, + phd, + vk::Format::B10G11R11_UFLOAT_PACK32, + vk::ImageTiling::OPTIMAL, + vk::FormatFeatureFlags::COLOR_ATTACHMENT + | vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND, + ); + features.set(F::RG11B10UFLOAT_RENDERABLE, rg11b10ufloat_renderable); + (features, dl_flags) } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 360b9ed7cd..f73892be4a 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2712,7 +2712,7 @@ impl TextureFormat { /// Returns the format features guaranteed by the WebGPU spec. /// /// Additional features are available if `Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES` is enabled. - pub fn guaranteed_format_features(&self) -> TextureFormatFeatures { + pub fn guaranteed_format_features(&self, device_features: Features) -> TextureFormatFeatures { // Multisampling let noaa = TextureFormatFeatureFlags::empty(); let msaa = TextureFormatFeatureFlags::MULTISAMPLE_X4; @@ -2724,6 +2724,11 @@ impl TextureFormat { let attachment = basic | TextureUsages::RENDER_ATTACHMENT; let storage = basic | TextureUsages::STORAGE_BINDING; let all_flags = TextureUsages::all(); + let rg11b10f = if device_features.contains(Features::RG11B10UFLOAT_RENDERABLE) { + attachment + } else { + basic + }; #[rustfmt::skip] // lets make a nice table let ( @@ -2755,7 +2760,7 @@ impl TextureFormat { Self::Bgra8Unorm => (msaa_resolve, attachment), Self::Bgra8UnormSrgb => (msaa_resolve, attachment), Self::Rgb10a2Unorm => (msaa_resolve, attachment), - Self::Rg11b10Float => ( msaa, basic), + Self::Rg11b10Float => ( msaa, rg11b10f), Self::Rg32Uint => ( noaa, all_flags), Self::Rg32Sint => ( noaa, all_flags), Self::Rg32Float => ( noaa, all_flags), diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 743c51b9df..17c82ecbd8 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1095,11 +1095,11 @@ impl crate::context::Context for Context { fn adapter_get_texture_format_features( &self, - _adapter: &Self::AdapterId, - _adapter_data: &Self::AdapterData, + adapter: &Self::AdapterId, + adapter_data: &Self::AdapterData, format: wgt::TextureFormat, ) -> wgt::TextureFormatFeatures { - format.guaranteed_format_features() + format.guaranteed_format_features(self.adapter_features(adapter, adapter_data)) } fn adapter_get_presentation_timestamp(