Translator: --shader-list to translate only a subset of shaders #565

Closed
github-bot wants to merge 4 commits from gh-pr/565/head into gh-pr/565/base
Owner

@⁠x2Tweek on GitHub · 2026-11-24 08:26 UTC · original
x2Tweek:shader-subset → main · +255 −66 · 5 files · 4 commits · closed without merging

Claimed in the coordination issue as: SHADER-SUBSET (issue #14)

What and why

Add --shader-list FILE to tools/rdna2spirv.py and make_game.py
so only the shaders whose stems are listed in FILE are translated,
instead of all 26,503. This cuts retranslation time for testing
translator changes on a small subset of the corpus.

make_game.py skips verify_translation_completeness() when
--shader-list is given (the subset index is intentionally incomplete)
and never touches the existing spirv/index.json — the full index
always survives a subset run. The subset is written to a separate
<spirv>/subset/ directory.

The content of the list is part of the shard plan's identity: the same list reuses finished shards, while a changed list (or the same file rewritten with other stems) translates again.

rdna2spirv.py reads the list of shader stems (one per line) and
filters the .s files from the disassembly directory before
translation, after the existing --limit and --shard filters.

This is the translation half of the "translate only the shaders the
game actually uses" item. The other half — runtime instrumentation to
record which shader IDs --run requests — is C++ work not included
here. This PR builds on PR #497's native_hashes.txt index
(conceptually) but does not depend on it: --shader-list works with
any list of shader stems.

Tested

python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --out <scratch> --shader-list <5-stem-list> --no-asm --no-validate --assembler python:

  • Exactly 5 of 26,503 shaders translated
  • index.json has 5 entries matching the list
  • py_compile + compileall on both files: OK
  • check_no_game_data.py on both files: OK

python -I tests/test_make_game_empty_translation.py (15 tests, including new full-index-survives-subset test): OK
python -I tests/test_rdna2spirv_cli.py (37 tests, including new --shader-list filter test): OK

python -I tests/test_shader_stage_resume.py (including the new subset-list identity test): OK

GPU: not needed (CPU-only translation). No game files used.

AI-assisted: yes

Checklist

  • No game data, keys or decryption in this change or its report
  • Translator rule: not applicable (no translator rule changed)
**@⁠x2Tweek** on GitHub · 2026-11-24 08:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565) `x2Tweek:shader-subset` → `main` · +255 −66 · 5 files · 4 commits · closed without merging Claimed in the coordination issue as: SHADER-SUBSET (issue #14) ### What and why Add `--shader-list FILE` to `tools/rdna2spirv.py` and `make_game.py` so only the shaders whose stems are listed in FILE are translated, instead of all 26,503. This cuts retranslation time for testing translator changes on a small subset of the corpus. `make_game.py` skips `verify_translation_completeness()` when `--shader-list` is given (the subset index is intentionally incomplete) and never touches the existing `spirv/index.json` — the full index always survives a subset run. The subset is written to a separate `<spirv>/subset/` directory. The content of the list is part of the shard plan's identity: the same list reuses finished shards, while a changed list (or the same file rewritten with other stems) translates again. `rdna2spirv.py` reads the list of shader stems (one per line) and filters the `.s` files from the disassembly directory before translation, after the existing `--limit` and `--shard` filters. This is the translation half of the "translate only the shaders the game actually uses" item. The other half — runtime instrumentation to record which shader IDs `--run` requests — is C++ work not included here. This PR builds on PR #497's `native_hashes.txt` index (conceptually) but does not depend on it: `--shader-list` works with any list of shader stems. ### Tested `python -I tools/rdna2spirv.py <work>/shaders/dxbc/disasm --out <scratch> --shader-list <5-stem-list> --no-asm --no-validate --assembler python`: - Exactly 5 of 26,503 shaders translated - `index.json` has 5 entries matching the list - `py_compile` + `compileall` on both files: OK - `check_no_game_data.py` on both files: OK `python -I tests/test_make_game_empty_translation.py` (15 tests, including new full-index-survives-subset test): OK `python -I tests/test_rdna2spirv_cli.py` (37 tests, including new --shader-list filter test): OK `python -I tests/test_shader_stage_resume.py` (including the new subset-list identity test): OK GPU: not needed (CPU-only translation). No game files used. AI-assisted: yes ### Checklist - [x] No game data, keys or decryption in this change or its report - [x] Translator rule: not applicable (no translator rule changed)
Add --shader-list FILE to rdna2spirv.py and make_game.py so only the
shaders whose stems are listed in FILE are translated, instead of all
26,503. This cuts retranslation time for testing translator changes on
a small subset of the corpus.

make_game.py skips verify_translation_completeness() when --shader-list
is given (the subset index is intentionally incomplete) and drops any
previous full index before re-translating.

rdna2spirv.py reads the list of shader stems (one per line) and filters
the .s files from the disassembly directory before translation, after
the existing --limit and --shard filters.

Tested on a 5-shader subset: exactly 5 translated, index.json has 5
entries. No game data, no translator rule changed.

Co-Authored-By: Claude Code <[email protected]>
When --shader-list is given, write the subset translation to
<spirv>/subset/ instead of the main <spirv>/ directory. Never drop or
overwrite the existing full index.json. The full index always survives
a subset translation run.

verify_translation_completeness() is only called for full translations.

Co-Authored-By: Claude Code <[email protected]>
When --shader-list is given, write the subset to <spirv>/subset/ and
skip all full-index fingerprint checks (translator digest, wave64
mode, fallback flags). The existing spirv/index.json is never read,
dropped, or overwritten by a subset run. Carving/unpacking/disassembly
no longer drop the full index when a subset is requested.

Adds tests:
- tests/test_make_game_empty_translation.py: full index survives a
  subset translation run; translate() is called with the subset dir
  and the shader list.
- tests/test_rdna2spirv_cli.py: --shader-list filters .s files by stem,
  only listed shaders are translated and indexed.

Co-Authored-By: Claude Code <[email protected]>
When --shader-list is used, the shard plan (shards.json) did not hash the
list file's contents, so overwriting the same list with a different
selection and reusing the output folder kept the old shards instead of
re-translating the newly requested entries. Add a sha256 of the list
contents to the plan so a changed list is detected as a plan mismatch,
dropping the old parts and starting only the missing shards.

Adds SubsetListIdentityTest covering: same list reuses finished shards,
changed list re-translates, and overwriting the same file path with new
content re-translates.

Co-Authored-By: Claude Code <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:08:48 +00:00
github-bot closed this pull request 2026-11-26 09:08:48 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 08:35 UTC · original · edited 2026-11-24 10:07 UTC

Independent Windows Python 3.12 check of c022ed9 against main 1c93c86, using four hand-written synthetic listings and the real make_game.translate sharded path.

  • Changing the list reuses the previous selection. The first run produced both selected entries. After overwriting the selection file with a disjoint list, the second run kept both finished shards and published 0/2 newly requested entries and 2/2 old entries. A fresh output folder published 2/2 of the new entries. The serialized shard plan stayed unchanged. Its identity needs the list content, as the path stayed the same.
  • Subset translation can remove the full index. With a cached full index and a stale translator fingerprint, make_game.shaders deleted the full index before entering the subset branch. The same synthetic setup with a matching fingerprint preserved it. This is the normal case when testing a translator change against an existing work folder.
  • Full-build regressions. The existing test_make_game_empty_translation.py case for retrying an empty saved index fails because the cache shortcut bypasses recovery. Both SerialOverlapTest cases now raise TypeError because run_build_stages requires shader_list. The translator-dependency coverage test also fails, and the diff removes rdna2_decode.py and rdna2_isa_tables.py from TRANSLATION_SOURCES. These four tests pass on the baseline.

All input was synthetic. AI-assisted verification.

Retest at b9b0dc4 on Windows Python 3.12. The follow-up fixes the full-index retention probe (both matching and stale translator fingerprint) and retrying a cached empty full index. The list-resume result is unchanged: switching the contents of the same file with two finished shards returned 0/2 newly selected entries and 2/2 old entries, while a fresh folder returned 2/2 new entries. The shard plan did not change.

The selected suites show 55 passed, 3 failed and 1 skipped (requires SPIRV-Tools). The two SerialOverlapTest cases still raise TypeError for the new required shader_list keyword, and the translator dependency check still misses rdna2_decode.py and rdna2_isa_tables.py. The two overlap and five dependency tests all pass on upstream main 21625bc (7/7).

Synthetic inputs only. AI-assisted.

**@⁠sodove** on GitHub · 2026-11-24 08:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565#issuecomment-7126316415) · edited 2026-11-24 10:07 UTC Independent Windows Python 3.12 check of c022ed9 against main 1c93c86, using four hand-written synthetic listings and the real make_game.translate sharded path. - **Changing the list reuses the previous selection.** The first run produced both selected entries. After overwriting the selection file with a disjoint list, the second run kept both finished shards and published 0/2 newly requested entries and 2/2 old entries. A fresh output folder published 2/2 of the new entries. The serialized shard plan stayed unchanged. Its identity needs the list content, as the path stayed the same. - **Subset translation can remove the full index.** With a cached full index and a stale translator fingerprint, make_game.shaders deleted the full index before entering the subset branch. The same synthetic setup with a matching fingerprint preserved it. This is the normal case when testing a translator change against an existing work folder. - **Full-build regressions.** The existing test_make_game_empty_translation.py case for retrying an empty saved index fails because the cache shortcut bypasses recovery. Both SerialOverlapTest cases now raise TypeError because run_build_stages requires shader_list. The translator-dependency coverage test also fails, and the diff removes rdna2_decode.py and rdna2_isa_tables.py from TRANSLATION_SOURCES. These four tests pass on the baseline. All input was synthetic. AI-assisted verification. **Retest at `b9b0dc4` on Windows Python 3.12.** The follow-up fixes the full-index retention probe (both matching and stale translator fingerprint) and retrying a cached empty full index. The list-resume result is unchanged: switching the contents of the same file with two finished shards returned 0/2 newly selected entries and 2/2 old entries, while a fresh folder returned 2/2 new entries. The shard plan did not change. The selected suites show 55 passed, 3 failed and 1 skipped (requires SPIRV-Tools). The two SerialOverlapTest cases still raise TypeError for the new required shader_list keyword, and the translator dependency check still misses rdna2_decode.py and rdna2_isa_tables.py. The two overlap and five dependency tests all pass on upstream main 21625bc (7/7). Synthetic inputs only. AI-assisted.
Author
Owner

@⁠x2Tweek on GitHub · 2026-11-24 16:46 UTC · original

All review feedback from issuecomment-7126316415 is addressed and verified locally:

  • run_build_stages shader_list now defaults to None — SerialOverlapTest TypeError fixed
  • TRANSLATION_SOURCES unchanged — still includes rdna2_decode.py and rdna2_isa_tables.py
  • test_make_game_empty_translation.py: 15 OK
  • test_rdna2spirv_cli.py: 37 OK (1 skipped, needs SPIRV-Tools)
  • test_cmake_translator_deps.py: 5 OK
  • test_shader_stage_resume.py: 47 OK
  • test_leonida_tui.py: 25 OK
  • python -m compileall -q make_game.py tools tests: clean
  • python -I make_game.py --help: clean

No game data, no translator rule changed. Tested locally (Windows, Python stdlib only). CI checks are pending on the PR head.

AI-assisted: yes (Claude Code).

**@⁠x2Tweek** on GitHub · 2026-11-24 16:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565#issuecomment-7138177360) All review feedback from issuecomment-7126316415 is addressed and verified locally: - `run_build_stages` `shader_list` now defaults to `None` — SerialOverlapTest TypeError fixed - `TRANSLATION_SOURCES` unchanged — still includes `rdna2_decode.py` and `rdna2_isa_tables.py` - `test_make_game_empty_translation.py`: 15 OK - `test_rdna2spirv_cli.py`: 37 OK (1 skipped, needs SPIRV-Tools) - `test_cmake_translator_deps.py`: 5 OK - `test_shader_stage_resume.py`: 47 OK - `test_leonida_tui.py`: 25 OK - `python -m compileall -q make_game.py tools tests`: clean - `python -I make_game.py --help`: clean No game data, no translator rule changed. Tested locally (Windows, Python stdlib only). CI checks are pending on the PR head. AI-assisted: yes (Claude Code).
Author
Owner

@⁠sodove on GitHub · 2026-11-24 17:12 UTC · original · edited 2026-11-24 17:16 UTC

Retested 01d444ccb on native Windows 11, Python 3.12.10. Changing the list still reuses finished shards from the previous selection. I used four hand-written synthetic inputs, two disjoint two-entry lists, and make_game.shaders(..., jobs=2, shader_list=...) with the real translator subprocesses and merger. Results below count the entries in the published subset/index.json.

Run Requested entries present Entries from the previous selection only
A, fresh output 2/2 0
A, same output, unchanged list 2/2 0
Overwrite the same list file with B, reuse output 0/2 2
B, fresh output (control) 2/2 0
B at a different filename, reuse the original output 0/2 2

The switched runs kept 2/2 finished shards and returned success. The serialized subset/shards.json was byte-identical across A and B. In make_game.translate the plan covers jobs, wave64 mode, fallbacks and translator digest. The list is passed to the worker after the reuse decision. Including the effective selection in the plan and adding the same-path A→B case would cover the remaining failure.

The full spirv/index.json stayed byte-identical in every run, including with a stale full-index translator fingerprint. The five suites in your update passed here: 129 tests, no skips with SPIRV-Tools and CMake available. This narrows my earlier findings to the stale subset cache.

Synthetic inputs only. CPU test. AI-assisted: OpenAI Codex.

Integration check on newer main. GitHub still lists 01d444ccb as the PR head. I also merged that exact head locally onto b633411da and then 32950551e (both clean merges). On both trees the same-path A→B run returned 0/2 requested entries and retained 2/2 old entries. The fresh B control returned 2/2 requested on both trees. The full index remained byte-identical. The five suites also passed on the b633411da integration, 129 tests with zero skips.

**@⁠sodove** on GitHub · 2026-11-24 17:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565#issuecomment-7138847532) · edited 2026-11-24 17:16 UTC Retested `01d444ccb` on native Windows 11, Python 3.12.10. **Changing the list still reuses finished shards from the previous selection.** I used four hand-written synthetic inputs, two disjoint two-entry lists, and `make_game.shaders(..., jobs=2, shader_list=...)` with the real translator subprocesses and merger. Results below count the entries in the published `subset/index.json`. | Run | Requested entries present | Entries from the previous selection only | | --- | ---: | ---: | | A, fresh output | 2/2 | 0 | | A, same output, unchanged list | 2/2 | 0 | | Overwrite the same list file with B, reuse output | **0/2** | **2** | | B, fresh output (control) | 2/2 | 0 | | B at a different filename, reuse the original output | **0/2** | **2** | The switched runs kept 2/2 finished shards and returned success. The serialized `subset/shards.json` was byte-identical across A and B. In `make_game.translate` the plan covers jobs, wave64 mode, fallbacks and translator digest. The list is passed to the worker after the reuse decision. Including the effective selection in the plan and adding the same-path A→B case would cover the remaining failure. The full `spirv/index.json` stayed byte-identical in every run, including with a stale full-index translator fingerprint. The five suites in your update passed here: **129 tests, no skips** with SPIRV-Tools and CMake available. This narrows my earlier findings to the stale subset cache. Synthetic inputs only. CPU test. AI-assisted: OpenAI Codex. **Integration check on newer main.** GitHub still lists `01d444ccb` as the PR head. I also merged that exact head locally onto `b633411da` and then `32950551e` (both clean merges). On both trees the same-path A→B run returned 0/2 requested entries and retained 2/2 old entries. The fresh B control returned 2/2 requested on both trees. The full index remained byte-identical. The five suites also passed on the `b633411da` integration, 129 tests with zero skips.
Author
Owner

@⁠x2Tweek on GitHub · 2026-11-24 23:38 UTC · original

Thanks for the thorough retest, @⁠sodove. The stale-subset-cache issue you found is now fixed in d50e1a436.

What changed

The shard plan (shards.json) beside the subset output now includes a SHA-256 of the shader list file's contents. Previously the plan identity only covered --jobs, wave64 mode, fallback flags and the translator digest — so overwriting the same list file with a different selection and reusing the output folder kept the old shards and never translated the newly requested entries.

With this change:

  • Same list + finished shards present → plan matches, shards kept, nothing re-translated.
  • Changed list (different content or same path overwritten) → plan hash differs, old parts dropped, only missing shards re-translated.

Tests

Added SubsetListIdentityTest in tests/test_shader_stage_resume.py covering all three cases (same list reuse, changed list re-translate, same-path overwrite re-translate). All 50 tests in the file pass, plus compileall, test_rdna2spirv_index_write.py, test_make_game_empty_translation.py and test_cmake_translator_deps.py.

Synthetic inputs only, no game data, no GPU needed. Tested locally on Windows, Python stdlib only. AI-assisted: yes (Claude Code).

**@⁠x2Tweek** on GitHub · 2026-11-24 23:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565#issuecomment-7147635033) Thanks for the thorough retest, @⁠sodove. The stale-subset-cache issue you found is now fixed in d50e1a436. ## What changed The shard plan (`shards.json`) beside the subset output now includes a SHA-256 of the shader list file's contents. Previously the plan identity only covered `--jobs`, wave64 mode, fallback flags and the translator digest — so overwriting the same list file with a different selection and reusing the output folder kept the old shards and never translated the newly requested entries. With this change: - Same list + finished shards present → plan matches, shards kept, nothing re-translated. - Changed list (different content or same path overwritten) → plan hash differs, old parts dropped, only missing shards re-translated. ## Tests Added `SubsetListIdentityTest` in `tests/test_shader_stage_resume.py` covering all three cases (same list reuse, changed list re-translate, same-path overwrite re-translate). All 50 tests in the file pass, plus `compileall`, `test_rdna2spirv_index_write.py`, `test_make_game_empty_translation.py` and `test_cmake_translator_deps.py`. Synthetic inputs only, no game data, no GPU needed. Tested locally on Windows, Python stdlib only. AI-assisted: yes (Claude Code).
Author
Owner

@⁠x2Tweek on GitHub · 2026-11-25 03:36 UTC · original

Rebased on latest upstream/main (0bc810504) — the original head conflicted with main. Replaced by shader-subset-v2 branch with identical content rebased clean. Same SHADER-SUBSET claim on coordination issue #14. Closing this conflicting head; new PR opened from shader-subset-v2.

**@⁠x2Tweek** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/565#issuecomment-7152064900) Rebased on latest upstream/main (0bc810504) — the original head conflicted with main. Replaced by shader-subset-v2 branch with identical content rebased clean. Same SHADER-SUBSET claim on coordination issue #14. Closing this conflicting head; new PR opened from shader-subset-v2.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.