tools: add auto fallback to python disassembler in shader_disasm and shader_library #1712

Open
github-bot wants to merge 1 commit from github-bot/gh-1712 into main AGit
Owner

@⁠Tortoche on GitHub · 2026-11-25 09:15 UTC · original
Tortoche:feat/shader-disasm-auto-fallback → main · +100 −4 · 4 files · 1 commits · open

Claim: SHADER-DISASM-AUTO-FALLBACK (#1608#issuecomment-7158019367)
Findings: #1608 (#1608#issuecomment-7156808927, #1608#issuecomment-7157792566)
Related: #998
AI-assisted: yes

Summary

  • tools/shader_disasm.py:
    • Keep backend="llvm-mc" as the default in disasm() and --backend so FSSM callers and existing tests are unchanged.
    • Add backend="auto" (and --backend auto): runs llvm-mc first; if bad == 0 and output is non-empty, returns it immediately without invoking rdna2_decode. Otherwise runs the pure-Python decoder (rdna2_decode.disasm_bytes) and returns (py_asm, py_bad, "") iff py_asm.strip() and (not asm.strip() or py_bad < bad); otherwise returns the llvm-mc result.
    • Update main() to run probe(a.mcpu) when a.backend in ("llvm-mc", "auto").
  • tools/shader_library.py:
    • Add --backend (choices=("auto", "llvm-mc", "python"), default="auto"). make_game.py is intentionally untouched to stay conflict-free with #1592 and #1708.
    • Call disasm.probe(a.mcpu) upfront before ThreadPoolExecutor when work is non-empty and a.backend in ("llvm-mc", "auto").
    • Pass backend=a.backend to disasm.disasm(...) in one(job).
  • Tests (synthetic only, zero game data):
    • tests/test_shader_disasm.py: added DisasmAutoBackendTest (test_auto_backend_falls_back_to_python_on_invalid_words, test_auto_backend_preserves_clean_llvm_mc_output, test_auto_backend_keeps_llvm_mc_when_python_not_better).
    • tests/test_shader_library.py: added test_disasm_auto_falls_back_per_program_without_regressing_clean_programs.

Verification

  • python3 -I scripts/check_no_game_data.py tools/shader_disasm.py tools/shader_library.py tests/test_shader_disasm.py tests/test_shader_library.py -> exit 0
  • python3 -m compileall -q make_game.py tools tests -> exit 0
  • python3 -I tests/test_shader_disasm.py -> Ran 34 tests in 8.384s, OK
  • python3 -I tests/test_shader_library.py -> Ran 23 tests in 0.215s, OK
  • python3 -I tests/test_library_shaders_stage.py -> Ran 17 tests in 7.336s, OK
  • python3 -I tests/test_text_write_line_endings.py -> Ran 3 tests in 15.974s, OK
  • python3 -I tests/test_ci_registration.py -> Ran 16 tests in 9.878s, OK
**@⁠Tortoche** on GitHub · 2026-11-25 09:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1712) `Tortoche:feat/shader-disasm-auto-fallback` → `main` · +100 −4 · 4 files · 1 commits · open Claim: `SHADER-DISASM-AUTO-FALLBACK` (`#1608#issuecomment-7158019367`) Findings: `#1608` (`#1608#issuecomment-7156808927`, `#1608#issuecomment-7157792566`) Related: `#998` AI-assisted: yes ### Summary - **`tools/shader_disasm.py`**: - Keep `backend="llvm-mc"` as the default in `disasm()` and `--backend` so FSSM callers and existing tests are unchanged. - Add `backend="auto"` (and `--backend auto`): runs `llvm-mc` first; if `bad == 0` and output is non-empty, returns it immediately without invoking `rdna2_decode`. Otherwise runs the pure-Python decoder (`rdna2_decode.disasm_bytes`) and returns `(py_asm, py_bad, "")` iff `py_asm.strip()` and (`not asm.strip()` or `py_bad < bad`); otherwise returns the `llvm-mc` result. - Update `main()` to run `probe(a.mcpu)` when `a.backend in ("llvm-mc", "auto")`. - **`tools/shader_library.py`**: - Add `--backend` (`choices=("auto", "llvm-mc", "python")`, `default="auto"`). `make_game.py` is intentionally untouched to stay conflict-free with `#1592` and `#1708`. - Call `disasm.probe(a.mcpu)` upfront before `ThreadPoolExecutor` when `work` is non-empty and `a.backend in ("llvm-mc", "auto")`. - Pass `backend=a.backend` to `disasm.disasm(...)` in `one(job)`. - **Tests (synthetic only, zero game data)**: - `tests/test_shader_disasm.py`: added `DisasmAutoBackendTest` (`test_auto_backend_falls_back_to_python_on_invalid_words`, `test_auto_backend_preserves_clean_llvm_mc_output`, `test_auto_backend_keeps_llvm_mc_when_python_not_better`). - `tests/test_shader_library.py`: added `test_disasm_auto_falls_back_per_program_without_regressing_clean_programs`. ### Verification - `python3 -I scripts/check_no_game_data.py tools/shader_disasm.py tools/shader_library.py tests/test_shader_disasm.py tests/test_shader_library.py` -> exit 0 - `python3 -m compileall -q make_game.py tools tests` -> exit 0 - `python3 -I tests/test_shader_disasm.py` -> Ran 34 tests in 8.384s, OK - `python3 -I tests/test_shader_library.py` -> Ran 23 tests in 0.215s, OK - `python3 -I tests/test_library_shaders_stage.py` -> Ran 17 tests in 7.336s, OK - `python3 -I tests/test_text_write_line_endings.py` -> Ran 3 tests in 15.974s, OK - `python3 -I tests/test_ci_registration.py` -> Ran 16 tests in 9.878s, OK
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:57 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-25 10:29 UTC · original · reviewed

