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

Open
opened 2026-11-26 20:18:48 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/672
Author: @hamdog0203
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/shader-gsc-lowering


📝 Commits (1)

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

📊 Changes

2 files changed (+231 additions, -34 deletions)

View changed files

📝 tests/test_spirv_gs_to_compute.py (+136 -0)
📝 tools/spirv_gs_to_compute.py (+95 -34)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/672 **Author:** [@hamdog0203](https://github.com/hamdog0203) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shader-gsc-lowering` --- ### 📝 Commits (1) - [`9eb60cc`](https://github.com/ubiquitarianism/leonida/commit/9eb60cc0541f7fed67edf37e306715ec65bd1236) spirv_gs_to_compute: preserve implied Shader cap, fix 64-bit indices, output loads, comments, and helper guards (SHADER-GSC-LOWERING) ### 📊 Changes **2 files changed** (+231 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_spirv_gs_to_compute.py` (+136 -0) 📝 `tools/spirv_gs_to_compute.py` (+95 -34) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#711
No description provided.