Skip to content

Commit 34b0df2

Browse files
Support texture-compression-bc-sliced-3d in wgpu (#5751)
1 parent f6a3eef commit 34b0df2

File tree

12 files changed

+101
-14
lines changed

12 files changed

+101
-14
lines changed

deno_webgpu/01_webgpu.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5071,6 +5071,7 @@ webidl.converters["GPUFeatureName"] = webidl.createEnumConverter(
50715071
// texture formats
50725072
"depth32float-stencil8",
50735073
"texture-compression-bc",
5074+
"texture-compression-bc-sliced-3d",
50745075
"texture-compression-etc2",
50755076
"texture-compression-astc",
50765077
"rg11b10ufloat-renderable",

deno_webgpu/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
248248
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_BC) {
249249
return_features.push("texture-compression-bc");
250250
}
251+
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_BC_SLICED_3D) {
252+
return_features.push("texture-compression-bc-sliced-3d");
253+
}
251254
if features.contains(wgpu_types::Features::TEXTURE_COMPRESSION_ETC2) {
252255
return_features.push("texture-compression-etc2");
253256
}
@@ -491,6 +494,12 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
491494
wgpu_types::Features::TEXTURE_COMPRESSION_BC,
492495
required_features.0.contains("texture-compression-bc"),
493496
);
497+
features.set(
498+
wgpu_types::Features::TEXTURE_COMPRESSION_BC_SLICED_3D,
499+
required_features
500+
.0
501+
.contains("texture-compression-bc-sliced-3d"),
502+
);
494503
features.set(
495504
wgpu_types::Features::TEXTURE_COMPRESSION_ETC2,
496505
required_features.0.contains("texture-compression-etc2"),

deno_webgpu/webgpu.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ enum GPUFeatureName {
9797
// texture formats
9898
"depth32float-stencil8",
9999
"texture-compression-bc",
100+
"texture-compression-bc-sliced-3d",
100101
"texture-compression-etc2",
101102
"texture-compression-astc",
102103
// api

tests/tests/clear_texture.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async fn clear_texture_tests(ctx: TestingContext, formats: &'static [wgpu::Textu
273273
let is_compressed_or_depth_stencil_format =
274274
format.is_compressed() || format.is_depth_stencil_format();
275275
let supports_1d = !is_compressed_or_depth_stencil_format;
276-
let supports_3d = !is_compressed_or_depth_stencil_format;
276+
let supports_3d = format.is_bcn() || !is_compressed_or_depth_stencil_format;
277277

278278
// 1D texture
279279
if supports_1d {
@@ -385,7 +385,15 @@ static CLEAR_TEXTURE_DEPTH32_STENCIL8: GpuTestConfiguration = GpuTestConfigurati
385385
static CLEAR_TEXTURE_COMPRESSED_BCN: GpuTestConfiguration = GpuTestConfiguration::new()
386386
.parameters(
387387
TestParameters::default()
388-
.features(wgpu::Features::CLEAR_TEXTURE | wgpu::Features::TEXTURE_COMPRESSION_BC)
388+
.features(
389+
wgpu::Features::CLEAR_TEXTURE
390+
| wgpu::Features::TEXTURE_COMPRESSION_BC
391+
| wgpu::Features::TEXTURE_COMPRESSION_BC_SLICED_3D,
392+
)
393+
.limits(wgpu::Limits {
394+
max_texture_dimension_3d: 1024,
395+
..wgpu::Limits::downlevel_defaults()
396+
})
389397
// https://bugs.chromium.org/p/angleproject/issues/detail?id=7056
390398
.expect_fail(FailureCase::backend_adapter(wgpu::Backends::GL, "ANGLE"))
391399
// compressed texture copy to buffer not yet implemented

wgpu-core/src/device/resource.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,12 @@ impl<A: HalApi> Device<A> {
745745
desc.dimension,
746746
));
747747
}
748+
}
748749

749-
// Compressed textures can only be 2D
750+
if desc.dimension != wgt::TextureDimension::D2
751+
&& desc.dimension != wgt::TextureDimension::D3
752+
{
753+
// Compressed textures can only be 2D or 3D
750754
if desc.format.is_compressed() {
751755
return Err(CreateTextureError::InvalidCompressedDimension(
752756
desc.dimension,
@@ -777,6 +781,19 @@ impl<A: HalApi> Device<A> {
777781
},
778782
));
779783
}
784+
785+
if desc.dimension == wgt::TextureDimension::D3 {
786+
// Only BCn formats with Sliced 3D feature can be used for 3D textures
787+
if desc.format.is_bcn() {
788+
self.require_features(wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D)
789+
.map_err(|error| CreateTextureError::MissingFeatures(desc.format, error))?;
790+
} else {
791+
return Err(CreateTextureError::InvalidCompressedDimension(
792+
desc.dimension,
793+
desc.format,
794+
));
795+
}
796+
}
780797
}
781798

782799
{

wgpu-hal/src/dx12/adapter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ impl super::Adapter {
299299
| wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS
300300
| wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES
301301
| wgt::Features::TEXTURE_COMPRESSION_BC
302+
| wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D
302303
| wgt::Features::CLEAR_TEXTURE
303304
| wgt::Features::TEXTURE_FORMAT_16BIT_NORM
304305
| wgt::Features::PUSH_CONSTANTS

wgpu-hal/src/gles/adapter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ impl super::Adapter {
503503
wgt::Features::TEXTURE_COMPRESSION_BC,
504504
bcn_exts.iter().all(|&ext| extensions.contains(ext)),
505505
);
506+
features.set(
507+
wgt::Features::TEXTURE_COMPRESSION_BC_SLICED_3D,
508+
bcn_exts.iter().all(|&ext| extensions.contains(ext)), // BC guaranteed Sliced 3D
509+
);
506510
let has_etc = if cfg!(any(webgl, Emscripten)) {
507511
extensions.contains("WEBGL_compressed_texture_etc")
508512
} else {

wgpu-hal/src/metal/adapter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ impl super::PrivateCapabilities {
876876
features.set(F::TEXTURE_COMPRESSION_ASTC, self.format_astc);
877877
features.set(F::TEXTURE_COMPRESSION_ASTC_HDR, self.format_astc_hdr);
878878
features.set(F::TEXTURE_COMPRESSION_BC, self.format_bc);
879+
features.set(F::TEXTURE_COMPRESSION_BC_SLICED_3D, self.format_bc); // BC guarantees Sliced 3D
879880
features.set(F::TEXTURE_COMPRESSION_ETC2, self.format_eac_etc);
880881

881882
features.set(F::DEPTH_CLIP_CONTROL, self.supports_depth_clip_control);

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ impl PhysicalDeviceFeatures {
253253
)
254254
.texture_compression_bc(
255255
requested_features.contains(wgt::Features::TEXTURE_COMPRESSION_BC),
256+
// BC provides formats for Sliced 3D
256257
)
257258
//.occlusion_query_precise(requested_features.contains(wgt::Features::PRECISE_OCCLUSION_QUERY))
258259
.pipeline_statistics_query(
@@ -539,6 +540,10 @@ impl PhysicalDeviceFeatures {
539540
F::TEXTURE_COMPRESSION_BC,
540541
self.core.texture_compression_bc != 0,
541542
);
543+
features.set(
544+
F::TEXTURE_COMPRESSION_BC_SLICED_3D,
545+
self.core.texture_compression_bc != 0, // BC guarantees Sliced 3D
546+
);
542547
features.set(
543548
F::PIPELINE_STATISTICS_QUERY,
544549
self.core.pipeline_statistics_query != 0,

wgpu-types/src/lib.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,28 @@ bitflags::bitflags! {
290290
/// Support for this feature guarantees availability of [`TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING`] for BCn formats.
291291
/// [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] may enable additional usages.
292292
///
293+
/// This feature guarantees availability of sliced-3d textures for BC formats when combined with TEXTURE_COMPRESSION_BC_SLICED_3D.
294+
///
293295
/// Supported Platforms:
294296
/// - desktops
297+
/// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
295298
///
296299
/// This is a web and native feature.
297300
const TEXTURE_COMPRESSION_BC = 1 << 2;
298301

302+
303+
/// Allows the 3d dimension for textures with BC compressed formats.
304+
///
305+
/// This feature must be used in combination with TEXTURE_COMPRESSION_BC to enable 3D textures with BC compression.
306+
/// It does not enable the BC formats by itself.
307+
///
308+
/// Supported Platforms:
309+
/// - desktops
310+
/// - Mobile (All Apple9 and some Apple7 and Apple8 devices)
311+
///
312+
/// This is a web and native feature.
313+
const TEXTURE_COMPRESSION_BC_SLICED_3D = 1 << 3;
314+
299315
/// Enables ETC family of compressed textures. All ETC textures use 4x4 pixel blocks.
300316
/// ETC2 RGB and RGBA1 are 8 bytes per block. RTC2 RGBA8 and EAC are 16 bytes per block.
301317
///
@@ -310,7 +326,7 @@ bitflags::bitflags! {
310326
/// - Mobile (some)
311327
///
312328
/// This is a web and native feature.
313-
const TEXTURE_COMPRESSION_ETC2 = 1 << 3;
329+
const TEXTURE_COMPRESSION_ETC2 = 1 << 4;
314330

315331
/// Enables ASTC family of compressed textures. ASTC textures use pixel blocks varying from 4x4 to 12x12.
316332
/// Blocks are always 16 bytes.
@@ -326,7 +342,7 @@ bitflags::bitflags! {
326342
/// - Mobile (some)
327343
///
328344
/// This is a web and native feature.
329-
const TEXTURE_COMPRESSION_ASTC = 1 << 4;
345+
const TEXTURE_COMPRESSION_ASTC = 1 << 5;
330346

331347
/// Enables use of Timestamp Queries. These queries tell the current gpu timestamp when
332348
/// all work before the query is finished.
@@ -350,7 +366,7 @@ bitflags::bitflags! {
350366
/// - Metal
351367
///
352368
/// This is a web and native feature.
353-
const TIMESTAMP_QUERY = 1 << 5;
369+
const TIMESTAMP_QUERY = 1 << 6;
354370

355371
/// Allows non-zero value for the `first_instance` member in indirect draw calls.
356372
///
@@ -369,7 +385,7 @@ bitflags::bitflags! {
369385
/// - OpenGL ES / WebGL
370386
///
371387
/// This is a web and native feature.
372-
const INDIRECT_FIRST_INSTANCE = 1 << 6;
388+
const INDIRECT_FIRST_INSTANCE = 1 << 7;
373389

374390
/// Allows shaders to acquire the FP16 ability
375391
///
@@ -380,7 +396,7 @@ bitflags::bitflags! {
380396
/// - Metal
381397
///
382398
/// This is a web and native feature.
383-
const SHADER_F16 = 1 << 7;
399+
const SHADER_F16 = 1 << 8;
384400

385401

386402
/// Allows for usage of textures of format [`TextureFormat::Rg11b10Float`] as a render target
@@ -391,7 +407,7 @@ bitflags::bitflags! {
391407
/// - Metal
392408
///
393409
/// This is a web and native feature.
394-
const RG11B10UFLOAT_RENDERABLE = 1 << 8;
410+
const RG11B10UFLOAT_RENDERABLE = 1 << 9;
395411

396412
/// Allows the [`wgpu::TextureUsages::STORAGE_BINDING`] usage on textures with format [`TextureFormat::Bgra8unorm`]
397413
///
@@ -401,7 +417,7 @@ bitflags::bitflags! {
401417
/// - Metal
402418
///
403419
/// This is a web and native feature.
404-
const BGRA8UNORM_STORAGE = 1 << 9;
420+
const BGRA8UNORM_STORAGE = 1 << 10;
405421

406422

407423
/// Allows textures with formats "r32float", "rg32float", and "rgba32float" to be filterable.
@@ -413,9 +429,9 @@ bitflags::bitflags! {
413429
/// - GL with one of `GL_ARB_color_buffer_float`/`GL_EXT_color_buffer_float`/`OES_texture_float_linear`
414430
///
415431
/// This is a web and native feature.
416-
const FLOAT32_FILTERABLE = 1 << 10;
432+
const FLOAT32_FILTERABLE = 1 << 11;
417433

418-
// Bits 11-19 available for webgpu features. Should you chose to use some of them for
434+
// Bits 12-19 available for webgpu features. Should you chose to use some of them for
419435
// for native features, don't forget to update `all_webgpu_mask` and `all_native_mask`
420436
// accordingly.
421437

@@ -2562,102 +2578,116 @@ pub enum TextureFormat {
25622578
/// [`Features::TEXTURE_FORMAT_NV12`] must be enabled to use this texture format.
25632579
NV12,
25642580

2565-
// Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature.
2581+
// Compressed textures usable with `TEXTURE_COMPRESSION_BC` feature. `TEXTURE_COMPRESSION_SLICED_3D` is required to use with 3D textures.
25662582
/// 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.
25672583
/// [0, 63] ([0, 1] for alpha) converted to/from float [0, 1] in shader.
25682584
///
25692585
/// Also known as DXT1.
25702586
///
25712587
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2588+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
25722589
Bc1RgbaUnorm,
25732590
/// 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.
25742591
/// Srgb-color [0, 63] ([0, 1] for alpha) converted to/from linear-color float [0, 1] in shader.
25752592
///
25762593
/// Also known as DXT1.
25772594
///
25782595
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2596+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
25792597
Bc1RgbaUnormSrgb,
25802598
/// 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.
25812599
/// [0, 63] ([0, 15] for alpha) converted to/from float [0, 1] in shader.
25822600
///
25832601
/// Also known as DXT3.
25842602
///
25852603
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2604+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
25862605
Bc2RgbaUnorm,
25872606
/// 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.
25882607
/// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader.
25892608
///
25902609
/// Also known as DXT3.
25912610
///
25922611
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2612+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
25932613
Bc2RgbaUnormSrgb,
25942614
/// 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.
25952615
/// [0, 63] ([0, 255] for alpha) converted to/from float [0, 1] in shader.
25962616
///
25972617
/// Also known as DXT5.
25982618
///
25992619
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2620+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26002621
Bc3RgbaUnorm,
26012622
/// 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.
26022623
/// Srgb-color [0, 63] ([0, 255] for alpha) converted to/from linear-color float [0, 1] in shader.
26032624
///
26042625
/// Also known as DXT5.
26052626
///
26062627
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2628+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26072629
Bc3RgbaUnormSrgb,
26082630
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R.
26092631
/// [0, 255] converted to/from float [0, 1] in shader.
26102632
///
26112633
/// Also known as RGTC1.
26122634
///
26132635
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2636+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26142637
Bc4RUnorm,
26152638
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). 8 color pallet. 8 bit R.
26162639
/// [-127, 127] converted to/from float [-1, 1] in shader.
26172640
///
26182641
/// Also known as RGTC1.
26192642
///
26202643
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2644+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26212645
Bc4RSnorm,
26222646
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG.
26232647
/// [0, 255] converted to/from float [0, 1] in shader.
26242648
///
26252649
/// Also known as RGTC2.
26262650
///
26272651
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2652+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26282653
Bc5RgUnorm,
26292654
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). 8 color red pallet + 8 color green pallet. 8 bit RG.
26302655
/// [-127, 127] converted to/from float [-1, 1] in shader.
26312656
///
26322657
/// Also known as RGTC2.
26332658
///
26342659
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2660+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26352661
Bc5RgSnorm,
26362662
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit unsigned float RGB. Float in shader.
26372663
///
26382664
/// Also known as BPTC (float).
26392665
///
26402666
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2667+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26412668
Bc6hRgbUfloat,
26422669
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 16 bit signed float RGB. Float in shader.
26432670
///
26442671
/// Also known as BPTC (float).
26452672
///
26462673
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2674+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26472675
Bc6hRgbFloat,
26482676
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA.
26492677
/// [0, 255] converted to/from float [0, 1] in shader.
26502678
///
26512679
/// Also known as BPTC (unorm).
26522680
///
26532681
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2682+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26542683
Bc7RgbaUnorm,
26552684
/// 4x4 block compressed texture. 16 bytes per block (8 bit/px). Variable sized pallet. 8 bit integer RGBA.
26562685
/// Srgb-color [0, 255] converted to/from linear-color float [0, 1] in shader.
26572686
///
26582687
/// Also known as BPTC (unorm).
26592688
///
26602689
/// [`Features::TEXTURE_COMPRESSION_BC`] must be enabled to use this texture format.
2690+
/// [`Features::TEXTURE_COMPRESSION_BC_SLICED_3D`] must be enabled to use this texture format with 3D dimension.
26612691
Bc7RgbaUnormSrgb,
26622692
/// 4x4 block compressed texture. 8 bytes per block (4 bit/px). Complex pallet. 8 bit integer RGB.
26632693
/// [0, 255] converted to/from float [0, 1] in shader.
@@ -3201,6 +3231,11 @@ impl TextureFormat {
32013231
self.block_dimensions() != (1, 1)
32023232
}
32033233

3234+
/// Returns `true` for BCn compressed formats.
3235+
pub fn is_bcn(&self) -> bool {
3236+
self.required_features() == Features::TEXTURE_COMPRESSION_BC
3237+
}
3238+
32043239
/// Returns the required features (if any) in order to use the texture.
32053240
pub fn required_features(&self) -> Features {
32063241
match *self {

0 commit comments

Comments
 (0)