diff --git a/deno_webgpu/src/lib.rs b/deno_webgpu/src/lib.rs index d2d0c6cf8d..70644209bc 100644 --- a/deno_webgpu/src/lib.rs +++ b/deno_webgpu/src/lib.rs @@ -128,6 +128,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> { if features.contains(wgpu_types::Features::DEPTH_CLIP_CONTROL) { return_features.push("depth-clip-control"); } + if features.contains(wgpu_types::Features::DEPTH32FLOAT_STENCIL8) { + return_features.push("depth32float-stencil8"); + } if features.contains(wgpu_types::Features::PIPELINE_STATISTICS_QUERY) { return_features.push("pipeline-statistics-query"); } @@ -285,6 +288,10 @@ impl From for wgpu_types::Features { wgpu_types::Features::DEPTH_CLIP_CONTROL, required_features.0.contains("depth-clip-control"), ); + features.set( + wgpu_types::Features::DEPTH32FLOAT_STENCIL8, + required_features.0.contains("depth32float-stencil8"), + ); features.set( wgpu_types::Features::PIPELINE_STATISTICS_QUERY, required_features.0.contains("pipeline-statistics-query"), diff --git a/player/tests/data/pipeline-statistics-query.ron b/player/tests/data/pipeline-statistics-query.ron index 6e0f10e9a8..e4389d5a1b 100644 --- a/player/tests/data/pipeline-statistics-query.ron +++ b/player/tests/data/pipeline-statistics-query.ron @@ -1,5 +1,5 @@ ( - features: 0x0000_0000_0000_0010, // PIPELINE_STATISTICS_QUERY + features: 0x0000_0000_0000_0020, // PIPELINE_STATISTICS_QUERY expectations: [ ( name: "Queried number of compute invocations is correct", diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 1033feecee..d676bc1d3c 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -312,6 +312,7 @@ pub(crate) fn validate_texture_copy_range( match desc.format { wgt::TextureFormat::Depth32Float + | wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { if *copy_size != extent { diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index b6632b5903..7982390b55 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -15,7 +15,9 @@ pub fn is_valid_copy_src_texture_format(format: wgt::TextureFormat) -> bool { pub fn is_valid_copy_dst_texture_format(format: wgt::TextureFormat) -> bool { use wgt::TextureFormat as Tf; match format { - Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => false, + Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => { + false + } _ => true, } } diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 3b3f3f7904..148eeecfa5 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -702,7 +702,10 @@ impl NumericType { (NumericDimension::Vector(Vs::Quad), Sk::Sint) } Tf::Rg11b10Float => (NumericDimension::Vector(Vs::Tri), Sk::Float), - Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => { + Tf::Depth32Float + | Tf::Depth32FloatStencil8 + | Tf::Depth24Plus + | Tf::Depth24PlusStencil8 => { panic!("Unexpected depth format") } Tf::Rgb9e5Ufloat => (NumericDimension::Vector(Vs::Tri), Sk::Float), diff --git a/wgpu-hal/src/auxil/dxgi/conv.rs b/wgpu-hal/src/auxil/dxgi/conv.rs index dfcb95b0fc..2fd9bf04ca 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -47,6 +47,7 @@ pub fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT Tf::Rgba32Sint => DXGI_FORMAT_R32G32B32A32_SINT, Tf::Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT, Tf::Depth32Float => DXGI_FORMAT_D32_FLOAT, + Tf::Depth32FloatStencil8 => DXGI_FORMAT_D32_FLOAT_S8X24_UINT, Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT, Tf::Depth24PlusStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT, Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP, @@ -96,6 +97,9 @@ pub fn map_texture_format_nosrgb(format: wgt::TextureFormat) -> dxgiformat::DXGI pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { match format { wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_FLOAT, + wgt::TextureFormat::Depth32FloatStencil8 => { + dxgiformat::DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS + } wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS } @@ -112,6 +116,7 @@ pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXG pub fn map_texture_format_depth_typeless(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { match format { wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS, + wgt::TextureFormat::Depth32FloatStencil8 => dxgiformat::DXGI_FORMAT_R32G8X24_TYPELESS, wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { dxgiformat::DXGI_FORMAT_R24G8_TYPELESS } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 3be86494d8..d05f1c8d0f 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -185,6 +185,7 @@ impl super::Adapter { let mut features = wgt::Features::empty() | wgt::Features::DEPTH_CLIP_CONTROL + | wgt::Features::DEPTH32FLOAT_STENCIL8 | wgt::Features::INDIRECT_FIRST_INSTANCE | wgt::Features::MAPPABLE_PRIMARY_BUFFERS | wgt::Features::MULTI_DRAW_INDIRECT diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 7535c33cf2..44026341e3 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -659,7 +659,10 @@ impl crate::Adapter for super::Adapter { Tf::Rgba32Uint => renderable | storage, Tf::Rgba32Sint => renderable | storage, Tf::Rgba32Float => unfilterable | storage, - Tf::Depth32Float | Tf::Depth24Plus | Tf::Depth24PlusStencil8 => depth, + Tf::Depth32Float + | Tf::Depth32FloatStencil8 + | Tf::Depth24Plus + | Tf::Depth24PlusStencil8 => depth, Tf::Rgb9e5Ufloat | Tf::Bc1RgbaUnorm | Tf::Bc1RgbaUnormSrgb diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index d7a9268c28..fcd6e2791a 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -57,6 +57,9 @@ impl super::AdapterShared { Tf::Rgba32Sint => (glow::RGBA32I, glow::RGBA_INTEGER, glow::INT), Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT), Tf::Depth32Float => (glow::DEPTH_COMPONENT32F, glow::DEPTH_COMPONENT, glow::FLOAT), + Tf::Depth32FloatStencil8 => { + (glow::DEPTH32F_STENCIL8, glow::DEPTH_COMPONENT, glow::FLOAT) + } Tf::Depth24Plus => ( glow::DEPTH_COMPONENT24, glow::DEPTH_COMPONENT, diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 2cb03e2572..6eb297019a 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -602,7 +602,9 @@ impl From for FormatAspects { fn from(format: wgt::TextureFormat) -> Self { match format { wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth24Plus => Self::DEPTH, - wgt::TextureFormat::Depth24PlusStencil8 => Self::DEPTH | Self::STENCIL, + wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24PlusStencil8 => { + Self::DEPTH | Self::STENCIL + } _ => Self::COLOR, } } diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 53201c1472..28ae85ac08 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -180,7 +180,7 @@ impl crate::Adapter for super::Adapter { }; flags } - Tf::Depth32Float => { + Tf::Depth32Float | Tf::Depth32FloatStencil8 => { let mut flats = Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if; if pc.format_depth32float_filter { @@ -749,7 +749,8 @@ impl super::PrivateCapabilities { | F::POLYGON_MODE_LINE | F::CLEAR_TEXTURE | F::TEXTURE_FORMAT_16BIT_NORM - | F::SHADER_FLOAT16; + | F::SHADER_FLOAT16 + | F::DEPTH32FLOAT_STENCIL8; features.set(F::TEXTURE_COMPRESSION_ASTC_LDR, self.format_astc); features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr); @@ -889,6 +890,7 @@ impl super::PrivateCapabilities { Tf::Rgba32Sint => RGBA32Sint, Tf::Rgba32Float => RGBA32Float, Tf::Depth32Float => Depth32Float, + Tf::Depth32FloatStencil8 => Depth32Float_Stencil8, Tf::Depth24Plus => { if self.format_depth24_stencil8 { Depth24Unorm_Stencil8 diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index a6ad22e5c0..1d2fb08a1f 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -561,6 +561,17 @@ impl PhysicalDeviceFeatures { ); } + features.set( + F::DEPTH32FLOAT_STENCIL8, + caps.supports_format( + vk::Format::D32_SFLOAT_S8_UINT, + vk::ImageTiling::OPTIMAL, + vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT + | vk::FormatFeatureFlags::SAMPLED_IMAGE + | vk::FormatFeatureFlags::TRANSFER_SRC, + ), + ); + (features, dl_flags) } diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index 727502aed8..602dedb95a 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -49,6 +49,7 @@ impl super::PrivateCapabilities { Tf::Rgba32Sint => F::R32G32B32A32_SINT, Tf::Rgba32Float => F::R32G32B32A32_SFLOAT, Tf::Depth32Float => F::D32_SFLOAT, + Tf::Depth32FloatStencil8 => F::D32_SFLOAT_S8_UINT, Tf::Depth24Plus => { if self.texture_d24 { F::X8_D24_UNORM_PACK32 diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 9277eb16ab..d5ea4b8e56 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -185,6 +185,15 @@ bitflags::bitflags! { /// /// This is a web and native feature. const DEPTH_CLIP_CONTROL = 1 << 0; + /// Allows for explicit creation of textures of format [`TextureFormat::Depth32FloatStencil8`] + /// + /// Supported platforms: + /// - Vulkan (mostly) + /// - DX12 + /// - Metal + /// + /// This is a web and native feature. + const DEPTH32FLOAT_STENCIL8 = 1 << 1; /// Enables BCn family of compressed textures. All BCn textures use 4x4 pixel blocks /// with 8 or 16 bytes per block. /// @@ -198,7 +207,7 @@ bitflags::bitflags! { /// - desktops /// /// This is a web and native feature. - const TEXTURE_COMPRESSION_BC = 1 << 1; + const TEXTURE_COMPRESSION_BC = 1 << 2; /// Allows non-zero value for the "first instance" in indirect draw calls. /// /// Supported Platforms: @@ -207,7 +216,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const INDIRECT_FIRST_INSTANCE = 1 << 2; + const INDIRECT_FIRST_INSTANCE = 1 << 3; /// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when /// all work before the query is finished. Call [`CommandEncoder::write_timestamp`], /// [`RenderPassEncoder::write_timestamp`], or [`ComputePassEncoder::write_timestamp`] to @@ -225,7 +234,7 @@ bitflags::bitflags! { /// - DX12 (works) /// /// This is a web and native feature. - const TIMESTAMP_QUERY = 1 << 3; + const TIMESTAMP_QUERY = 1 << 4; /// Enables use of Pipeline Statistics Queries. These queries tell the count of various operations /// performed between the start and stop call. Call [`RenderPassEncoder::begin_pipeline_statistics_query`] to start /// a query, then call [`RenderPassEncoder::end_pipeline_statistics_query`] to stop one. @@ -240,7 +249,7 @@ bitflags::bitflags! { /// - DX12 (works) /// /// This is a web and native feature. - const PIPELINE_STATISTICS_QUERY = 1 << 4; + const PIPELINE_STATISTICS_QUERY = 1 << 5; /// Allows shaders to acquire the FP16 ability /// /// Note: this is not supported in naga yet,only through spir-v passthrough right now. @@ -250,7 +259,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const SHADER_FLOAT16 = 1 << 5; + const SHADER_FLOAT16 = 1 << 6; /// Webgpu only allows the MAP_READ and MAP_WRITE buffer usage to be matched with /// COPY_DST and COPY_SRC respectively. This removes this requirement. /// @@ -1838,6 +1847,9 @@ pub enum TextureFormat { /// Special depth format with 32 bit floating point depth. #[cfg_attr(feature = "serde", serde(rename = "depth32float"))] Depth32Float, + /// Special depth/stencil format with 32 bit floating point depth and 8 bits integer stencil. + #[cfg_attr(feature = "serde", serde(rename = "depth32float-stencil8"))] + Depth32FloatStencil8, /// Special depth format with at least 24 bit integer depth. #[cfg_attr(feature = "serde", serde(rename = "depth24plus"))] Depth24Plus, @@ -2046,6 +2058,7 @@ impl TextureFormat { let astc_ldr = Features::TEXTURE_COMPRESSION_ASTC_LDR; let astc_hdr = Features::TEXTURE_COMPRESSION_ASTC_HDR; let norm16bit = Features::TEXTURE_FORMAT_16BIT_NORM; + let d32_s8 = Features::DEPTH32FLOAT_STENCIL8; // Sample Types let uint = TextureSampleType::Uint; @@ -2135,6 +2148,7 @@ impl TextureFormat { // Depth-stencil textures Self::Depth32Float => ( native, depth, linear, msaa, (1, 1), 4, attachment, 1), + Self::Depth32FloatStencil8 =>( d32_s8, depth, linear, msaa, (1, 1), 4, attachment, 2), Self::Depth24Plus => ( native, depth, linear, msaa, (1, 1), 4, attachment, 1), Self::Depth24PlusStencil8 => ( native, depth, linear, msaa, (1, 1), 4, attachment, 2), diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 2696d158a6..18b84cb25c 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -543,6 +543,7 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture TextureFormat::Rgba32Sint => tf::Rgba32sint, TextureFormat::Rgba32Float => tf::Rgba32float, TextureFormat::Depth32Float => tf::Depth32float, + TextureFormat::Depth32FloatStencil8 => tf::Depth32floatStencil8, TextureFormat::Depth24Plus => tf::Depth24plus, TextureFormat::Depth24PlusStencil8 => tf::Depth24plusStencil8, _ => unimplemented!(), @@ -591,6 +592,7 @@ fn map_texture_format_from_web_sys( tf::Rgba32sint => TextureFormat::Rgba32Sint, tf::Rgba32float => TextureFormat::Rgba32Float, tf::Depth32float => TextureFormat::Depth32Float, + tf::Depth32floatStencil8 => TextureFormat::Depth32FloatStencil8, tf::Depth24plus => TextureFormat::Depth24Plus, tf::Depth24plusStencil8 => TextureFormat::Depth24PlusStencil8, _ => unimplemented!(), diff --git a/wgpu/tests/clear_texture.rs b/wgpu/tests/clear_texture.rs index 380d19c40a..09831d75e2 100644 --- a/wgpu/tests/clear_texture.rs +++ b/wgpu/tests/clear_texture.rs @@ -316,6 +316,22 @@ fn clear_texture_2d_uncompressed() { ) } +#[test] +fn clear_texture_d32_s8() { + initialize_test( + TestParameters::default() + .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::DEPTH32FLOAT_STENCIL8), + |ctx| { + clear_texture_tests( + &ctx, + &[wgpu::TextureFormat::Depth32FloatStencil8], + false, + false, + ); + }, + ) +} + #[test] fn clear_texture_2d_bc() { initialize_test(