diff --git a/CHANGELOG.md b/CHANGELOG.md index b92c3f02df..951238009a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Bottom level categories: #### General +- Add support for astc-sliced-3d feature. By @mehmetoguzderin in [#7577](https://github.com/gfx-rs/wgpu/issues/7577) - Add support for rendering to slices of 3D texture views and single layered 2D-Array texture views (this requires `VK_KHR_maintenance1` which should be widely available on newer drivers). By @teoxoy in [#7596](https://github.com/gfx-rs/wgpu/pull/7596) #### Naga diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index df2aef498f..cb4fff5965 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -99,6 +99,7 @@ enum GPUFeatureName { "texture-compression-bc-sliced-3d", "texture-compression-etc2", "texture-compression-astc", + "texture-compression-astc-sliced-3d", "timestamp-query", "indirect-first-instance", "shader-f16", diff --git a/deno_webgpu/webidl.rs b/deno_webgpu/webidl.rs index 97476a7ac3..dcc58aaff5 100644 --- a/deno_webgpu/webidl.rs +++ b/deno_webgpu/webidl.rs @@ -359,6 +359,8 @@ pub enum GPUFeatureName { TextureCompressionEtc2, #[webidl(rename = "texture-compression-astc")] TextureCompressionAstc, + #[webidl(rename = "texture-compression-astc-sliced-3d")] + TextureCompressionAstcSliced3d, #[webidl(rename = "rg11b10ufloat-renderable")] Rg11b10ufloatRenderable, #[webidl(rename = "bgra8unorm-storage")] @@ -451,6 +453,7 @@ pub fn feature_names_to_features(names: Vec) -> wgpu_types::Feat GPUFeatureName::TextureCompressionBcSliced3d => Features::TEXTURE_COMPRESSION_BC_SLICED_3D, GPUFeatureName::TextureCompressionEtc2 => Features::TEXTURE_COMPRESSION_ETC2, GPUFeatureName::TextureCompressionAstc => Features::TEXTURE_COMPRESSION_ASTC, + GPUFeatureName::TextureCompressionAstcSliced3d => Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D, GPUFeatureName::Rg11b10ufloatRenderable => Features::RG11B10UFLOAT_RENDERABLE, GPUFeatureName::Bgra8unormStorage => Features::BGRA8UNORM_STORAGE, GPUFeatureName::Float32Filterable => Features::FLOAT32_FILTERABLE, @@ -529,6 +532,9 @@ pub fn features_to_feature_names(features: wgpu_types::Features) -> HashSet bool { + let mut supports = true; + + let astc_formats = [ + vk::Format::ASTC_4X4_UNORM_BLOCK, + vk::Format::ASTC_4X4_SRGB_BLOCK, + vk::Format::ASTC_5X4_UNORM_BLOCK, + vk::Format::ASTC_5X4_SRGB_BLOCK, + vk::Format::ASTC_5X5_UNORM_BLOCK, + vk::Format::ASTC_5X5_SRGB_BLOCK, + vk::Format::ASTC_6X5_UNORM_BLOCK, + vk::Format::ASTC_6X5_SRGB_BLOCK, + vk::Format::ASTC_6X6_UNORM_BLOCK, + vk::Format::ASTC_6X6_SRGB_BLOCK, + vk::Format::ASTC_8X5_UNORM_BLOCK, + vk::Format::ASTC_8X5_SRGB_BLOCK, + vk::Format::ASTC_8X6_UNORM_BLOCK, + vk::Format::ASTC_8X6_SRGB_BLOCK, + vk::Format::ASTC_8X8_UNORM_BLOCK, + vk::Format::ASTC_8X8_SRGB_BLOCK, + vk::Format::ASTC_10X5_UNORM_BLOCK, + vk::Format::ASTC_10X5_SRGB_BLOCK, + vk::Format::ASTC_10X6_UNORM_BLOCK, + vk::Format::ASTC_10X6_SRGB_BLOCK, + vk::Format::ASTC_10X8_UNORM_BLOCK, + vk::Format::ASTC_10X8_SRGB_BLOCK, + vk::Format::ASTC_10X10_UNORM_BLOCK, + vk::Format::ASTC_10X10_SRGB_BLOCK, + vk::Format::ASTC_12X10_UNORM_BLOCK, + vk::Format::ASTC_12X10_SRGB_BLOCK, + vk::Format::ASTC_12X12_UNORM_BLOCK, + vk::Format::ASTC_12X12_SRGB_BLOCK, + ]; + + for &format in &astc_formats { + let result = unsafe { + instance.get_physical_device_image_format_properties( + phd, + format, + vk::ImageType::TYPE_3D, + vk::ImageTiling::OPTIMAL, + vk::ImageUsageFlags::SAMPLED, + vk::ImageCreateFlags::empty(), + ) + }; + if result.is_err() { + supports = false; + break; + } + } + + supports +} + fn supports_bgra8unorm_storage( instance: &ash::Instance, phd: vk::PhysicalDevice, diff --git a/wgpu-types/src/features.rs b/wgpu-types/src/features.rs index a3bd0498e1..e99e77f809 100644 --- a/wgpu-types/src/features.rs +++ b/wgpu-types/src/features.rs @@ -37,25 +37,28 @@ mod webgpu_impl { pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC: u64 = 1 << 5; #[doc(hidden)] - pub const WEBGPU_FEATURE_TIMESTAMP_QUERY: u64 = 1 << 6; + pub const WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC_SLICED_3D: u64 = 1 << 6; #[doc(hidden)] - pub const WEBGPU_FEATURE_INDIRECT_FIRST_INSTANCE: u64 = 1 << 7; + pub const WEBGPU_FEATURE_TIMESTAMP_QUERY: u64 = 1 << 7; #[doc(hidden)] - pub const WEBGPU_FEATURE_SHADER_F16: u64 = 1 << 8; + pub const WEBGPU_FEATURE_INDIRECT_FIRST_INSTANCE: u64 = 1 << 8; #[doc(hidden)] - pub const WEBGPU_FEATURE_RG11B10UFLOAT_RENDERABLE: u64 = 1 << 9; + pub const WEBGPU_FEATURE_SHADER_F16: u64 = 1 << 9; #[doc(hidden)] - pub const WEBGPU_FEATURE_BGRA8UNORM_STORAGE: u64 = 1 << 10; + pub const WEBGPU_FEATURE_RG11B10UFLOAT_RENDERABLE: u64 = 1 << 10; #[doc(hidden)] - pub const WEBGPU_FEATURE_FLOAT32_FILTERABLE: u64 = 1 << 11; + pub const WEBGPU_FEATURE_BGRA8UNORM_STORAGE: u64 = 1 << 11; #[doc(hidden)] - pub const WEBGPU_FEATURE_DUAL_SOURCE_BLENDING: u64 = 1 << 12; + pub const WEBGPU_FEATURE_FLOAT32_FILTERABLE: u64 = 1 << 12; + + #[doc(hidden)] + pub const WEBGPU_FEATURE_DUAL_SOURCE_BLENDING: u64 = 1 << 13; } macro_rules! bitflags_array_impl { @@ -1294,6 +1297,9 @@ bitflags_array! { /// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for ASTC formats with Unorm/UnormSrgb channel type. /// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages. /// + /// This feature does not guarantee availability of sliced 3d textures for ASTC formats. + /// If available, 3d support can be enabled by TEXTURE_COMPRESSION_ASTC_SLICED_3D feature. + /// /// Supported Platforms: /// - Vulkan on Intel /// - Mobile (some) @@ -1301,6 +1307,23 @@ bitflags_array! { /// This is a web and native feature. const TEXTURE_COMPRESSION_ASTC = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC; + + /// Allows the 3d dimension for textures with ASTC compressed formats. + /// + /// This feature must be used in combination with TEXTURE_COMPRESSION_ASTC to enable 3D textures with ASTC compression. + /// It does not enable the ASTC formats by itself. + /// + /// Supported Platforms: + /// - Vulkan (some) + /// - Metal on Apple3+ + /// - OpenGL/WebGL (some) + /// + /// Not Supported: + /// - DX12 + /// + /// This is a web and native feature. + const TEXTURE_COMPRESSION_ASTC_SLICED_3D = WEBGPU_FEATURE_TEXTURE_COMPRESSION_ASTC_SLICED_3D; + /// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when /// all work before the query is finished. /// diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 7a3907f3fb..7f53a2a1c4 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2769,6 +2769,13 @@ impl TextureFormat { self.required_features() == Features::TEXTURE_COMPRESSION_BC } + /// Returns `true` for ASTC compressed formats. + #[must_use] + pub fn is_astc(&self) -> bool { + self.required_features() == Features::TEXTURE_COMPRESSION_ASTC + || self.required_features() == Features::TEXTURE_COMPRESSION_ASTC_HDR + } + /// Returns the required features (if any) in order to use the texture. #[must_use] pub fn required_features(&self) -> Features { diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index bf074a65a3..282819e58e 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -708,7 +708,7 @@ fn map_map_mode(mode: crate::MapMode) -> u32 { } } -const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 13] = [ +const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 14] = [ ( wgt::Features::DEPTH_CLIP_CONTROL, webgpu_sys::GpuFeatureName::DepthClipControl, @@ -733,6 +733,10 @@ const FEATURES_MAPPING: [(wgt::Features, webgpu_sys::GpuFeatureName); 13] = [ wgt::Features::TEXTURE_COMPRESSION_ASTC, webgpu_sys::GpuFeatureName::TextureCompressionAstc, ), + ( + wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D, + webgpu_sys::GpuFeatureName::TextureCompressionAstcSliced3d, + ), ( wgt::Features::TIMESTAMP_QUERY, webgpu_sys::GpuFeatureName::TimestampQuery,