spirv_interface: validate outer array length, initializer ID, struct/member and stage decorations (SPIRV-INTERFACE-DECORATION-VALIDATION) #1542

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:57 UTC · original
IlyassRS3:fix/spirv-interface-decoration-validation → main · +195 −9 · 2 files · 1 commits · open

What changed

  • Outer per-vertex / per-primitive array length validation (tools/spirv_interface.py:varying_type): call array_count(args[1]) before unwrapping the outer OpTypeArray on GS inputs, MS outputs, and PS PerVertexKHR inputs so zero, negative, non-integer, or undefined length constants raise InterfaceError instead of passing silently.
  • OpVariable initializer ID validation (tools/spirv_interface.py:read_instruction): validate the optional 4th operand (Initializer) with require_id() when present.
  • Decoration group target check (tools/spirv_interface.py:apply_decoration_groups): reject OpMemberDecorate targeting a DecorationGroup ID.
  • Struct-type decorations and out-of-range member indices (tools/spirv_interface.py:shape, declaration):
    • Track decorated member indices per struct and raise InterfaceError if any member decoration index is >= len(members) on a top-level or nested interface struct.
    • Check Patch / PassthroughNV on top-level and nested struct types themselves (not only on variables and members), and propagate PerPrimitiveEXT from a top-level interface struct type to its members.
  • Stage/storage rules for Index, PerPrimitiveEXT, and PerVertexKHR (tools/spirv_interface.py:address, declaration):
    • Reject Index on variables/members outside fragment (ps) outputs.
    • Reject PerPrimitiveEXT outside mesh (ms) outputs and fragment (ps) inputs.
    • Reject PerVertexKHR combined with PerPrimitiveEXT on the same varying, and reject PerVertexKHR on struct types or members.
  • Tests (tests/test_spirv_interface.py): added 5 synthetic binary SPIR-V regression tests (23 assertions) covering every check above.

Claimed in the coordination issue as:

SPIRV-INTERFACE-DECORATION-VALIDATION (#14 reached GitHub's 2,500-comment cap with no successor coordination issue open yet; checked #14 and open PRs — 0 claims and 0 open PRs touch tools/spirv_interface.py)

How it was tested

  • python3 -I -W error tests/test_spirv_interface.py: 48/48 passed (0 warnings).
  • python3 -I tests/test_spirv_interface_extra.py: 3/3 passed.
  • python3 -I tests/test_shader_link_check.py: 51/51 passed.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/spirv_interface.py tests/test_spirv_interface.py: passed.
  • python3 -m compileall -q tools/spirv_interface.py tests/test_spirv_interface.py: passed.
  • Mutation check against unpatched main:tools/spirv_interface.py: all 5 new tests fail (FAILED (failures=23)), all 43 baseline tests pass.

Metadata

  • AI-assisted: yes
  • GPUs tested: none (CPU-only synthetic SPIR-V binary reflection unit tests on macOS arm64; no game files used)
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1542) `IlyassRS3:fix/spirv-interface-decoration-validation` → `main` · +195 −9 · 2 files · 1 commits · open ## What changed - **Outer per-vertex / per-primitive array length validation (`tools/spirv_interface.py:varying_type`)**: call `array_count(args[1])` before unwrapping the outer `OpTypeArray` on GS inputs, MS outputs, and PS `PerVertexKHR` inputs so zero, negative, non-integer, or undefined length constants raise `InterfaceError` instead of passing silently. - **`OpVariable` initializer ID validation (`tools/spirv_interface.py:read_instruction`)**: validate the optional 4th operand (`Initializer`) with `require_id()` when present. - **Decoration group target check (`tools/spirv_interface.py:apply_decoration_groups`)**: reject `OpMemberDecorate` targeting a `DecorationGroup` ID. - **Struct-type decorations and out-of-range member indices (`tools/spirv_interface.py:shape`, `declaration`)**: - Track decorated member indices per struct and raise `InterfaceError` if any member decoration index is `>= len(members)` on a top-level or nested interface struct. - Check `Patch` / `PassthroughNV` on top-level and nested struct types themselves (not only on variables and members), and propagate `PerPrimitiveEXT` from a top-level interface struct type to its members. - **Stage/storage rules for `Index`, `PerPrimitiveEXT`, and `PerVertexKHR` (`tools/spirv_interface.py:address`, `declaration`)**: - Reject `Index` on variables/members outside fragment (`ps`) outputs. - Reject `PerPrimitiveEXT` outside mesh (`ms`) outputs and fragment (`ps`) inputs. - Reject `PerVertexKHR` combined with `PerPrimitiveEXT` on the same varying, and reject `PerVertexKHR` on struct types or members. - **Tests (`tests/test_spirv_interface.py`)**: added 5 synthetic binary SPIR-V regression tests (23 assertions) covering every check above. ## Claimed in the coordination issue as: `SPIRV-INTERFACE-DECORATION-VALIDATION` (#14 reached GitHub's 2,500-comment cap with no successor coordination issue open yet; checked #14 and open PRs — 0 claims and 0 open PRs touch `tools/spirv_interface.py`) ## How it was tested - `python3 -I -W error tests/test_spirv_interface.py`: 48/48 passed (0 warnings). - `python3 -I tests/test_spirv_interface_extra.py`: 3/3 passed. - `python3 -I tests/test_shader_link_check.py`: 51/51 passed. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/spirv_interface.py tests/test_spirv_interface.py`: passed. - `python3 -m compileall -q tools/spirv_interface.py tests/test_spirv_interface.py`: passed. - Mutation check against unpatched `main:tools/spirv_interface.py`: all 5 new tests fail (`FAILED (failures=23)`), all 43 baseline tests pass. ## Metadata - AI-assisted: yes - GPUs tested: none (CPU-only synthetic SPIR-V binary reflection unit tests on macOS arm64; no game files used)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:57 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 03:58 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 03:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1542#pullrequestreview-6051653198) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 04:20 UTC · original

Tested a0996d0b0 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main c7e82e26e (Python SPIR-V tool; no GPU):

  • pytest 9.2.0 on tests/test_spirv_interface.py: 48 passed, 108 subtests passed at this head.
  • The same file on main: 23 failed, 46 passed, 87 subtests — the new array-length, initializer-ID, struct/member-decoration and stage-decoration checks are not there.
  • Not run: anything beyond the synthetic SPIR-V modules; no corpus.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1542#issuecomment-7152748227) Tested `a0996d0b0` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `c7e82e26e` (Python SPIR-V tool; no GPU): - pytest 9.2.0 on `tests/test_spirv_interface.py`: **48 passed, 108 subtests passed** at this head. - The same file on `main`: **23 failed**, 46 passed, 87 subtests — the new array-length, initializer-ID, struct/member-decoration and stage-decoration checks are not there. - Not run: anything beyond the synthetic SPIR-V modules; no corpus. AI-assisted; synthetic fixtures only, no game data.
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/1542/head:github-bot/gh-1542'
git switch 'github-bot/gh-1542'

Merge

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