Repository navigation
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
Conversation
…), ~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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 oftools/bcpack_calibration(#6308) andtools/bc7_native(#8447): a crate with no dependencies, loaded through ctypes, falling back to Python.What changes
tools/rdna2_decode_native/src/lib.rsports_decode_one,_format_operandandformat_insnbranch by branch, so the listing text and the invalid-word count are byte-identical. Each instruction is decoded into one reused scratch buffer, so there is no allocation per operand.tools/rdna2_native.pyis the loader. The opcode tables (rdna2_isa_tables.py) and the name maps ofrdna2_decode.py(hwreg, sendmsg, SDWA, omod, inline floats, MTBUF formats, the literal and SOPP sets) stay in Python. They are serialised to the library when it loads, so a pull request that only changes a table or a map keeps the native path working with no Rust change.tools/rdna2_decode.pygets a small hook (+10 lines): a lazy loader and an early return indisasm_bytes.decode_bytesand all decode logic are untouched, which keeps conflicts with the openrdna2_decodepull requests (rdna2_decode: ~30% faster listing and ~20% faster decode_bytes, output unchanged (PERF-RDNA2-DECODE) #7044, rdna2_decode: decode the gfx101x SMEM stores, scratch ops, atomics and s_atc_probe* #7421, rdna2_decode: decode the 31 GFX10 DS *_src2_* ops, and give ds_condxchg32_rtn_b64 one offset #7337, rdna2_decode: name hwreg ids as GFX10 does (HW_ID1 is 23, HW_ID2 24, POPS_PACKER 25) #7300, rdna2_decode: name the GFX10 special sources 230-239 as llvm-mc does (src_shared_base ...) #7369, ...) to a minimum.LEONIDA_RDNA2_DECODE_NATIVE=0is set;FINGERPRINTinlib.rsis the SHA-256 of the source of the ported functions, and the loader compares it with the live source. So a staletarget/build, or a decoder fix merged before it is ported, can never print different text; it just turns the fast path off;_decode_one,format_insnor_iter_insns;bcpack_calibrationrunscargo buildandcargo test(--locked --offline), thentests/test_rdna2_decode_native.pyandtests/test_rdna2_decode.pywith the library present.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
FINGERPRINTrefreshed. Output stays correct either way.tests/test_rdna2_decode_native.pythen 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.pyhas 16 tests and runs in about 13 s:s_waitcnt,s_sendmsg,s_branch,s_ttracedata_imm,s_getreg_b32,s_movk_i32andds_swizzle_b32;saddr;en;Mutation check: 11 single-line mutations of
lib.rs, such as a DPP name, the swizzle REVERSE width, hwreg sizes, the MIMG gradient count, FLATsaddr127, the imm-to-hex threshold, VOP3Pop_sel_hi, the export separator and a signed SOPK name. Each makes the suite fail, except one equivalent mutant: thes_waitcnt_vscntguard is dead code in SOPP for Python too.Also run:
python -m compileall -q make_game.py tools testsandpython -I make_game.py --help: OK.python -I tests/test_rdna2_decode.py: OK with and without the library (skipped=1is the existing llvm-mc test).cargo build --releaseandcargo test --release: 0 warnings, 5 Rust tests pass.cargo fmt --checkis clean.python -I scripts/check_no_game_data.pyon every changed file: exit 0.tests/semanticwas not run; the translator is unchanged.tests/test_runtime_paths.pyfails, already onorigin/main:tools/replace_retry.pyis missing fromruntime.ymlviardna2spirv.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_bytesincluding the ctypes call and the UTF-8 decode. Output was asserted equal before timing.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 pythonwith the library built and unbuilt.AI-assisted (Claude Code). Tested on Windows only; the CI step covers Linux.
🤖 Generated with Claude Code