Skip to content

rdna2_decode: optional native disasm_bytes (tools/rdna2_decode_native), ~36x, same bytes (PERF-RDNA2-DECODE-NATIVE) - #8761

Open
TG0000 wants to merge 1 commit into
ItsNotRexed:mainfrom
TG0000:perf/rust-rdna2-decode-native
Open

TG0000 wants to merge 1 commit into
ItsNotRexed:mainfrom
TG0000:perf/rust-rdna2-decode-native

Conversation

@TG0000

@TG0000 TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

PERF-RDNA2-DECODE-NATIVE (claim)

An optional Rust build of rdna2_decode.disasm_bytes, the decoder that disassembles the shaders without LLVM. It follows the pattern of tools/bcpack_calibration (#6308) and tools/bc7_native (#8447): a crate with no dependencies, loaded through ctypes, falling back to Python.

What changes

Once this merges, a pull request that changes a ported function, such as #7044 or the decoder fixes above, turns the native path off until the change is ported and FINGERPRINT refreshed. Output stays correct either way. tests/test_rdna2_decode_native.py then reports the fingerprint test as skipped with the old and new hashes. The README gives the one-liner that prints the new hash.

Tests (synthetic words only, no game data)

tests/test_rdna2_decode_native.py has 16 tests and runs in about 13 s:

  • every one of the 1,470 opcodes in every table x 16, with random operand and modifier bits, inline constants, literals and NSA dwords;
  • field sweeps:
    • every DPP16 control, plus DPP8 and SDWA on VOP1, VOP2 and VOPC;
    • all 65,536 immediates of s_waitcnt, s_sendmsg, s_branch, s_ttracedata_imm, s_getreg_b32, s_movk_i32 and ds_swizzle_b32;
    • every source code in each source slot (VOP1, VOP2, VOP3 with 32- and 64-bit sources, VOP3B, VOP3P including fma_mix, SOP1, SOP2, SOPC);
    • SMEM data widths 1 to 16 and offsets;
    • all 128 MTBUF formats;
    • FLAT, SCRATCH and GLOBAL with each saddr;
    • all 64 export targets x en;
    • VINTRP;
    • every MIMG opcode x dim x a16 x d16 x NSA;
  • wave32 and wave64, gfx1013 and gfx1030, truncated instructions, random bytes of 0 to 65,539 bytes, one long stream;
  • fallbacks: environment variable set to 0 (in a subprocess), missing library, changed fingerprint, wrapped decoder, unusual arguments, a refused call, and the blob covering every table.

Mutation check: 11 single-line mutations of lib.rs, such as a DPP name, the swizzle REVERSE width, hwreg sizes, the MIMG gradient count, FLAT saddr 127, the imm-to-hex threshold, VOP3P op_sel_hi, the export separator and a signed SOPK name. Each makes the suite fail, except one equivalent mutant: the s_waitcnt_vscnt guard is dead code in SOPP for Python too.

Also run:

  • python -m compileall -q make_game.py tools tests and python -I make_game.py --help: OK.
  • python -I tests/test_rdna2_decode.py: OK with and without the library (skipped=1 is the existing llvm-mc test).
  • cargo build --release and cargo test --release: 0 warnings, 5 Rust tests pass. cargo fmt --check is clean.
  • python -I scripts/check_no_game_data.py on every changed file: exit 0.
  • tests/semantic was not run; the translator is unchanged.
  • tests/test_runtime_paths.py fails, already on origin/main: tools/replace_retry.py is missing from runtime.yml via rdna2spirv.py. This branch touches neither file.

Benchmark

Windows 11, Python 3.12.10, rustc 1.100.0 (stable-x86_64-pc-windows-gnu), CPU only; there is no GPU or driver in this path. Times are the best of 3 runs for Python and 7 for native, end to end through disasm_bytes including the ctypes call and the UTF-8 decode. Output was asserted equal before timing.

input Python native speedup
1 MiB synthetic shader-like stream (230,832 instructions) 1,557 ms 43.6 ms 36x
same 1 MiB as 336 shaders of 0.5 to 8 KiB 1,637 ms 45.7 ms 36x
1 MiB random bytes 1,726 ms 43.4 ms 40x

Loading costs about 40 ms once per process, including the imports, fingerprint, table blob and parse. I had no work folder here, so these numbers come from synthetic input, not the 26,503-shader corpus. Someone with a work folder can compare tools/shader_disasm.py --backend python with the library built and unbuilt.

AI-assisted (Claude Code). Tested on Windows only; the CI step covers Linux.

🤖 Generated with Claude Code

…), ~36x, same bytes

An optional Rust port of _decode_one / _format_operand / format_insn, with no
crate dependencies. disasm_bytes loads it on its first call through
tools/rdna2_native.py, which passes the Python opcode tables and name maps to
the library. It decodes in Python when the library is not built, when
LEONIDA_RDNA2_DECODE_NATIVE=0, when the library was built from another
version of the Python decoder (a SHA-256 of the ported functions' source), when
a test wraps the decoder, or when the library refuses a case Python would
raise on.

tests/test_rdna2_decode_native.py compares the two on synthetic words only:
every opcode of every table, field sweeps (DPP controls, swizzle, waitcnt,
hwreg, sendmsg, every source code per slot, MTBUF formats, MIMG dims with
a16/d16/NSA, export targets, FLAT saddr), wave32/wave64, gfx1013/gfx1030,
truncations and random bytes. CI builds the crate and runs it.

PERF-RDNA2-DECODE-NATIVE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant