[PR #1712] tools: add auto fallback to python disassembler in shader_disasm and shader_library #1727

Open
opened 2026-11-26 21:18:45 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1712
Author: @Tortoche
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: feat/shader-disasm-auto-fallback


📝 Commits (1)

  • 70315b5 tools: add auto fallback to python disassembler in shader_disasm and shader_library

📊 Changes

4 files changed (+100 additions, -4 deletions)

View changed files

📝 tests/test_shader_disasm.py (+42 -0)
📝 tests/test_shader_library.py (+41 -0)
📝 tools/shader_disasm.py (+11 -3)
📝 tools/shader_library.py (+6 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1712 **Author:** [@Tortoche](https://github.com/Tortoche) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/shader-disasm-auto-fallback` --- ### 📝 Commits (1) - [`70315b5`](https://github.com/ubiquitarianism/leonida/commit/70315b5fdfadf08f0b67d474d8e465c658a036b6) tools: add auto fallback to python disassembler in shader_disasm and shader_library ### 📊 Changes **4 files changed** (+100 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_shader_disasm.py` (+42 -0) 📝 `tests/test_shader_library.py` (+41 -0) 📝 `tools/shader_disasm.py` (+11 -3) 📝 `tools/shader_library.py` (+6 -1) </details> ### 📄 Description 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1727
No description provided.