rdna2spirv: compact SPIR-V modules on request (SHADER-COMPACT-SPIRV) #1073

Closed
github-bot wants to merge 1 commit from gh-pr/1073/head into gh-pr/1073/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 17:50 UTC · original
split/shader-compact-spirv → main · +4 −0 · 2 files · 1 commits · closed without merging

Rebased onto bfef489c at 363fed0f. Main already exposes SPIR-V compaction. This diff adds the contract row and tests that the build command forwards the flag. The two focused suites ran 49 cases with five Windows-only skips.

Claimed in the coordination issue as: SHADER-COMPACT-SPIRV (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #544 changes the existing Python optimizer. The two options can run independently. A merge-tree check against #1068 also completed without conflicts.

What and why

The translator and shader build rejected --compact-spirv on Linux. To try smaller modules, a developer had to run the optimizer separately and validate the result again. This adds the option to both entry points. It runs local load elimination, redundancy elimination and dead-code elimination on the assembled staging file before the normal validation and publication step. It preserves stage interfaces, descriptor bindings and specialization constants. Compaction is off by default. Only an opted-in build needs spirv-opt.

A hand-written pixel program produced a 4,076-byte module by default and a 908-byte module with compaction. Both the Python assembler and spirv-as produced those sizes. All four outputs passed Vulkan 1.2 validation and had matching shader index metadata. This is a synthetic size comparison.

Tested

Ran the compiler tests on Linux and cross-built the Windows runtime.

Applied only the two test additions to pristine main 32950551e, then ran the same commands on this child:

Command Main plus tests Child
python3 -I tests/test_native_tool_paths.py AssembleSpirv.test_compact_binary_before_publish 1 error. The assembler function rejected the compact keyword. 1 passed
python3 -I tests/test_make_game_translator_flags.py MainWiringTest.test_compact_spirv_reaches_the_shaders_stage 1 error. The build CLI rejected --compact-spirv. 1 passed
Command or check Child result
python3 -I tests/test_native_tool_paths.py 8 passed, 5 Windows-only skips
python3 -I tests/test_make_game_translator_flags.py 34 passed
python3 -I tests/test_run_gpu_tests_python_assembler.py 10 passed
python3 -I scripts/run_semantic_tests.py tests/semantic -j 2 6,168 tests in 470 files, zero failing files. Standalone run 643 s, full CI repeat 455 s.
python3 -I -m compileall -q make_game.py tools tests Passed
Python CI loop over 520 nonsemantic files, using python3 -I <file> or python3 -I -m pytest -q <file> One failing file on each tree, tests/test_imhex_patterns.py. The same 6 of its 9 tests failed. Zero new failing files.
python3 -I scripts/check_no_game_data.py Passed, 2,457 tracked entries
cmake -S runtime -B runtime/build/boot and cmake --build runtime/build/boot --target gta6rt -j6 Linked the x86-64 Windows executable using the configured cross-toolchain.

On a second synthetic module, spirv-dis retained the location, descriptor set, binding and specialization ID after compaction, and the dead add disappeared. An optimizer failure took the existing rejection path and left zero stale modules or staging files. With spirv-opt absent, the default CLI succeeded and the compact CLI reported the missing tool with exit code 2.

GPUs tested: none. The tests ran on the CPU. Native Windows, Wine, AMD GPU and Intel GPU runs were not performed.

AI-assisted: yes

Checklist

  • Based on upstream main at the cut, 32950551e. Merged cleanly in a temporary checkout of the newer 3aa975421. The native tool paths, build flag and build destination suites ran 56 cases there, with 51 passes and five Windows-only skips.
  • One topic in one commit.
  • Synthetic inputs and a passing game-data check.
  • The SPIR-V compaction contract and its confirmation are in the translator contract table in docs/design.md.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 17:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1073) `split/shader-compact-spirv` → `main` · +4 −0 · 2 files · 1 commits · closed without merging **Rebased onto `bfef489c` at `363fed0f`.** Main already exposes SPIR-V compaction. This diff adds the contract row and tests that the build command forwards the flag. The two focused suites ran 49 cases with five Windows-only skips. Claimed in the coordination issue as: SHADER-COMPACT-SPIRV ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #544 changes the existing Python optimizer. The two options can run independently. A merge-tree check against #1068 also completed without conflicts. ### What and why The translator and shader build rejected `--compact-spirv` on Linux. To try smaller modules, a developer had to run the optimizer separately and validate the result again. This adds the option to both entry points. It runs local load elimination, redundancy elimination and dead-code elimination on the assembled staging file before the normal validation and publication step. It preserves stage interfaces, descriptor bindings and specialization constants. Compaction is off by default. Only an opted-in build needs `spirv-opt`. A hand-written pixel program produced a 4,076-byte module by default and a 908-byte module with compaction. Both the Python assembler and `spirv-as` produced those sizes. All four outputs passed Vulkan 1.2 validation and had matching shader index metadata. This is a synthetic size comparison. ### Tested Ran the compiler tests on Linux and cross-built the Windows runtime. Applied only the two test additions to pristine main `32950551e`, then ran the same commands on this child: | Command | Main plus tests | Child | |---|---|---| | `python3 -I tests/test_native_tool_paths.py AssembleSpirv.test_compact_binary_before_publish` | 1 error. The assembler function rejected the `compact` keyword. | 1 passed | | `python3 -I tests/test_make_game_translator_flags.py MainWiringTest.test_compact_spirv_reaches_the_shaders_stage` | 1 error. The build CLI rejected `--compact-spirv`. | 1 passed | | Command or check | Child result | |---|---| | `python3 -I tests/test_native_tool_paths.py` | 8 passed, 5 Windows-only skips | | `python3 -I tests/test_make_game_translator_flags.py` | 34 passed | | `python3 -I tests/test_run_gpu_tests_python_assembler.py` | 10 passed | | `python3 -I scripts/run_semantic_tests.py tests/semantic -j 2` | 6,168 tests in 470 files, zero failing files. Standalone run 643 s, full CI repeat 455 s. | | `python3 -I -m compileall -q make_game.py tools tests` | Passed | | Python CI loop over 520 nonsemantic files, using `python3 -I <file>` or `python3 -I -m pytest -q <file>` | One failing file on each tree, `tests/test_imhex_patterns.py`. The same 6 of its 9 tests failed. Zero new failing files. | | `python3 -I scripts/check_no_game_data.py` | Passed, 2,457 tracked entries | | `cmake -S runtime -B runtime/build/boot` and `cmake --build runtime/build/boot --target gta6rt -j6` | Linked the x86-64 Windows executable using the configured cross-toolchain. | On a second synthetic module, `spirv-dis` retained the location, descriptor set, binding and specialization ID after compaction, and the dead add disappeared. An optimizer failure took the existing rejection path and left zero stale modules or staging files. With `spirv-opt` absent, the default CLI succeeded and the compact CLI reported the missing tool with exit code 2. GPUs tested: none. The tests ran on the CPU. Native Windows, Wine, AMD GPU and Intel GPU runs were not performed. AI-assisted: yes ### Checklist - [x] Based on upstream main at the cut, `32950551e`. Merged cleanly in a temporary checkout of the newer `3aa975421`. The native tool paths, build flag and build destination suites ran 56 cases there, with 51 passes and five Windows-only skips. - [x] One topic in one commit. - [x] Synthetic inputs and a passing game-data check. - [x] The SPIR-V compaction contract and its confirmation are in the translator contract table in `docs/design.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add --compact-spirv to make_game and the translator. Run the selected
SPIRV-Tools passes on the staging file before validation. Keep the default
output and the runtime interface contract.

Both new tests error on main without the option and pass here. The semantic
suite ran 6168 tests in 470 files with no failing files. The Windows
runtime cross-build and tracked-file content check passed.

AI-assisted (Codex and Claude Code agents).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:36:38 +00:00
github-bot closed this pull request 2026-11-26 09:36:39 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 17:57 UTC · original

Independent Windows check of b22d5af4 on an RTX 5070 Ti (driver 610.74, Windows 11 build 26100.7623, SPIRV-Tools 2026.1). I used eight hand-written fixtures from the repository, with both spirv-as and the Python assembler.

  • For each assembler, --compact-spirv reduced the combined size from 64,976 to 49,528 bytes (23.8%). All eight modules got smaller. All 32 outputs passed spirv-val for Vulkan 1.2, and the eight-entry shader index matched across all four configurations.
  • Seven 64×64 draws per configuration ran on native Windows Vulkan with subgroup size 32. Each passed the fixture checks. All four channels of every pixel matched between plain and compact output for both assemblers. The ballot/atomic case also produced the expected counter and the same set of 1,024 writes, allowing for allocation order.
  • Reused one two-shard output directory with compaction off, on, then off again. All eight binaries and the merged index matched the corresponding clean translation at every step.
  • Both assemblers also worked with a Unicode output path. With spirv-opt removed from the tool path, plain translation still succeeded and a compact translation into a fresh directory exited 2, named the missing tool, and published no module or index.

Synthetic fixtures only. AI-assisted: yes (OpenAI Codex).

**@⁠sodove** on GitHub · 2026-11-24 17:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1073#issuecomment-7139959352) Independent Windows check of `b22d5af4` on an RTX 5070 Ti (driver 610.74, Windows 11 build 26100.7623, SPIRV-Tools 2026.1). I used eight hand-written fixtures from the repository, with both `spirv-as` and the Python assembler. - For each assembler, `--compact-spirv` reduced the combined size from 64,976 to 49,528 bytes (23.8%). All eight modules got smaller. All 32 outputs passed `spirv-val` for Vulkan 1.2, and the eight-entry shader index matched across all four configurations. - Seven 64×64 draws per configuration ran on native Windows Vulkan with subgroup size 32. Each passed the fixture checks. All four channels of every pixel matched between plain and compact output for both assemblers. The ballot/atomic case also produced the expected counter and the same set of 1,024 writes, allowing for allocation order. - Reused one two-shard output directory with compaction off, on, then off again. All eight binaries and the merged index matched the corresponding clean translation at every step. - Both assemblers also worked with a Unicode output path. With `spirv-opt` removed from the tool path, plain translation still succeeded and a compact translation into a fresh directory exited 2, named the missing tool, and published no module or index. Synthetic fixtures only. AI-assisted: yes (OpenAI Codex).
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 18:50 UTC · original · approved these changes

Reviewed and verified. Introduces optional --compact-spirv flag running spirv-opt (local load/dead-code/redundancy elimination) on assembled SPIR-V modules before validation, while preserving interface decorations and descriptor bindings. Clean fallback handling when spirv-opt is absent. Verified with tests/test_native_tool_paths.py and test_make_game_translator_flags.py. 100% clean-room.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1073#pullrequestreview-6045349311) · **approved these changes** Reviewed and verified. Introduces optional --compact-spirv flag running spirv-opt (local load/dead-code/redundancy elimination) on assembled SPIR-V modules before validation, while preserving interface decorations and descriptor bindings. Clean fallback handling when spirv-opt is absent. Verified with tests/test_native_tool_paths.py and test_make_game_translator_flags.py. 100% clean-room.
Author
Owner

@⁠iFeyz on GitHub · 2026-11-24 19:51 UTC · original

AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo.

Head c86f50e87:

  • scripts/run_gpu_tests.py with this translator: 261 of 261 shaders translated and spirv-val-clean, 236 of 252 pass, 16 skipped, 0 failed (native, subgroup 64).
  • tests/test_make_game_translator_flags.py (34), tests/test_native_tool_paths.py (13): OK.
**@⁠iFeyz** on GitHub · 2026-11-24 19:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1073#issuecomment-7142677533) AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo. Head `c86f50e87`: - `scripts/run_gpu_tests.py` with this translator: 261 of 261 shaders translated and `spirv-val`-clean, **236 of 252 pass, 16 skipped, 0 failed** (native, subgroup 64). - `tests/test_make_game_translator_flags.py` (34), `tests/test_native_tool_paths.py` (13): OK.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 21:10 UTC · original

GPU/tooling verification (AI-assisted, overnight worker w4; independent run, not the author's).

Head tested: c86f50e. Note: run_gpu_tests.py does not forward --compact-spirv, so I verified compacted modules by translating the full GPU-test corpus with the flag and A/B-running every module against its non-compacted twin on both GPUs.

Translator correctness (CPU)

  • tests/test_native_tool_paths.py: 13 tests OK (the new test_compact_binary_before_publish ran and passed; 1 unrelated 8.3-name skip).
  • tests/test_make_game_translator_flags.py: 34 tests OK.
  • scripts/run_semantic_tests.py tests/semantic: 6168 tests / 470 files / 0 failed in 552 s — matches the PR's claim.

Compact translation of the GPU corpus

  • tools/rdna2spirv.py <disasm> --out <spirv> --compact-spirv --pc-tail-ubo (Vulkan SDK 1.4.363 spirv-opt/spirv-val): 261/261 shaders translated, all pass spirv-val. Every module is smaller; corpus total ~15% smaller (6.44 MB → 5.50 MB).

GPU A/B, AMD Radeon iGPU (gfx1035, driver 24.10.24, Vulkan 1.3.280) — env: VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1

  • All 126 cs_ modules*: vk_compute_test <spv> 4 dump with VKC_DUMP — identical exit codes and byte-identical full buffer dumps vs the non-compacted modules.
  • 15 draw cases via vk_harness (9 ps, 3 vs, gs_tri, ms_tri, ms_v5_workgroup): byte-identical raw output.

GPU A/B, NVIDIA RTX 4070 SUPER — env: VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~

  • Same 126 cs_* dump comparison and same 15 draw cases: all identical.

Verdict: the compact pass preserves semantics on both GPUs and keeps every module valid; size win is real (~15%). LGTM from this hardware.

**@⁠whoalin1** on GitHub · 2026-11-24 21:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1073#issuecomment-7144579591) GPU/tooling verification (AI-assisted, overnight worker w4; independent run, not the author's). Head tested: c86f50e. Note: `run_gpu_tests.py` does not forward `--compact-spirv`, so I verified compacted modules by translating the full GPU-test corpus with the flag and A/B-running every module against its non-compacted twin on both GPUs. **Translator correctness (CPU)** - `tests/test_native_tool_paths.py`: 13 tests OK (the new `test_compact_binary_before_publish` ran and passed; 1 unrelated 8.3-name skip). - `tests/test_make_game_translator_flags.py`: 34 tests OK. - `scripts/run_semantic_tests.py tests/semantic`: **6168 tests / 470 files / 0 failed** in 552 s — matches the PR's claim. **Compact translation of the GPU corpus** - `tools/rdna2spirv.py <disasm> --out <spirv> --compact-spirv --pc-tail-ubo` (Vulkan SDK 1.4.363 `spirv-opt`/`spirv-val`): **261/261 shaders translated, all pass spirv-val**. Every module is smaller; corpus total ~15% smaller (6.44 MB → 5.50 MB). **GPU A/B, AMD Radeon iGPU (gfx1035, driver 24.10.24, Vulkan 1.3.280)** — env: `VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1` - All **126 cs_* modules**: `vk_compute_test <spv> 4 dump` with `VKC_DUMP` — identical exit codes and **byte-identical full buffer dumps** vs the non-compacted modules. - 15 draw cases via `vk_harness` (9 ps, 3 vs, gs_tri, ms_tri, ms_v5_workgroup): **byte-identical raw output**. **GPU A/B, NVIDIA RTX 4070 SUPER** — env: `VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~` - Same 126 cs_* dump comparison and same 15 draw cases: **all identical**. Verdict: the compact pass preserves semantics on both GPUs and keeps every module valid; size win is real (~15%). LGTM from this hardware.

Pull request closed

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