Skip to content

Recompiler: decode RDNA2 instructions without hashing or scratch Vecs - #1387

Open
mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:perf/rdna2-decode-no-hash
Open

mastrr9 wants to merge 1 commit into
xcl-dev:mainfrom
mastrr9:perf/rdna2-decode-no-hash

Conversation

@mastrr9

@mastrr9 mastrr9 commented Nov 24, 2026 •

Copy link
Copy Markdown

Targets #1269 (shader translation / compilation speed).

What changed

rdna2::decode runs once or more for every console instruction during shader translation (and across every instruction of a pack in xcl shaders). Previously it spent ~1,850 CPU instructions per decoded instruction on a bit-by-bit field extraction loop, two scratch Vec heap 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_value in the emitter benefits too.
  • Opcode lookup tables are now flat Vecs indexed by (encoding, opcode) filled in identical priority order.
  • Primary instruction dwords stay on the stack ([u32; 2]) instead of allocating scratch Vecs.
  • Unit tests keep the original decoder as a reference and compare every decoded field (or identical error) across the LLVM gfx10 corpus cut at every length, every encoding/instruction with random operand bits, SDWA/DPP/literal/short buffers, and 100,000 random instructions.

Benchmark (bench_decode, release, median of 7)

  • Windows 11 / RTX 5080 host (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

  • Windows 11 x64, NVIDIA GeForce RTX 5080, DXC 1.9.2602.17, Rust MSVC, head 2159c3bb7750e25f57e17adb81584bf628d16c72 on main 930e8b4:
    • cargo build --workspace: 0 new compiler warnings
    • cargo test --workspace -- --test-threads=4: 753 passed / 0 failed / 42 ignored
    • cargo 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: #1387 (comment)
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.

main:

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1508)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14730 MB

PR:

xcl-smoke v1
commit: 2159c3bb7750e25f57e17adb81584bf628d16c72
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14712 MB

Tester's setup: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release

Tester's AI use: Antigravity (Gemini 4 Neon) ran the build, tests, and smoke runs and drafted this report from the command outputs.

Not tested

  • Whether the community regression run reaches the changed code; play past its 60 s.
  • AMD / Linux (Wine) hosts.

AI use

  • Claude Code (Claude Opus 5.5) drafted the optimization and tests; T3 Code (Gemini 4 Neon + Claude Sonnet 5.5) verified the build, full workspace test suite, and release benchmark on our Windows 11 / RTX 5080 PC.
  • Claude Code (Claude Sonnet 5.5) added the community regression run to this description and updated the lines that it made out of date or that the PR check requires.

`rdna2::decode` runs once or more for every instruction the recompiler
translates (and for every instruction of a pack in `xcl shaders`).
Under callgrind on the LLVM gfx10 corpus it took ~1 850 instructions per
call: a bit-by-bit loop in `bits` (every field read, ~28 %), two
scratch `Vec`s for the first dwords next to the one `Decoded` keeps
(~17 % in malloc / free), and a SipHash lookup of (encoding, opcode)
for every candidate encoding (~10 %).

- `bits` reads a field of up to 32 bits (all the tables have) with one
  shift of the two dwords it spans; wider counts keep the old loop.
  Missing dwords still read as 0. This also speeds up every
  `field_value` call of the emitter.
- The opcode tables are vectors indexed by encoding and opcode, filled in
  the same order (the first instruction per opcode wins, as with
  `entry().or_insert`), and each primary encoding keeps its OP field.
- The first dwords are a `[u32; 2]` on the stack (primary encodings are
  32 or 64 bits; a 32-bit one reads its second dword as 0, as the
  one-dword `Vec` did).

The tests keep the old decoder as a reference and compare every field of
the result (same instruction, encoding and table entries, dwords,
length, literal, variant) or the same error on the LLVM corpus cut at
every length, on every encoding of every instruction with random
operand bits, literal / SDWA / DPP source codes and short buffers, and
on 100 000 random instructions; `bits` is compared with the bit loop for
every offset and width on short and empty dword slices.

Release, median of 7 alternating runs, ns per instruction:
decode on the LLVM corpus (23 812 instructions) 112 before, 66 after
(1.7x); a whole `translate` of six synthetic programs (34 552
instructions, structured control flow) 91.8 ms before, 79.5 ms after
(both commits of this series; this one is most of it).

Assisted-by: Claude Code
@Frtuchinno

Copy link
Copy Markdown
Contributor

Test report for #1387 on an AMD host (Ryzen 5 7600, Windows): decode 123–129 → 63–65 ns per instruction; 753 passed, 0 failed, 42 ignored

This covers the "Not tested: AMD hosts" line. The speedup reproduces on Zen 4: decode is about 1.9× faster, and the other decoder functions are unchanged.

Tested

  • Head 2159c3b, baseline main 930e8b4

  • AMD Ryzen 5 7600, 32 GB RAM, AMD Radeon RX 7800 XT (driver 32.0.32029.2010), Windows 11 Pro build 26300

  • rustc 1.100.0 stable-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):

    • main 930e8b4: 751 passed, 0 failed, 41 ignored, 0 SKIPPED
    • 2159c3b: 753 passed, 0 failed, 42 ignored, 0 SKIPPED; decode_matches_the_hash_map_reference and llvm_gfx10_corpus pass
  • bench_decode (release, cargo test --release -p xcl --lib rdna2::tests::bench_decode -- --ignored --nocapture). For the baseline I copied the PR's llvm_encodings, per_instruction and bench_decode unchanged into the test module of a main 930e8b4 worktree. The two test binaries were run alternately, three times each (ns per instruction, median of 7, 23 812 instructions):

    run decode main → PR sgpr_uses vgpr_uses branch_target format
    1 123 → 65 138 → 141 90 → 86 2 → 1 374 → 374
    2 123 → 64 141 → 137 91 → 89 2 → 1 366 → 366
    3 129 → 63 145 → 140 93 → 86 2 → 1 365 → 369

