shader_disasm: hand llvm-mc its input in lines of 64 bytes (OLD-10020) #623

Closed
github-bot wants to merge 1 commit from gh-pr/623/head into gh-pr/623/base
Owner

@⁠jarvixaiassistant-glitch on GitHub · 2026-11-24 10:03 UTC · original
jarvixaiassistant-glitch:fix/old-10020-shader-disasm-input-lines → main · +94 −5 · 2 files · 1 commits · closed without merging

Claimed in the coordination issue as: OLD-10020

What and why

Carries forward old-pr/10020 (draft #289) onto main (21625bca8), preserving beamdotdev's original commit verbatim per CONTRIBUTING.md:

  • Splits the hex-byte stdin passed to llvm-mc --disassemble in tools/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.
  • Verified against upstream LLVM (llvm/tools/llvm-mc/Disassembler.cpp): SkipToToken() strips " \t\r\n," and byteArrayFromString() accumulates bytes continuously across newlines into a single ByteArray (only [, ], or EOF flush printInsts()), so multi-dword RDNA2 instructions spanning a 64-byte line boundary decode byte-identically while avoiding llvm::SourceMgr quadratic line scanning on long single-line inputs (reported 58.6 s → 0.2 s on a 90 KB shader).
  • Adds tests/test_shader_disasm_input_lines.py (stdlib-only, stubs subprocess.run, no llvm-mc or game data required).
  • Audited by JARVIX's 4-model review pipeline (Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B); confirmed clean across empty 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-mc installed locally):

  • python -I tests/test_shader_disasm_input_lines.py -v — 4/4 passed
  • python -I tests/test_ci_registration.py — 15/15 passed
  • python -I tests/test_runtime_paths.py — 5/5 passed
  • python -I scripts/check_no_game_data.py — passed (0 forbidden tracked extensions)
  • python -m compileall -q make_game.py tools tests — passed
  • python -I tests/test_text_write_line_endings.py, tests/test_report_paths.py, tests/test_i18n_index.py, and all tests/test_docs_*.py — passed
  • node --test tests/test_viewer_streaming.cjs — passed

GPUs 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — llvm-mc stdin line wrapping only; no shader-translator rule changed.)
**@⁠jarvixaiassistant-glitch** on GitHub · 2026-11-24 10:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623) `jarvixaiassistant-glitch:fix/old-10020-shader-disasm-input-lines` → `main` · +94 −5 · 2 files · 1 commits · closed without merging Claimed in the coordination issue as: OLD-10020 ### What and why Carries forward `old-pr/10020` (draft #289) onto `main` (`21625bca8`), preserving `beamdotdev`'s original commit verbatim per `CONTRIBUTING.md`: - Splits the hex-byte stdin passed to `llvm-mc --disassemble` in `tools/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. - Verified against upstream LLVM (`llvm/tools/llvm-mc/Disassembler.cpp`): `SkipToToken()` strips `" \t\r\n,"` and `byteArrayFromString()` accumulates bytes continuously across newlines into a single `ByteArray` (only `[`, `]`, or EOF flush `printInsts()`), so multi-dword RDNA2 instructions spanning a 64-byte line boundary decode byte-identically while avoiding `llvm::SourceMgr` quadratic line scanning on long single-line inputs (reported 58.6 s → 0.2 s on a 90 KB shader). - Adds `tests/test_shader_disasm_input_lines.py` (stdlib-only, stubs `subprocess.run`, no `llvm-mc` or game data required). - Audited by JARVIX's 4-model review pipeline (Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B); confirmed clean across empty `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-mc` installed locally): - `python -I tests/test_shader_disasm_input_lines.py -v` — 4/4 passed - `python -I tests/test_ci_registration.py` — 15/15 passed - `python -I tests/test_runtime_paths.py` — 5/5 passed - `python -I scripts/check_no_game_data.py` — passed (0 forbidden tracked extensions) - `python -m compileall -q make_game.py tools tests` — passed - `python -I tests/test_text_write_line_endings.py`, `tests/test_report_paths.py`, `tests/test_i18n_index.py`, and all `tests/test_docs_*.py` — passed - `node --test tests/test_viewer_streaming.cjs` — passed GPUs 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(N/A — `llvm-mc` stdin line wrapping only; no shader-translator rule changed.)*
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:12:27 +00:00
github-bot closed this pull request 2026-11-26 09:12:27 +00:00
Author
Owner

@⁠bobcatchris on GitHub · 2026-11-25 00:46 UTC · original · approved these changes

Reviewed 0b04572d9 on Windows 11, LLVM 21.1.8, Python 3.12. No GPU. AI-assisted.

  • tests/test_shader_disasm_input_lines.py and tests/test_shader_disasm.py pass (35 tests).
  • git merge-tree against main at 507029d1e is 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, and invalid_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.

**@⁠bobcatchris** on GitHub · 2026-11-25 00:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623#pullrequestreview-6049810788) · **approved these changes** Reviewed `0b04572d9` on Windows 11, LLVM 21.1.8, Python 3.12. No GPU. AI-assisted. - `tests/test_shader_disasm_input_lines.py` and `tests/test_shader_disasm.py` pass (35 tests). - `git merge-tree` against `main` at `507029d1e` is 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, and `invalid_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.
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 01:12 UTC · original

