RDNA2 decoder: opcodes from a table per encoding, fields a word at a time #474
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/479"
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 TG0000 on 2026-11-24T00:53:40Z.
The RDNA2 decoder is the first stage of every shader translation. The recompiler reads every operand through the same
field_value, so a faster decoder speeds up all of them. Per instruction,decode()used to:HashMap<(encoding, opcode), _>once for every primary encoding whose fixed bits matched,Vec<u32>: the head, the base words and the final words.What is in it
crates/xcl/src/gpu/rdna2.rsonly. Each primary encoding now keeps a dense1 << width(OP)table of its instructions (at most 1024 entries; the EXP encoding, which has no OP field, uses slot 0). When two instructions claim an opcode, the first one keeps it (spec before console extensions), as the oldor_insertdid, and the tables are still tried in spec priority order.bits()takes whole runs of a word at once. Bits past the last word still read as 0.[u32; 5]on the stack (the widest encoding is 160 bits). OnlyDecoded::wordsis allocated: 1 allocation per decode instead of 3.decode,field_value,Decoded) or to its results.Release microbenchmark (
#[ignore]d testgpu::rdna2::tests::bench_decode): it decodes the 23 812 instructions of the LLVM gfx10 disassembler corpus already intests/data/llvm-amdgpuand reads every operand field, as the recompiler does. Each figure is the best of 15 runs of 8 rounds. Before and after alternated, with a rebuild each time:origin/mainThat is ≈1.8× faster. The checksum over decoded lengths and field values is identical (
sink 1484757240) in every run.Tested
stable-x86_64-pc-windows-msvc; debug and release.bits_matches_one_at_a_time: every offset (also past the end) and every count 0..=64, on 0–6 random words, against the old bit-at-a-time loop.field_value_matches_one_at_a_time_for_every_field: every field of every encoding.opcode_tables_match_first_claim_lookup: every slot of every table against a first-claimHashMapbuilt like the old one.decoded_words_are_the_instruction_dwords: across the whole LLVM corpus, plus a trailing partial dword.llvm_gfx10_corpustest (name and length of 23 812 instructions) and the other decoder tests pass:cargo test --release -p xcl --lib rdna2: 13 passed, 2 ignored (one is the benchmark).cargo test --workspace --no-fail-fast -- --test-threads=4: lib 637 passed, 3 failed, 22 ignored; all integration tests pass (e2e 3/3). The three failures are GPU tests inhle::d3d12x(title_textures::placed_title_textures_share_vram_and_preserve_pixels,title_textures::transitions_apply_when_their_list_is_submitted,vram::d32s8_targets_take_their_own_size_of_video_memory). They fail the same way onorigin/mainon this machine, in two runs with main'srdna2.rs.cargo clippy -p xcl --all-targets: same warning counts asorigin/main(lib 422, lib test 632), so no new warnings.Regression run
main:
PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by brothernog on 2026-11-24T01:22:53Z.
Independent check of
cbb03e1on NVIDIA. I read the decoder change against the old lookup, and I didn't find a behaviour difference:if let Some(s @ None)keeps the oldor_insertorder. Instructions of non-primary encodings are skipped, as before, since the oldby_opentries for them were never looked up. EXP (no OP field) uses slot 0, which is the oldno_opmap.1 << field_width("OP")slots, so a decoded OP always indexes inside it.field_widthsums the field's ranges.HEAD_WORDS = 5covers the widest encoding inrdna2_spec.rs: 160 bits, one encoding.base_wordsis sliced from it, and bytes past the input still read as 0, asread_wordsdid.Tested
cargo test -p xcl --lib rdna2: 13 passed, 0 failed, 2 ignored.cargo test --workspace --no-fail-fast -- --test-threads=4: 680 passed, 0 failed, 42 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware. Unlike your RX 6800 run, the threehle::d3d12xGPU tests pass here.Not tested
This review was AI-assisted.
Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T02:42:19Z.
Hardware check of
cbb03e1b250e32801f1a5d6be6c5077e1961fc20(verified clean merge withmain3db536e): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace -- --test-threads=4:680 passed, 0 failed, 42 ignored(GPU tests skipped on this adapter:none; the threehle::d3d12xGPU tests that failed on RX 6800 also pass here)cargo test --release -p xcl --lib rdna2::tests::bench_decode -- --ignored --nocapture:23812 instructions x 8, best of 15: 12.94 ms, 68.0 ns/instruction (sink 1484757240)Regression run
main(9ce2070):PR (
cbb03e1):Not tested
AI use
scripts/smoke.ps1harness on this machine and formatted this report.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:12:07Z.
Both AMD (RX 9070 XT) and NVIDIA verification look great on
cbb03e1. Please rebase ontomainto resolve the currentrdna2.rsmerge conflict soBuild and test (Windows, no GPU)can run cleanly.Imported from ivall/xcl. Originally posted by TG0000 on 2026-11-25T12:28:41Z.
Rebased onto main
1a0bbe3: head0f112d4. The conflict was in the tests only (main's SDWA text test and this PR's tests now stand side by side); the decoder change is as reviewed.Run on this head (Ryzen 9 5900X, Windows 11, MSVC):
cargo test -p xcl --lib rdna2: 24 passed, 0 failed, 2 ignored.bench_decode, release, one run: 111.4 ns per instruction, the checksum (1484757240) as before; main was not measured again beside it. Clippy stops on threeTAUconstants in files this PR does not touch, with this toolchain.Not run on this head: the whole suite, and the
xcl-smokepair. The blocks in the description are ofcbb03e1, so the description check is expected to ask for a fresh one until it is run.AI-assisted (Claude Code).
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T14:05:18Z.
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.Imported from ivall/xcl. Originally posted by TG0000 on 2026-11-25T15:04:31Z.
@DavidM1911 Rebased onto latest
main(head0ee075f) — thanks for testing!Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T02:45:58Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:41:24Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:34:41Z.
Triage (#1607) – head
0ee075fmain already has this change. Commit
2159c3b(#1387, merged) changesgpu/rdna2.rstables()from the(encoding, opcode)HashMap to indexed per-encodingVectables, reads the head without scratch Vecs, and extracts fields of up to 32 bits with a single shift instead of the bit-at-a-time loop inbits. This PR does the same with a slightly different layout (Primary { enc, op, insts }, a word-run loop inbits). It now conflicts with that code.The parts main lacks (the bits/field equivalence tests,
decoded_words_are_the_instruction_dwords) could be a small test-only PR on top of main.Recommendation: close (superseded by main commit
2159c3b, #1387).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:37:49Z.
Closing as superseded: this change is already on
main(2159c3bb). main rdna2.rs has per-encoding opcode tables (no HashMap) and the word-run bits() read; same change as the PRTwo independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed