Support texture-compression-bc-sliced-3d in wgpu (#5751)

This commit is contained in:
Mehmet Oguz Derin 2024-08-10 19:02:29 +09:00 committed by GitHub
parent f6a3eef77e
commit 34b0df277c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 101 additions and 14 deletions

View File

@ -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",

View File

@ -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,12 @@ impl From<GpuRequiredFeatures> 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"),

View File

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

View File

@ -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_bcn() || !is_compressed_or_depth_stencil_format;
// 1D texture
if supports_1d {
@ -385,7 +385,15 @@ 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()
})
// 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

View File

@ -745,8 +745,12 @@ impl<A: HalApi> Device<A> {
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,
@ -777,6 +781,19 @@ impl<A: HalApi> Device<A> {
},
));
}
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,
));
}
}
}
{

View File

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

View File

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

View File

@ -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);

View File

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

View File

@ -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 << 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.
///
@ -310,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.
@ -326,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.
@ -350,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.
///
@ -369,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
///
@ -380,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
@ -391,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`]
///
@ -401,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.
@ -413,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.
@ -2562,13 +2578,14 @@ pub enum TextureFormat {
/// [`Features::TEXTURE_FORMAT_NV12`] must be enabled to use this texture format.
NV12,
// Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature.
// 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.
///
/// 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.
@ -2576,6 +2593,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.
@ -2583,6 +2601,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.
@ -2590,6 +2609,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.
@ -2597,6 +2617,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.
@ -2604,6 +2625,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.
@ -2611,6 +2633,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.
@ -2618,6 +2641,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.
@ -2625,6 +2649,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.
@ -2632,18 +2657,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.
@ -2651,6 +2679,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.
@ -2658,6 +2687,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.
@ -3201,6 +3231,11 @@ impl TextureFormat {
self.block_dimensions() != (1, 1)
}
/// Returns `true` for BCn compressed formats.
pub fn is_bcn(&self) -> bool {
self.required_features() == Features::TEXTURE_COMPRESSION_BC
}
/// Returns the required features (if any) in order to use the texture.
pub fn required_features(&self) -> Features {
match *self {

View File

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

View File

@ -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",