A measurement for why this is worth having, from make_game.py --stages shaders on my own 1.0.2.1 copy (Windows 10 19045, Ryzen 7 7700, native llvm-mc 21.1.8, 13-14 jobs). It is about the pipeline library step (shader_library.py --disasm, 2,684 compute programs):

  • main (single input line): 955 listings written after 30 minutes, with 14 llvm-mc processes busy, the oldest at 40 s of CPU; I stopped it there.
  • #984's tree, whose shader_disasm.py splits the input the same way but into 4-byte lines: 2,244 listings about a minute after the step started, and the whole step with translation took 2 min 46 s.

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).

**@⁠Snooozs** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7149306031) A measurement for why this is worth having, from `make_game.py --stages shaders` on my own 1.0.2.1 copy (Windows 10 19045, Ryzen 7 7700, native `llvm-mc` 21.1.8, 13-14 jobs). It is about the pipeline library step (`shader_library.py --disasm`, 2,684 compute programs): - `main` (single input line): 955 listings written after 30 minutes, with 14 `llvm-mc` processes busy, the oldest at 40 s of CPU; I stopped it there. - #984's tree, whose `shader_disasm.py` splits the input the same way but into 4-byte lines: 2,244 listings about a minute after the step started, and the whole step with translation took 2 min 46 s. 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).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 01:16 UTC · original

Reviewed 0b04572d. Its only change against main is ee7667a4; the rest is a merge of main. I ran everything in a Linux arm64 sandbox with a real llvm-mc (LLVM 22):

  • tests/test_shader_disasm_input_lines.py and tests/test_shader_disasm.py: both OK on this branch.
  • The new test copied onto a main worktree: 2 failures. It tests the change.
  • check_no_game_data.py on both changed files: clean.

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 llvm-mc. The input was 15 s_nop, then v_add_f32_e64 v0, v1, v2 (VOP3, 8 bytes, straddling byte 64), then s_endpgm, for -mcpu=gfx1030 -show-encoding. The one-line and 64-byte-line inputs gave byte-identical output, and the straddling instruction decoded correctly. llvm-mc takes newlines as plain whitespace between bytes, so splitting the lines does not change decoding.

I did not re-measure the timing. No findings.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7149383638) Reviewed 0b04572d. Its only change against main is ee7667a4; the rest is a merge of main. I ran everything in a Linux arm64 sandbox with a real `llvm-mc` (LLVM 22): - `tests/test_shader_disasm_input_lines.py` and `tests/test_shader_disasm.py`: both OK on this branch. - The new test copied onto a main worktree: 2 failures. It tests the change. - `check_no_game_data.py` on both changed files: clean. 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 `llvm-mc`. The input was 15 `s_nop`, then `v_add_f32_e64 v0, v1, v2` (VOP3, 8 bytes, straddling byte 64), then `s_endpgm`, for `-mcpu=gfx1030 -show-encoding`. The one-line and 64-byte-line inputs gave byte-identical output, and the straddling instruction decoded correctly. llvm-mc takes newlines as plain whitespace between bytes, so splitting the lines does not change decoding. I did not re-measure the timing. No findings. AI-assisted review. **Recommendation:** Merge
Author
Owner

@⁠jarvixaiassistant-glitch on GitHub · 2026-11-25 03:17 UTC · original

Closing as superseded by #984 (commit 18a22c1ae), 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!

**@⁠jarvixaiassistant-glitch** on GitHub · 2026-11-25 03:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7151782637) Closing as superseded by #984 (commit 18a22c1ae), 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!
Author
Owner

@⁠bobcatchris on GitHub · 2026-11-25 04:08 UTC · original

Heads-up for this PR's fate: main landed the same input split independently in d04655943 (SHADER-VOPC-DPP, #957) - run_mc now hands llvm-mc its input in 4-byte lines with a line-and-column INVALID_AT, which bounds every diagnostic to one dword. Verified on this box against your PR: with the 4-byte lines the 158 KB library program that took 53.2 s and 162 MB of stderr on the single line takes ~0.1 s, and the library stage's whole 2,684-listing step is fast and small. The listing text is byte-identical either way, so the practical gain this PR described is now on main; the mergeable diff left here is effectively the LINE_BYTES = 64 naming and the new test. AI-assisted review; measured on Windows 11, LLVM 21.1.8.

**@⁠bobcatchris** on GitHub · 2026-11-25 04:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7152567957) Heads-up for this PR's fate: `main` landed the same input split independently in `d04655943` (SHADER-VOPC-DPP, #957) - `run_mc` now hands llvm-mc its input in 4-byte lines with a line-and-column `INVALID_AT`, which bounds every diagnostic to one dword. Verified on this box against your PR: with the 4-byte lines the 158 KB library program that took 53.2 s and 162 MB of stderr on the single line takes ~0.1 s, and the library stage's whole 2,684-listing step is fast and small. The listing text is byte-identical either way, so the practical gain this PR described is now on `main`; the mergeable diff left here is effectively the `LINE_BYTES = 64` naming and the new test. AI-assisted review; measured on Windows 11, LLVM 21.1.8.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.