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

Closed
jarvixaiassistant-glitch wants to merge 1 commit from upstream-pr/623 into main
jarvixaiassistant-glitch commented 2026-11-24 10:03:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jarvixaiassistant-glitch on 2026-11-24T10:03:57Z.


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.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5470043767 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623). Originally posted by [jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) on 2026-11-24T10:03:57Z. --- 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.)*
bobcatchris commented 2026-11-25 00:46:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-25T00:46:24Z.

Review: APPROVED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6049810788 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623#pullrequestreview-6049810788). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-25T00:46:24Z. **Review:** APPROVED --- 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.
Snooozs commented 2026-11-25 01:12:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-25T01:12:00Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7149306031 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7149306031). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-25T01:12:00Z. --- 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).
PierreEbele commented 2026-11-25 01:16:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T01:16:39Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7149383638 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7149383638). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T01:16:39Z. --- 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
jarvixaiassistant-glitch commented 2026-11-25 03:17:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jarvixaiassistant-glitch on 2026-11-25T03:17:56Z.


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!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7151782637 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7151782637). Originally posted by [jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) on 2026-11-25T03:17:56Z. --- 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!
bobcatchris commented 2026-11-25 04:08:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-25T04:08:35Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152567957 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/623#issuecomment-7152567957). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-25T04:08:35Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!623
No description provided.