Support Sliced 3D for ASTC (#7577)

Enables "texture-compression-astc-sliced-3d" for backends that support ASTC (such as excluding D3D12).
This commit is contained in:
Mehmet Oguz Derin
2025-05-04 13:48:16 +03:00
committed by GitHub
parent 50eb207a77
commit 2a62299a84
12 changed files with 131 additions and 9 deletions

View File

@@ -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.
///

View File

@@ -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 {