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

Closed
leonida/mandy
quietfold wants to merge 0 commits from fix/rgba4-fragment-validation-and-tests into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 08:36:24 +00:00

Item ID: RGBA4-FRAGMENT-VALIDATION-AND-TESTS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157180890

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)

Item ID: `RGBA4-FRAGMENT-VALIDATION-AND-TESTS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157180890 ## 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)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 08:36:39 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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.
MoonEyes commented 2026-11-28 02:50:52 +00:00

Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @IlyassRS3, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:37:00 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.