Repository navigation
hk: compress large G17P RGBA8/BGRA8 mip chains that are only sampled and transferred - #63
Merged
Conversation
…red to G17P kept every RGBA8/BGRA8 UNORM image with mip levels and without colour attachment usage uncompressed, so that its mip blits stayed on the raw compute kernels. Those kernels could not write compression metadata, and a compressed destination took one render job per level. hk_g17p_compressed_blit has since made mip generation into compressed images fast, so the rule only costs time now. It covers the common sampled texture, created for sampling and transfers only, uploaded with vkCmdCopyBufferToImage and mipmapped with vkCmdBlitImage. The same texture in R8G8B8A8_SRGB was already compressed. Uploads into a compressed image are still a render pass per region, where a plain image takes one compute copy, so small textures stay plain. Compress from HK_G17P_MIP_PBE_MIN_TEXELS texels at level 0, the size where a render pass already beats compute for a mip level. Measured on the A18 Pro with sampled, transfer-only textures and full mip chains (median GPU time, compressed over plain): size content upload mip gen sample read back 1024x1024 UI 0.67 0.67 0.81 0.91 2048x2048 UI 0.55 0.40 0.69 0.92 4096x4096 UI 0.47 0.23 0.61 0.91 2048x2048 noise 0.64 0.57 0.84 0.95 4096x4096 noise 0.64 0.58 0.85 1.02 Batches of 200 128x128 and 100 256x256 textures are unchanged (0.99, 1.00). Compressing those too would have made them 2.6 and 1.2 times slower. G13 and G14 never take this policy. Assisted-by: LLM Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
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.
DJ asked us to check that transfer compression works on the Neo. Mostly it does. On G17P, TRANSFER_SRC and TRANSFER_DST never stop an image being compressed, and no transfer path decompresses anything. Copies, uploads, blits, resolves and clears read compressed sources through the texture unit, and they write compressed destinations through the PBE or the metadata fast clear. Layout transitions to and from the transfer layouts don't touch the data either.
The one gap we can close without new hardware facts is in the allocation policy. G17P kept every RGBA8/BGRA8 UNORM mip chain that isn't a colour attachment uncompressed. That's the usual sampled texture, uploaded with vkCmdCopyBufferToImage and mipmapped with vkCmdBlitImage. The rule is from before #33, when mip blits into a compressed image cost a render job per level. #33's compressed mip path removed that reason, so now the rule only makes these textures slower. The same texture as R8G8B8A8_SRGB was already compressed.
Uploads into a compressed image are still a render pass per region, while a plain image takes one compute copy. So small textures stay plain. This compresses from 2^17 texels at level 0 (HK_G17P_MIP_PBE_MIN_TEXELS), the size where DJ measured a render pass beating compute for a mip level. M1/M2 never use this policy (it returns early for anything but G17P).
Benchmarks (Neo, A18 Pro, 7.3.0-aurora-73t)
Method: a scratch Vulkan microbench (not in the tree). Each run creates a sampled RGBA8 UNORM texture with a full mip chain and SAMPLED, TRANSFER_SRC and TRANSFER_DST usage only. It then times four steps in separate submissions with GPU timestamps:
Content is either "ui" (32x32 flat blocks with borders) or "noise" (random, incompressible). There's also a batch case, 200 128x128 or 100 256x256 textures uploaded and mipmapped in one command buffer, which is what toolkits do at startup.
The policy was picked by an environment variable in a measurement-only build, so all three policies ran on the same binary in the same boot: off (current), gate (this PR), all (no exclusion). 8 outer reps rotated the order of the three policies, with 5 inner reps each (inner rep 0 dropped). All units ran on E-cores 1 to 4 with the seat idle, and P-core peak stayed under 60 C. Numbers are median GPU microseconds, with the range of per-rep medians in brackets.
Below 2^17 texels "gate" runs exactly the same code as "off", so the small sizes are unchanged by construction. The "all" column is why the gate exists. Compressing small textures makes the batches 2.6 and 1.2 times slower, because every upload becomes a render pass.
The one step that gets slower is reading back an incompressible 4096x4096 level, by 2% (3666 vs 3579 us). For the same texture, upload, mip gen and sampling together drop from 8082 to 5208 us.
Conformance
Vulkan CTS 1.4.6.2, same kit and kernel for base and candidate (73t on all three machines). The candidate was 7615582 + #55..#60 + the #57 fixups + this commit, and the base was 7615582. Today's aurora-wip has all of that except #56, which touches index draws only.
GL CTS samples through zink on the Neo (every 20th name of gl46, gles2-aosp and gles3-aosp): identical with and without this commit. Zink gives its textures colour-attachment usage, so it was never affected.
Unit test:
hk_g17p_compressionpasses (3359 checks) with the new boundary cases at 362x362 (just under 2^17) and 512x256 (exactly 2^17).Not covered here
These G17P images stay uncompressed until we have the hardware facts to compress them:
🤖 Generated with Claude Code