Add slot-67 pipeline-library shader build and runtime loading #19

Manually merged
github merged 3 commits from gh-pr/19/head into gh-pr/19/base 2026-11-26 08:40:38 +00:00
Owner

@⁠moffington on GitHub · 2026-11-24 01:47 UTC · original
moffington:contrib/pipeline-library-upstream → main · +695 −15 · 9 files · 3 commits · merged 2026-11-24 02:27 UTC

Add slot-67 pipeline-library shader build and runtime loading

Summary

Completes the pipeline-library shader path by connecting build-time extraction and translation with runtime shader lookup.

  • Load optional library/index.json alongside existing FSPX/BVH indexes.
  • Add library_shaders() to the game build pipeline, including caching, invalidation, and stale-artifact cleanup.
  • Fix a TypeError when compute pipeline records contain a NONE state index.
  • Add regression coverage for state-specific shader selection, index ordering, missing states, and cache cleanup.
  • Document the pipeline-library build and lookup behavior.

Validation

  • Python shader/build-stage regression suites: pass.
  • C++ shader_library CTest: pass.
  • Shader index verification: 16/16 checks pass.
  • Synthetic build-to-runtime round-trip: pass.
  • RTX 3060 Vulkan validation fixture: 8/8 cases pass.
  • Targeted mutation tests confirm regression coverage for index ordering and stale-state cleanup.

Limitations

Validation used synthetic shader inputs and a bounded Vulkan runtime fixture. Retail shaders.rpf processing and live Windows D3D12 slot-67 execution have not been verified.

One unrelated BVH test failure (ShadersStageWithTheDlls) also reproduces on the original baseline.

**@⁠moffington** on GitHub · 2026-11-24 01:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/19) `moffington:contrib/pipeline-library-upstream` → `main` · +695 −15 · 9 files · 3 commits · merged 2026-11-24 02:27 UTC ## Add slot-67 pipeline-library shader build and runtime loading ### Summary Completes the pipeline-library shader path by connecting build-time extraction and translation with runtime shader lookup. - Load optional `library/index.json` alongside existing FSPX/BVH indexes. - Add `library_shaders()` to the game build pipeline, including caching, invalidation, and stale-artifact cleanup. - Fix a `TypeError` when compute pipeline records contain a `NONE` state index. - Add regression coverage for state-specific shader selection, index ordering, missing states, and cache cleanup. - Document the pipeline-library build and lookup behavior. ### Validation - Python shader/build-stage regression suites: pass. - C++ `shader_library` CTest: pass. - Shader index verification: 16/16 checks pass. - Synthetic build-to-runtime round-trip: pass. - RTX 3060 Vulkan validation fixture: 8/8 cases pass. - Targeted mutation tests confirm regression coverage for index ordering and stale-state cleanup. ### Limitations Validation used synthetic shader inputs and a bounded Vulkan runtime fixture. Retail `shaders.rpf` processing and live Windows D3D12 slot-67 execution have not been verified. One unrelated BVH test failure (`ShadersStageWithTheDlls`) also reproduces on the original baseline.
ShaderLibrary::load read the main index plus fspx/ and bvh/, but not library/index.json, where the pipeline library's compute programs are translated. Slot-67 FSPX lookups therefore found no entry for those programs even when the index existed.

Read library/index.json as an optional sub-index and count its entries with the FSPX ones. Add regression coverage for fspx/-before-library/ ordering, code/state lookup, and absent or malformed library indexes.
Add the build-side pipeline-library translation stage to make_game.py on top of the .state emission already merged in tools/shader_library.py, and fix a TypeError when a compute pipeline record has a NONE (0xFFFFFFFF) state index.

- tools/shader_library.py: filter NONE program/state indices when building cs_state so records without a state blob do not crash with TypeError.
- make_game.py: add LIBRARY_ARCHIVE, LIBRARY_TOOLS, library_settings(), and library_shaders() to the shaders() stage (unpacking cs programs with --disasm and --carve, translating via rdna2spirv.py, validating fspx_key_clash against non-dict/unreadable indexes, cleaning stale unpacked artifacts, and writing library_build.json).
- docs/fspx.md, docs/shader_library.md: document library_shaders(), .state emission, and runtime loading of library/index.json.
- tests/test_shader_library.py, tests/test_library_shaders_stage.py: add NONE-state cleanup and shared-code/distinct-state regression tests plus full stage reuse, invalidation, stale-artifact cleanup, clash, malformed-index, and real-tool tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:40:35 +00:00
github manually merged commit 642880a217 into gh-pr/19/base 2026-11-26 08:40:38 +00:00
Author
Owner

@⁠wavehs on GitHub · 2026-11-24 02:06 UTC · original

macOS arm64 review (Apple M3 Pro) — the stage works, the crash it fixes reproduces exactly on base, and one build-time concern

Head ee2b087b6, merge base 30daa6958, 8 files +536/−11; it merges cleanly into ubi/main (9ec34cdff, git merge-tree --write-tree rc=0). Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0 / KosmicKrisp (Mesa 26.3.0) for the GPU smoke.

Check At ee2b087b6 At 30daa6958 / ubi/main
tests/test_library_shaders_stage.py 15/15 OK file does not exist; head's tests against base code: 15 errors (make_game has no library_shaders)
tests/test_shader_library.py 15/15 OK 15 tests with head's file on base tools: 1 error, test_compute_missing_state_removes_stale_state_and_skips_none_blob
tests/test_fspx_shaders_stage.py 23/23 OK —
tests/test_bvh_shaders_stage.py 13 tests, 1 failure (ShadersStageWithTheDlls…) the same failure, reproduced here; it is pre-existing, as you noted
cmake -S runtime -B build19 && cmake --build build19 -j8 builds clean, 0 errors —
ctest --test-dir build19 70/70 pass, 2 skipped (shader_library_corpus wants LEONIDA_GAME_DIR, vk_sync_validation) —
./build19/shader_library_test with base runtime/src/shader_library.h — fails at line 798 (size() == 5 && fspx_size() == 4)
run_gpu_tests.py --build build19 --filter cs_lds 4/4 PASS on MoltenVK and on KosmicKrisp —
scripts/run_semantic_tests.py tests/semantic 463 files, 6,075 tests, 2 failed 463 files, 6,075 tests, 2 failed (test_exec_computed, test_image_atomics_guard, both present on main)

The negative control is the crash itself, and it is exactly the one the PR describes. On base code:

tools/shader_library.py:320  state = blob(b, lib, cs_state[i]) if i in cs_state else None
tools/shader_library.py:228  o, s = lib["blobs"][i]
TypeError: list indices must be integers or slices, not NoneType

that is cs_state[i] holding None from a compute record whose state is 0xFFFFFFFF. At this head the same input returns 0, leaves no .state, and omits fspx_state_sha256, which the test checks through shader_meta.fspx_state_sha256_file. The C++ half is pinned too: with the base header the new block fails on the first count, with this header it passes (… FSPX programs and index lookup OK), so the loader's new library/ folder is what makes it green rather than the test restating itself.

One concern worth fixing before this lands: the new step translates ~2.7k programs on one core.

library_shaders calls py("rdna2spirv.py", …) directly (make_game.py, the py("rdna2spirv.py", os.path.join(unpacked, "disasm"), …) line), while the corpus uses translate(), whose own docstring is "rdna2spirv.py runs on one core: start one --shard per job side by side, then merge their index parts" (make_game.py, def translate(). The step already receives jobs and uses it for shader_library.py --jobs, so the unpacking is parallel and the translation is not. With the 2,684-program count your doc gives, that is a single-threaded pass over about a tenth of the corpus added to every shaders build, on a stage whose corpus translation is already "the longest step". translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks) would give the same output through the existing shard plan, and fspx_cache_complete would still see a complete index.

