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 9 commits into
base: trunk
Choose a base branch
from
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Bottom level categories:

#### Naga

### Bux Fixes
### Bug Fixes

#### Naga

Expand All @@ -63,6 +63,7 @@ Naga now infers the correct binding layout when a resource appears only in an as

#### General

- Add support for the astc-slice-3d feature. By @mehmetoguzderin in [#7577](https://github.com/gfx-rs/wgpu/issues/7577)
- Removed `MaintainBase` in favor of using `PollType`. By @waywardmonkeys in [#7508](https://github.com/gfx-rs/wgpu/pull/7508).

#### 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 @@ -978,6 +978,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
1 change: 1 addition & 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);
}
if context
.glow_context
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 @@ -665,6 +665,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 @@ -222,6 +222,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 @@ -716,6 +716,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 @@ -2607,6 +2614,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
30 changes: 23 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 @@ -1301,6 +1304,19 @@ 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:
/// - Desktop (some)
/// - Mobile (some)
///
/// 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 @@ -2720,6 +2720,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
Loading