shader: validate spirv_ballot_extract inputs/structure and add unit suite #2684

Merged
Ammmae0x merged 2 commits from upstream-pr/2692 into main 2026-11-26 03:10:08 +00:00
Ammmae0x commented 2026-11-26 02:10:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-26T02:10:55Z.


Change

Add input and structural validation guards to tools/spirv_ballot_extract.py and add a pure-Python unit and mutation test suite (tests/spirv_ballot_extract_check.py) registered in CMakeLists.txt as shader_spirv_ballot_extract_check (TIMEOUT 60).

  • Validate isinstance(assembly, str) upfront in lower_ballot_extract() with TypeError("assembly must be a str").
  • When OpGroupNonUniformBallotBitExtract or OpGroupNonUniformBallotFindLSB lowering runs, raise ValueError if no OpFunction declaration was found to anchor injected constants, and raise ValueError if GLSL.std.450 import injection was required (import_needed) without an OpMemoryModel instruction.
  • Preserve all existing pass-through and SPIR-V lowering output unchanged.

Verification

  • Commit: ab7a14b8 (based on upstream/main f02ebd66)
  • out\pe-env\Scripts\python.exe -B tests\spirv_ballot_extract_check.py -> Ran 7 tests in 0.041s / OK (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\spirv_address_window_check.py -> spirv_address_window: unit lowering, composed passes, and CLI error handling passed (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py -> form coverage checks passed (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 515 links. (exit 0)
  • out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py -> Self-test passed. Checked 1910 tracked source, script and build/CI files: no bidirectional controls. (exit 0)
  • Spot-mutation gate: 3/3 mutations killed (non-str type check, missing OpFunction check, missing OpMemoryModel check).
  • Negative controls: non-str inputs (None, bytes, int, list), reserved %x2w_ballot_ ID collision, non-Subgroup scope constants, missing OpFunction on extract and find-LSB modules, missing OpMemoryModel when GLSL.std.450 import injection is needed, and 5 in-suite temp-file mutation controls.

Evidence and follow-up

All fixtures in tests/spirv_ballot_extract_check.py are synthetic SPIR-V assembly snippets and the existing synthetic tests/spirv_window/ballot.spvasm under the repository MIT license; no external binaries or game files are used.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6617964814 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2692). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-26T02:10:55Z. --- ## Change Add input and structural validation guards to `tools/spirv_ballot_extract.py` and add a pure-Python unit and mutation test suite (`tests/spirv_ballot_extract_check.py`) registered in `CMakeLists.txt` as `shader_spirv_ballot_extract_check` (`TIMEOUT 60`). - Validate `isinstance(assembly, str)` upfront in `lower_ballot_extract()` with `TypeError("assembly must be a str")`. - When `OpGroupNonUniformBallotBitExtract` or `OpGroupNonUniformBallotFindLSB` lowering runs, raise `ValueError` if no `OpFunction` declaration was found to anchor injected constants, and raise `ValueError` if `GLSL.std.450` import injection was required (`import_needed`) without an `OpMemoryModel` instruction. - Preserve all existing pass-through and SPIR-V lowering output unchanged. ## Verification - Commit: `ab7a14b8` (based on `upstream/main` `f02ebd66`) - `out\pe-env\Scripts\python.exe -B tests\spirv_ballot_extract_check.py` -> `Ran 7 tests in 0.041s / OK` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\spirv_address_window_check.py` -> `spirv_address_window: unit lowering, composed passes, and CLI error handling passed` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 515 links.` (exit 0) - `out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py` -> `Self-test passed. Checked 1910 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) - Spot-mutation gate: 3/3 mutations killed (non-`str` type check, missing `OpFunction` check, missing `OpMemoryModel` check). - Negative controls: non-`str` inputs (`None`, `bytes`, `int`, `list`), reserved `%x2w_ballot_` ID collision, non-Subgroup scope constants, missing `OpFunction` on extract and find-LSB modules, missing `OpMemoryModel` when `GLSL.std.450` import injection is needed, and 5 in-suite temp-file mutation controls. ## Evidence and follow-up All fixtures in `tests/spirv_ballot_extract_check.py` are synthetic SPIR-V assembly snippets and the existing synthetic `tests/spirv_window/ballot.spvasm` under the repository MIT license; no external binaries or game files are used. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
tedin7 commented 2026-11-26 03:03:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:47:56Z.


Review at head 6ca82a76 (after update with main). Verdict: sound, no blocking findings.

  • The three guards in tools/spirv_ballot_extract.py turn silently invalid output (no OpFunction to anchor constants, no OpMemoryModel for the GLSL import) into a clear error. Pass-through output is unchanged.
  • The new suite covers pass-through, extract, find-lsb with and without an existing import, combined, and negative controls.
  • Not a startup claim; it only touches a pure-Python tool, its test, and one CTest registration.

Commands executed (Linux):

  • python3 -I -B tests/spirv_ballot_extract_check.py OK
  • python3 -I -B tests/spirv_address_window_check.py OK
  • python3 -I -B tests/docs_links_check.py and tests/bidi_controls_check.py OK
  • git diff --check origin/main...HEAD clean
  • Mutations (each guard replaced with if False:): non-str check, missing-OpFunction check, missing-OpMemoryModel check. Each made the suite fail; restored afterwards.

Windows receipt follows from the pipeline run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181128600 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2692#issuecomment-7181128600). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:47:56Z. --- Review at head `6ca82a76` (after update with main). Verdict: sound, no blocking findings. - The three guards in `tools/spirv_ballot_extract.py` turn silently invalid output (no `OpFunction` to anchor constants, no `OpMemoryModel` for the GLSL import) into a clear error. Pass-through output is unchanged. - The new suite covers pass-through, extract, find-lsb with and without an existing import, combined, and negative controls. - Not a startup claim; it only touches a pure-Python tool, its test, and one CTest registration. Commands executed (Linux): - `python3 -I -B tests/spirv_ballot_extract_check.py` OK - `python3 -I -B tests/spirv_address_window_check.py` OK - `python3 -I -B tests/docs_links_check.py` and `tests/bidi_controls_check.py` OK - `git diff --check origin/main...HEAD` clean - Mutations (each guard replaced with `if False:`): non-str check, missing-OpFunction check, missing-OpMemoryModel check. Each made the suite fail; restored afterwards. Windows receipt follows from the pipeline run. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 04:04:22 +00:00
tedin7 commented 2026-11-26 04:04:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:09:51Z.

Review: COMMENTED


Review at head 6ca82a76 (after update with main). Verdict: sound, no blocking findings.

  • The three guards in tools/spirv_ballot_extract.py turn silently invalid output (no OpFunction to anchor constants, no OpMemoryModel for the GLSL import) into a clear error. Pass-through output is unchanged.
  • The new suite covers pass-through, extract, find-lsb with and without an existing import, combined, and negative controls.
  • Not a startup claim; it only touches a pure-Python tool, its test, and one CTest registration.

Commands executed (Linux):

  • python3 -I -B tests/spirv_ballot_extract_check.py OK
  • python3 -I -B tests/spirv_address_window_check.py OK
  • python3 -I -B tests/docs_links_check.py and tests/bidi_controls_check.py OK
  • git diff --check origin/main...HEAD clean
  • Mutations (each guard replaced with if False:): non-str check, missing-OpFunction check, missing-OpMemoryModel check. Each made the suite fail; restored afterwards.

Windows receipt follows from the pipeline run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068031554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2692#pullrequestreview-6068031554). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:09:51Z. **Review:** COMMENTED --- Review at head `6ca82a76` (after update with main). Verdict: sound, no blocking findings. - The three guards in `tools/spirv_ballot_extract.py` turn silently invalid output (no `OpFunction` to anchor constants, no `OpMemoryModel` for the GLSL import) into a clear error. Pass-through output is unchanged. - The new suite covers pass-through, extract, find-lsb with and without an existing import, combined, and negative controls. - Not a startup claim; it only touches a pure-Python tool, its test, and one CTest registration. Commands executed (Linux): - `python3 -I -B tests/spirv_ballot_extract_check.py` OK - `python3 -I -B tests/spirv_address_window_check.py` OK - `python3 -I -B tests/docs_links_check.py` and `tests/bidi_controls_check.py` OK - `git diff --check origin/main...HEAD` clean - Mutations (each guard replaced with `if False:`): non-str check, missing-OpFunction check, missing-OpMemoryModel check. Each made the suite fail; restored afterwards. Windows receipt follows from the pipeline run. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:09:47Z.


Win2025 WARP receipt for head 6ca82a76 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 6ca82a7618a493aebedc46ce78cbbc6fba9cef38:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 373.71s (configure 4.88s)
    • Test (ctest --preset dev -R 'spirv_ballot_extract|spirv_address_window|shader_spirv' --parallel 2 --no-tests=error --output-on-failure): 2/16 passed (1.42s: spirv_address_window_atomic_hardware 0.09s, spirv_address_window_hardware 0.11s, spirv_address_window_float_hardware 0.08s, spirv_address_window_signed_hardware 0.10s, spirv_address_window_vec4_hardware 0.10s, spirv_address_window_qword_hardware 0.11s, spirv_ballot_extract_hardware 0.11s, spirv_address_window_warp 0.11s, spirv_address_window_atomic_warp 0.08s, spirv_address_window_signed_warp 0.10s, spirv_address_window_float_warp 0.09s, spirv_address_window_vec4_warp 0.10s, spirv_address_window_qword_warp 0.09s, spirv_ballot_extract_warp 0.10s, shader_spirv_ballot_extract_check 0.32s, spirv_address_window_check 0.41s); skipped (capability, not a pass): spirv_address_window_atomic_hardware, spirv_address_window_hardware, spirv_address_window_float_hardware, spirv_address_window_signed_hardware, spirv_address_window_vec4_hardware, spirv_address_window_qword_hardware, spirv_ballot_extract_hardware, spirv_address_window_warp, spirv_address_window_atomic_warp, spirv_address_window_signed_warp, spirv_address_window_float_warp, spirv_address_window_vec4_warp, spirv_address_window_qword_warp, spirv_ballot_extract_warp
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 522.77s (configure 4.65s)
    • Test (ctest --preset release -R 'spirv_ballot_extract|spirv_address_window|shader_spirv' --parallel 2 --no-tests=error --output-on-failure): 2/16 passed (1.25s: spirv_address_window_hardware 0.09s, spirv_address_window_atomic_hardware 0.09s, spirv_address_window_signed_hardware 0.09s, spirv_address_window_float_hardware 0.09s, spirv_address_window_vec4_hardware 0.09s, spirv_address_window_qword_hardware 0.09s, spirv_ballot_extract_hardware 0.09s, spirv_address_window_warp 0.09s, spirv_address_window_atomic_warp 0.09s, spirv_address_window_signed_warp 0.09s, spirv_address_window_float_warp 0.10s, spirv_address_window_vec4_warp 0.10s, spirv_address_window_qword_warp 0.09s, spirv_ballot_extract_warp 0.10s, shader_spirv_ballot_extract_check 0.34s, spirv_address_window_check 0.39s); skipped (capability, not a pass): spirv_address_window_hardware, spirv_address_window_atomic_hardware, spirv_address_window_signed_hardware, spirv_address_window_float_hardware, spirv_address_window_vec4_hardware, spirv_address_window_qword_hardware, spirv_ballot_extract_hardware, spirv_address_window_warp, spirv_address_window_atomic_warp, spirv_address_window_signed_warp, spirv_address_window_float_warp, spirv_address_window_vec4_warp, spirv_address_window_qword_warp, spirv_ballot_extract_warp
  • sccache: 2473/2870 hits; wall 920.3s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181451695 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2692#issuecomment-7181451695). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:09:47Z. --- Win2025 WARP receipt for head 6ca82a76 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `6ca82a7618a493aebedc46ce78cbbc6fba9cef38`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `373.71s` (configure `4.88s`) - Test (`ctest --preset dev -R 'spirv_ballot_extract|spirv_address_window|shader_spirv' --parallel 2 --no-tests=error --output-on-failure`): **2/16 passed** (`1.42s`: `spirv_address_window_atomic_hardware` `0.09s`, `spirv_address_window_hardware` `0.11s`, `spirv_address_window_float_hardware` `0.08s`, `spirv_address_window_signed_hardware` `0.10s`, `spirv_address_window_vec4_hardware` `0.10s`, `spirv_address_window_qword_hardware` `0.11s`, `spirv_ballot_extract_hardware` `0.11s`, `spirv_address_window_warp` `0.11s`, `spirv_address_window_atomic_warp` `0.08s`, `spirv_address_window_signed_warp` `0.10s`, `spirv_address_window_float_warp` `0.09s`, `spirv_address_window_vec4_warp` `0.10s`, `spirv_address_window_qword_warp` `0.09s`, `spirv_ballot_extract_warp` `0.10s`, `shader_spirv_ballot_extract_check` `0.32s`, `spirv_address_window_check` `0.41s`); skipped (capability, not a pass): `spirv_address_window_atomic_hardware`, `spirv_address_window_hardware`, `spirv_address_window_float_hardware`, `spirv_address_window_signed_hardware`, `spirv_address_window_vec4_hardware`, `spirv_address_window_qword_hardware`, `spirv_ballot_extract_hardware`, `spirv_address_window_warp`, `spirv_address_window_atomic_warp`, `spirv_address_window_signed_warp`, `spirv_address_window_float_warp`, `spirv_address_window_vec4_warp`, `spirv_address_window_qword_warp`, `spirv_ballot_extract_warp` - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `522.77s` (configure `4.65s`) - Test (`ctest --preset release -R 'spirv_ballot_extract|spirv_address_window|shader_spirv' --parallel 2 --no-tests=error --output-on-failure`): **2/16 passed** (`1.25s`: `spirv_address_window_hardware` `0.09s`, `spirv_address_window_atomic_hardware` `0.09s`, `spirv_address_window_signed_hardware` `0.09s`, `spirv_address_window_float_hardware` `0.09s`, `spirv_address_window_vec4_hardware` `0.09s`, `spirv_address_window_qword_hardware` `0.09s`, `spirv_ballot_extract_hardware` `0.09s`, `spirv_address_window_warp` `0.09s`, `spirv_address_window_atomic_warp` `0.09s`, `spirv_address_window_signed_warp` `0.09s`, `spirv_address_window_float_warp` `0.10s`, `spirv_address_window_vec4_warp` `0.10s`, `spirv_address_window_qword_warp` `0.09s`, `spirv_ballot_extract_warp` `0.10s`, `shader_spirv_ballot_extract_check` `0.34s`, `spirv_address_window_check` `0.39s`); skipped (capability, not a pass): `spirv_address_window_hardware`, `spirv_address_window_atomic_hardware`, `spirv_address_window_signed_hardware`, `spirv_address_window_float_hardware`, `spirv_address_window_vec4_hardware`, `spirv_address_window_qword_hardware`, `spirv_ballot_extract_hardware`, `spirv_address_window_warp`, `spirv_address_window_atomic_warp`, `spirv_address_window_signed_warp`, `spirv_address_window_float_warp`, `spirv_address_window_vec4_warp`, `spirv_address_window_qword_warp`, `spirv_ballot_extract_warp` - `sccache`: 2473/2870 hits; wall `920.3s` AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2684
No description provided.