rgba4_fragment: harden SPIR-V output quantization and add portable unit test #1696

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

@⁠IlyassRS3 on GitHub · 2026-11-25 08:36 UTC · original
IlyassRS3:fix/rgba4-fragment-validation-and-tests → main · +439 −24 · 3 files · 1 commits · open

Item ID: RGBA4-FRAGMENT-VALIDATION-AND-TESTS
Claim: #1608

Summary

Hardens leonida::rgba4::quantize in runtime/src/rgba4_fragment.h and adds a portable CPU-only unit test (runtime/test/rgba4_fragment_test.cpp, registered in runtime/CMakeLists.txt):

  • Allow shaders with no masked outputs and no f32 type: resolve outputs against mask before checking !float_type, so depth-only / integer-output shaders with no outputs in mask return true instead of failing PSO creation with E_INVALIDARG.
  • Reject masked outputs with missing pointer types: if an Output variable matches mask but its OpTypePointer Output is absent, fail conservatively instead of silently skipping quantization.
  • Support OpGroupDecorate locations: propagate Location decorations applied via decoration groups (OpGroupDecorate, opcode 74) onto Output variables.
  • Require valid OpMemoryModel placement before emitting GLSL.std.450: ensure OpExtInstImport is inserted exactly once before OpMemoryModel (and before OpFunction) when needed; otherwise fail without mutating words instead of returning invalid SPIR-V with an undeclared import_id. Also tighten GLSL.std.450 import matching to exact 6-word length and non-zero result ID.
  • Track OpPtrAccessChain/OpInBoundsPtrAccessChain and reject untracked pointer escapes: reject OpCopyMemorySized, unknown result pointer types on access chains / OpCopyObject, and OpBitcast / OpSelect / OpPhi / OpFunctionCall involving a masked output pointer.
  • Guard SPIR-V ID bound (words[3]): reject zero bound and prevent 32-bit ID wraparound when allocating new IDs.

Verification

  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined runtime/test/rgba4_fragment_test.cpp -> exit 0, all checks pass, 0 warnings / 0 sanitizer errors.

  • Mutation check against unpatched main (git show main:runtime/src/rgba4_fragment.h with new test) -> exit 1 (15 failures reproducing every fix).

  • python3 -I scripts/check_no_game_data.py runtime/src/rgba4_fragment.h runtime/test/rgba4_fragment_test.cpp runtime/CMakeLists.txt -> OK.

  • python3 -m compileall -q make_game.py tools tests and python3 -I tests/test_text_write_line_endings.py -> OK (3/3).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only portable SPIR-V rewriter + synthetic unit tests; no game files)

**@⁠IlyassRS3** on GitHub · 2026-11-25 08:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1696) `IlyassRS3:fix/rgba4-fragment-validation-and-tests` → `main` · +439 −24 · 3 files · 1 commits · open Item ID: `RGBA4-FRAGMENT-VALIDATION-AND-TESTS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ## Summary Hardens `leonida::rgba4::quantize` in `runtime/src/rgba4_fragment.h` and adds a portable CPU-only unit test (`runtime/test/rgba4_fragment_test.cpp`, registered in `runtime/CMakeLists.txt`): - **Allow shaders with no masked outputs and no `f32` type**: resolve `outputs` against `mask` before checking `!float_type`, so depth-only / integer-output shaders with no outputs in `mask` return `true` instead of failing PSO creation with `E_INVALIDARG`. - **Reject masked outputs with missing pointer types**: if an `Output` variable matches `mask` but its `OpTypePointer Output` is absent, fail conservatively instead of silently skipping quantization. - **Support `OpGroupDecorate` locations**: propagate `Location` decorations applied via decoration groups (`OpGroupDecorate`, opcode 74) onto `Output` variables. - **Require valid `OpMemoryModel` placement before emitting `GLSL.std.450`**: ensure `OpExtInstImport` is inserted exactly once before `OpMemoryModel` (and before `OpFunction`) when needed; otherwise fail without mutating `words` instead of returning invalid SPIR-V with an undeclared `import_id`. Also tighten `GLSL.std.450` import matching to exact 6-word length and non-zero result ID. - **Track `OpPtrAccessChain`/`OpInBoundsPtrAccessChain` and reject untracked pointer escapes**: reject `OpCopyMemorySized`, unknown result pointer types on access chains / `OpCopyObject`, and `OpBitcast` / `OpSelect` / `OpPhi` / `OpFunctionCall` involving a masked output pointer. - **Guard SPIR-V ID bound (`words[3]`)**: reject zero bound and prevent 32-bit ID wraparound when allocating new IDs. ## Verification - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined runtime/test/rgba4_fragment_test.cpp` -> exit 0, all checks pass, 0 warnings / 0 sanitizer errors. - Mutation check against unpatched `main` (`git show main:runtime/src/rgba4_fragment.h` with new test) -> exit 1 (`15` failures reproducing every fix). - `python3 -I scripts/check_no_game_data.py runtime/src/rgba4_fragment.h runtime/test/rgba4_fragment_test.cpp runtime/CMakeLists.txt` -> OK. - `python3 -m compileall -q make_game.py tools tests` and `python3 -I tests/test_text_write_line_endings.py` -> OK (3/3). - AI-assisted: yes - GPUs tested: none (CPU-only portable SPIR-V rewriter + synthetic unit tests; no game files)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:13 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 08:36 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 08:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1696#pullrequestreview-6054239038) · **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.
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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