Skip to content

Support Sliced 3D for ASTC #7577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d2e6e60
Support Sliced 3D for ASTC
mehmetoguzderin Apr 19, 2025
4c697aa
Changelog
mehmetoguzderin Apr 19, 2025
ab7afd9
Cover in `deno_webgpu`
mehmetoguzderin Apr 19, 2025
54e2285
Match length for WASM
mehmetoguzderin Apr 19, 2025
2ad3a26
Fix spelling of enum
mehmetoguzderin Apr 19, 2025
6049d53
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 21, 2025
bb8ed59
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 21, 2025
030b337
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 22, 2025
a13e28a
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 23, 2025
be727bd
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 23, 2025
77c8cb3
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 24, 2025
bd99a7e
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 25, 2025
b334e43
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 27, 2025
dc52d75
Update wgpu-types/src/features.rs
mehmetoguzderin Apr 27, 2025
63798c5
Adjust support for ASTC sliced 3D
mehmetoguzderin Apr 27, 2025
f8ae95a
Update ASTC sliced 3D feature check to require both base and sliced e…
mehmetoguzderin Apr 28, 2025
a67d683
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 28, 2025
5a430bd
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 29, 2025
eee9822
Merge branch 'trunk' into oguz-20250419-astc-sliced-3d
mehmetoguzderin Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions deno_webgpu/webidl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -451,6 +453,7 @@ pub fn feature_names_to_features(names: Vec<GPUFeatureName>) -> 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,
Expand Down Expand Up @@ -529,6 +532,9 @@ pub fn features_to_feature_names(features: wgpu_types::Features) -> HashSet<GPUF
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC) {
return_features.insert(TextureCompressionAstc);
}
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D) {
return_features.insert(TextureCompressionAstcSliced3d);
}
if features.contains(wgpu_types::Features::RG11B10UFLOAT_RENDERABLE) {
return_features.insert(Rg11b10ufloatRenderable);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/tests/wgpu-gpu/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,14 @@ static CLEAR_TEXTURE_COMPRESSED_BCN: GpuTestConfiguration = GpuTestConfiguration
static CLEAR_TEXTURE_COMPRESSED_ASTC: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(
TestParameters::default()
.features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_ASTC)
.features(
wgpu::Features::CLEAR_TEXTURE
| wgpu::Features::TEXTURE_COMPRESSION_ASTC
| wgpu::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D,
)
.limits(wgpu::Limits {
max_texture_dimension_2d: wgpu::COPY_BYTES_PER_ROW_ALIGNMENT * 12,
max_texture_dimension_3d: wgpu::COPY_BYTES_PER_ROW_ALIGNMENT * 12,
..wgpu::Limits::downlevel_defaults()
})
// https://bugs.chromium.org/p/angleproject/issues/detail?id=7056
Expand Down
3 changes: 3 additions & 0 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,9 @@ impl Device {
if desc.format.is_bcn() {
self.require_features(wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D)
.map_err(|error| CreateTextureError::MissingFeatures(desc.format, error))?;
} else if desc.format.is_astc() {
self.require_features(wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D)
.map_err(|error| CreateTextureError::MissingFeatures(desc.format, error))?;
} else {
return Err(CreateTextureError::InvalidCompressedDimension(
desc.dimension,
Expand Down
7 changes: 7 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ impl super::Adapter {
.compressed_texture_astc_supports_ldr_profile()
{
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC);
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused about the extension zoo here tbh. So apparently [WEBGL_compressed_texture_astc])https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/) implies all of KHR_texture_compression_astc_hdr, which in turn says It includes support for 2D and slice-based 3D textures, with low and high dynamic range, at bitrates from below 1 bit/pixel up to 8 bits/pixel in fine steps.
Which kinda implies that for webgl, either profile should imply sliced 3d.

The else block (native gl) should then instead check for GL_KHR_texture_compression_astc_sliced_3d to activate the feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wumpf good one, I missed the native GL block. I tried to address in latest commit! PLMK if it helps sufficiently.

}
if context
.glow_context
Expand All @@ -543,13 +544,19 @@ impl super::Adapter {
#[cfg(any(native, Emscripten))]
{
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC);
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D);
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR);
}
} else {
features.set(
wgt::Features::TEXTURE_COMPRESSION_ASTC,
extensions.contains("GL_KHR_texture_compression_astc_ldr"),
);
features.set(
wgt::Features::TEXTURE_COMPRESSION_ASTC_SLICED_3D,
extensions.contains("GL_KHR_texture_compression_astc_ldr")
&& extensions.contains("GL_KHR_texture_compression_astc_sliced_3d"),
);
features.set(
wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR,
extensions.contains("GL_KHR_texture_compression_astc_hdr"),
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ impl super::PrivateCapabilities {
|| Self::supports_any(device, ASTC_PIXEL_FORMAT_FEATURES),
// A13(Apple6) M1(Apple7) and later always support HDR ASTC pixel formats
format_astc_hdr: family_check && device.supports_family(MTLGPUFamily::Apple6),
// Apple3 and later supports compressed volume texture formats including ASTC Sliced 3D
format_astc_3d: family_check && device.supports_family(MTLGPUFamily::Apple3),
format_any8_unorm_srgb_all: Self::supports_any(device, ANY8_UNORM_SRGB_ALL),
format_any8_unorm_srgb_no_write: !Self::supports_any(device, ANY8_UNORM_SRGB_ALL)
&& !os_is_mac,
Expand Down Expand Up @@ -938,6 +940,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_ASTC_SLICED_3D, self.format_astc_3d);
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);
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ struct PrivateCapabilities {
format_eac_etc: bool,
format_astc: bool,
format_astc_hdr: bool,
format_astc_3d: bool,
format_any8_unorm_srgb_all: bool,
format_any8_unorm_srgb_no_write: bool,
format_any8_snorm_all: bool,
Expand Down
61 changes: 61 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,13 @@ impl PhysicalDeviceFeatures {
);
}

if self.core.texture_compression_astc_ldr != 0 {
features.set(
F::TEXTURE_COMPRESSION_ASTC_SLICED_3D,
supports_astc_3d(instance, phd),
);
}

if let Some((ref f16_i8, ref bit16)) = self.shader_float16 {
features.set(
F::SHADER_F16,
Expand Down Expand Up @@ -2604,6 +2611,60 @@ fn supports_format(
}
}

fn supports_astc_3d(instance: &ash::Instance, phd: vk::PhysicalDevice) -> 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,
Expand Down
37 changes: 30 additions & 7 deletions wgpu-types/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1294,13 +1297,33 @@ 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)
///
/// 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.
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to mention on the above feature that volume textures aren't included unless TEXTURE_COMPRESSION_ASTC_SLICED_3D is enabled.

Wondering what to do with the non-webgpu _HDR variant, seems a bit underspeced 🤔. I'm fine with ignoring that for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wumpf makes sense, does the new commit look sufficient?

/// 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.
///
Expand Down
7 changes: 7 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down