From 3580be7ee675754ac54e28721d4a5449c62d780b Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Wed, 29 May 2024 08:32:19 +0900 Subject: [PATCH 01/12] Enable compressed formats in wgpu for 3D textures --- tests/tests/clear_texture.rs | 2 +- wgpu-core/src/device/resource.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 175c642b93..6ceee6c727 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -273,7 +273,7 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu let is_compressed_or_depth_stencil_format = format.is_compressed() || format.is_depth_stencil_format(); let supports_1d = !is_compressed_or_depth_stencil_format; - let supports_3d = !is_compressed_or_depth_stencil_format; + let supports_3d = !format.is_depth_stencil_format(); // 1D texture if supports_1d { diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index ba51507d1f..e4eeb606e4 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -755,8 +755,12 @@ impl Device { desc.dimension, )); } + } - // Compressed textures can only be 2D + if desc.dimension != wgt::TextureDimension::D2 + && desc.dimension != wgt::TextureDimension::D3 + { + // Compressed textures can only be 2D or 3D if desc.format.is_compressed() { return Err(CreateTextureError::InvalidCompressedDimension( desc.dimension, From 87a36d11cd59d16cc110038cbccfbe9e8108ecc6 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Wed, 29 May 2024 09:21:37 +0900 Subject: [PATCH 02/12] Use `align_to` for rounding --- tests/tests/clear_texture.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 6ceee6c727..1056ad2cbe 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -267,8 +267,8 @@ async fn single_texture_clear_test( async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::TextureFormat]) { for &format in formats { let (block_width, block_height) = format.block_dimensions(); - let rounded_width = block_width * wgpu::COPY_BYTES_PER_ROW_ALIGNMENT; - let rounded_height = block_height * wgpu::COPY_BYTES_PER_ROW_ALIGNMENT; + let rounded_width = wgpu::util::align_to(block_width, wgpu::COPY_BYTES_PER_ROW_ALIGNMENT); + let rounded_height = wgpu::util::align_to(block_height, wgpu::COPY_BYTES_PER_ROW_ALIGNMENT); let is_compressed_or_depth_stencil_format = format.is_compressed() || format.is_depth_stencil_format(); From 3456c25780bb0ed6a42ed13218e158f3ab7dd9df Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Wed, 29 May 2024 10:43:54 +0900 Subject: [PATCH 03/12] Case rounded sizes according if uncompressed --- tests/tests/clear_texture.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 1056ad2cbe..3097d7576a 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -267,8 +267,16 @@ async fn single_texture_clear_test( async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::TextureFormat]) { for &format in formats { let (block_width, block_height) = format.block_dimensions(); - let rounded_width = wgpu::util::align_to(block_width, wgpu::COPY_BYTES_PER_ROW_ALIGNMENT); - let rounded_height = wgpu::util::align_to(block_height, wgpu::COPY_BYTES_PER_ROW_ALIGNMENT); + let rounded_width = if block_width == 1 { + wgpu::COPY_BYTES_PER_ROW_ALIGNMENT + } else { + block_width + }; + let rounded_height = if block_height == 1 { + wgpu::COPY_BYTES_PER_ROW_ALIGNMENT + } else { + block_height + }; let is_compressed_or_depth_stencil_format = format.is_compressed() || format.is_depth_stencil_format(); From 8413a049bb7614ae87ccdb72fd89eb82bada6304 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Fri, 31 May 2024 03:44:56 +0900 Subject: [PATCH 04/12] Please see https://github.com/gpuweb/gpuweb/pull/4685 --- tests/tests/clear_texture.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 3097d7576a..63311f16de 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -267,21 +267,14 @@ async fn single_texture_clear_test( async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::TextureFormat]) { for &format in formats { let (block_width, block_height) = format.block_dimensions(); - let rounded_width = if block_width == 1 { - wgpu::COPY_BYTES_PER_ROW_ALIGNMENT - } else { - block_width - }; - let rounded_height = if block_height == 1 { - wgpu::COPY_BYTES_PER_ROW_ALIGNMENT - } else { - block_height - }; + let rounded_width = block_width * wgpu::COPY_BYTES_PER_ROW_ALIGNMENT; + let rounded_height = block_height * wgpu::COPY_BYTES_PER_ROW_ALIGNMENT; let is_compressed_or_depth_stencil_format = format.is_compressed() || format.is_depth_stencil_format(); + let is_bcn_format = TEXTURE_FORMATS_BC.contains(&format); let supports_1d = !is_compressed_or_depth_stencil_format; - let supports_3d = !format.is_depth_stencil_format(); + let supports_3d = is_bcn_format || !format.is_depth_stencil_format(); // 1D texture if supports_1d { @@ -323,6 +316,14 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu .await; if supports_3d { // volume texture + let rounded_width = wgpu::util::align_to( + (block_width + 1) + * format + .block_copy_size(Some(wgpu::TextureAspect::All)) + .unwrap(), + wgpu::COPY_BYTES_PER_ROW_ALIGNMENT, + ) / block_width; + let rounded_height = 1; single_texture_clear_test( &ctx, format, @@ -394,6 +395,10 @@ static CLEAR_TEXTURE_COMPRESSED_BCN: GpuTestConfiguration = GpuTestConfiguration .parameters( TestParameters::default() .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_BC) + .limits(wgpu::Limits { + max_texture_dimension_3d: 1024, + ..wgpu::Limits::downlevel_defaults() + }) // https://bugs.chromium.org/p/angleproject/issues/detail?id=7056 .expect_fail(FailureCase::backend_adapter(wgpu::Backends::GL, "ANGLE")) // compressed texture copy to buffer not yet implemented From 42b202d60bac0de03c26cbd0a41d2983bef250d3 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Fri, 31 May 2024 03:45:55 +0900 Subject: [PATCH 05/12] Please see https://github.com/gpuweb/gpuweb/pull/4685 --- tests/tests/clear_texture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 63311f16de..88b6e46c89 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -274,7 +274,7 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu format.is_compressed() || format.is_depth_stencil_format(); let is_bcn_format = TEXTURE_FORMATS_BC.contains(&format); let supports_1d = !is_compressed_or_depth_stencil_format; - let supports_3d = is_bcn_format || !format.is_depth_stencil_format(); + let supports_3d = is_bcn_format || !is_compressed_or_depth_stencil_format; // 1D texture if supports_1d { From d9e4d738bb90f004ac4acfcf2ca1f755958fcf18 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Fri, 31 May 2024 03:55:23 +0900 Subject: [PATCH 06/12] Please see https://github.com/gpuweb/gpuweb/pull/4685 --- tests/tests/clear_texture.rs | 11 +---------- wgpu-core/src/device/resource.rs | 8 ++++++++ wgpu-types/src/lib.rs | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 88b6e46c89..208cc4a896 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -272,9 +272,8 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu let is_compressed_or_depth_stencil_format = format.is_compressed() || format.is_depth_stencil_format(); - let is_bcn_format = TEXTURE_FORMATS_BC.contains(&format); let supports_1d = !is_compressed_or_depth_stencil_format; - let supports_3d = is_bcn_format || !is_compressed_or_depth_stencil_format; + let supports_3d = format.is_bcn() || !is_compressed_or_depth_stencil_format; // 1D texture if supports_1d { @@ -316,14 +315,6 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu .await; if supports_3d { // volume texture - let rounded_width = wgpu::util::align_to( - (block_width + 1) - * format - .block_copy_size(Some(wgpu::TextureAspect::All)) - .unwrap(), - wgpu::COPY_BYTES_PER_ROW_ALIGNMENT, - ) / block_width; - let rounded_height = 1; single_texture_clear_test( &ctx, format, diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index b3200b51d3..9ce005f035 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -791,6 +791,14 @@ impl Device { }, )); } + + // Only BCn formats are supported for 3D textures + if desc.dimension == wgt::TextureDimension::D3 && !desc.format.is_bcn() { + return Err(CreateTextureError::InvalidCompressedDimension( + desc.dimension, + desc.format, + )); + } } { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 943d8eb75c..ebb43bcf08 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -3153,6 +3153,27 @@ impl TextureFormat { self.block_dimensions() != (1, 1) } + /// Returns `true` for BCn compressed formats. + pub fn is_bcn(&self) -> bool { + match *self { + Self::Bc1RgbaUnorm + | Self::Bc1RgbaUnormSrgb + | Self::Bc2RgbaUnorm + | Self::Bc2RgbaUnormSrgb + | Self::Bc3RgbaUnorm + | Self::Bc3RgbaUnormSrgb + | Self::Bc4RUnorm + | Self::Bc4RSnorm + | Self::Bc5RgUnorm + | Self::Bc5RgSnorm + | Self::Bc6hRgbUfloat + | Self::Bc6hRgbFloat + | Self::Bc7RgbaUnorm + | Self::Bc7RgbaUnormSrgb => true, + _ => false, + } + } + /// Returns the required features (if any) in order to use the texture. pub fn required_features(&self) -> Features { match *self { From a7ebdf26c3c3785a88c29d0e97578118e1b07747 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Sat, 1 Jun 2024 02:06:40 +0900 Subject: [PATCH 07/12] Update lib.rs Co-authored-by: Teodor Tanasoaia <28601907+teoxoy@users.noreply.github.com> --- wgpu-types/src/lib.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index ebb43bcf08..06894b37ce 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -3155,23 +3155,7 @@ impl TextureFormat { /// Returns `true` for BCn compressed formats. pub fn is_bcn(&self) -> bool { - match *self { - Self::Bc1RgbaUnorm - | Self::Bc1RgbaUnormSrgb - | Self::Bc2RgbaUnorm - | Self::Bc2RgbaUnormSrgb - | Self::Bc3RgbaUnorm - | Self::Bc3RgbaUnormSrgb - | Self::Bc4RUnorm - | Self::Bc4RSnorm - | Self::Bc5RgUnorm - | Self::Bc5RgSnorm - | Self::Bc6hRgbUfloat - | Self::Bc6hRgbFloat - | Self::Bc7RgbaUnorm - | Self::Bc7RgbaUnormSrgb => true, - _ => false, - } + self.required_features() == Features::TEXTURE_COMPRESSION_BC } /// Returns the required features (if any) in order to use the texture. From 237c1b7adb65f2d83ac4601c35cdde86cd3e925f Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Tue, 30 Jul 2024 20:03:22 +0900 Subject: [PATCH 08/12] Move into extension --- deno_webgpu/01_webgpu.js | 1 + deno_webgpu/lib.rs | 7 +++++ deno_webgpu/webgpu.idl | 1 + tests/tests/clear_texture.rs | 6 +++- wgpu-core/src/device/resource.rs | 17 ++++++---- wgpu-hal/src/dx12/adapter.rs | 1 + wgpu-hal/src/gles/adapter.rs | 4 +++ wgpu-hal/src/metal/adapter.rs | 1 + wgpu-hal/src/vulkan/adapter.rs | 5 +++ wgpu-types/src/lib.rs | 31 +++++++++++++++++++ wgpu/src/backend/webgpu.rs | 4 +++ .../webgpu/webgpu_sys/gen_GpuFeatureName.rs | 1 + 12 files changed, 72 insertions(+), 7 deletions(-) diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index f226c8ab5f..b5bf0afc7a 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -5071,6 +5071,7 @@ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter( // texture formats "depth32float-stencil8", "texture-compression-bc", + "texture-compression-bc-sliced-3d", "texture-compression-etc2", "texture-compression-astc", "rg11b10ufloat-renderable", diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index aafb225fb9..30ff9e2edd 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -248,6 +248,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> { if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_BC) { return_features.push("texture-compression-bc"); } + if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_BC_SLICED_3D) { + return_features.push("texture-compression-bc-sliced-3d"); + } if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ETC2) { return_features.push("texture-compression-etc2"); } @@ -491,6 +494,10 @@ impl From for wgpu_types::Features { wgpu_types::Features::TEXTURE_COMPRESSION_BC, required_features.0.contains("texture-compression-bc"), ); + features.set( + wgpu_types::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, + required_features.0.contains("texture-compression-bc-sliced-3d"), + ); features.set( wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, required_features.0.contains("texture-compression-etc2"), diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index 07d9d60ec7..41949feb1f 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -97,6 +97,7 @@ enum GPUFeatureName { // texture formats "depth32float-stencil8", "texture-compression-bc", + "texture-compression-bc-sliced-3d", "texture-compression-etc2", "texture-compression-astc", // api diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 208cc4a896..5e7d86ed88 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -385,7 +385,11 @@ static CLEAR_TEXTURE_DEPTH32_STENCIL8: GpuTestConfiguration = GpuTestConfigurati static CLEAR_TEXTURE_COMPRESSED_BCN: GpuTestConfiguration = GpuTestConfiguration::new() .parameters( TestParameters::default() - .features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_BC) + .features( + wgpu::Features::CLEAR_TEXTURE + | wgpu::Features::TEXTURE_COMPRESSION_BC + | wgpu::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, + ) .limits(wgpu::Limits { max_texture_dimension_3d: 1024, ..wgpu::Limits::downlevel_defaults() diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 84c8779e96..2b664b295a 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -771,12 +771,17 @@ impl Device { )); } - // Only BCn formats are supported for 3D textures - if desc.dimension == wgt::TextureDimension::D3 && !desc.format.is_bcn() { - return Err(CreateTextureError::InvalidCompressedDimension( - desc.dimension, - desc.format, - )); + if desc.dimension == wgt::TextureDimension::D3 { + // Only BCn formats with Sliced 3D feature can be used for 3D textures + if desc.format.is_bcn() { + self.require_features(wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D) + .map_err(|error| CreateTextureError::MissingFeatures(desc.format, error))?; + } else { + return Err(CreateTextureError::InvalidCompressedDimension( + desc.dimension, + desc.format, + )); + } } } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index cb2636611b..72b9d04b71 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -299,6 +299,7 @@ impl super::Adapter { | wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS | wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES | wgt::Features::TEXTURE_COMPRESSION_BC + | wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D | wgt::Features::CLEAR_TEXTURE | wgt::Features::TEXTURE_FORMAT_16BIT_NORM | wgt::Features::PUSH_CONSTANTS diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 1cda99b338..bd2410e273 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -503,6 +503,10 @@ impl super::Adapter { wgt::Features::TEXTURE_COMPRESSION_BC, bcn_exts.iter().all(|&ext| extensions.contains(ext)), ); + features.set( + wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, + bcn_exts.iter().all(|&ext| extensions.contains(ext)), // BC guaranteed Sliced 3D + ); let has_etc = if cfg!(any(webgl, Emscripten)) { extensions.contains("WEBGL_compressed_texture_etc") } else { diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 924902517f..7e0043790c 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -876,6 +876,7 @@ impl super::PrivateCapabilities { features.set(F::TEXTURE_COMPRESSION_ASTC, self.format_astc); features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr); features.set(F::TEXTURE_COMPRESSION_BC, self.format_bc); + features.set(F::TEXTURE_COMPRESSION_BC_SLICED_3D, self.format_bc); // BC guarantees Sliced 3D features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc); features.set(F::DEPTH_CLIP_CONTROL, self.supports_depth_clip_control); diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 215c0dd958..22b897f09b 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -253,6 +253,7 @@ impl PhysicalDeviceFeatures { ) .texture_compression_bc( requested_features.contains(wgt::Features::TEXTURE_COMPRESSION_BC), + // BC provides formats for Sliced 3D ) //.occlusion_query_precise(requested_features.contains(wgt::Features::PRECISE_OCCLUSION_QUERY)) .pipeline_statistics_query( @@ -539,6 +540,10 @@ impl PhysicalDeviceFeatures { F::TEXTURE_COMPRESSION_BC, self.core.texture_compression_bc != 0, ); + features.set( + F::TEXTURE_COMPRESSION_BC_SLICED_3D, + self.core.texture_compression_bc != 0, // BC guarantees Sliced 3D + ); features.set( F::PIPELINE_STATISTICS_QUERY, self.core.pipeline_statistics_query != 0, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 2e31e3f975..0ff537abeb 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -290,12 +290,28 @@ bitflags::bitflags! { /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for BCn formats. /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages. /// + /// This feature guarantees availability of sliced-3d textures for BC formats when combined with TEXTURE_COMPRESSION_BC_SLICED_3D. + /// /// Supported Platforms: /// - desktops + /// - Mobile (All Apple9 and some Apple7 and Apple8 devices) /// /// This is a web and native feature. const TEXTURE_COMPRESSION_BC = 1 << 2; + + /// Allows the 3d dimension for textures with BC compressed formats. + /// + /// This feature must be used in combination with TEXTURE_COMPRESSION_BC to enable 3D textures with BC compression. + /// It does not enable the BC formats by itself. + /// + /// Supported Platforms: + /// - desktops + /// - Mobile (All Apple9 and some Apple7 and Apple8 devices) + /// + /// This is a web and native feature. + const TEXTURE_COMPRESSION_BC_SLICED_3D = 1 << 11; + /// Enables ETC family of compressed textures. All ETC textures use 4x4 pixel blocks. /// ETC2 RGB and RGBA1 are 8 bytes per block. RTC2 RGBA8 and EAC are 16 bytes per block. /// @@ -2560,12 +2576,14 @@ pub enum TextureFormat { NV12, // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. + // `TEXTURE_COMPRESSION_SLICED_3D` is required for usage with 3D textures. /// 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. /// [0, 63] ([0, 1] for alpha) converted to/from float [0, 1] in shader. /// /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc1RgbaUnorm, /// 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. /// Srgb-color [0, 63] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -2573,6 +2591,7 @@ pub enum TextureFormat { /// Also known as DXT1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc1RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// [0, 63] ([0, 15] for alpha) converted to/from float [0, 1] in shader. @@ -2580,6 +2599,7 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc2RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet. 5 bit R + 6 bit G + 5 bit B + 4 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -2587,6 +2607,7 @@ pub enum TextureFormat { /// Also known as DXT3. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc2RgbaUnormSrgb, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// [0, 63] ([0, 255] for alpha) converted to/from float [0, 1] in shader. @@ -2594,6 +2615,7 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc3RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 4 color pallet + 8 alpha pallet. 5 bit R + 6 bit G + 5 bit B + 8 bit alpha. /// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader. @@ -2601,6 +2623,7 @@ pub enum TextureFormat { /// Also known as DXT5. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc3RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2608,6 +2631,7 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc4RUnorm, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -2615,6 +2639,7 @@ pub enum TextureFormat { /// Also known as RGTC1. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc4RSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2622,6 +2647,7 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc5RgUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG. /// [-127, 127] converted to/from float [-1, 1] in shader. @@ -2629,18 +2655,21 @@ pub enum TextureFormat { /// Also known as RGTC2. /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc5RgSnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit unsigned float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc6hRgbUfloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit signed float RGB. Float in shader. /// /// Also known as BPTC (float). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc6hRgbFloat, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// [0, 255] converted to/from float [0, 1] in shader. @@ -2648,6 +2677,7 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc7RgbaUnorm, /// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA. /// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader. @@ -2655,6 +2685,7 @@ pub enum TextureFormat { /// Also known as BPTC (unorm). /// /// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format. + /// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension. Bc7RgbaUnormSrgb, /// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB. /// [0, 255] converted to/from float [0, 1] in shader. diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 573db58a83..32c8d3516f 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -740,6 +740,10 @@ const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 11] = [ wgt::Features::TEXTURE_COMPRESSION_BC, webgpu_sys::GpuFeatureName::TextureCompressionBc, ), + ( + wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, + webgpu_sys::GpuFeatureName::TextureCompressionBcSliced3d, + ), ( wgt::Features::TEXTURE_COMPRESSION_ETC2, webgpu_sys::GpuFeatureName::TextureCompressionEtc2, diff --git a/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs b/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs index ed39a14c51..ef2119a88b 100644 --- a/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs +++ b/wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs @@ -21,6 +21,7 @@ pub enum GpuFeatureName { DepthClipControl = "depth-clip-control", Depth32floatStencil8 = "depth32float-stencil8", TextureCompressionBc = "texture-compression-bc", + TextureCompressionBcSliced3d = "texture-compression-bc-sliced-3d", TextureCompressionEtc2 = "texture-compression-etc2", TextureCompressionAstc = "texture-compression-astc", TimestampQuery = "timestamp-query", From c76dc29f1f4a097ccbf3c1b095e34adfcd58f294 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Tue, 30 Jul 2024 20:06:41 +0900 Subject: [PATCH 09/12] Format deno directory --- deno_webgpu/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/deno_webgpu/lib.rs b/deno_webgpu/lib.rs index 30ff9e2edd..c1822ee2bc 100644 --- a/deno_webgpu/lib.rs +++ b/deno_webgpu/lib.rs @@ -496,7 +496,9 @@ impl From for wgpu_types::Features { ); features.set( wgpu_types::Features::TEXTURE_COMPRESSION_BC_SLICED_3D, - required_features.0.contains("texture-compression-bc-sliced-3d"), + required_features + .0 + .contains("texture-compression-bc-sliced-3d"), ); features.set( wgpu_types::Features::TEXTURE_COMPRESSION_ETC2, From a747de8be67006b148914825844b71918cb25e21 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Tue, 30 Jul 2024 20:08:34 +0900 Subject: [PATCH 10/12] WASM Clippy Fix --- wgpu/src/backend/webgpu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 32c8d3516f..d008093132 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -726,7 +726,7 @@ fn map_map_mode(mode: crate::MapMode) -> u32 { } } -const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 11] = [ +const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 12] = [ //TODO: update the name ( wgt::Features::DEPTH_CLIP_CONTROL, From 1fd2ddf8aff1b7464f461775db6b9b85a55e396f Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Tue, 30 Jul 2024 20:37:40 +0900 Subject: [PATCH 11/12] Make comments single line --- wgpu-types/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 0ff537abeb..6b327df246 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2575,8 +2575,7 @@ pub enum TextureFormat { /// [`Features::TEXTURE_FORMAT_NV12`] must be enabled to use this texture format. NV12, - // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. - // `TEXTURE_COMPRESSION_SLICED_3D` is required for usage with 3D textures. + // Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. `TEXTURE_COMPRESSION_SLICED_3D` is required to use with 3D textures. /// 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. /// [0, 63] ([0, 1] for alpha) converted to/from float [0, 1] in shader. /// From e690729c4497a0eebfb527901fa7b4a0bc89ce29 Mon Sep 17 00:00:00 2001 From: Mehmet Oguz Derin Date: Sat, 10 Aug 2024 06:33:29 +0900 Subject: [PATCH 12/12] Update command and flag in order --- wgpu-types/src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a9da2b77e1..6cf007e2f9 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -310,7 +310,7 @@ bitflags::bitflags! { /// - Mobile (All Apple9 and some Apple7 and Apple8 devices) /// /// This is a web and native feature. - const TEXTURE_COMPRESSION_BC_SLICED_3D = 1 << 11; + const TEXTURE_COMPRESSION_BC_SLICED_3D = 1 << 3; /// Enables ETC family of compressed textures. All ETC textures use 4x4 pixel blocks. /// ETC2 RGB and RGBA1 are 8 bytes per block. RTC2 RGBA8 and EAC are 16 bytes per block. @@ -326,7 +326,7 @@ bitflags::bitflags! { /// - Mobile (some) /// /// This is a web and native feature. - const TEXTURE_COMPRESSION_ETC2 = 1 << 3; + const TEXTURE_COMPRESSION_ETC2 = 1 << 4; /// Enables ASTC family of compressed textures. ASTC textures use pixel blocks varying from 4x4 to 12x12. /// Blocks are always 16 bytes. @@ -342,7 +342,7 @@ bitflags::bitflags! { /// - Mobile (some) /// /// This is a web and native feature. - const TEXTURE_COMPRESSION_ASTC = 1 << 4; + const TEXTURE_COMPRESSION_ASTC = 1 << 5; /// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when /// all work before the query is finished. @@ -366,7 +366,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const TIMESTAMP_QUERY = 1 << 5; + const TIMESTAMP_QUERY = 1 << 6; /// Allows non-zero value for the `first_instance` member in indirect draw calls. /// @@ -385,7 +385,7 @@ bitflags::bitflags! { /// - OpenGL ES / WebGL /// /// This is a web and native feature. - const INDIRECT_FIRST_INSTANCE = 1 << 6; + const INDIRECT_FIRST_INSTANCE = 1 << 7; /// Allows shaders to acquire the FP16 ability /// @@ -396,7 +396,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const SHADER_F16 = 1 << 7; + const SHADER_F16 = 1 << 8; /// Allows for usage of textures of format [`TextureFormat::Rg11b10Float`] as a render target @@ -407,7 +407,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const RG11B10UFLOAT_RENDERABLE = 1 << 8; + const RG11B10UFLOAT_RENDERABLE = 1 << 9; /// Allows the [`wgpu::TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8unorm`] /// @@ -417,7 +417,7 @@ bitflags::bitflags! { /// - Metal /// /// This is a web and native feature. - const BGRA8UNORM_STORAGE = 1 << 9; + const BGRA8UNORM_STORAGE = 1 << 10; /// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be filterable. @@ -429,9 +429,9 @@ bitflags::bitflags! { /// - GL with one of `GL_ARB_color_buffer_float`/`GL_EXT_color_buffer_float`/`OES_texture_float_linear` /// /// This is a web and native feature. - const FLOAT32_FILTERABLE = 1 << 10; + const FLOAT32_FILTERABLE = 1 << 11; - // Bits 11-19 available for webgpu features. Should you chose to use some of them for + // Bits 12-19 available for webgpu features. Should you chose to use some of them for // for native features, don't forget to update `all_webgpu_mask` and `all_native_mask` // accordingly.