fix: drop the code dependency on third_party/leonida (HLSL structurer, SPIR-V path) #342

Manually merged
github merged 1 commit from gh-pr/342/head into gh-pr/342/base 2026-11-26 11:03:14 +00:00
Owner

@⁠KainanP on GitHub · 2026-11-26 09:38 UTC · original
KainanP:fix/drop-leonida-code → main · +87 −27395 · 36 files · 1 commits · merged 2026-11-26 10:42 UTC

Change

Code half of the Leonida removal asked on #252 (rule 2): nothing imports third_party/leonida any more, and the folder is gone. The docs and credits half is #252 (it is rebased on this branch).

  • HLSL control flow (emu/rdna2_hlsl.py): the cfg_structure import and the structured path are removed. What is left is our own lowering:
    • a program with one basic block and no branch is still written as straight-line code (no loop, no pc), as before;
    • any other program becomes one [loop] while (pc != END_PC) with an if (pc == <offset>u) { ... } guard per basic block; each block ends with pc = <next>u; continue;, a branch, or finish.
    • It is a guard chain and not the old switch (pc) fallback because WARP crashes on the switch: with a switch inside that loop, anyxboxx_gpu_run.exe exits with 0xC0000005 on WARP when a block holds a group barrier (the wave64 Ballot64). Measured: test_vccnz_loop_runs_until_every_lane_is_done, test_divergent_exec_across_both_halves_matches (wave64) and test_gpu_matches_interpreter_and_exact_rounding_on_memory_operands failed on WARP with the switch version and pass with the guards; RTX and Intel passed with both.
    • Branch targets are checked again: a target that is not the start of an instruction or the end of the program is refused by name (cible de branchement invalide : <offset>). The old switch fallback had lost that check when the structured path was added.
  • SPIR-V path removed: emu/rdna2_spirv.py (a wrapper around Leonida's translator), tools/fssm_mesure.py (it only measured that translator) and their tests. scarlett.py --rdna2 <shader.bin> --spirv is refused by name (exit 2, --spirv : le traducteur SPIR-V a été retiré (#262) ; utilisez --hlsl) and not silently ignored (rule 3).
  • Folder and its rows: third_party/leonida/ deleted, with its THIRD_PARTY.md row, its AGENTS.md layout row and the SPIR-V row of the nine READMEs (row counts stay in sync).

Linked issue: Fixes #262. Refs #252.

Cost of dropping the structurer

All the HLSL handed to dxc during a full RTX run was recorded, before (main c4c93bd) and after. 132 distinct shaders each time; 123 are byte-identical (every straight-line program). The 9 that differ are the programs with branches:

Test (program) HLSL bytes, before → after DXIL bytes, before → after dxc ms (median of 15), before → after
test_gpu_matches_interpreter_and_exact_rounding_on_memory_operands (was structured) 51076 → 51253 9068 → 9460 77 → 84
test_scalar_loop_and_divergence_match (was structured) 50097 → 50254 3600 → 3724 32 → 33
test_nested_loops_and_branch_match_interpreter (was structured) 50082 → 50258 3232 → 3584 33 → 34
test_if_else_diamond_matches_interpreter, s4 = 0 / 1 (was structured) 49772 → 49984 3232 → 3472 / 3468 31 → 32, 30 → 32
test_irreducible_cfg_matches_interpreter, two inputs (was switch) 50268 → 50337 3552 → 3640, 3556 → 3644 32 → 32, 29 → 30
test_divergent_exec_across_both_halves_matches (wave64, was structured) 51046 → 51319 4876 → 5404 35 → 41
test_vccnz_loop_runs_until_every_lane_is_done (wave64, was structured) 50384 → 50543 4364 → 4600 34 → 36

So: DXIL +2 % to +11 % on branchy programs, dxc +0 to +7 ms, and no GPU parity difference (every parity test passes on the three adapters, below). These are small test programs; on large console shaders the dispatch loop could cost more at run time (one loop iteration and a guard chain per block taken, which the driver may or may not fold). That is not measured here. A clean-room structurer written from published algorithms (for example reducible-CFG structuring from the compiler literature, not from Leonida's code) could come later as a separate PR, measured against this baseline.

Verification

Full suite, one adapter at a time, runtime built from this branch's runtime/ (unchanged from main):

RTX 4060 Laptop  python -m pytest → 1639 passed, 15 skipped     (main c4c93bd: 1648 passed, 17 skipped)
WARP             python -m pytest → 1638 passed, 15 skipped     (main: 1648 passed, 17 skipped)
Intel UHD        python -m pytest → 1636 passed, 17 skipped     (main: 1646 passed, 19 skipped)
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

(The WARP and Intel runs were taken before the last test, test_spirv_option_is_refused_by_name, was added; it does not touch the GPU.) The count drops by the removed SPIR-V and fssm_mesure tests (2 of the skips were spirv-as/spirv-val checks); 1654 collected, so the READMEs' "1600+" stays.

Oracle and test data

HLSL translation: compared with the reference interpreter, byte for byte, by the existing parity tests (unchanged: nested loops, if/else diamond, two-entry loop, wave64 loops, FMA on memory operands). tests/test_rdna2_hlsl_cfg.py now checks the lowering itself: straight-line programs (wave32 and wave64) have no pc loop; a branch back to the start, if/else, nested loops and a two-entry loop give one while (pc loop with if (pc == ...) guards and no switch; a branch past the end is refused; graphics stages have no switch or break;. All test programs are built in the tests.

Failure cases: without the guard chain, the three WARP tests above fail; without the target check, test_branch_outside_the_program_is_refused fails; without the --spirv refusal, test_spirv_option_is_refused_by_name fails.

Checklist

  • The PR covers a single reviewable behaviour (removing the code that needs third_party/leonida).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success: --spirv is refused by name.
  • README: the same change in all 9 languages (test_readme_sync.py checks it).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none.
  • Code taken from another project: none; this removes Leonida's code. No replacement structurer was written.

Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP.

🤖 Generated with Claude Code

**@⁠KainanP** on GitHub · 2026-11-26 09:38 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/342) `KainanP:fix/drop-leonida-code` → `main` · +87 −27395 · 36 files · 1 commits · merged 2026-11-26 10:42 UTC ## Change Code half of the Leonida removal asked on #252 (rule 2): nothing imports `third_party/leonida` any more, and the folder is gone. The docs and credits half is #252 (it is rebased on this branch). - **HLSL control flow** (`emu/rdna2_hlsl.py`): the `cfg_structure` import and the structured path are removed. What is left is our own lowering: - a program with one basic block and no branch is still written as straight-line code (no loop, no `pc`), as before; - any other program becomes one `[loop] while (pc != END_PC)` with an `if (pc == <offset>u) { ... }` guard per basic block; each block ends with `pc = <next>u; continue;`, a branch, or `finish`. - It is a guard chain and not the old `switch (pc)` fallback because WARP crashes on the `switch`: with a `switch` inside that loop, `anyxboxx_gpu_run.exe` exits with 0xC0000005 on WARP when a block holds a group barrier (the wave64 `Ballot64`). Measured: `test_vccnz_loop_runs_until_every_lane_is_done`, `test_divergent_exec_across_both_halves_matches` (wave64) and `test_gpu_matches_interpreter_and_exact_rounding_on_memory_operands` failed on WARP with the `switch` version and pass with the guards; RTX and Intel passed with both. - Branch targets are checked again: a target that is not the start of an instruction or the end of the program is refused by name (`cible de branchement invalide : <offset>`). The old `switch` fallback had lost that check when the structured path was added. - **SPIR-V path removed**: `emu/rdna2_spirv.py` (a wrapper around Leonida's translator), `tools/fssm_mesure.py` (it only measured that translator) and their tests. `scarlett.py --rdna2 <shader.bin> --spirv` is refused by name (exit 2, `--spirv : le traducteur SPIR-V a été retiré (#262) ; utilisez --hlsl`) and not silently ignored (rule 3). - **Folder and its rows**: `third_party/leonida/` deleted, with its THIRD_PARTY.md row, its AGENTS.md layout row and the SPIR-V row of the nine READMEs (row counts stay in sync). Linked issue: Fixes #262. Refs #252. ## Cost of dropping the structurer All the HLSL handed to dxc during a full RTX run was recorded, before (`main` `c4c93bd`) and after. 132 distinct shaders each time; **123 are byte-identical** (every straight-line program). The 9 that differ are the programs with branches: | Test (program) | HLSL bytes, before → after | DXIL bytes, before → after | dxc ms (median of 15), before → after | | --- | --- | --- | --- | | `test_gpu_matches_interpreter_and_exact_rounding_on_memory_operands` (was structured) | 51076 → 51253 | 9068 → 9460 | 77 → 84 | | `test_scalar_loop_and_divergence_match` (was structured) | 50097 → 50254 | 3600 → 3724 | 32 → 33 | | `test_nested_loops_and_branch_match_interpreter` (was structured) | 50082 → 50258 | 3232 → 3584 | 33 → 34 | | `test_if_else_diamond_matches_interpreter`, s4 = 0 / 1 (was structured) | 49772 → 49984 | 3232 → 3472 / 3468 | 31 → 32, 30 → 32 | | `test_irreducible_cfg_matches_interpreter`, two inputs (was `switch`) | 50268 → 50337 | 3552 → 3640, 3556 → 3644 | 32 → 32, 29 → 30 | | `test_divergent_exec_across_both_halves_matches` (wave64, was structured) | 51046 → 51319 | 4876 → 5404 | 35 → 41 | | `test_vccnz_loop_runs_until_every_lane_is_done` (wave64, was structured) | 50384 → 50543 | 4364 → 4600 | 34 → 36 | So: DXIL +2 % to +11 % on branchy programs, dxc +0 to +7 ms, and no GPU parity difference (every parity test passes on the three adapters, below). These are small test programs; on large console shaders the dispatch loop could cost more at run time (one loop iteration and a guard chain per block taken, which the driver may or may not fold). That is not measured here. A clean-room structurer written from published algorithms (for example reducible-CFG structuring from the compiler literature, not from Leonida's code) could come later as a separate PR, measured against this baseline. ## Verification Full suite, one adapter at a time, runtime built from this branch's `runtime/` (unchanged from `main`): ``` RTX 4060 Laptop python -m pytest → 1639 passed, 15 skipped (main c4c93bd: 1648 passed, 17 skipped) WARP python -m pytest → 1638 passed, 15 skipped (main: 1648 passed, 17 skipped) Intel UHD python -m pytest → 1636 passed, 17 skipped (main: 1646 passed, 19 skipped) python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` (The WARP and Intel runs were taken before the last test, `test_spirv_option_is_refused_by_name`, was added; it does not touch the GPU.) The count drops by the removed SPIR-V and `fssm_mesure` tests (2 of the skips were `spirv-as`/`spirv-val` checks); 1654 collected, so the READMEs' "1600+" stays. ## Oracle and test data HLSL translation: compared with the reference interpreter, byte for byte, by the existing parity tests (unchanged: nested loops, if/else diamond, two-entry loop, wave64 loops, FMA on memory operands). `tests/test_rdna2_hlsl_cfg.py` now checks the lowering itself: straight-line programs (wave32 and wave64) have no `pc` loop; a branch back to the start, if/else, nested loops and a two-entry loop give one `while (pc` loop with `if (pc == ...)` guards and no `switch`; a branch past the end is refused; graphics stages have no `switch` or `break;`. All test programs are built in the tests. Failure cases: without the guard chain, the three WARP tests above fail; without the target check, `test_branch_outside_the_program_is_refused` fails; without the `--spirv` refusal, `test_spirv_option_is_refused_by_name` fails. ## Checklist - [x] The PR covers a single reviewable behaviour (removing the code that needs `third_party/leonida`). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success: `--spirv` is refused by name. - [x] README: the same change in all 9 languages (`test_readme_sync.py` checks it). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none. - [x] Code taken from another project: none; this removes Leonida's code. No replacement structurer was written. Made with AI assistance: Claude Code with Claude Opus 5.5, for KainanP. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The Leonida project was taken down; AGENTS.md rule 2 needs its code gone.

- rdna2_hlsl.py no longer imports third_party/leonida/cfg_structure.py. A
  program with no branch is still emitted as straight-line code; any other
  program uses one `while (pc != END_PC)` loop with an `if (pc == ...)`
  guard per basic block. The guard chain replaces the old `switch (pc)`
  fallback because WARP crashes (0xC0000005 in anyxboxx_gpu_run.exe) on a
  `switch` in that loop when a block holds a group barrier (wave64 Ballot64),
  measured with tests/test_rdna2_hlsl_wave64.py. Branch targets that are not
  an instruction start or the program end are refused by name again.
- The SPIR-V path built on Leonida's translator is removed: emu/rdna2_spirv.py,
  tools/fssm_mesure.py and their tests. `scarlett.py --rdna2 ... --spirv` is
  refused by name (exit 2) instead of being ignored.
- third_party/leonida/ is deleted, with its THIRD_PARTY.md row, its AGENTS.md
  layout row and the SPIR-V row of the nine READMEs.
- tests/test_rdna2_hlsl_cfg.py now tests the loop and its guards instead of
  structured output; the GPU parity tests are unchanged.

Closes #262.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:03:14 +00:00
github manually merged commit 9981b5ceaa into gh-pr/342/base 2026-11-26 11:03:14 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.