Repository navigation
Conversation
…thon fallback A zero-dependency Rust port of assemble(): same tokenizer, ID numbering, operand grammar walk, literal rules and header, so the .spv bytes are identical. The grammar tables stay in spirv_asm_tables.py; spirv_asm.py serialises them and passes them in once. The native path declines (and assemble() goes on in Python, with its usual result or SpirvAsmError) on every error and on what it does not reproduce exactly, when the library is not built, or with LEONIDA_SPIRV_ASM_NATIVE=0. The hook is a loader plus three lines at the top of assemble(). On the 221 synthetic audit shaders (14.6 MB of text): 221/221 byte-identical, none declined, assemble() 0.86-0.93 s in Python and 53-56 ms native (16.4x-16.5x). 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.
Item: PERF-SPIRV-ASM-NATIVE (claim). Same pattern as #6308 / #8447.
What
tools/spirv_asm_nativeis a zero-dependency Rust port ofassemble()intools/spirv_asm.py. It uses the same tokenizer, ID numbering, operand grammar walk, literal rules and header as the Python code, so the.spvbytes are identical. The literal rules cover integers of every width and signedness, decimal and hex floats, OpSwitch case widths and bit-mask parameters in ascending bit order.spirv_asm.pyserialisesINSTRUCTIONS,VALUE_ENUMS,BIT_ENUMSand_EXT_SETSfromspirv_asm_tables.pyand passes them in once.assemble()continues in Python with its usual result orSpirvAsmError. So error messages are unchanged. Inputs it declines:int(tok, 0)spellings with_;infornan;float.fromhex;LEONIDA_SPIRV_ASM_NATIVE=0also keep everything in Python._native_assemble/_load_nativeloader just aboveassemble(), plus three lines at its top.git merge-tree).mainwithout this PR.float.fromhexbranch, which the port already leaves to Python, so it stays consistent.tests/test_spirv_asm_native.pywill flag any divergence.--locked --offline), asserts the library loads, then runstest_spirv_asm_native.py,test_spirv_asm.pyandtest_spirv_asm_tables.pywith the native path on.Benchmarks
Timings cover
assemble()over the 221 synthetic audit shaders: hand-written RDNA listings, no game data, translated withrdna2spirv.py --assembler python, 14.6 MB of.spvasm. Taken on an AMD Ryzen 9 5900X, Windows 11, Python 3.12.10, rustc 1.100.0, with the min of 3 Python runs and 7 native runs. The machine was shared and noisy, so three separate runs are shown:assemble()(before)Byte-identical: 221/221, none declined. The Python output also matches the
.spvfilesrdna2spirv.pywrote. The hook overhead (ASCII encode plus copy-out) is about 6 ms. The Rust core alone runs at about 280–290 MB/s.Tests
cargo build --releaseandcargo test --release(12 tests): 0 warnings.python -I tests/test_spirv_asm_native.py(new, 14 tests), comparing native against Python:tests/semanticfixtures that need no compute header;SpirvAsmErrormessage;assemble();The comparisons skip when the library is not built.
python -I tests/test_spirv_asm.pywith native on and withLEONIDA_SPIRV_ASM_NATIVE=0: OK (1 skip; spirv-as and spirv-val are not installed here).python -I tests/test_spirv_asm_tables.py: OK.python -m compileall -q make_game.py tools tests: OK.python -I scripts/check_no_game_data.pyon every changed file: clean.tests/semanticwas not run, as asked; the translator is unchanged.tests/test_text_write_line_endings.pyfails onmainalready (tools/leonida_tui.py:753,tools/wave_diff.py:373); nothing here touches those files.CPU-only change; no GPU or driver involved. Tested on Windows 11 (AMD Ryzen 9 5900X).
AI-assisted: written with Claude Code (Claude Opus 5.5) and reviewed by me.
🤖 Generated with Claude Code