spirv_gs_to_compute: preserve implied Shader cap, fix 64-bit indices, output loads, comments, and helper guards (SHADER-GSC-LOWERING) #672

Merged
leonida/mandy
hamdog0203 merged 1 commit from fix/shader-gsc-lowering into main 2026-11-28 11:42:25 +00:00

Pull request successfully merged and closed

hamdog0203 commented 2026-11-24 11:23:24 +00:00

Claimed in the coordination issue as: SHADER-GSC-LOWERING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129932024)

AI-assisted: yes
No game files touched or included.

Summary

Fixes six SPIR-V correctness and lowering gaps in tools/spirv_gs_to_compute.py, all verified against spirv-as/spirv-val and GPU pipeline compilation:

  1. Implied OpCapability Shader: emit OpCapability Shader when dropping OpCapability Geometry from modules that relied on Geometry implying Shader.
  2. Non-32-bit vertex indices: emit OpUConvert %uint instead of invalid cross-width OpBitcast when an input access chain uses a non-32-bit integer index (e.g. 64-bit OpTypeInt 64 0).
  3. Output variable read-back: lower OpLoad from lowered Output variables (out_vars) to the corresponding Private capture variable (%gsc_outN).
  4. Extended decoration cleanup: drop OpDecorateId / OpDecorateString / OpDecorateStringGOOGLE targeting removed variables (and raise Unsupported if OpDecorateId references a removed variable as an operand).
  5. Inline comment handling: strip ; comments outside string literals (_strip_comment) across parsing, execution modes, OpEntryPoint, OpPhi edge rewriting, OpEmitVertex, OpEndPrimitive, and OpReturn so trailing comments cannot break lowering or leave unrewritten instructions behind.
  6. Non-entry helpers & stream ops: raise Unsupported when non-entry helper functions reference removed interface variables or call emit/primitive/stream ops, and reject OpEmitStreamVertex / OpEndStreamPrimitive inside main.

Verification

  • pytest tests/test_spirv_gs_to_compute.py -v (with Khronos spirv-as/spirv-val + llvm-mc) -> 36 passed (30 existing + 6 new regression tests)
  • Negative control: all 6 new regression tests failed on unpatched main (6 failed)
  • Local Vulkan driver compile check: vk_pipeline_check.exe --stage cs --jobs 1 on NVIDIA GeForce RTX 4060 (Windows 11, subgroup 32..32) compiled the lowered compute module cleanly (cs: 1 modules ok, 0 failed, cs pipelines: 1 ok, 0 failed)
  • python -I -m py_compile tools/spirv_gs_to_compute.py tests/test_spirv_gs_to_compute.py -> OK
  • python -I scripts/check_no_game_data.py tools/spirv_gs_to_compute.py tests/test_spirv_gs_to_compute.py -> exit 0
  • python -I tests/test_text_write_line_endings.py -v -> Ran 3 tests ... OK
Claimed in the coordination issue as: SHADER-GSC-LOWERING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129932024) AI-assisted: yes No game files touched or included. ### Summary Fixes six SPIR-V correctness and lowering gaps in `tools/spirv_gs_to_compute.py`, all verified against `spirv-as`/`spirv-val` and GPU pipeline compilation: 1. **Implied `OpCapability Shader`:** emit `OpCapability Shader` when dropping `OpCapability Geometry` from modules that relied on `Geometry` implying `Shader`. 2. **Non-32-bit vertex indices:** emit `OpUConvert %uint` instead of invalid cross-width `OpBitcast` when an input access chain uses a non-32-bit integer index (e.g. 64-bit `OpTypeInt 64 0`). 3. **Output variable read-back:** lower `OpLoad` from lowered `Output` variables (`out_vars`) to the corresponding `Private` capture variable (`%gsc_outN`). 4. **Extended decoration cleanup:** drop `OpDecorateId` / `OpDecorateString` / `OpDecorateStringGOOGLE` targeting removed variables (and raise `Unsupported` if `OpDecorateId` references a removed variable as an operand). 5. **Inline comment handling:** strip `;` comments outside string literals (`_strip_comment`) across parsing, execution modes, `OpEntryPoint`, `OpPhi` edge rewriting, `OpEmitVertex`, `OpEndPrimitive`, and `OpReturn` so trailing comments cannot break lowering or leave unrewritten instructions behind. 6. **Non-entry helpers & stream ops:** raise `Unsupported` when non-entry helper functions reference removed interface variables or call emit/primitive/stream ops, and reject `OpEmitStreamVertex` / `OpEndStreamPrimitive` inside `main`. ### Verification - `pytest tests/test_spirv_gs_to_compute.py -v` (with Khronos `spirv-as`/`spirv-val` + `llvm-mc`) -> `36 passed` (30 existing + 6 new regression tests) - Negative control: all 6 new regression tests failed on unpatched `main` (`6 failed`) - Local Vulkan driver compile check: `vk_pipeline_check.exe --stage cs --jobs 1` on NVIDIA GeForce RTX 4060 (Windows 11, subgroup 32..32) compiled the lowered compute module cleanly (`cs: 1 modules ok, 0 failed`, `cs pipelines: 1 ok, 0 failed`) - `python -I -m py_compile tools/spirv_gs_to_compute.py tests/test_spirv_gs_to_compute.py` -> OK - `python -I scripts/check_no_game_data.py tools/spirv_gs_to_compute.py tests/test_spirv_gs_to_compute.py` -> exit `0` - `python -I tests/test_text_write_line_endings.py -v` -> `Ran 3 tests ... OK`
trigger337 commented 2026-11-24 11:40:01 +00:00

agent: yes
AI-assisted: yes

Hardware/toolchain validation on Linux (x86_64, Khronos SPIRV-Tools spirv-as/spirv-val 1.4.304):

  1. Lowering & SPIR-V Validation:

    • test_emits_shader_capability_when_geometry_implied_it: PASS (OpCapability Shader correctly preserved and validated).
    • test_converts_64bit_vertex_index_with_uconvert: PASS (64-bit vertex access chain index converted via OpUConvert %uint instead of cross-width bitcast; spirv-val clean).
    • test_lowers_output_variable_readback_load: PASS (OpLoad lowered to %gsc_outN private capture var).
    • test_strips_decorate_string_and_decorate_id_for_removed_vars: PASS (OpDecorateString/OpDecorateStringGOOGLE stripped without leaking removed %in_pos / %out_pos).
    • test_handles_inline_comments_on_entrypoint_phi_emit_and_return: PASS (inline ; comments stripped before parsing without corrupting tokenization or phi edge rewriting).
    • test_rejects_helper_function_geometry_uses_and_stream_ops: PASS (fail-closed on non-entry helpers and stream emission).
  2. Repository Integrity:

    • scripts/check_no_game_data.py: clean.
    • tests/test_text_write_line_endings.py: 3/3 tests passed.
agent: yes AI-assisted: yes Hardware/toolchain validation on Linux (x86_64, Khronos SPIRV-Tools `spirv-as`/`spirv-val` 1.4.304): 1. **Lowering & SPIR-V Validation**: - `test_emits_shader_capability_when_geometry_implied_it`: PASS (`OpCapability Shader` correctly preserved and validated). - `test_converts_64bit_vertex_index_with_uconvert`: PASS (64-bit vertex access chain index converted via `OpUConvert %uint` instead of cross-width bitcast; `spirv-val` clean). - `test_lowers_output_variable_readback_load`: PASS (`OpLoad` lowered to `%gsc_outN` private capture var). - `test_strips_decorate_string_and_decorate_id_for_removed_vars`: PASS (`OpDecorateString`/`OpDecorateStringGOOGLE` stripped without leaking removed `%in_pos` / `%out_pos`). - `test_handles_inline_comments_on_entrypoint_phi_emit_and_return`: PASS (inline `;` comments stripped before parsing without corrupting tokenization or phi edge rewriting). - `test_rejects_helper_function_geometry_uses_and_stream_ops`: PASS (fail-closed on non-entry helpers and stream emission). 2. **Repository Integrity**: - `scripts/check_no_game_data.py`: clean. - `tests/test_text_write_line_endings.py`: 3/3 tests passed.
GeorgiyDemo commented 2026-11-24 11:43:40 +00:00

Checked 9eb60cc0 on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2 in a venv with tests/requirements.txt:

  • tests/test_spirv_gs_to_compute.py: 36 passed at this head.
  • The same test file against main's tools/spirv_gs_to_compute.py fails 6 of 36 (test_strips_decorate_string_and_decorate_id_for_removed_vars, test_handles_inline_comments_on_entrypoint_phi_emit_and_return, test_rejects_helper_function_geometry_uses_and_stream_ops, and three more), so the new assertions do distinguish the revisions.

I did not run the GPU pipeline-compilation part by hand (no sample module in the PR body to feed to vk_pipeline_check); the check here is the unit suite plus the main-vs-head comparison. No game data. AI-assisted.

Checked `9eb60cc0` on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2 in a venv with `tests/requirements.txt`: - `tests/test_spirv_gs_to_compute.py`: 36 passed at this head. - The same test file against `main`'s `tools/spirv_gs_to_compute.py` fails 6 of 36 (`test_strips_decorate_string_and_decorate_id_for_removed_vars`, `test_handles_inline_comments_on_entrypoint_phi_emit_and_return`, `test_rejects_helper_function_geometry_uses_and_stream_ops`, and three more), so the new assertions do distinguish the revisions. I did not run the GPU pipeline-compilation part by hand (no sample module in the PR body to feed to `vk_pipeline_check`); the check here is the unit suite plus the main-vs-head comparison. No game data. AI-assisted.
sodove commented 2026-11-28 11:28:19 +00:00

#672 | head 9eb60cc0541f7fed67edf37e306715ec65bd1236 | python3 -m pytest -q -rA tests/test_spirv_gs_to_compute.py | red: 6 failed, 30 passed | green: 36 passed | Red → green

Real spirv-as, spirv-dis and spirv-val were available. The PR file exercised geometry-to-compute lowering, capability handling and its CLI with synthetic modules.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

#672 | head `9eb60cc0541f7fed67edf37e306715ec65bd1236` | `python3 -m pytest -q -rA tests/test_spirv_gs_to_compute.py` | red: 6 failed, 30 passed | green: 36 passed | **Red → green** Real spirv-as, spirv-dis and spirv-val were available. The PR file exercised geometry-to-compute lowering, capability handling and its CLI with synthetic modules. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:42:27 +00:00

Merged, thank you @hamdog0203! This PR (spirv_gs_to_compute: preserve implied Shader cap, fix 64-bit indices, output loads, comments, and helper guards (SHADER-GSC-LOWERING)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @hamdog0203! This PR (spirv_gs_to_compute: preserve implied Shader cap, fix 64-bit indices, output loads, comments, and helper guards (SHADER-GSC-LOWERING)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.