Recompiler: decode RDNA2 instructions without hashing or scratch Vecs #1377
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1387"
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?
Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T15:31:10Z.
Targets #1269 (shader translation / compilation speed).
What changed
rdna2::decoderuns once or more for every console instruction during shader translation (and across every instruction of a pack inxcl shaders). Previously it spent ~1,850 CPU instructions per decoded instruction on a bit-by-bit field extraction loop, two scratchVecheap allocations per call, and SipHash(encoding, opcode)table lookups.bits()now reads fields up to 32 bits in a single shift across up to two dwords (keeping the loop for wider widths);field_valuein the emitter benefits too.Vecs indexed by(encoding, opcode)filled in identical priority order.[u32; 2]) instead of allocating scratchVecs.Benchmark (
bench_decode, release, median of 7)cargo test -p xcl --release --lib rdna2::tests::bench_decode -- --ignored --nocapture): 54 ns / instruction across 23,812 LLVM corpus instructions (~1.7–2× faster decode vs ~112 ns baseline).Tested
2159c3bb7750e25f57e17adb81584bf628d16c72onmain930e8b4:cargo build --workspace: 0 new compiler warningscargo test --workspace -- --test-threads=4: 753 passed / 0 failed / 42 ignoredcargo test -p xcl --release --lib rdna2::tests::bench_decode -- --ignored --nocapture: passed (23812 instructions, ns per instruction (median of 7): decode 54)Regression run
Smoke run by @LocranKing in comment below: https://github.com/xcl-dev/xcl/pull/1387#issuecomment-7139613745
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.
main:
PR:
Tester's setup: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (
8024 MiB VRAM, driver32.0.16.2101),rustc 1.100.0(x86_64-pc-windows-msvc, MSVC14.44.35207), DXC1.9.2602.17(SDK10.0.26100.0),--releaseTester's AI use: Antigravity (
Gemini 4 Neon) ran the build, tests, and smoke runs and drafted this report from the command outputs.Not tested
AI use
Imported from ivall/xcl. Originally posted by Frtuchinno on 2026-11-24T15:50:31Z.
Test report for #1387 on an AMD host (Ryzen 5 7600, Windows):
decode123–129 → 63–65 ns per instruction; 753 passed, 0 failed, 42 ignoredThis covers the "Not tested: AMD hosts" line. The speedup reproduces on Zen 4:
decodeis about 1.9× faster, and the other decoder functions are unchanged.Tested
2159c3b, baselinemain930e8b4stable-x86_64-pc-windows-msvc, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4(debug):main930e8b4: 751 passed, 0 failed, 41 ignored, 0 SKIPPED2159c3b: 753 passed, 0 failed, 42 ignored, 0 SKIPPED;decode_matches_the_hash_map_referenceandllvm_gfx10_corpuspassbench_decode(release,cargo test --release -p xcl --lib rdna2::tests::bench_decode -- --ignored --nocapture). For the baseline I copied the PR'sllvm_encodings,per_instructionandbench_decodeunchanged into the test module of amain930e8b4worktree. The two test binaries were run alternately, three times each (ns per instruction, median of 7, 23 812 instructions):decodemain → PRsgpr_usesvgpr_usesbranch_targetformatNot tested
xcl shaderstranslation timing, no smoke runAI use
Imported from ivall/xcl. Originally posted by ArturoWolff on 2026-11-24T15:51:07Z.
Tested the decoder change inside #1269’s
lane_masks::analyze_code(&code, true), not justrdna2::decodein isolation. Same analyzer (gefydev/xcl51f977a7f29171c88307f152d529bed8bcc0d468), swapping only the decoder from930e8b49c1c2ec683d22c724a398b39111cd0e56to2159c3bb7750e25f57e17adb81584bf628d16c72.The decoder alone used 41% and 34% less CPU time respectively. Both decoders produced identical per-instruction records and every returned analyzer field matched. The join kept all seven guard sites; the mixer needed none.
Method: Ryzen 5 5600, native Linux x86-64, rustc 1.92.0,
-C opt-level=3, one codegen unit. Private CPU harness:python3 -IB measure2.pythenpython3 -IB stats.py; eight alternating A/B pairs, equal calls per pair, pinned to one hardware thread, warm inputs, measured process CPU time. No outliers removed; the mixer’s paired whole-analysis change ranged from 7.3% slower to 19.9% faster. This measures two generated programs, not total shader compilation or title loading. No DXC, GPU dispatch or full Windows suite in this test.AI use: Hermes Agent (gpt-6.2-astra) prepared and ran the harness, checked outputs and wrote this report.
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T15:54:53Z.
Windows test report and paired decoder benchmark for
2159c3bOn the Ryzen 7 9800X3D, median
decodetime fell from 112.5 to 56 ns per instruction (2.01× throughput).Tested
2159c3bb7750e25f57e17adb81584bf628d16c72,cargo build --workspace --lockedandcargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-outputpassed. Cargo reported 753 passed, 0 failed, 42 ignored, including passing decoder equivalence tests and the synthetic end-to-end title. Two GPU tests reportedSKIPPEDfor lack of native wave64 and are included in Cargo’s pass count:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware.mainworktree at930e8b49c1c2ec683d22c724a398b39111cd0e56. I built each withcargo test --locked --release -p xcl --lib --no-runand rangpu::rdna2::tests::bench_decodedirectly from the two compiled test binaries with--exact --ignored --nocapture --test-threads=1. Both used the same 23,812-entry LLVM gfx10 corpus. The table shows thedecodemedian reported for each run, with the order reversed on every other pair.mainNot tested
AI use
Imported from ivall/xcl. Originally posted by mastrr9 on 2026-11-24T16:04:54Z.
Huge thanks @Frtuchinno, @ArturoWolff, and @nnonno91 for the independent AMD Zen 4 (1.9x), RTX 5090 / 9800X3D (2.01x), and
lane_masksverification runs!Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T16:55:32Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.Thanks!
Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-24T17:43:32Z.
Independent Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, wave32) test and retail smoke report on clean head
2159c3bb7750e25f57e17adb81584bf628d16c72.Tested
2159c3bb7750e25f57e17adb81584bf628d16c72(clean tree, merge-base930e8b4)8024 MiB VRAM, driver32.0.16.2101),rustc 1.100.0(x86_64-pc-windows-msvc, MSVC14.44.35207), DXC1.9.2602.17(SDK10.0.26100.0),--releasecargo build --release --workspace: ok (exit 0)cargo test --workspace --release --no-fail-fast -- --test-threads=4: 753 passed, 0 failed, 42 ignored, exit0SKIPPED(no wave64):gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardwareRegression run
mainbaseline (b7aa9f3bd212088e0d927439284dc5ed325ce3c7):PR head (
2159c3bb7750e25f57e17adb81584bf628d16c72):Not tested: debug build, isolated decode throughput microbenchmark, AMD / native wave64 hardware, extended gameplay past 60 s.
AI use: Antigravity (
Gemini 4 Neon) ran the build, tests, and smoke runs and drafted this report from the command outputs.Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-24T19:16:30Z.
Linux (Wine + vkd3d-proton) + NVIDIA test of
2159c3bonmain9e3831e+ #684: in a retail title the burst of pipeline creation after the loading screen starts (about 10,500 shaders parsed on the title's threads) took 2.9 to 5.1 s with it against 4.2 to 7.3 s without, shorter in 4 of 5 alternated pairs. Its tests pass under Wine.Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch,
VKD3D_CONFIG=ignore_shared_fence. RTX 4070 12 GB (driver 615.71.09), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled tox86_64-pc-windows-gnu(rustc 1.98.0), DXC 1.9.2609.5,XCL_NETWORK=0. Retail title 1.0.2.1, the first-run screens completed once and no story progress.2159c3bmerged ontomain9e3831e+ #684 (e56dbc3) without conflicts;mainisc160d86now. The machine was busy with other work throughout (load 6 to 16 on 32 threads), so the timings are noisier than they would be alone.Tested
cargo test --release -p xcl --lib rdna2::under Wine, on the merge: 11 passed, 0 failed, 1 ignored (the benchmark). That includesbits_match_the_bitwise_referenceanddecode_matches_the_hash_map_reference.bench_decodeunder Wine, 3 runs:decode53, 55 and 52 ns per instruction.mainhas no such benchmark, so I have no figure without the change here.XCL_PSO_PRELOAD=0, caches warm. The burst is timed from its 100th[SHADER]line to its 10,400th:9e3831e+ #6842159c3bFour earlier runs of the same baseline tree today gave 4.28 to 4.62 s (two of them on a rebuilt copy of the same vkd3d-proton). All ten runs reached 60 s without a fault; one with the change then hung in XCL's shutdown and was ended by the harness.
ntdll.dllunderdxcompiler.dll. The machine had 7 to 10 GB of memory free before those two; 9 other cold starts with the change and 11 without had no fault, so I cannot tie them to the change.Read
rdna2.rs:203and:226: the two scratchVecs ofdecodeare arrays on the stack now. One allocation per instruction is left,read_wordsat:264forDecoded::words(up to 5 dwords). In the thread dumps on #688 the title's threads waited for the process heap's lock insiderdna2::decode, and a DXC worker was at the same lock from an allocation of its own; I have not taken a dump with this change, but this is the allocation they would still wait on. Would a[u32; 5]with the length do forwords?rdna2.rs:137: the one-shift path ofbitscoverscntup to 32 and reads a missing dword as 0, as the loop did. I found no field it reads differently, and the reference test agrees.Not tested: the burst with the preload on and an empty DXIL cache (5 runs were made, 2 of them beside a test suite of ours that faulted on the same card, so they do not compare); the offline pass (
xcl shaders --precompile) with and without; a quiet machine; AMD and Intel graphics.AI use: Claude Code (Claude Fable 5.2) read the diff, built the trees, ran the tests, the benchmark and the runs, compared the logs and wrote this report.
Posted without review by a person: the account owner was away and reads replies later.
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-25T17:42:14Z.
Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head
2159c3bb7750e25f57e17adb81584bf628d16c72(merged locally ontomain68a284a, clean merge).Hardware & environment
experimental-11.0-20261112),vkd3d-protonmasterec207194(3.2.0) +dxil-spirvb540c8a2+ relaxed-vtable patch (-Db_ndebug=true), DXVKv3.1.1-209, DXC1.9.2609.5, Rustx86_64-pc-windows-gnu(debug)Tested (
XCL_REQUIRE_GPU=wave64,VKD3D_CONFIG=ignore_shared_fence,--test-threads=1 --nocapture)gpu::rdna2: 19 passed, 0 failed, 1 ignored (0 skipped)Not tested
bench_decodetiming, retail title smoke run, native Windows.AI use
Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-27T17:02:32Z.
merge-check
base:
6089122a1c(origin/main, re-fetched before the run)head:
2159c3bb77merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1466 passed, 1 failed, 48 ignored; failing:
gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, which also fails on the base (1464 passed, 1 failed, 47 ignored; the difference is the PR's 2 new tests passing plus 1 new#[ignore]benchmark). Both new tests (bits_match_the_bitwise_reference,decode_matches_the_hash_map_reference) ran and passed. SKIPPED lines are identical on base and merge (f16 / f32-conversion per-lane programs refused by the translator, one "no heap windows"); no GPU test skipped for lack of hardware. Debug profile, real GPU, no WARP.review: none, after reading the whole diff of the merge result (one file,
gpu/rdna2.rs). The indexed tables are equivalent to the hash maps: same first-instruction-wins rule, sameop as u16truncation.bits()fast path is correct for cnt <= 32 (off % 32 + cnt <= 63 in the u64 shift; dwords past the end read as 0, as before).head_wordsis safe because every primary encoding is 32 or 64 bits; the 96/128/160-bit ones are all non-primary. The tests compare against a copy of the old implementation on the LLVM corpus (also truncated), every encoding of every instruction, and 100k random dwords. The benchmark is#[ignore]by design, not hiding a failure.performance: CPU only, no frame-time effect: faster instruction decode during shader translation (the PR measures it; I did not benchmark). Memory: the tables are a few KB. Nothing changes in the translated output, so no re-translation of shader caches.
verdict: safe to merge
hardware / tool and model: AMD RX 7800 XT (driver 32.0.31035.1003), Ryzen 7 5700X3D, Windows 11 build 26200, Rust stable-x86_64-pc-windows-msvc. Claude Code (Claude Sonnet 5.5). No retail-title run (not required for a merge check, per #3041).
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-27T17:27:03Z.
merge-check
base:
6089122a1c96dff16e93b6fdf04c8ed20cfb6102(main, checked 2026-11-27)head:
2159c3bb7750e25f57e17adb81584bf628d16c72merge: clean
build:
cargo build --workspace-> ok in an isolated merged-tree build directorytests:
cargo test --workspace --no-fail-fast -- --test-threads=4-> 1,466 passed, 1 failed, 48 ignored; 25 GPUSKIPPEDnotices within Cargo's passing counts. The sole failure wasgpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk(cached_only console_mesh hit: "DXIL not compiled yet"). The same focused test failed with that error on untouched base6089122in my earlier current-base check. The newdecode_matches_the_hash_map_referencetest and the LLVM gfx10 corpus test passed.review: none found in the merged one-file diff. The indexed opcode tables retain first-match priority; the two-dword scratch read preserves zero fill for short input; all current primary encodings are 32 or 64 bits, and decoded instructions still own their extension/literal words. The differential test covers truncation, encodings, and random instruction words.
performance: the default decode path removes per-instruction scratch allocations and hash probes, replacing field extraction up to 32 bits with constant work. Its tables are built once. I did not benchmark throughput or title frame time on this merge; existing PR reports measure decoder/startup improvements on other hardware.
verdict: safe to merge on this base and head. The one workspace failure is reproduced on the unmodified base; I found no new failure or open source finding attributable to this PR. This check did not run a retail title.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, NVIDIA RTX 3080 Ti 12 GB / driver 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the build/tests and reviewed the merge; Codex (GPT-6.2 Astra) independently reviewed the low-level decoder path.