Independent native Windows verification at 70315b5f: all 34 disassembler and 23 shader-library tests passed. A separate CLI run with synthetic input found one gap in auto mode when llvm-mc is unavailable. Details inline.

AI-assisted review. CPU only, synthetic inputs.

**@⁠lixonik** on GitHub · 2026-11-25 10:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1712#pullrequestreview-6055862800) · **reviewed** Independent native Windows verification at `70315b5f`: all 34 disassembler and 23 shader-library tests passed. A separate CLI run with synthetic input found one gap in auto mode when llvm-mc is unavailable. Details inline. AI-assisted review. CPU only, synthetic inputs.
@ -443,6 +446,8 @@ def main(argv=None) -> int:
f.write("\n; --- llvm-mc messages ---\n; " + err.strip().replace("\n", "\n; ") + "\n")
if work:
if a.backend in ("llvm-mc", "auto"):
Author
Owner

@⁠lixonik on GitHub · 2026-11-25 10:29 UTC · original

This upfront probe can exit before auto reaches the Python decoder. I pointed LLVM_MC at a nonexistent executable and used the repository's synthetic FSSM and shader-library fixtures. Both CLIs exited 1 with zero listings in auto mode. Explicit --backend python with the same inputs exited 0 and wrote one and four listings, respectively. This also affects shader_library.py --disasm by default. Could auto switch to the Python backend when the probe fails, while explicit llvm-mc keeps the hard error? The same check applies to shader_disasm.py.

**@⁠lixonik** on GitHub · 2026-11-25 10:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1712#discussion_r4693551210) This upfront probe can exit before `auto` reaches the Python decoder. I pointed `LLVM_MC` at a nonexistent executable and used the repository's synthetic FSSM and shader-library fixtures. Both CLIs exited 1 with zero listings in `auto` mode. Explicit `--backend python` with the same inputs exited 0 and wrote one and four listings, respectively. This also affects `shader_library.py --disasm` by default. Could `auto` switch to the Python backend when the probe fails, while explicit `llvm-mc` keeps the hard error? The same check applies to `shader_disasm.py`.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 10:33 UTC · original

Tested 70315b5fd on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 57ba40bd6 (Python tools; no GPU):

  • pytest 9.2.0 on tests/test_shader_disasm.py + tests/test_shader_library.py: 57 passed, 28 subtests passed at this head.
  • The same two files on main: 2 failed, 55 passed, 28 subtests — test_auto_backend_falls_back_to_python_on_invalid_words and the per-program fallback in shader_library.
  • Not run: an end-to-end --backend auto pass over a real listing set with llvm-mc rejecting words — this machine has the Homebrew llvm-mc, so the fallback itself is exercised through the tests' mocks; the default llvm-mc path is unchanged by design.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 10:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1712#issuecomment-7159862007) Tested `70315b5fd` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `57ba40bd6` (Python tools; no GPU): - pytest 9.2.0 on `tests/test_shader_disasm.py` + `tests/test_shader_library.py`: **57 passed, 28 subtests passed** at this head. - The same two files on `main`: **2 failed**, 55 passed, 28 subtests — `test_auto_backend_falls_back_to_python_on_invalid_words` and the per-program fallback in `shader_library`. - Not run: an end-to-end `--backend auto` pass over a real listing set with llvm-mc rejecting words — this machine has the Homebrew `llvm-mc`, so the fallback itself is exercised through the tests' mocks; the default `llvm-mc` path is unchanged by design. AI-assisted; synthetic fixtures only, no game data.
This pull request has changes conflicting with the target branch.
  • tools/shader_disasm.py
  • tools/shader_library.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1712/head:github-bot/gh-1712'
git switch 'github-bot/gh-1712'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1712'
git switch 'github-bot/gh-1712'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1712'
git switch 'github-bot/gh-1712'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1712'
git switch 'main'
git merge --squash 'github-bot/gh-1712'
git switch 'main'
git merge --ff-only 'github-bot/gh-1712'
git switch 'main'
git merge 'github-bot/gh-1712'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.