Skip to content
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

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

Merged
merged 25 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3580be7
Enable compressed formats in wgpu for 3D textures
mehmetoguzderin May 28, 2024
87a36d1
Use `align_to` for rounding
mehmetoguzderin May 29, 2024
3456c25
Case rounded sizes according if uncompressed
mehmetoguzderin May 29, 2024
8413a04
Please see https://github.com/gpuweb/gpuweb/pull/4685
mehmetoguzderin May 30, 2024
8fc7489
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin May 30, 2024
42b202d
Please see https://github.com/gpuweb/gpuweb/pull/4685
mehmetoguzderin May 30, 2024
d9e4d73
Please see https://github.com/gpuweb/gpuweb/pull/4685
mehmetoguzderin May 30, 2024
99f1b9a
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin May 30, 2024
a7ebdf2
Update lib.rs
mehmetoguzderin May 31, 2024
533629c
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jun 1, 2024
b0a5c05
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jun 3, 2024
bd21ec6
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jun 3, 2024
e5ac970
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jun 4, 2024
c72af0c
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jul 26, 2024
65be71e
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Jul 30, 2024
237c1b7
Move into extension
mehmetoguzderin Jul 30, 2024
c76dc29
Format deno directory
mehmetoguzderin Jul 30, 2024
a747de8
WASM Clippy Fix
mehmetoguzderin Jul 30, 2024
1fd2ddf
Make comments single line
mehmetoguzderin Jul 30, 2024
c035e83
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Aug 4, 2024
9e8b74c
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Aug 5, 2024
1bd768f
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Aug 5, 2024
1f01ac0
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Aug 6, 2024
5bb449e
Merge branch 'trunk' into oguz-20240530-compress3d
mehmetoguzderin Aug 8, 2024
e690729
Update command and flag in order
mehmetoguzderin Aug 9, 2024
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 deno_webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions deno_webgpu/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tests/tests/clear_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
));
}
}
}

{
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
37 changes: 36 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 << 11;

/// 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.
///
Expand Down Expand Up @@ -2562,102 +2578,116 @@ 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
///
/// 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.
Expand Down Expand Up @@ -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 {
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 @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading