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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1542 into main 2026-11-28 10:44:20 +00:00
IlyassRS3 commented 2026-11-25 03:57:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T03:57:46Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484899174 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1542). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T03:57:46Z. --- ## 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)
copilot-pull-request-reviewer[bot] commented 2026-11-25 03:58:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T03:58:00Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051653198 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1542#pullrequestreview-6051653198). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T03:58:00Z. **Review:** COMMENTED --- 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.
GeorgiyDemo commented 2026-11-25 04:20:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T04:20:06Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152748227 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1542#issuecomment-7152748227). Originally posted by [GeorgiyDemo](https://github.com/GeorgiyDemo) on 2026-11-25T04:20:06Z. --- 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.
MoonEyes commented 2026-11-28 10:44:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:44:17Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238089556 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1542#issuecomment-7238089556). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:44:17Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1542
No description provided.