Repository navigation
shader_disasm: hand llvm-mc its input in lines of 64 bytes (OLD-10020) - #623
Conversation
…ong line llvm-mc slows down sharply on one long input line. disasm() joined each program's bytes with spaces into a single line, so large programs took tens of seconds each: a 90 KB library program took 58.6 s that way and 0.2 s split into lines of 64 bytes, with byte-identical disassembly (the same .s text and the same count of undecodable words; only the line/column numbers in llvm-mc's diagnostics change). make_game.py's pipeline-library step (2,684 programs from shaders.rpf) went from about one program per minute to about 1.5 minutes for all of them. tests/test_shader_disasm_input_lines.py stubs subprocess.run and checks the text llvm-mc would receive: lines of at most 64 bytes, the same bytes in order, no empty or trailing lines, and inputs of up to 64 bytes (the probe included) unchanged. It needs no llvm-mc and no game data. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ee7667a to
0b04572
Compare
bobcatchris
left a comment
There was a problem hiding this comment.
Reviewed 0b04572d9 on Windows 11, LLVM 21.1.8, Python 3.12. No GPU. AI-assisted.
tests/test_shader_disasm_input_lines.pyandtests/test_shader_disasm.pypass (35 tests).git merge-treeagainstmainat507029d1eis clean. The PR is 135 commits behind.- On real pipeline-library compute programs of 1.0.2.1 (counts and sizes only), I compared
main's one-line input with this PR's 64-byte lines: six flagged programs (the five smallest, 8.6 KB to 11 KB, and the largest, 158 KB with 147 rejected words) and six clean programs (the three largest, 77 KB, 67 KB and 40 KB, and three of 8 bytes). The listing text is byte-identical every time, andinvalid_offsets()returns the same set from each tree's own diagnostics.
What this fixes, measured. With one line, llvm-mc prints its whole input before each warning, so both the time and the diagnostics grow with warnings × program size:
| program | code | rejected words | main |
this PR |
|---|---|---|---|---|
lib_cs_01631 |
158 KB | 147 | 53.2 s, 162,622,231 characters of stderr | 0.12 s, 80,112 |
lib_cs_01239 |
11 KB | 5 | 0.17 s, 493,945 | 0.02 s, 2,380 |
lib_cs_01202 (clean) |
77 KB | 0 | 0.05 s | 0.05 s |
Clean programs take the same on both, so the single line is not slow by itself; it is the echo.
The library stage copies that stderr into the listing (; --- llvm-mc messages ---), so on main a flagged listing is 60 KB to 250 MB. Running shader_library.py --stages cs --disasm on this package with one worker wrote 8.9 GB for its first 170 flagged listings and then stopped at 829 of 2,684 with OSError: [Errno 28] No space left on device. With this PR the whole set is a few hundred MB, and the stage is minutes instead of hours.
Not run: shader_disasm.py on a folder of FSSM blobs end to end; any llvm-mc other than 21.1.8 on Windows.
Recommendation: Merge.
|
A measurement for why this is worth having, from
Not a clean A/B: other shader jobs ran at the same time, and I did not run this PR's 64-byte lines. But the order of magnitude matches the 58.6 s to 0.2 s in the description, and without it the library step looks hung. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Reviewed 0b04572. Its only change against main is ee7667a; the rest is a merge of main. I ran everything in a Linux arm64 sandbox with a real
The one risk I could see is an 8-byte instruction that starts at byte 60 and continues on the next 64-byte line. I checked it with the real I did not re-measure the timing. No findings. AI-assisted review. Recommendation: Merge |
|
Closing as superseded by #984 (commit 18a22c1), which landed one-dword-per-line input splitting in ools/shader_disasm.py:run_mc() together with the matching multi-line invalid_offsets() calculation ((int(line) - 1) * 4 + (int(col) - 1) // 5). Many thanks to @bobcatchris, @Snooozs, and @PierreEbele for the reviews and pipeline-library benchmarks! |
|
Heads-up for this PR's fate: |
Claimed in the coordination issue as: OLD-10020
What and why
Carries forward
old-pr/10020(draft #289) ontomain(21625bca8), preservingbeamdotdev's original commit verbatim perCONTRIBUTING.md:llvm-mc --disassembleintools/shader_disasm.py(disasm()) into lines of 64 bytes ("\n".join(" ".join(f"0x{b:02x}" for b in code[i:i + 64]) for i in range(0, len(code), 64))) instead of a single line.llvm/tools/llvm-mc/Disassembler.cpp):SkipToToken()strips" \t\r\n,"andbyteArrayFromString()accumulates bytes continuously across newlines into a singleByteArray(only[,], or EOF flushprintInsts()), so multi-dword RDNA2 instructions spanning a 64-byte line boundary decode byte-identically while avoidingllvm::SourceMgrquadratic line scanning on long single-line inputs (reported 58.6 s → 0.2 s on a 90 KB shader).tests/test_shader_disasm_input_lines.py(stdlib-only, stubssubprocess.run, nollvm-mcor game data required).b"",bytearray/memoryview, boundary sizes (1, 63, 64, 65, 128, 129), and downstream callers (NO_HARDENING_NEEDED).Tested
All synthetic CPU/stdlib/docs checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files, no
llvm-mcinstalled locally):python -I tests/test_shader_disasm_input_lines.py -v— 4/4 passedpython -I tests/test_ci_registration.py— 15/15 passedpython -I tests/test_runtime_paths.py— 5/5 passedpython -I scripts/check_no_game_data.py— passed (0 forbidden tracked extensions)python -m compileall -q make_game.py tools tests— passedpython -I tests/test_text_write_line_endings.py,tests/test_report_paths.py,tests/test_i18n_index.py, and alltests/test_docs_*.py— passednode --test tests/test_viewer_streaming.cjs— passedGPUs tested: n/a (CPU disassembler input formatting / unit tests only)
AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (N/A —llvm-mcstdin line wrapping only; no shader-translator rule changed.)