Not tested

  • No retail title or shader pack on this machine: no xcl shaders translation timing, no smoke run
  • Linux / Wine, Intel CPUs

AI use

  • Claude Code (Claude Opus 5.5) installed the toolchain, set up the baseline worktree, ran the commands above and wrote this report.

@ArturoWolff

Copy link
Copy Markdown

Tested the decoder change inside #1269’s lane_masks::analyze_code(&code, true), not just rdna2::decode in isolation. Same analyzer (gefydev/xcl 51f977a7f29171c88307f152d529bed8bcc0d468), swapping only the decoder from 930e8b49c1c2ec683d22c724a398b39111cd0e56 to 2159c3bb7750e25f57e17adb81584bf628d16c72.

Generated wave64 program Whole-analysis CPU time, base → head (median) Median within-pair CPU reduction Head faster
Branch join, 36 instructions 33.36 → 31.12 µs 6.89% 8/8 pairs
Arithmetic mixer, 6,166 instructions 4.605 → 4.359 ms 5.60% 7/8 pairs

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.py then python3 -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.

@nnonno91

Copy link
Copy Markdown

Windows test report and paired decoder benchmark for 2159c3b

On the Ryzen 7 9800X3D, median decode time fell from 112.5 to 56 ns per instruction (2.01× throughput).

Tested

  • Ryzen 7 9800X3D, GeForce RTX 5090 (driver 617.42), Windows 11 25H2 (26200.9974), Rust 1.100.0 MSVC, DXC 1.8.2502.11.
  • On clean head 2159c3bb7750e25f57e17adb81584bf628d16c72, cargo build --workspace --locked and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-output passed. Cargo reported 753 passed, 0 failed, 42 ignored, including passing decoder equivalence tests and the synthetic end-to-end title. Two GPU tests reported SKIPPED for lack of native wave64 and are included in Cargo’s pass count: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware.
  • I copied only the PR’s benchmark harness into a temporary main worktree at 930e8b49c1c2ec683d22c724a398b39111cd0e56. I built each with cargo test --locked --release -p xcl --lib --no-run and ran gpu::rdna2::tests::bench_decode directly 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 the decode median reported for each run, with the order reversed on every other pair.
Build Decode time across six runs (ns/instruction) Median
main 126, 110, 111, 114, 110, 126 112.5
PR 56, 60, 56, 56, 56, 55 56

Not tested

  • Retail-title smoke runs and end-to-end shader compilation time.

AI use

  • OpenAI Codex (GPT-6, exact model variant unavailable) ran the tests and prepared this report.

@mastrr9

mastrr9 commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Huge thanks @Frtuchinno, @ArturoWolff, and @nnonno91 for the independent AMD Zen 4 (1.9x), RTX 5090 / 9800X3D (2.01x), and lane_masks verification runs!

@mastrr9
mastrr9 marked this pull request as ready for review November 24, 2026 16:41
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@LocranKing

Copy link
Copy Markdown

Independent Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, wave32) test and retail smoke report on clean head 2159c3bb7750e25f57e17adb81584bf628d16c72.

Tested

  • Commit: 2159c3bb7750e25f57e17adb81584bf628d16c72 (clean tree, merge-base 930e8b4)
  • Hardware / software: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo build --release --workspace: ok (exit 0)
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 753 passed, 0 failed, 42 ignored, exit 0
    • SKIPPED (no wave64): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware

Regression run
main baseline (b7aa9f3bd212088e0d927439284dc5ed325ce3c7):

xcl-smoke v1
commit: b7aa9f3bd212088e0d927439284dc5ed325ce3c7
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1508 (PresentX 1508)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14730 MB

PR head (2159c3bb7750e25f57e17adb81584bf628d16c72):

xcl-smoke v1
commit: 2159c3bb7750e25f57e17adb81584bf628d16c72
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14712 MB

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.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of 2159c3b on main 9e3831e + #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 to x86_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. 2159c3b merged onto main 9e3831e + #684 (e56dbc3) without conflicts; main is c160d86 now. 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 includes bits_match_the_bitwise_reference and decode_matches_the_hash_map_reference.
  • bench_decode under Wine, 3 runs: decode 53, 55 and 52 ns per instruction. main has no such benchmark, so I have no figure without the change here.
  • The title, 60 s runs, A pressed on the account screen at 16 to 20 s, XCL_PSO_PRELOAD=0, caches warm. The burst is timed from its 100th [SHADER] line to its 10,400th:
pair 9e3831e + #684 the same + 2159c3b
1 7.25 s 3.17 s
2 4.28 s 5.12 s
3 4.46 s 2.86 s
4 4.59 s 3.15 s
5 4.17 s 2.88 s

Four 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.

  • Two cold starts with the change (the preload of D3D12.X: pipelines an earlier run used are built ahead of their first use #690 on, an empty DXIL cache) faulted at 4.4 and 4.7 s with an access violation in ntdll.dll under dxcompiler.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:203 and :226: the two scratch Vecs of decode are arrays on the stack now. One allocation per instruction is left, read_words at :264 for Decoded::words (up to 5 dwords). In the thread dumps on Shaders: isolate DXC compiler heaps for parallel AOT #688 the title's threads waited for the process heap's lock inside rdna2::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 for words?
  • rdna2.rs:137: the one-shift path of bits covers cnt up 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.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants