shader_disasm: hand llvm-mc its input in lines of 64 bytes, not one long line (up to ~380x faster, identical output) #289

Closed
Andretuta wants to merge 1 commit from upstream-pr/289 into main
Andretuta commented 2026-11-24 03:00:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T03:00:17Z.


Carried over from old PR 10020 by beamdotdev in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10020, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
beamdotdev: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Item: new BUILD item, claimed in the coordination issue: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117003507

Depends on: none (applies to main).

Why

tools/shader_disasm.py's disasm() joins a program's bytes with spaces into one line of hex and hands it to llvm-mc. llvm-mc slows down sharply on one long input line, so large programs took tens of seconds each. That makes make_game.py's pipeline-library step (2,684 compute programs from shaders.rpf) run at about one program per minute: in one run, 994 programs in about an hour, with about 1,700 left.

What

  • disasm() passes the same bytes in lines of 64 bytes. Inputs of up to 64 bytes, the s_endpgm probe among them, are unchanged.
  • 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, a partial last line, no empty or trailing lines, short inputs unchanged). Standard library only; no llvm-mc, no game data. Red without the change (2 of 4 fail), green with it.

Same output

Byte-identical disassembly: the same .s text and the same count of undecodable words. Only the line/column numbers in llvm-mc's diagnostics differ. make_game.py already fingerprints shader_disasm.py for the library, FSPX, BVH and exe steps, so those rerun once after this; the main corpus's disassembly and translation do not.

Measured with the old and new disasm() side by side on six real library programs (own 1.0.2.1 copy; sizes and timings only):

program size before after output
256 B 0.02 s 0.01 s identical
1,536 B 0.02 s 0.01 s identical
13,568 B 4.45 s 0.03 s identical
60,904 B 2.37 s 0.06 s identical
88,128 B 42.35 s 0.11 s identical
120,064 B 28.39 s 0.12 s identical

The library step's unpack and disassembly then took about 1.5 minutes for all 2,684 programs.

Tested

Windows 11, i5-9600K, Python 3.14.10, native llvm-mc 21.1.8 (AMDGPU, built with scripts/build_llvm_mc.ps1).

  • python -I tests/test_shader_disasm_input_lines.py: 4/4.
  • test_shader_disasm.py (30), test_fssm_crosscheck.py (6), test_shader_stage_resume.py (46), test_fspx_shaders_stage.py (23): OK.
  • test_bvh_shaders_stage.py (test_the_builder_runs_after_fspx_and_alone_when_only_its_dll_changes) and test_rdna2_decode.py (test_parity_with_llvm_mc_on_shader_fixtures) fail once each, identically on main without this change.
  • python -m compileall -q make_game.py tools tests: clean.
  • A full make_game.py --stages check,shaders on a work folder (ladder-frame base): library 1,538 of 2,684 translated and all 1,538 pass spirv-val; BVH 52/52; exe 10/10. The untranslated library programs are translator gaps, unrelated to this change.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465256343 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/289). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T03:00:17Z. --- > Carried over from **old PR 10020** by `beamdotdev` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10020`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `beamdotdev`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Item: new BUILD item, claimed in the coordination issue: https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117003507 Depends on: none (applies to `main`). ## Why `tools/shader_disasm.py`'s `disasm()` joins a program's bytes with spaces into **one** line of hex and hands it to `llvm-mc`. `llvm-mc` slows down sharply on one long input line, so large programs took tens of seconds each. That makes `make_game.py`'s pipeline-library step (2,684 compute programs from `shaders.rpf`) run at about one program per minute: in one run, 994 programs in about an hour, with about 1,700 left. ## What - `disasm()` passes the same bytes in lines of 64 bytes. Inputs of up to 64 bytes, the `s_endpgm` probe among them, are unchanged. - `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, a partial last line, no empty or trailing lines, short inputs unchanged). Standard library only; no `llvm-mc`, no game data. Red without the change (2 of 4 fail), green with it. ## Same output Byte-identical disassembly: the same `.s` text and the same count of undecodable words. Only the line/column numbers in `llvm-mc`'s diagnostics differ. `make_game.py` already fingerprints `shader_disasm.py` for the library, FSPX, BVH and exe steps, so those rerun once after this; the main corpus's disassembly and translation do not. Measured with the old and new `disasm()` side by side on six real library programs (own 1.0.2.1 copy; sizes and timings only): | program size | before | after | output | |---:|---:|---:|---| | 256 B | 0.02 s | 0.01 s | identical | | 1,536 B | 0.02 s | 0.01 s | identical | | 13,568 B | 4.45 s | 0.03 s | identical | | 60,904 B | 2.37 s | 0.06 s | identical | | 88,128 B | 42.35 s | 0.11 s | identical | | 120,064 B | 28.39 s | 0.12 s | identical | The library step's unpack and disassembly then took about 1.5 minutes for all 2,684 programs. ## Tested Windows 11, i5-9600K, Python 3.14.10, native `llvm-mc` 21.1.8 (AMDGPU, built with `scripts/build_llvm_mc.ps1`). - `python -I tests/test_shader_disasm_input_lines.py`: 4/4. - `test_shader_disasm.py` (30), `test_fssm_crosscheck.py` (6), `test_shader_stage_resume.py` (46), `test_fspx_shaders_stage.py` (23): OK. - `test_bvh_shaders_stage.py` (`test_the_builder_runs_after_fspx_and_alone_when_only_its_dll_changes`) and `test_rdna2_decode.py` (`test_parity_with_llvm_mc_on_shader_fixtures`) fail once each, identically on `main` without this change. - `python -m compileall -q make_game.py tools tests`: clean. - A full `make_game.py --stages check,shaders` on a work folder (ladder-frame base): library 1,538 of 2,684 translated and all 1,538 pass `spirv-val`; BVH 52/52; exe 10/10. The untranslated library programs are translator gaps, unrelated to this change. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
aslan2142 commented 2026-11-24 19:18:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:18:26Z.


This carry-over of old upstream PR 10020 has been taken over in #623, so I'm closing this draft as #17 describes. The branch old-pr/10020 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7141904006 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/289#issuecomment-7141904006). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:18:26Z. --- This carry-over of old upstream PR 10020 has been taken over in #623, so I'm closing this draft as #17 describes. The branch `old-pr/10020` stays. AI-assisted (Claude Code, Claude Opus 5.5).

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!289
No description provided.