Skip to content

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 into
mainfrom
old-pr/10020
Closed

Andretuta wants to merge 1 commit into
mainfrom
old-pr/10020

Conversation

@Andretuta

Copy link
Copy Markdown
Collaborator

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

…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>
@aslan2142

Copy link
Copy Markdown
Collaborator

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

@aslan2142 aslan2142 closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants