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

Open
github-bot wants to merge 1 commit from github-bot/gh-672 into main AGit
Owner

@⁠hamdog0203 on GitHub · 2026-11-24 11:23 UTC · original
hamdog0203:fix/shader-gsc-lowering → main · +231 −34 · 2 files · 1 commits · open

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

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
**@⁠hamdog0203** on GitHub · 2026-11-24 11:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/672) `hamdog0203:fix/shader-gsc-lowering` → `main` · +231 −34 · 2 files · 1 commits · open Claimed in the coordination issue as: SHADER-GSC-LOWERING (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:15:25 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 11:40 UTC · original

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.
**@⁠trigger337** on GitHub · 2026-11-24 11:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/672#issuecomment-7130390778) 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.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-24 11:43 UTC · original

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.

**@⁠GeorgiyDemo** on GitHub · 2026-11-24 11:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/672#issuecomment-7130468858) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/672/head:github-bot/gh-672'
git switch 'github-bot/gh-672'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-672'
git switch 'github-bot/gh-672'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-672'
git switch 'github-bot/gh-672'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-672'
git switch 'main'
git merge --squash 'github-bot/gh-672'
git switch 'main'
git merge --ff-only 'github-bot/gh-672'
git switch 'main'
git merge 'github-bot/gh-672'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.