Three smaller notes.

  • fspx_key_clash now raises ValueError for an index that is not a JSON object (the new raise ValueError("index.json must contain a JSON object")), and library_shaders catches (OSError, ValueError, TypeError) to fail cleanly. The other caller, fspx_shaders, still calls it bare, so an unreadable FSPX index is still a traceback (it was a TypeError traceback before, so nothing regresses). The new contract has two call sites and only one is guarded.
  • docs/shader_library.md says "every compute program has exactly one (2,684 programs, 2,693 records)". That is a corpus measurement I cannot check here — no game files — and the doc does not say which archive or how it was counted. One sentence naming the source would let the next person redo the count.
  • When shaders.rpf is absent, library_shaders deletes index.json and library_build.json but leaves spirv/library/*.spv in place. Harmless (nothing loads without the index) and consistent with how the other steps drop only their markers, but it is the one stale output the rebuild cleanup does not reach.

I also ran check_no_game_data.py over all eight changed files: clean.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-24 02:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/19#issuecomment-7119768805) **macOS arm64 review (Apple M3 Pro) — the stage works, the crash it fixes reproduces exactly on base, and one build-time concern** Head `ee2b087b6`, merge base `30daa6958`, 8 files +536/−11; it merges cleanly into `ubi/main` (`9ec34cdff`, `git merge-tree --write-tree` rc=0). Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2, Apple clang 21.0.0, CMake 4.5.0, MoltenVK 1.4.0 / KosmicKrisp (Mesa 26.3.0) for the GPU smoke. | Check | At `ee2b087b6` | At `30daa6958` / `ubi/main` | |---|---|---| | `tests/test_library_shaders_stage.py` | **15/15 OK** | file does not exist; head's tests against base code: **15 errors** (`make_game` has no `library_shaders`) | | `tests/test_shader_library.py` | **15/15 OK** | 15 tests with head's file on base tools: **1 error**, `test_compute_missing_state_removes_stale_state_and_skips_none_blob` | | `tests/test_fspx_shaders_stage.py` | 23/23 OK | — | | `tests/test_bvh_shaders_stage.py` | 13 tests, **1 failure** (`ShadersStageWithTheDlls…`) | **the same failure**, reproduced here; it is pre-existing, as you noted | | `cmake -S runtime -B build19 && cmake --build build19 -j8` | builds clean, 0 errors | — | | `ctest --test-dir build19` | **70/70 pass**, 2 skipped (`shader_library_corpus` wants `LEONIDA_GAME_DIR`, `vk_sync_validation`) | — | | `./build19/shader_library_test` with base `runtime/src/shader_library.h` | — | **fails at line 798** (`size() == 5 && fspx_size() == 4`) | | `run_gpu_tests.py --build build19 --filter cs_lds` | **4/4 PASS** on MoltenVK and on KosmicKrisp | — | | `scripts/run_semantic_tests.py tests/semantic` | 463 files, **6,075 tests, 2 failed** | 463 files, **6,075 tests, 2 failed** (`test_exec_computed`, `test_image_atomics_guard`, both present on main) | The negative control is the crash itself, and it is exactly the one the PR describes. On base code: ``` tools/shader_library.py:320 state = blob(b, lib, cs_state[i]) if i in cs_state else None tools/shader_library.py:228 o, s = lib["blobs"][i] TypeError: list indices must be integers or slices, not NoneType ``` that is `cs_state[i]` holding `None` from a compute record whose state is `0xFFFFFFFF`. At this head the same input returns 0, leaves no `.state`, and omits `fspx_state_sha256`, which the test checks through `shader_meta.fspx_state_sha256_file`. The C++ half is pinned too: with the base header the new block fails on the first count, with this header it passes (`… FSPX programs and index lookup OK`), so the loader's new `library/` folder is what makes it green rather than the test restating itself. **One concern worth fixing before this lands: the new step translates ~2.7k programs on one core.** `library_shaders` calls `py("rdna2spirv.py", …)` directly (`make_game.py`, the `py("rdna2spirv.py", os.path.join(unpacked, "disasm"), …)` line), while the corpus uses `translate()`, whose own docstring is "rdna2spirv.py runs on one core: start one `--shard` per job side by side, then merge their index parts" (`make_game.py`, `def translate(`). The step already receives `jobs` and uses it for `shader_library.py --jobs`, so the unpacking is parallel and the translation is not. With the 2,684-program count your doc gives, that is a single-threaded pass over about a tenth of the corpus added to every `shaders` build, on a stage whose corpus translation is already "the longest step". `translate(disasm, spirv, jobs, emulate=emulate, fallbacks=fallbacks)` would give the same output through the existing shard plan, and `fspx_cache_complete` would still see a complete index. **Three smaller notes.** - `fspx_key_clash` now raises `ValueError` for an index that is not a JSON object (the new `raise ValueError("index.json must contain a JSON object")`), and `library_shaders` catches `(OSError, ValueError, TypeError)` to fail cleanly. The other caller, `fspx_shaders`, still calls it bare, so an unreadable FSPX index is still a traceback (it was a `TypeError` traceback before, so nothing regresses). The new contract has two call sites and only one is guarded. - `docs/shader_library.md` says "every compute program has exactly one (2,684 programs, 2,693 records)". That is a corpus measurement I cannot check here — no game files — and the doc does not say which archive or how it was counted. One sentence naming the source would let the next person redo the count. - When `shaders.rpf` is absent, `library_shaders` deletes `index.json` and `library_build.json` but leaves `spirv/library/*.spv` in place. Harmless (nothing loads without the index) and consistent with how the other steps drop only their markers, but it is the one stale output the rebuild cleanup does not reach. I also ran `check_no_game_data.py` over all eight changed files: clean. No game files. AI-assisted.
Author
Owner

@⁠moffington on GitHub · 2026-11-24 02:22 UTC · original

Thank you.

Addressed the serial translation concern in 642880a21 by switching library_shaders() to the existing parallel translate() helper. Also added shard/cache regression tests, unified the FSPX index error handling, and clarified the shader count provenance.

Verified byte-identical serial/parallel outputs, 70/70 C++ tests, and 8/8 RTX 3060 Vulkan fixture cases. The pre-existing BVH failure remains unchanged.

I left the unindexed .spv cleanup behavior consistent with the existing BVH stage.

**@⁠moffington** on GitHub · 2026-11-24 02:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/19#issuecomment-7120078861) Thank you. Addressed the serial translation concern in `642880a21` by switching `library_shaders()` to the existing parallel `translate()` helper. Also added shard/cache regression tests, unified the FSPX index error handling, and clarified the shader count provenance. Verified byte-identical serial/parallel outputs, 70/70 C++ tests, and 8/8 RTX 3060 Vulkan fixture cases. The pre-existing BVH failure remains unchanged. I left the unindexed `.spv` cleanup behavior consistent with the existing BVH stage.
This discussion has been locked. Commenting is limited to contributors.
No description provided.