Repository navigation
Fix: block-aligned mip extents for non-power-of-2 and non-square ASTC blocks - #293
Merged
dzhdanNV merged 1 commit intoOct 23, 2026
Merged
Conversation
… blocks GetDimension rounded the width and height up with Align, which only works for power-of-2 alignments, and used blockWidth for the height too. For 24 of the 28 ASTC formats (all but 4x4 and 8x8) it returned extents that are not block multiples and often exceed the mip, e.g. 34x34 for a 30x30 ASTC_5X5 texture or 40x48 for a 40x45 ASTC_8X5 one. The WGPU backend uses these extents for WHOLE_SIZE copies (GetCopySize, which also serves UploadData) and for host copies, where GetHostCopyLayout had the same Align rounding. Round up with an integer division per axis, as the Metal backend already does. Results for all other formats, and for VK, are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thanks a lot. Merged! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetDimension(Source/Shared/SharedExternal.h) rounds the width and height of non-VK textures up to the block size withAlign.Alignonly works for power-of-2 alignments, and the height was rounded withblockWidthas well. For 24 of the 28 ASTC formats (all except 4x4 and 8x8) the result is not a multiple of the block size and is often larger than the mip itself. For example,Align(30, 5)is(30 + 4) & ~4, which is 34:ASTC_5X5_UNORMASTC_6X6_UNORMASTC_6X6_UNORMASTC_8X5_UNORMASTC_10X10_UNORMASTC_12X12_UNORMThe WGPU backend exposes these formats when
features.textureCompressionASTCis set. It usesGetDimensionas the copy extent ofWHOLE_SIZEregions inGetCopySize, which servesCmdUploadBufferToTexture,CmdReadbackTextureToBufferandCmdCopyTexture, and thereforeUploadDatatoo.DeviceWGPU::GetHostCopyLayout, used byUploadHostMemoryToTextureandReadbackTextureToHostMemory, rounds its extent with the sameAlign. WebGPU rejects these copies: the extent of a compressed copy must be a multiple of the block size and must fit in the block-rounded mip (see "validating texture copy range" in the WebGPU spec). On non-VK backends,StreamTextureDataalso takes itsWHOLE_SIZEstaging size fromGetDimension.Fix: in both
GetDimensionandGetHostCopyLayout, round up with an integer division per axis (blockWidthfor x,blockHeightfor y).CommandBufferMetal::CmdCopyTexturealready does it this way. Results don't change for the depth axis, for VK, or for any non-ASTC format, so D3D11 and D3D12 behave as before.Verification was host-side only. No GPU or WebGPU device is available here, so none of this ran on a driver.
GetDimension(WGPU, ...)from the realSharedExternal.h/.hppwithceil(max(size >> mip, 1) / block) * block. This covered all formats, block-multiple sizes up to 48 blocks, and all mips. Before the fix, 8062 of 31260 results were wrong, all in the 24 formats above. After the fix, none are.GetDimensionover all formats, all 6GraphicsAPIvalues, sizes 1..300, 10 mips and 3 axes (5,832,000 cases). The only differences are in those 24 ASTC formats on non-VK APIs. Results for BC, ETC2, ASTC 4x4/8x8, NV12/P010/P016, uncompressed formats and VK are identical.DeviceWGPU::GetHostCopyLayoutandGetCopySizeon texture descs for all ASTC formats and mips. Both were compiled from each tree'sImplWGPU.cpp, and no WebGPU device was created. Before the fix, 6970 of 9088 host copy layouts and 3584 of 4544 copy sizes were wrong. After the fix, none are.-Wextra -Werror, Release and Debug) withNRI_ENABLE_WGPU_SUPPORT=ON. VK was off because this machine has no Vulkan SDK, and D3D11/D3D12 were not built.clang-format19.1.7 leaves both files unchanged.🤖 Generated with Claude Code