feat(vk): the CPU texture decoders are ported ones (texdecode), and suyu's two texture sources leave the build #2307
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!2307
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:feat/texdecode-ported-cpu"
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
When the renderer decodes a texture on the CPU (the block-linear unswizzle and swizzle, and ASTC), it called suyu's decoders from
gpu/third_party/suyu/video_core/textures/. suyu's ASTC decoder is wrong on some legal blocks. This swaps it for a decoder and a block-linear swizzle ported from ocarina-recomp (MIT), ingpu/vk/texdecode/, and drops suyu'sdecoders.cppandastc.cppfrom the build. There is no switch: the port is the CPU path.The fault, and how to see it on main. In a legal multi-partition ASTC block, the colour endpoints are a sequence of values in groups of 5 (trits) or 3 (quints) whose high code bits are missing when the last group is not full, and the specification reads the missing bits as zero. suyu copies the spare bits after the sequence into the buffer it decodes and reads them as those code bits, so a partial last group can unquantise to other values and one partition's endpoints move. Only blocks with a partial last group, nonzero spare bits and more than 8 colour values are affected (about 6% of such random blocks go wrong); an encoder that zeroes the spare bits hides it.
tests/test_texdecode_astc_partitions.pyholds 8 such blocks and 3 controls with ARM's astcenc 6.0.0 answers and passes with the port.python -I -B tests/test_texdecode_astc_partitions.py --decoder suyu(not run byrun_all.py) builds suyu'sastc.cppalone and shows the fault on main's decoder: 8 of the 11 blocks more than one step from astcenc, the largest difference 117 of 255 in a channel; the 3 controls are one step off (suyu's rounding). Two lines in suyu's file would fix it, andgpu/third_partyis not edited.What changed, in four commits:
gpu/vk/texdecode/: the library (ASTC LDR 4x4 to 12x12, linear and sRGB modes; block-linear swizzle and deswizzle), itsPROVENANCE.mdandLICENSE-MIT, the vector generator and the two library tests. The ASTC decode takes an error colour (default: the specification's opaque magenta, which astcenc and the ported original write). The ASTC test harnesses receive their inputs through standard input, so input paths work with Unicode.vk_texture.cppcalls the library at the four CPU sites;nx2/build.pybuilds it and no longer builds suyu's two sources; every check that assumed suyu's decoder is updated, none weakened; two stale doc lines that said suyu's texture decoders were compiled are corrected.The ASTC decode runs on the calling thread, as before; the unswizzle keeps its strip threads.
What does not change. The default route for 2D ASTC is still the GPU decoder (Eden's compute shader), and big block-linear textures still use the GPU unswizzle. The CPU decoder runs when the GPU path declines (3D ASTC, no
VK_KHR_push_descriptor, layout or stride limits, out of staging memory) and withRX_VK_ASTC_CPU=1(its switch row now says so). The GPU decoder stays because CPU-only decode measured 3 to 8 times worse hitches and 4 times the VRAM (earlier branch, below). No shader is changed.An illegal ASTC block stays transparent black, as main's decoder and the GPU shader write it:
vk_texture.cpppassesRgba8{0, 0, 0, 0}to the library's error colour. This matters because an all-zero block is an illegal one (texdecode's default, magenta, givesff00fffffor it),upload_all_zeroskips ASTC, and storage the game has not written yet, or a zero-padded tail, is decoded: magenta there would be a visible change.tests/test_astc_cpu_call.pycompiles the renderer's own call as cut fromvk_texture.cppand checks that an all-zero block gives00000000and that the count of illegal blocks comes back. The count is logged once per texture (the first 16), never a texel value. HDR endpoint modes keep magenta for their partition (astcenc's behaviour; whether the game has any was not measured).What a player can see. Only where the CPU decoder runs, texels are slightly different, towards the specification: ASTC is truncated to 8 bits as astcenc does where suyu rounded (about a fifth of texels one step apart); blocks suyu decoded wrongly are right; sRGB ASTC formats (NVN 0x87 to 0x94, viewed as R8G8B8A8_SRGB) decode in the specification's sRGB mode. The CPU and GPU routes now differ by one step on about 18% of texels, where before both rounded (Eden's GPU decoder rounds, and so did suyu's CPU decoder; the port truncates, as astcenc's 8-bit decode does).
Refusals. The library refuses bad arguments and short spans, which no caller can trigger today. The unswizzle's and ASTC's output is then zeroed (never what staging memory held) and one line says so (5 at most). A refused swizzle is not written back: that part is skipped and the flush reports not ok (zeroing it would overwrite the game's bytes).
Not in this pull request. The GPU decoder's own inaccuracies are a separate, later piece. Main's decoder (
astc_decoder.comp, which #2194 rewrote for speed and which also startscolor_endpoint_dataat zero) read back from the GPU in the game and compared with this port's decoder over 1,119,311,811 texels (22 formats; Link's house, Kokiri Forest and Hyrule Field, route twice; scratch harness,Longshot/work/texshaders2/timing/runs/chk_hm1/log.txt): linear formats 82.24% equal, 17.57% one step, 0.193% more than one step, largest difference 113; sRGB formats (against the specification's sRGB mode) 81.13% / 18.82% / 0.051%, largest 113. That is what the decoder before #2194 gave (906,813,582 texels: 81.95% / 17.86% / 0.187%, largest 113): #2194 did not remove the larger differences, the first-seen largest (113) is still there, and it still rounds where astcenc truncates. Earlier, on the pre-#2194 shader, astcenc sided with this port on all 222,925 blocks that held a texel more than one step off (at most 4,096 blocks a level-layer).Licence chain (
gpu/vk/texdecode/PROVENANCE.mdhas it in full).astc.cppis ported from ocarina-recomp'sruntime/tex_astc.c(itself from LAS Recomp, MIT, Copyright (c) 2026 Peiikai) andblock_linear.cppfrom itsruntime/tex_deswizzle.c(from MacNativeGames, MIT, Copyright (c) 2026 jhaizhou), at the commits and file hashes PROVENANCE.md gives; the code around the ported core (checks, size functions, the error-block count, the error-colour parameter) and the tests are written here. ocarina-recomp's own additions on top of the MIT originals (at most the copy-loop split and the Switch 2 bit order) are GPL-3.0-or-later: its author told the project owner so on 2026-11-21 (its README's own wording is "GPL-3.0"; this is the owner's report, not a file in this repository). Not settled: whether the files came through TotK Recomp (ocarina-recomp's base, MIT, Copyright (c) 2026 Valiantsin Dzerakh), so that notice is carried inLICENSE-MITin case it is owed. Not checked: the upstreamLICENSEtexts of LAS Recomp and MacNativeGames at the cited commits, and the upstream files themselves.Other pull requests. #2143 (the switch table) adds
SW(RX_ASTC_THREADS, ...)described as "suyu's decoder, built into the game" and putsgpu/third_party/suyu/video_core/texturesinTHIRD_PARTY_IN_GAME; after this series that is false (it was already dead: only suyu'sDecompress, which nothing calls, reads the switch). Whichever lands second drops the folder from the list and makes the rowGONE(...), or never adds it. #2040 (Direct3D 12) is not broken: itsgpu/d3d12/build.pycompiles suyu's two files itself; only its docstring goes stale. #1281 does not interact. #2194 (merged: Eden's GPU ASTC decoder rewritten) and #2227 (gpu_arch.h) do not touch a file this series changes; the GPU decoder's output is unchanged by this series either way.Read first:
gpu/vk/texdecode/texdecode.handPROVENANCE.md, then the four call sites ingpu/vk/vk_texture.cpp(unswizzle_upload, thetex.astcbranch ofupload_inner, and the swizzle inflush_finish), thentests/test_texdecode_astc_partitions.pyandtests/test_astc_cpu_call.py. AI-assisted (Claude Code, under the owner's direction); the commits carryCo-Authored-By:. No issue is closed.Testing
Tested: Linux, RTX 4070 Ti, NVIDIA 595.99.02, Vulkan 1.4; a runtime made over base
3e4b1faf(the measured head was8d0e56c11on main9e10f6f7, whose changes since the base did not touch the texture decoders; the series is now rebased onto main67ba729d2with all three patches unchanged,git range-diffshows=for each, and main's changes since touch none ofvk_texture.cpp,gpu/vk/texdecode/ornx2/build.py, so these runs are not repeated; the GPU decoder #2194 rewrote is on neither side's CPU route and unchanged by the series on the default route) with this branch's pack, against the same base alone, through the job queue, from thekokiri-startsave. Default settings: Link's house, Kokiri Forest and Hyrule Field's tunnel, 30 s each, a shot each, and the same three withRX_VK_ASTC_CPU=1, so the port decodes every ASTC texture: all twelve runs (branch and base) stopped cleanly with no warning or error line,logdiff.pyagainst the base's logs shows no new, gone or much-changed warning or error kind in any pair, and neither the illegal-block line nor a refusal line appears in any of them or in the 24 timing runs below. The shots show the scenes as on the base, no magenta, no corrupted textures. These runs are at the previous head; the code since changed in the error colour (transparent black, as main), the swizzle refusal, comments and tests. The timing runs below predate the change to pass ASTC test inputs through standard input. Scene shots (scripts/scene_shots.py, Link's house, 5 runs a side, both underRX_VK_ASTC_CPU=1, at the previous head): PASS (B's worst shot 6.30 against a bound of 8.44); this coarse check cannot see a one-step difference on a fifth of the texels, it says only that nothing broke.Checks before the ASTC test input change: the library tests and the fault test pass with clang++ 21 and g++ 15, and the library tests under
-fsanitize=address,undefined.suite.py compare(run_all.py, this PC) atac04b9572(rebased on main67ba729d2): head 911 passed / 23 failed / 26 skipped, base 905 / 23 / 26; 6 new checks, all passing; no check fails only on the branch, none only on the base, the same skips, and the failing sets are the same (the environment's: missing glslang, PIL, stale fixtures on main; logLongshot/work/texshaders2/logs/suite-A.txt).Measured on the earlier branch (
feat/first-party-texture-decode, with its temporary check switches, since removed), in the game, fromlongshot-renderer-log.md: swizzle and deswizzle byte-identical to suyu over 2,046,052,525 blocks and 5.6 GB; ASTC against suyu over 905 M texels: 81.8% equal, 18.2% one step, 10,634 larger (0.0012%), astcenc agreeing with the port on 479 of 479 such blocks and with suyu on none; the new ASTC decode 5.1 s against suyu's 29.3 s per load (5.7 times; 3 interleaved rounds). Those runs saw 0 illegal ASTC blocks in the game's data, and so do the runs above; what was covered is Link's house, Kokiri Forest and the Hyrule Field tunnel mouth, not the whole game.Still to test:
RX_VK_ASTC_CPU=1, expecting a clean start and no new warning (@Beanstalk build and start withRX_VK_ASTC_CPU=1)RX_VK_ASTC_CPU=1in Kokiri Forest, expecting the scene as on main and no new warning (@Beanstalk)Measurements
Verdict: On the CPU route the port is about 5.6 times better on the worst frame (13.3 s to 2.4 s) and about 5.6 times on slow-upload time (22 s to 3.9 s a run), with no change in time to map. On the default route, where the GPU decoder runs, there is no difference: the worst frames (about 200 to 260 ms in both) and the time to map overlap.
Setup: Linux, RTX 4070 Ti, NVIDIA 595.99.02; the two teleports (Kokiri Forest, Hyrule Field's tunnel), 30 s each through
gamerun.py --mode timing(alone on the GPU), three interleaved rounds a side (base, branch in each round), base = the runtime of3e4b1fafalone, branch = this PR's head at the time,8d0e56c11, which isac04b9572before the rebase onto main67ba729d2(same three patches). Time to map is the run'sload_seconds; worst frame is the largestslowestof the run'svk: statuswindows (the whole run); slow uploads is the sum of the run'svk: slow uploadlines. Every run's log has the same texture budget (7164 MB; the driver allows 10228 to 10306 MB in all of them, so no other program was holding VRAM): no run was discarded.With
RX_VK_ASTC_CPU=1(the port against suyu's decoder, which decodes serially):3e4b1faf(the base)Default settings (the GPU decoder; expected no difference):
3e4b1faf(the base)The default-route differences are inside the runs' own spread. An earlier two-round default-route run had one 402 ms worst frame on the branch in Kokiri Forest; that run did 3.6 MB of CPU unswizzle in 0.4 ms in total and no CPU ASTC decode, so the decoders did not cause it, and it did not come back in the six branch runs here. From a scratch benchmark of the review (unprofiled, not part of this pull request): the port's deswizzle is 1.7 to 7.3 times faster than suyu's on 11 layouts with identical output, and its ASTC decode 3.4 to 4.4 times faster.
Risks
A CPU-decoded ASTC texture is slightly different from before, towards the specification (above); a revert is enough, there is no switch and no cache or option changes. The shader stamp and every cache stay as they are (the translator stamp is made of
gpu/vk/eden,sirit,compat,vk_shader.cpp,vk_bank.cppandvk_state.h: computed for main and for this branch it is2200067913ddd7e1both times). suyu's two sources stay ingpu/third_party/suyu(not edited) and are no longer compiled for the Vulkan back end. The CPU and GPU routes round differently now (above). A release build compiles texdecode without a play profile: the shippedassets/profiles/longshot_vk.profdata.xzhas records for suyu'sDecompressBlockandSwizzleImpl, none for texdecode, so a release's CPU-route time may differ from the unprofiled figures above; it was not measured (listed in Still to test).Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses on the current head (any failure that also fails onmainis named); the earlier comparison is in Testing.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.tests/that reads changed source is updated, not weakened.mainand here, for a change that shows on screen: the shots of the six runs are on the author's PC, none attached; the difference is a one-step change in a fifth of the CPU-decoded texels, not visible in a shot.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Linux, RTX 4070 Ti, NVIDIA 595.99.02: Link's house, Kokiri Forest and Hyrule Field, default settings and with RX_VK_ASTC_CPU=1 so the ported decoder handles every ASTC texture; clean stops, no new warning or error kinds against main, shots look right. With RX_VK_ASTC_CPU=1 the worst frame entering Kokiri Forest went from 13.3 s to 2.4 s (three interleaved rounds); default route unchanged. Measured at 8d0e56c1; this head is the same three commits rebased onto main
753fb5afwith the game-free tests rerun.@review
Recommendation: Approve. The CPU decoder fixes the demonstrated ASTC blocks and substantially reduces the measured CPU-route hitch, but its new tests cannot read their input files from some Windows paths. Windows, AMD, Steam Deck and release-profile runs are also still needed. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The Vulkan CPU texture path replaces suyu's decoders with a ported ASTC decoder and block-linear swizzler. It corrects the demonstrated partial endpoint-group error and speeds up the tested CPU route, at the cost of changed rounding and sRGB output and a larger body of maintained decoding code.
Should fix (1): not blocking, but worth doing before merging.
tests/texdecode_astc_test.cpp:19: The new ASTC tests open Windows paths through narrow C or C++ file APIs, which do not reliably accept the Unicode paths supplied by Python. (more on the line) Do: Pass the input through a Unicode-safe Windows file API, or have the Python harness supply the bytes over standard input; cover both the vector and partition harnesses.Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
@fixcan do L1.Questions (1) (not confirmed from the code; they don't hold the recommendation)
Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes, on the tested CPU route: the author's three interleaved Linux RTX 4070 Ti runs report median worst frames falling from 13.3 s to 2.4 s and slow-upload time from about 22 s to 3.9 s. The game-free fault test reports eight formerly incorrect blocks corrected; release-profile performance and other supported systems remain untested.
Other systems: The CPU decoder also runs on GPU-decode fallback paths, including 3D ASTC and devices without push descriptors; the block-linear code also affects texture write-back. Windows, RADV and Steam Deck have no reported runs. The default NVIDIA GPU path was measured within run-to-run spread, and Direct3D 12 retains its own suyu build according to the description.
Switches: RX_VK_ASTC_CPU is unchanged and defaults off; its table description now identifies the new CPU decoder. RX_VK_UNSWIZZLE_CHECK remains off by default and now compares against the new decoder. No switch is added or removed.
Reviewed:
37af5747ffagainst753fb5af68: Read the repository rules, available template and standards, commit messages, changed decoder and integration code, provenance, relevant build and test changes, and surrounding upload and flush paths. Skimmed the vector generator and generated binary vectors; did not independently verify upstream licence texts or provenance, which are unavailable in the checkout. docs/review-checklist.md and the sibling Tooling AGENTS.md were absent.; nothing run (a code review).Checked and fine:
Testing: No code, tests or project scripts were run during this read-only review. The author reports Linux game runs, decoder tests with Clang and GCC, and sanitizer runs; CI is still running.
Overlaps and merge order: #2143 changes the switch table and third-party list; whichever lands second must reconcile RX_ASTC_THREADS and the suyu texture folder. The description reports no conflicting changes from #2194, #2227 or #1281; #2040 builds its own suyu sources.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +16,4 @@static uint64_t le64(const uint8_t* p) { uint64_t v = 0; for (int i = 7; i >= 0; i--) v = v << 8 | p[i]; return v; }int main(int argc, char** argv) {if (argc != 2) { fprintf(stderr, "usage: test vectors.bin\n"); return 2; }L1 (should fix): The new ASTC tests open Windows paths through narrow C or C++ file APIs, which do not reliably accept the Unicode paths supplied by Python.
When: On Windows, a checkout path containing characters outside the active ANSI code page makes the vector test fail to open its committed input. The partition test similarly opens its temporary input with std::ifstream and fails when the user's temporary directory contains such characters.
Do: Pass the input through a Unicode-safe Windows file API, or have the Python harness supply the bytes over standard input; cover both the vector and partition harnesses.
@fix
37af5747ff6e6cecd466Recommendation: Approve. The code is ready: only testing is left. The CPU decoder shows a substantial improvement in the reported Linux runs, but Windows, Tier 1 AMD or Steam Deck, and release-profile measurements remain outstanding. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
6e6cecd466. I rebased it ontomain(21d5bdf9bc). I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The change replaces the CPU ASTC and block-linear decoders, correcting the documented ASTC fault and reducing CPU-route stalls. It adds a maintained decoder port and changes CPU-decoded texels toward the specification.
Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head; 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 reported three interleaved Linux runs show median worst frames falling from about 13.3 s to 2.4 s on the forced CPU route; default-route results overlap. Release-profile timing remains unmeasured.
Other systems: Linux NVIDIA game runs and game-free decoder comparisons are reported. Windows CPU decode and write-back, Tier 1 AMD or Steam Deck, and the shipped release profile still need the runs in the ledger.
Switches: RX_VK_ASTC_CPU remains off by default; its description now names the CPU fallback cases. The reported default-route measurements support retaining the default.
Reviewed:
6e6cecd466against21d5bdf9bc: Read the four ASTC test files changed by the fix, the fix diff, the texture decoder interface and provenance, and the renderer and build integration diff. Skimmed the wider pull request diff; the other changed code and generated vectors were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run project code were executed. The supplied report records Linux game and decoder tests before the test-input change; CI has not yet run on this head.
Overlaps and merge order: The description identifies #2143 as needing a switch-table and third-party-list adjustment whichever lands second; #2040 retains its own suyu sources.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
6e6cecd4660db7f2f119WIP: feat(vk): the CPU texture decoders are ported ones (texdecode), and suyu's two texture sources leave the buildto feat(vk): the CPU texture decoders are ported ones (texdecode), and suyu's two texture sources leave the buildJer9 referenced this pull request2026-11-23 16:17:47 +00:00