diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index a1405009c1..b1d0278ad0 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -314,11 +314,12 @@ pub(crate) fn validate_texture_copy_range( let extent = extent_virtual.physical_size(desc.format); match desc.format { - wgt::TextureFormat::Depth32Float + //wgt::TextureFormat::Stencil8 | + wgt::TextureFormat::Depth16Unorm + | wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth32FloatStencil8 | wgt::TextureFormat::Depth24Plus - | wgt::TextureFormat::Depth24PlusStencil8 - | wgt::TextureFormat::Depth24UnormStencil8 => { + | wgt::TextureFormat::Depth24PlusStencil8 => { if *copy_size != extent { return Err(TransferError::InvalidDepthTextureExtent); } diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index fd59a25eb4..6a0da9d29a 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -19,11 +19,12 @@ 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::Stencil8 | + Tf::Depth16Unorm + | Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus - | Tf::Depth24PlusStencil8 - | Tf::Depth24UnormStencil8 => false, + | Tf::Depth24PlusStencil8 => false, _ => true, } } diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index aef7cc46a9..a6dee7d974 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -704,11 +704,12 @@ impl NumericType { (NumericDimension::Vector(Vs::Quad), Sk::Sint) } Tf::Rg11b10Float => (NumericDimension::Vector(Vs::Tri), Sk::Float), - Tf::Depth32Float + //Tf::Stencil8 | + Tf::Depth16Unorm + | Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus - | Tf::Depth24PlusStencil8 - | Tf::Depth24UnormStencil8 => { + | 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 46bc11332d..8eddf7678b 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -33,6 +33,7 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option DXGI_FORMAT_B8G8R8A8_UNORM, Tf::Rgba8Uint => DXGI_FORMAT_R8G8B8A8_UINT, Tf::Rgba8Sint => DXGI_FORMAT_R8G8B8A8_SINT, + Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP, Tf::Rgb10a2Unorm => DXGI_FORMAT_R10G10B10A2_UNORM, Tf::Rg11b10Float => DXGI_FORMAT_R11G11B10_FLOAT, Tf::Rg32Uint => DXGI_FORMAT_R32G32_UINT, @@ -46,11 +47,12 @@ pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option DXGI_FORMAT_R32G32B32A32_UINT, Tf::Rgba32Sint => DXGI_FORMAT_R32G32B32A32_SINT, Tf::Rgba32Float => DXGI_FORMAT_R32G32B32A32_FLOAT, + //Tf::Stencil8 => DXGI_FORMAT_R8_UNORM, + Tf::Depth16Unorm => DXGI_FORMAT_D16_UNORM, + Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT, + Tf::Depth24PlusStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT, Tf::Depth32Float => DXGI_FORMAT_D32_FLOAT, Tf::Depth32FloatStencil8 => DXGI_FORMAT_D32_FLOAT_S8X24_UINT, - Tf::Depth24Plus => DXGI_FORMAT_D24_UNORM_S8_UINT, - Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => DXGI_FORMAT_D24_UNORM_S8_UINT, - Tf::Rgb9e5Ufloat => DXGI_FORMAT_R9G9B9E5_SHAREDEXP, Tf::Bc1RgbaUnorm => DXGI_FORMAT_BC1_UNORM, Tf::Bc1RgbaUnormSrgb => DXGI_FORMAT_BC1_UNORM_SRGB, Tf::Bc2RgbaUnorm => DXGI_FORMAT_BC2_UNORM, @@ -103,13 +105,15 @@ pub fn map_texture_format_nosrgb(format: wgt::TextureFormat) -> dxgiformat::DXGI //TODO: stencil views? pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { match format { + //wgt::TextureFormat::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM, + wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM, wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_FLOAT, wgt::TextureFormat::Depth32FloatStencil8 => { dxgiformat::DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS } - wgt::TextureFormat::Depth24Plus - | wgt::TextureFormat::Depth24PlusStencil8 - | wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS, + wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { + dxgiformat::DXGI_FORMAT_R24_UNORM_X8_TYPELESS + } _ => { assert_eq!( crate::FormatAspects::from(format), @@ -122,11 +126,13 @@ 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::Stencil8 => dxgiformat::DXGI_FORMAT_R8_UNORM, + wgt::TextureFormat::Depth16Unorm => dxgiformat::DXGI_FORMAT_D16_UNORM, wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS, wgt::TextureFormat::Depth32FloatStencil8 => dxgiformat::DXGI_FORMAT_R32G8X24_TYPELESS, - wgt::TextureFormat::Depth24Plus - | wgt::TextureFormat::Depth24PlusStencil8 - | wgt::TextureFormat::Depth24UnormStencil8 => dxgiformat::DXGI_FORMAT_R24G8_TYPELESS, + wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { + dxgiformat::DXGI_FORMAT_R24G8_TYPELESS + } _ => unreachable!(), } } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index d7fe659dfa..c44cf664e2 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -189,7 +189,7 @@ impl super::Adapter { let mut features = wgt::Features::empty() | wgt::Features::DEPTH_CLIP_CONTROL - | wgt::Features::DEPTH24UNORM_STENCIL8 + | wgt::Features::DEPTH24PLUS_STENCIL8 | wgt::Features::DEPTH32FLOAT_STENCIL8 | wgt::Features::INDIRECT_FIRST_INSTANCE | wgt::Features::MAPPABLE_PRIMARY_BUFFERS diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 992f565c98..d6cff0932e 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -725,11 +725,12 @@ impl crate::Adapter for super::Adapter { Tf::Rgba32Uint => renderable | storage, Tf::Rgba32Sint => renderable | storage, Tf::Rgba32Float => unfilterable | storage | float_renderable, - Tf::Depth32Float + //Tf::Stencil8 | + Tf::Depth16Unorm + | Tf::Depth32Float | Tf::Depth32FloatStencil8 | Tf::Depth24Plus - | Tf::Depth24PlusStencil8 - | Tf::Depth24UnormStencil8 => depth, + | Tf::Depth24PlusStencil8 => depth, Tf::Rgb9e5Ufloat => filterable, Tf::Bc1RgbaUnorm | Tf::Bc1RgbaUnormSrgb diff --git a/wgpu-hal/src/gles/conv.rs b/wgpu-hal/src/gles/conv.rs index bf0f3bf0bd..78fa6fbcc0 100644 --- a/wgpu-hal/src/gles/conv.rs +++ b/wgpu-hal/src/gles/conv.rs @@ -56,6 +56,12 @@ impl super::AdapterShared { Tf::Rgba32Uint => (glow::RGBA32UI, glow::RGBA_INTEGER, glow::UNSIGNED_INT), Tf::Rgba32Sint => (glow::RGBA32I, glow::RGBA_INTEGER, glow::INT), Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT), + //Tf::Stencil8 => (glow::R8UI, glow::STENCIL_COMPONENTS, glow::UNSIGNED_BYTE), + Tf::Depth16Unorm => ( + glow::DEPTH_COMPONENT16, + glow::DEPTH_COMPONENT, + glow::UNSIGNED_SHORT, + ), Tf::Depth32Float => (glow::DEPTH_COMPONENT32F, glow::DEPTH_COMPONENT, glow::FLOAT), Tf::Depth32FloatStencil8 => { (glow::DEPTH32F_STENCIL8, glow::DEPTH_COMPONENT, glow::FLOAT) @@ -65,7 +71,7 @@ impl super::AdapterShared { glow::DEPTH_COMPONENT, glow::UNSIGNED_NORMALIZED, ), - Tf::Depth24PlusStencil8 | Tf::Depth24UnormStencil8 => ( + Tf::Depth24PlusStencil8 => ( glow::DEPTH24_STENCIL8, glow::DEPTH_COMPONENT, glow::UNSIGNED_INT, diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 2d5806323c..3f09101c2e 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -612,10 +612,12 @@ impl From for FormatAspects { impl From for FormatAspects { fn from(format: wgt::TextureFormat) -> Self { match format { + //wgt::TextureFormat::Stencil8 => Self::STENCIL, + wgt::TextureFormat::Depth16Unorm => Self::DEPTH, wgt::TextureFormat::Depth32Float | wgt::TextureFormat::Depth24Plus => Self::DEPTH, - wgt::TextureFormat::Depth32FloatStencil8 - | wgt::TextureFormat::Depth24PlusStencil8 - | wgt::TextureFormat::Depth24UnormStencil8 => 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 7a219ed88a..844a2f0563 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -180,6 +180,21 @@ impl crate::Adapter for super::Adapter { }; flags } + /*Tf::Stencil8 => { + let mut flags = all_caps + | Tfc::DEPTH_STENCIL_ATTACHMENT + | Tfc::MULTISAMPLE + | msaa_resolve_apple3x_if; + flags + }*/ + Tf::Depth16Unorm => { + let mut flags = + Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if; + if pc.format_depth16unorm { + flags |= Tfc::SAMPLED_LINEAR + } + flags + } Tf::Depth32Float | Tf::Depth32FloatStencil8 => { let mut flags = Tfc::DEPTH_STENCIL_ATTACHMENT | Tfc::MULTISAMPLE | msaa_resolve_apple3x_if; @@ -200,12 +215,6 @@ impl crate::Adapter for super::Adapter { } flags } - Tf::Depth24UnormStencil8 => { - Tfc::DEPTH_STENCIL_ATTACHMENT - | Tfc::SAMPLED_LINEAR - | Tfc::MULTISAMPLE - | Tfc::MULTISAMPLE_RESOLVE - } Tf::Rgb9e5Ufloat => { if pc.msaa_apple3 { all_caps @@ -769,7 +778,7 @@ impl super::PrivateCapabilities { features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc); features.set(F::DEPTH_CLIP_CONTROL, self.supports_depth_clip_control); - features.set(F::DEPTH24UNORM_STENCIL8, self.format_depth24_stencil8); + features.set(F::DEPTH24PLUS_STENCIL8, self.format_depth24_stencil8); features.set( F::TEXTURE_BINDING_ARRAY @@ -902,6 +911,8 @@ impl super::PrivateCapabilities { Tf::Rgba32Uint => RGBA32Uint, Tf::Rgba32Sint => RGBA32Sint, Tf::Rgba32Float => RGBA32Float, + //Tf::Stencil8 => R8Unorm, + Tf::Depth16Unorm => Depth16Unorm, Tf::Depth32Float => Depth32Float, Tf::Depth32FloatStencil8 => Depth32Float_Stencil8, Tf::Depth24Plus => { @@ -918,7 +929,6 @@ impl super::PrivateCapabilities { Depth32Float_Stencil8 } } - Tf::Depth24UnormStencil8 => Depth24Unorm_Stencil8, Tf::Rgb9e5Ufloat => RGB9E5Float, Tf::Bc1RgbaUnorm => BC1_RGBA, Tf::Bc1RgbaUnormSrgb => BC1_RGBA_sRGB, diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index ae17684b49..1353cdaf32 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -482,7 +482,7 @@ impl PhysicalDeviceFeatures { ); features.set( - F::DEPTH24UNORM_STENCIL8, + F::DEPTH24PLUS_STENCIL8, supports_format( instance, phd, diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index a2e7b7a598..ba1428ded5 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -64,7 +64,8 @@ impl super::PrivateCapabilities { F::D32_SFLOAT_S8_UINT } } - Tf::Depth24UnormStencil8 => F::D24_UNORM_S8_UINT, + //Tf::Stencil8 => F::R8_UNORM, + Tf::Depth16Unorm => F::D16_UNORM, Tf::Rgb9e5Ufloat => F::E5B9G9R9_UFLOAT_PACK32, Tf::Bc1RgbaUnorm => F::BC1_RGBA_UNORM_BLOCK, Tf::Bc1RgbaUnormSrgb => F::BC1_RGBA_SRGB_BLOCK, diff --git a/wgpu-info/src/main.rs b/wgpu-info/src/main.rs index 34260e10c2..9840511491 100644 --- a/wgpu-info/src/main.rs +++ b/wgpu-info/src/main.rs @@ -50,11 +50,12 @@ mod inner { wgpu::TextureFormat::Rgba32Uint, wgpu::TextureFormat::Rgba32Sint, wgpu::TextureFormat::Rgba32Float, + //wgpu::TextureFormat::Stencil8, + wgpu::TextureFormat::Depth16Unorm, wgpu::TextureFormat::Depth32Float, wgpu::TextureFormat::Depth32FloatStencil8, wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Depth24PlusStencil8, - wgpu::TextureFormat::Depth24UnormStencil8, wgpu::TextureFormat::Rgb9e5Ufloat, wgpu::TextureFormat::Bc1RgbaUnorm, wgpu::TextureFormat::Bc1RgbaUnormSrgb, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 5a3b916b42..ab00124f61 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -191,7 +191,7 @@ bitflags::bitflags! { /// /// This is a web and native feature. const DEPTH_CLIP_CONTROL = 1 << 0; - /// Allows for explicit creation of textures of format [`TextureFormat::Depth24UnormStencil8`] + /// Allows for explicit creation of textures of format [`TextureFormat::Depth24PlusStencil8`] /// /// Supported platforms: /// - Vulkan (some) @@ -199,7 +199,7 @@ bitflags::bitflags! { /// - Metal (Macs with amd GPUs) /// /// This is a web and native feature. - const DEPTH24UNORM_STENCIL8 = 1 << 1; + const DEPTH24PLUS_STENCIL8 = 1 << 1; /// Allows for explicit creation of textures of format [`TextureFormat::Depth32FloatStencil8`] /// /// Supported platforms: @@ -1865,6 +1865,9 @@ pub enum TextureFormat { Bgra8UnormSrgb, // Packed 32 bit formats + /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent + #[cfg_attr(feature = "serde", serde(rename = "rgb9e5ufloat"))] + Rgb9e5Ufloat, /// Red, green, blue, and alpha channels. 10 bit integer for RGB channels, 2 bit integer for alpha channel. [0, 1023] ([0, 3] for alpha) converted to/from float [0, 1] in shader. #[cfg_attr(feature = "serde", serde(rename = "rgb10a2unorm"))] Rgb10a2Unorm, @@ -1914,26 +1917,24 @@ pub enum TextureFormat { Rgba32Float, // Depth and stencil formats - /// 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, + /// Stencil format with 8 bit integer stencil. + //#[cfg_attr(feature = "serde", serde(rename = "stencil8"))] + //Stencil8, + /// Special depth format with 16 bit integer depth. + #[cfg_attr(feature = "serde", serde(rename = "depth16unorm"))] + Depth16Unorm, /// Special depth format with at least 24 bit integer depth. #[cfg_attr(feature = "serde", serde(rename = "depth24plus"))] Depth24Plus, /// Special depth/stencil format with at least 24 bit integer depth and 8 bits integer stencil. #[cfg_attr(feature = "serde", serde(rename = "depth24plus-stencil8"))] Depth24PlusStencil8, - /// Special depth/stencil format with 24 bit integer depth and 8 bits integer stencil. - #[cfg_attr(feature = "serde", serde(rename = "depth24unorm-stencil8"))] - Depth24UnormStencil8, - - // Packed uncompressed texture formats - /// Packed unsigned float with 9 bits mantisa for each RGB component, then a common 5 bits exponent - #[cfg_attr(feature = "serde", serde(rename = "rgb9e5ufloat"))] - Rgb9e5Ufloat, + /// 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, // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 4 color + alpha pallet. 5 bit R + 6 bit G + 5 bit B + 1 bit alpha. @@ -2132,7 +2133,7 @@ impl TextureFormat { let astc_hdr = Features::TEXTURE_COMPRESSION_ASTC_HDR; let norm16bit = Features::TEXTURE_FORMAT_16BIT_NORM; let d32_s8 = Features::DEPTH32FLOAT_STENCIL8; - let d24_s8 = Features::DEPTH24UNORM_STENCIL8; + let d24_s8 = Features::DEPTH24PLUS_STENCIL8; // Sample Types let uint = TextureSampleType::Uint; @@ -2178,7 +2179,6 @@ impl TextureFormat { Self::R8Snorm => ( native, float, linear, msaa, (1, 1), 1, basic, 1), Self::R8Uint => ( native, uint, linear, msaa, (1, 1), 1, attachment, 1), Self::R8Sint => ( native, sint, linear, msaa, (1, 1), 1, attachment, 1), - // Normal 16 bit textures Self::R16Uint => ( native, uint, linear, msaa, (1, 1), 2, attachment, 1), Self::R16Sint => ( native, sint, linear, msaa, (1, 1), 2, attachment, 1), @@ -2187,7 +2187,6 @@ impl TextureFormat { Self::Rg8Snorm => ( native, float, linear, msaa, (1, 1), 2, attachment, 2), Self::Rg8Uint => ( native, uint, linear, msaa, (1, 1), 2, attachment, 2), Self::Rg8Sint => ( native, sint, linear, msaa, (1, 1), 2, basic, 2), - // Normal 32 bit textures Self::R32Uint => ( native, uint, linear, noaa, (1, 1), 4, all_flags, 1), Self::R32Sint => ( native, sint, linear, noaa, (1, 1), 4, all_flags, 1), @@ -2202,11 +2201,9 @@ impl TextureFormat { Self::Rgba8Sint => ( native, sint, linear, msaa, (1, 1), 4, all_flags, 4), Self::Bgra8Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 4), Self::Bgra8UnormSrgb => ( native, float, corrected, msaa_resolve, (1, 1), 4, attachment, 4), - // Packed 32 bit textures Self::Rgb10a2Unorm => ( native, float, linear, msaa_resolve, (1, 1), 4, attachment, 4), Self::Rg11b10Float => ( native, float, linear, msaa, (1, 1), 4, basic, 3), - // Packed 32 bit textures Self::Rg32Uint => ( native, uint, linear, noaa, (1, 1), 8, all_flags, 2), Self::Rg32Sint => ( native, sint, linear, noaa, (1, 1), 8, all_flags, 2), @@ -2214,22 +2211,18 @@ impl TextureFormat { Self::Rgba16Uint => ( native, uint, linear, msaa, (1, 1), 8, all_flags, 4), Self::Rgba16Sint => ( native, sint, linear, msaa, (1, 1), 8, all_flags, 4), Self::Rgba16Float => ( native, float, linear, msaa_resolve, (1, 1), 8, all_flags, 4), - // Packed 32 bit textures Self::Rgba32Uint => ( native, uint, linear, noaa, (1, 1), 16, all_flags, 4), Self::Rgba32Sint => ( native, sint, linear, noaa, (1, 1), 16, all_flags, 4), Self::Rgba32Float => ( native, nearest, linear, noaa, (1, 1), 16, all_flags, 4), - // Depth-stencil textures + Self::Depth16Unorm => ( native, depth, linear, msaa, (1, 1), 2, attachment, 1), + Self::Depth24Plus => ( native, depth, linear, msaa, (1, 1), 4, attachment, 1), + Self::Depth24PlusStencil8 => ( d24_s8, depth, linear, msaa, (1, 1), 4, attachment, 2), 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), - Self::Depth24UnormStencil8 => ( d24_s8, depth, linear, msaa, (1, 1), 4, attachment, 2), - // Packed uncompressed Self::Rgb9e5Ufloat => ( native, float, linear, noaa, (1, 1), 4, basic, 3), - // Optional normalized 16-bit-per-channel formats Self::R16Unorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1), Self::R16Snorm => (norm16bit, float, linear, msaa, (1, 1), 2, storage, 1), @@ -2237,7 +2230,6 @@ impl TextureFormat { Self::Rg16Snorm => (norm16bit, float, linear, msaa, (1, 1), 4, storage, 2), Self::Rgba16Unorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4), Self::Rgba16Snorm => (norm16bit, float, linear, msaa, (1, 1), 8, storage, 4), - // BCn compressed textures Self::Bc1RgbaUnorm => ( bc, float, linear, noaa, (4, 4), 8, basic, 4), Self::Bc1RgbaUnormSrgb => ( bc, float, corrected, noaa, (4, 4), 8, basic, 4), @@ -2253,7 +2245,6 @@ impl TextureFormat { Self::Bc6hRgbSfloat => ( bc, float, linear, noaa, (4, 4), 16, basic, 3), Self::Bc7RgbaUnorm => ( bc, float, linear, noaa, (4, 4), 16, basic, 4), Self::Bc7RgbaUnormSrgb => ( bc, float, corrected, noaa, (4, 4), 16, basic, 4), - // ETC compressed textures Self::Etc2Rgb8Unorm => ( etc2, float, linear, noaa, (4, 4), 8, basic, 3), Self::Etc2Rgb8UnormSrgb => ( etc2, float, corrected, noaa, (4, 4), 8, basic, 3), @@ -2265,7 +2256,6 @@ impl TextureFormat { Self::EacR11Snorm => ( etc2, float, linear, noaa, (4, 4), 8, basic, 1), Self::EacRg11Unorm => ( etc2, float, linear, noaa, (4, 4), 16, basic, 2), Self::EacRg11Snorm => ( etc2, float, linear, noaa, (4, 4), 16, basic, 2), - // ASTC compressed textures Self::Astc { block, channel } => { let (feature, color_space) = match channel { diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index f6cba40b1c..afb3c45915 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -511,10 +511,12 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture use web_sys::GpuTextureFormat as tf; use wgt::TextureFormat; match texture_format { + // 8-bit formats TextureFormat::R8Unorm => tf::R8unorm, TextureFormat::R8Snorm => tf::R8snorm, TextureFormat::R8Uint => tf::R8uint, TextureFormat::R8Sint => tf::R8sint, + // 16-bit formats TextureFormat::R16Uint => tf::R16uint, TextureFormat::R16Sint => tf::R16sint, TextureFormat::R16Float => tf::R16float, @@ -522,6 +524,7 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture TextureFormat::Rg8Snorm => tf::Rg8snorm, TextureFormat::Rg8Uint => tf::Rg8uint, TextureFormat::Rg8Sint => tf::Rg8sint, + // 32-bit formats TextureFormat::R32Uint => tf::R32uint, TextureFormat::R32Sint => tf::R32sint, TextureFormat::R32Float => tf::R32float, @@ -535,21 +538,29 @@ fn map_texture_format(texture_format: wgt::TextureFormat) -> web_sys::GpuTexture TextureFormat::Rgba8Sint => tf::Rgba8sint, TextureFormat::Bgra8Unorm => tf::Bgra8unorm, TextureFormat::Bgra8UnormSrgb => tf::Bgra8unormSrgb, + // Packed 32-bit formats + TextureFormat::Rgb9e5Ufloat => tf::Rgb9e5ufloat, TextureFormat::Rgb10a2Unorm => tf::Rgb10a2unorm, TextureFormat::Rg11b10Float => tf::Rg11b10ufloat, + // 64-bit formats TextureFormat::Rg32Uint => tf::Rg32uint, TextureFormat::Rg32Sint => tf::Rg32sint, TextureFormat::Rg32Float => tf::Rg32float, TextureFormat::Rgba16Uint => tf::Rgba16uint, TextureFormat::Rgba16Sint => tf::Rgba16sint, TextureFormat::Rgba16Float => tf::Rgba16float, + // 128-bit formats TextureFormat::Rgba32Uint => tf::Rgba32uint, TextureFormat::Rgba32Sint => tf::Rgba32sint, TextureFormat::Rgba32Float => tf::Rgba32float, - TextureFormat::Depth32Float => tf::Depth32float, - TextureFormat::Depth32FloatStencil8 => tf::Depth32floatStencil8, + // Depth/stencil formats + //TextureFormat::Stencil8 => tf::Stencil8, + TextureFormat::Depth16Unorm => tf::Depth16unorm, TextureFormat::Depth24Plus => tf::Depth24plus, TextureFormat::Depth24PlusStencil8 => tf::Depth24plusStencil8, + TextureFormat::Depth32Float => tf::Depth32float, + // "depth32float-stencil8" feature + TextureFormat::Depth32FloatStencil8 => tf::Depth32floatStencil8, _ => unimplemented!(), } } diff --git a/wgpu/tests/clear_texture.rs b/wgpu/tests/clear_texture.rs index a96922de3f..9abf7e043d 100644 --- a/wgpu/tests/clear_texture.rs +++ b/wgpu/tests/clear_texture.rs @@ -41,9 +41,9 @@ static TEXTURE_FORMATS_UNCOMPRESSED: &[wgpu::TextureFormat] = &[ ]; static TEXTURE_FORMATS_DEPTH: &[wgpu::TextureFormat] = &[ - wgpu::TextureFormat::Depth32Float, + //wgpu::TextureFormat::Stencil8, + wgpu::TextureFormat::Depth16Unorm, wgpu::TextureFormat::Depth24Plus, - wgpu::TextureFormat::Depth24PlusStencil8, ]; // needs TEXTURE_COMPRESSION_BC @@ -333,11 +333,11 @@ fn clear_texture_d32_s8() { fn clear_texture_d24_s8() { initialize_test( TestParameters::default() - .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::DEPTH24UNORM_STENCIL8), + .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::DEPTH24PLUS_STENCIL8), |ctx| { clear_texture_tests( &ctx, - &[wgpu::TextureFormat::Depth24UnormStencil8], + &[wgpu::TextureFormat::Depth24PlusStencil8], false, false, ); diff --git a/wgpu/tests/zero_init_texture_after_discard.rs b/wgpu/tests/zero_init_texture_after_discard.rs index 6043d0388f..9307bc7fbd 100644 --- a/wgpu/tests/zero_init_texture_after_discard.rs +++ b/wgpu/tests/zero_init_texture_after_discard.rs @@ -110,55 +110,58 @@ fn discarding_depth_target_resets_texture_init_state_check_visible_on_copy_in_sa #[test] fn discarding_either_depth_or_stencil_aspect() { - initialize_test(TestParameters::default(), |ctx| { - let (texture, _) = create_white_texture_and_readback_buffer( - &ctx, - wgpu::TextureFormat::Depth24PlusStencil8, - ); - // TODO: How do we test this other than "doesn't crash"? We can't copy the texture to/from buffers, so we would need to do a copy in a shader - { - let mut encoder = ctx - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); - encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("Depth Discard, Stencil Load"), - color_attachments: &[], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { - view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), - depth_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Load, - store: false, // discard! - }), - stencil_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Clear(0), - store: true, - }), - }), - }); - ctx.queue.submit([encoder.finish()]); - } - { - let mut encoder = ctx - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); - encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("Depth Load, Stencil Discard"), - color_attachments: &[], - depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { - view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), - depth_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Clear(0.0), - store: true, + initialize_test( + TestParameters::default().features(wgpu::Features::DEPTH24PLUS_STENCIL8), + |ctx| { + let (texture, _) = create_white_texture_and_readback_buffer( + &ctx, + wgpu::TextureFormat::Depth24PlusStencil8, + ); + // TODO: How do we test this other than "doesn't crash"? We can't copy the texture to/from buffers, so we would need to do a copy in a shader + { + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("Depth Discard, Stencil Load"), + color_attachments: &[], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Load, + store: false, // discard! + }), + stencil_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(0), + store: true, + }), }), - stencil_ops: Some(wgpu::Operations { - load: wgpu::LoadOp::Load, - store: false, // discard! + }); + ctx.queue.submit([encoder.finish()]); + } + { + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("Depth Load, Stencil Discard"), + color_attachments: &[], + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &texture.create_view(&wgpu::TextureViewDescriptor::default()), + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(0.0), + store: true, + }), + stencil_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Load, + store: false, // discard! + }), }), - }), - }); - ctx.queue.submit([encoder.finish()]); - } - }); + }); + ctx.queue.submit([encoder.finish()]); + } + }, + ); } const TEXTURE_SIZE: wgpu::Extent3d = wgpu::Extent3d {