Skip to content

Add TEXTURE_COMPRESSION_UNALIGNED feature - #10247

Open
castano wants to merge 11 commits into
gfx-rs:trunkfrom
castano:texture-compression-unaligned
Open

castano wants to merge 11 commits into
gfx-rs:trunkfrom
castano:texture-compression-unaligned

Conversation

@castano

@castano castano commented Sep 2, 2026

Copy link
Copy Markdown

Implements the WebGPU texture-compression-unaligned feature (gpuweb/gpuweb#6312), which allows creating block-compressed textures whose size is not a multiple of the texel block dimensions, i.e. textures with partial edge blocks in mip level 0.

The feature is supported unconditionally on the Vulkan, Metal and GLES backends. On DX12 it is exposed only when UnalignedBlockTexturesSupported is true in D3D12_FEATURE_DATA_D3D12_OPTIONS8.

Copy validation needs no changes: it already validates against the physical (rounded-up) subresource size, which handles partial edge blocks at any mip level.

This feature has already landed in dawn/chromium and the implementation here mirrors it closely: https://issues.chromium.org/issues/528245806

Connections

Spec: gpuweb/gpuweb#6312
CTS: gpuweb/cts#4676
Discussion: gpuweb/gpuweb#2006

Description

It implements the texture-compression-unaligned WebGPU feature.

Testing

I've run the CTS in macOS under Metal (cargo xtask cts --backend metal) and all tests pass. I think test.lst already includes the new unaligned-compression test, but I also specifically confirmed that the tests that were added or changed in gpuweb/cts#4676 all pass:

cargo xtask cts --skip-checkout \
  'webgpu:api,validation,capability_checks,features,texture_compression_unaligned:*' \
  'webgpu:api,validation,createTexture:texture_size,2d_texture,compressed_format:*' \
  'webgpu:api,validation,createTexture:texture_size,3d_texture,compressed_format:*' \
  'webgpu:api,operation,command_buffer,image_copy:compressed_textures,unaligned_mip_level_0:*' \
  'webgpu:api,operation,command_buffer,copyTextureToTexture:color_textures,compressed,unaligned,non_array:*'

I haven't run the tests on other platforms. I'm hoping CI coverage will do that, but if not, I can look into testing on Windows.

I also added three new tests to texture_compression_unaligned.rs which cover some of the same ground as the CTS tests:

  • unaligned compressed texture creation without the feature fails.
  • unaligned compressed texture creation with the feature succeeds.
  • writing and reading back the contents of an unaligned BC1 texture round-trip correctly.

I tested with:

cargo test -p wgpu-test --test wgpu-gpu -- texture_compression_unaligned --test-threads=1

And all tests pass in Metal, MoltenVK and KosmicKrisp.

Checklist

  • I self-reviewed and fully understand this PR.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.
  • (If applicable) WebGPU implementations built with wgpu may be affected behaviorally.
  • (If applicable) Validation and feature gates are in place to confine behavioral changes.
  • (If applicable) Tests demonstrate the validation and altered logic works.

Implements the WebGPU texture-compression-unaligned feature
(gpuweb/gpuweb#6312), which allows creating block-compressed textures
whose size is not a multiple of the texel block dimensions, i.e.
textures with partial edge blocks in mip level 0.

Copy validation needs no changes: it already validates against the
physical (rounded-up) subresource size, which handles partial edge
blocks at any mip level.

The feature is supported unconditionally on the Vulkan, Metal and GLES
backends. On DX12 it is exposed only when UnalignedBlockTexturesSupported
is true in D3D12_FEATURE_DATA_D3D12_OPTIONS8.
@github-project-automation github-project-automation Bot moved this to To triage in Triage Sep 2, 2026
@castano
castano force-pushed the texture-compression-unaligned branch 3 times, most recently from 198a701 to 4e936c8 Compare September 2, 2026 17:06
@castano

castano commented Sep 2, 2026

Copy link
Copy Markdown
Author

Looking into this error:

FAIL [   0.031s] ( 429/1071) wgpu-core limits::tests::enumerate_webgpu_features

I'm adding the TEXTURE_COMPRESSION_UNALIGNED feature to the M1 and llvmpipe buckets. Not sure if I should add it to other buckets. On Windows the feature is conditionally available depending on the UnalignedBlockTexturesSupported feature cap.

@castano

castano commented Sep 2, 2026

Copy link
Copy Markdown
Author

Looks like the GLES backend does not implement compressed texture to buffer copies. CopyTextureToBuffer in wgpu-hal/src/gles/queue.rs:929 issues:

log::error!("Not implemented yet: compressed texture copy to buffer");

Looks like the CLEAR_TEXTURE_COMPRESSED_BCN test runs into the same issue and handles it thusly:

// compressed texture copy to buffer not yet implemented
.expect_fail(FailureCase::backend(wgpu::Backends::GL)),

I'll do the same in this case.

@inner-daemons
inner-daemons self-requested a review September 3, 2026 02:36
@inner-daemons inner-daemons self-assigned this Sep 3, 2026
@castano

castano commented Sep 3, 2026

Copy link
Copy Markdown
Author

The WebGL failure is to be expected, I'll correct that. The BC extensions in WebGL all have the alignment constraint, because WebGL is often implemented on top of D3D11/12, so I'll stop advertising the feature on non-native GL implementations. This is unfortunate, because in WebGL the constraint only applies to BC formats, not to ASTC/ETC, but there's no way to express that in WebGPU.

@cwfitzgerald cwfitzgerald self-assigned this Sep 9, 2026
@cwfitzgerald cwfitzgerald moved this from To triage to Small in Triage Sep 9, 2026
///
/// This is a web and native feature.
#[name("texture-compression-unaligned")]
const TEXTURE_COMPRESSION_UNALIGNED = WEBGPU_FEATURE_TEXTURE_COMPRESSION_UNALIGNED;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you also wire this up in the browser WebGPU backend? FEATURES_MAPPING in wgpu/src/backend/webgpu.rs and in in wgpu/src/backend/webgpu/webgpu_sys/gen_GpuFeatureName.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

#10265 is also relevant here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Small

Development

Successfully merging this pull request may close these issues.

5 participants