fix(vk): the GPU ASTC decoder decodes exactly as astcenc does: 8-bit conversion, sRGB mode and four decoding faults #2314
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2314
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:fix/astc-gpu-exact"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Stacked on #2307 (the texdecode CPU decoder), because its test uses that decoder, which equals ARM's astcenc 6.0.0 on 28 million fuzzed blocks, as the reference. It builds on #2194's decoder (
gpu/vk/host_shaders/astc_decoder.comp) and keeps its structure and speed; it does not rewrite it.The GPU ASTC decoder is fast but not exact. Read back in the game against texdecode on 1,119,311,811 texels in 22 formats, linear formats were 82.24% equal, 17.57% one step off and 0.193% more than one step off (largest 113); sRGB formats 81.13% / 18.82% / 0.051% against the specification's sRGB mode. Three kinds of cause, found with a game-free test over astcenc's block vectors:
R8G8B8A8_UNORMimage, which rounds. That was all the one-step differences in linear mode (2,031 of 2,114 legal vector blocks). The shader now stores the bytes through anR8G8B8A8_UINTview (rgba8ui), which keeps the bits as they are on every driver; a UNORM store of n/255 is exact only where the driver rounds to nearest.(v << 8) | 0x80, notv * 257. A push constantsrgb, set from the texture's NVN format, selects it.floor(0.5 + v * 64 / (2^n - 1)); the specification's table is the bits replicated to six, plus 1 above 32. Value 7 of 4 bits gave 30 where the table has 29.Illegal blocks and HDR void extents stay transparent black (the renderer's colour, as texdecode's renderer call writes them); the shader now agrees with that call on every vector block.
How to see it on main:
python -I -B tests/test_astc_decoder_gpu.py --headers <Vulkan headers> --device llvmpipe(lavapipe, validation on) fails with 3,888 of 9,388 vector decodes differing and a table of the classes that differ. Files to read first:gpu/vk/host_shaders/astc_decoder.comp(small hunks:UnquantizeTexelWeight,DecodeColorValues,ComputeEndpoints, the store at the end ofDecompressBlock),tests/astc_decoder_gpu.cpp, and the view changes ingpu/vk/vk_texture.cpp(astc_target_view,astc_level_view,bc_scratch_make).What a player can see: textures decoded as the specification says. About 18% of texels change by one step (of 255), 0.19% by more, and sRGB textures by the sRGB mode's difference; most of this is invisible, the larger differences are the rare wrong blocks.
Renderer side of the 8-bit change: the decoded textures are
MUTABLE_FORMATalready and their level views areR8G8B8A8_UINT; the BC scratch images (big and small) are madeMUTABLE_FORMATand get UINT twins of their views, which the decoder writes, while the BC encoders still read the UNORM views.R8G8B8A8_UINTstorage is mandatory in Vulkan, so no feature or format check is needed, and the shader no longer needsStorageImageWriteWithoutFormat.Testing
Tested: Linux, RTX 4070 Ti (NVIDIA 595.99.02), the AMD integrated GPU of a Ryzen 7 9800X3D (RADV), and lavapipe (LLVM 21.1.8) with Khronos validation, glslangValidator 16.6.0 for the headers (
scripts/shaders.py hostreproduces them).tests/test_astc_decoder_gpu.py(replaces #2194's comparison with suyu and its one-step tolerance; keeps its hand-built cases): on lavapipe 100% of the 9,388 astcenc vector decodes (4,694 blocks, linear and sRGB), 58 whole levels (layers, clipped edge blocks, GOB tiles of 1, 2 and 4 GOBs, a short binding) and 56 hand-built levels equal texdecode, no validation error. On main: 3,888 of 9,388 differ. Undoing any one of the eight shader changes makes it fail again (weights 551, partial group 14, more than 18 values 18, fewer than 6 levels 102, void bounds 532, HDR magenta 492, top 8 bits 4,223, sRGB mode 2,115 vector decodes differ). Bothg++andclang++build it.RX_VK_TEXDECODE_CHECK=3reads every decoded level back and compares it with texdecode, in the renderer's error colour and the format's sRGB mode): RTX, route house, Kokiri Forest twice, Hyrule Field twice: 22 formats, 8,159 level-layers, 1,392,369,615 texels, all equal, largest difference 0 (main: 82.2%/81.1% equal, largest 113); the BC re-encoder's input equal too. Integrated GPU (RX_VK_DEVICE=1, 1280x720,RX_VK_AUTO_TUNE=0): house to Kokiri 617,680,800 texels in 20 formats and house to Hyrule 704,151,971 texels in 22 formats, all equal. No device loss or Vulkan error.gamerunkokiri-interior, kokiri-forest, hyrule-field, branch against base: all ok, clean stop, 0 warning lines;logdiff --levels problem: no new kinds; shots of Kokiri Forest and Hyrule Field read: no corrupted or magenta textures.suite.py compareagainst #2307's head: 934 passed, 3 failed, 26 skipped on both sides, nothing fails only here, no checks added or removed. Three checks that readvk_texture.cpp(test_astc_cpu_call,test_astc_upload_chunking,test_bc_small_scratch) needed their cut or stand-ins updated for the UINT views and the srgb field; they were updated, not weakened. The translator stamp (nx2/translator_files.stamp(gpu/vk)) is unchanged.gpu/vk/vk_texture.cpp(objcmp build).Still to test:
tests/run_vulkan_fixtures.pyand a house-to-Kokiri read-back, expecting every texel equal (@Beanstalk run the ASTC decoder test and a texture check on Windows with an NVIDIA and an AMD card).rgba8uistore and the UINT views of the BC scratch, expecting no change in the picture (by hand or a Test Farm tag).Measurements
Verdict: no measurable cost: the decoder is within 3% of #2194's at every footprint on the RTX (worst 1.019) and 5 to 8% faster on the integrated GPU; in the game one round a side shows nothing outside the run-to-run spread. One round only, not a repeated measurement.
Setup: Linux, RTX 4070 Ti and the AMD integrated GPU (RADV), queue timing mode (alone on the GPU); decoder microbenchmark: one 2048x2048 level of astcenc-legal vector blocks per footprint, block-linear tile_h 4, GPU timestamps around one dispatch, median of 20 dispatches, three runs, the median of the runs; the game:
drive.pyroute house, Kokiri Forest 45 s, Hyrule Field 45 s on the RTX; house to Kokiri Forest and house to Hyrule Field separately on the integrated GPU (RX_VK_DEVICE=1, 1280x720,RX_VK_AUTO_TUNE=0), the whole run's frame log.37af5747f(#2194 as merged, in #2307)d24736a6d(One of the three RTX runs read 1.195 at 12x10; the median is shown.)
37af5747f(#2307)d24736a6dRisks
What could break: the decoded textures' and the BC scratch images' storage views are now
R8G8B8A8_UINT(mandatory storage format, but untested on Windows and on drivers other than NVIDIA and RADV on Linux); a driver that mishandles an integer view of aMUTABLE_FORMATimage would show wrong or black textures. A revert of the commits is enough; there is no switch. A partition with an HDR endpoint mode is magenta where it was a clamped colour, which affects no block the game was seen to use (0 such blocks in the read-backs). Illegal blocks are now error blocks (transparent black) in more cases, as astcenc has them. After updating, textures change by up to one step (most of them) or, in the rare wrong blocks, by more; nothing in saves, options or caches. No speed or memory cost beyond the measurements above (two more image views per BC scratch).Checklist
Ready for review
main; the title is a Conventional Commit. (One topic; the title is one. Stacked on #2307, not onmain: it waits for #2307 to merge, then rebases.)mise run testpasses (any failure that also fails onmainis named). (suite.py compare: 3 checks fail on both sides, unchanged; nothing fails only here.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.gpu/vk/switches.def. (n/a: no switch.)tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged). (n/a:vk_api.his not changed.)mainand here, for a change that shows on screen. (Shots of the same spots read, not published; the change is at most a step per texel.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Written with AI agents (Claude) under the owner's direction; the commits carry
Co-Authored-By: Claude Sonnet 5.5.Tested in game: Linux, RTX 4070 Ti (NVIDIA 595.99.02) and the Ryzen integrated GPU on RADV: Link's house, Kokiri Forest and Hyrule Field. A temporary read-back check (not in this branch) compared every decoded level with the CPU decoder: 1,392,369,615 texels in 22 formats on the RTX and 1,321,832,771 on the integrated GPU, all equal, where main's decoder on the same route had 1,895,679 texels more than one step off (largest 113). Three scenes branch against base: clean stops, no new warning or error kinds, shots look right. Decoder benchmark against #2194 as merged: 0.93 to 1.02 of its time on the RTX, 0.92 to 0.95 on the integrated GPU; in-game timing is one round a side and shows no regression.
d24736a6db511dd4049b@rebase
I rebased this pull request onto
main(3e75d518bf): the new head isbb832f2bfe.Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
511dd4049bbb832f2bfeRecommendation: Request changes. The decoder’s Linux results show a substantial correctness improvement, but the new fixture cannot open its vector file from some Windows checkout paths. The changed Vulkan image-view path also still needs coverage on supported Tier 1 systems.
The shader now matches the CPU reference’s 8-bit and sRGB decoding and corrects several malformed-block and endpoint cases. It adds integer storage views and replaces the GPU comparison fixture; those views need cross-platform validation.
Blocking (1): must change before merging.
tests/astc_decoder_gpu.cpp:95: The new vector-file input is opened with the narrow Windows file API. (more on the line) Do: Accept and open the vector path with Windows wide-character APIs, while retaining the normal POSIX path on Linux.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1.Checks: Still running:
PR description / Description follows the template (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Yes. The reported Linux read-backs match the CPU decoder on 1,392,369,615 RTX texels and 1,321,832,771 integrated-GPU texels; the vector fixture reports 9,388 exact decodes versus 3,888 differing on the base. The reported decoder timings are within 3% on the RTX and 5–8% faster on RADV, while single in-game rounds do not establish a performance difference.
Other systems: The change affects decoded RGBA textures and BC encoder inputs, including scratch-image views and the resized BC path. Linux NVIDIA, RADV integrated graphics and lavapipe were reported tested; Windows drivers, discrete AMD Tier 1 hardware and Steam Deck remain unverified.
Switches: None added, changed or removed.
Reviewed:
bb832f2bfeagainst3e75d518bf: Read the repository rules, PR template, standards, commit messages, shader changes, renderer view and upload changes, fixture runner and test changes. Skimmed the generated SPIR-V header and portions of the large fixture and renderer files; the full renderer and every changed test file were not read in full. docs/review-checklist.md and the sibling Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The review used the author’s reported test and measurement results.
Overlaps and merge order: Stacked on #2307, which must merge first; no other overlap was established from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@ -326,2 +94,2 @@std::memcpy(img.linear_astc.data() + static_cast<size_t>(idx) * 16u, blk.b, 16u);}std::vector<Vector> load_vectors(const char* path) {FILE* f = std::fopen(path, "rb");L1 (blocking): The new vector-file input is opened with the narrow Windows file API.
When: When the checkout path contains characters outside the Windows active code page, the Python runner passes that path to the fixture, but fopen cannot open the vector file, so the default check and GPU fixture fail before testing the decoder.
Do: Accept and open the vector path with Windows wide-character APIs, while retaining the normal POSIX path on Linux.
@fix
bb832f2bfe8f8398ba86Recommendation: Approve. The code is ready: only testing is left. The Windows vector-file path fix is in place, but the integer storage views still need coverage on the affected Tier 1 systems. The stacked CPU decoder PR must also merge first. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
8f8398ba86. I rebased it ontomain(6acae6aa87).Changed
Nothing was built or run: the checks run again on the new head.
The GPU ASTC decoder produces specification-matching texture bytes and fixes several decoding faults. It adds integer image views and some renderer complexity; the reported Linux runs show correct output without a clear in-game performance cost.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head (
Guide screenshots / Guide images and local UI source review (pull_request)failed on the last one); a failure shows on the pull request.Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes. The author reports all 9,388 vector decodes and more than 2.7 billion in-game texels matching the CPU reference on Linux NVIDIA and RADV; main differed on 3,888 vector decodes. The in-game timing comparison was only one round per side.
Other systems: The UINT views affect decoded textures and BC scratch images. Linux NVIDIA and RADV runs are reported; Windows NVIDIA and AMD, discrete AMD on Linux, and Steam Deck coverage remain outstanding.
Switches: None.
Reviewed:
8f8398ba86against6acae6aa87: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the fix diff and test_astc_decoder_gpu.py. Inspected the fixture, renderer and shader changes and their callers; the large fixture and renderer diff output was truncated, and the generated SPIR-V header and other changed files were not read in full.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run. CI has not run on this head; the reported Linux fixture and game runs are author evidence.
Overlaps and merge order: Stacked on Longshot #2307; merge that first.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: fix(vk): the GPU ASTC decoder decodes exactly as astcenc does: 8-bit conversion, sRGB mode and four decoding faultsto fix(vk): the GPU ASTC decoder decodes exactly as astcenc does: 8-bit conversion, sRGB mode and four decoding faults