shader: lower DWORD atomics through the SPIR-V address window #1088

Manually merged
github merged 3 commits from gh-pr/1088/head into gh-pr/1088/base 2026-11-26 22:40:44 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:46 UTC · original
tedin7:x2w-spirv-address-window-physical-atomics → main · +218 −11 · 8 files · 3 commits · merged 2026-11-24 01:48 UTC

Change

Refs #218. Extend the bounded SPIR-V address-window bridge from #553 to accept eight unsigned DWORD atomics. Direct casts and indexed physical addresses use the existing window checks and storage buffer bindings. The lowering preserves each atomic instruction, including its result, scope, memory semantics and compare-exchange operand order.

Verification

Linux, Python 3.14.8 and SPIRV-Tools 2025.1. Tested commit 6dad87b0.

  • python3 -B tests/spirv_window/check.py passed. Both physical and logical modules assembled and passed spirv-val --target-env vulkan1.2. The test checked all eight atomic instructions, both pointer forms and rejection of OpAtomicISub.
  • With the new test and the adapter from ed983c1c (origin/main), the same command exited 1 at the first atomic with ValueError: unhandled physical word pointer use, after validation of the physical input.
  • python3 -B tests/spirv_window/sampler.py spirv-as spirv-val spirv-cross passed.
  • python3 -B tests/spirv_window/ballot.py spirv-as spirv-val spirv-cross passed.
  • python3 -B tests/spirv_window/compare_sampler.py spirv-as spirv-val spirv-cross passed.
  • python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py and git diff --check passed.

Evidence and follow-up

The MIT synthetic variant is generated from the existing source-built fixture in tests/spirv_window/check.py. The reproduction command and scope are recorded in docs/experiments.md. GPU execution and out-of-bounds atomic behavior require separate readback evidence.

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.

**@⁠tedin7** on GitHub · 2026-11-24 00:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088) `tedin7:x2w-spirv-address-window-physical-atomics` → `main` · +218 −11 · 8 files · 3 commits · merged 2026-11-24 01:48 UTC ## Change Refs #218. Extend the bounded SPIR-V address-window bridge from #553 to accept eight unsigned DWORD atomics. Direct casts and indexed physical addresses use the existing window checks and storage buffer bindings. The lowering preserves each atomic instruction, including its result, scope, memory semantics and compare-exchange operand order. ## Verification Linux, Python 3.14.8 and SPIRV-Tools 2025.1. Tested commit `6dad87b0`. - `python3 -B tests/spirv_window/check.py` passed. Both physical and logical modules assembled and passed `spirv-val --target-env vulkan1.2`. The test checked all eight atomic instructions, both pointer forms and rejection of `OpAtomicISub`. - With the new test and the adapter from `ed983c1c` (origin/main), the same command exited 1 at the first atomic with `ValueError: unhandled physical word pointer use`, after validation of the physical input. - `python3 -B tests/spirv_window/sampler.py spirv-as spirv-val spirv-cross` passed. - `python3 -B tests/spirv_window/ballot.py spirv-as spirv-val spirv-cross` passed. - `python3 -B tests/spirv_window/compare_sampler.py spirv-as spirv-val spirv-cross` passed. - `python3 -B tests/docs_links_check.py`, `python3 -B tests/bidi_controls_check.py` and `git diff --check` passed. ## Evidence and follow-up The MIT synthetic variant is generated from the existing source-built fixture in `tests/spirv_window/check.py`. The reproduction command and scope are recorded in `docs/experiments.md`. GPU execution and out-of-bounds atomic behavior require separate readback evidence. ## 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.
An atomic on a misaligned or out-of-window address used the substitute out-of-range index, whose effect SPIR-V validation does not define. Issue each atomic only inside a branch taken for a valid address, with a phi of the old value and zero as its result, and extend the Linux check to verify the branch structure around every one of the eight atomics.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:40:43 +00:00
github manually merged commit 423c2e0a36 into gh-pr/1088/base 2026-11-26 22:40:44 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 00:47 UTC · original · edited 2026-11-24 00:49 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T00:49:54.889672Z 6dad87b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 00:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118429396) · edited 2026-11-24 00:49 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6dad87b0ab5b197e4e600ecc77a3aef2aa3959b4","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T00:49:54.889672Z">2026-11-24T00:49:54.889672Z</relative-time> | `6dad87b` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 01:07 UTC · original

Added the source-built OpAtomicIAdd readback in 423c2e0a (AI-assisted). The valid case expects word 11 to contain the old value fedcba98 and word 3 to become fedcba9f. Each invalid case expects word 11 to contain zero and all other words to retain their initial contents.

For the negative control, the driver maps the lowering’s substitute index to the last bound DWORD (word 15) in this fixture. I assembled and validated the physical and logical modules with SPIRV-Tools and converted them with SPIRV-Cross on Linux. The pre-guard lowering (6dad87b0) emits an unconditional InterlockedAdd; the current lowering emits it inside the validity branch. On Windows, the pre-guard variant would fail first at word 11 for the misaligned case (expected 00000000, predicted cba98765), and it would change word 15 from cba98765 to cba9876c. The word 15 check would also catch a mutation that issues the atomic unconditionally but still masks its return value to zero.

python3 -B tests/spirv_window/check.py passed on Linux. Windows compilation and D3D12 readback on WARP and hardware were not run locally. Reproduce with ctest --preset dev --no-tests=error -R '^spirv_address_window_atomic_' -V after building.

**@⁠tedin7** on GitHub · 2026-11-24 01:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118785086) Added the source-built `OpAtomicIAdd` readback in `423c2e0a` (AI-assisted). The valid case expects word 11 to contain the old value `fedcba98` and word 3 to become `fedcba9f`. Each invalid case expects word 11 to contain zero and all other words to retain their initial contents. For the negative control, the driver maps the lowering’s substitute index to the last bound DWORD (word 15) in this fixture. I assembled and validated the physical and logical modules with SPIRV-Tools and converted them with SPIRV-Cross on Linux. The pre-guard lowering (`6dad87b0`) emits an unconditional `InterlockedAdd`; the current lowering emits it inside the validity branch. On Windows, the pre-guard variant would fail first at word 11 for the misaligned case (expected `00000000`, predicted `cba98765`), and it would change word 15 from `cba98765` to `cba9876c`. The word 15 check would also catch a mutation that issues the atomic unconditionally but still masks its return value to zero. `python3 -B tests/spirv_window/check.py` passed on Linux. Windows compilation and D3D12 readback on WARP and hardware were not run locally. Reproduce with `ctest --preset dev --no-tests=error -R '^spirv_address_window_atomic_' -V` after building.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 01:12 UTC · original

Addressed in fba92c8f and 423c2e0a.

  • Invalid addresses no longer issue an atomic: each of the eight atomics now sits in a branch taken only for an aligned, in-window address, and its result is a phi of the old value and zero. The substitute index of the plain loads and stores is never used for an atomic. The Linux check (tests/spirv_window/check.py) verifies the branch structure around every atomic and that operands, scope and semantics are unchanged.
  • New separate GPU readback (tests/spirv_window/atomic.spvasm, atomic.py, a new case in readback.cpp), kept apart from the earlier load/store observations: it checks the returned old value and the bound buffer for a valid address, and that misaligned, out-of-window and index-wrapped addresses change no bound word and return zero.
  • I could not run the Windows readback locally; the CI jobs on the new commit are the first run of it.

AI-assisted.

**@⁠tedin7** on GitHub · 2026-11-24 01:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118864992) Addressed in fba92c8f and 423c2e0a. - Invalid addresses no longer issue an atomic: each of the eight atomics now sits in a branch taken only for an aligned, in-window address, and its result is a phi of the old value and zero. The substitute index of the plain loads and stores is never used for an atomic. The Linux check (tests/spirv_window/check.py) verifies the branch structure around every atomic and that operands, scope and semantics are unchanged. - New separate GPU readback (tests/spirv_window/atomic.spvasm, atomic.py, a new case in readback.cpp), kept apart from the earlier load/store observations: it checks the returned old value and the bound buffer for a valid address, and that misaligned, out-of-window and index-wrapped addresses change no bound word and return zero. - I could not run the Windows readback locally; the CI jobs on the new commit are the first run of it. AI-assisted.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 01:01 UTC · original · requested changes

I confirmed that all eight operations assemble and validate with the pinned SPIR-V tools. The address rewrite currently substitutes an out-of-range sentinel index when a pointer is misaligned or outside the window. Passing spirv-val does not define the effect or returned old value of an atomic issued at that index. Please keep invalid addresses from issuing an atomic, or constrain this profile to addresses proven in range. Add a source-built check that verifies the valid atomic's old value and bound buffer, and that misaligned/out-of-range inputs cannot change any bound word. Keep this separate from earlier load/store observations.

**@⁠R0Y00** on GitHub · 2026-11-24 01:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088#pullrequestreview-6032024546) · **requested changes** I confirmed that all eight operations assemble and validate with the pinned SPIR-V tools. The address rewrite currently substitutes an out-of-range sentinel index when a pointer is misaligned or outside the window. Passing spirv-val does not define the effect or returned old value of an atomic issued at that index. Please keep invalid addresses from issuing an atomic, or constrain this profile to addresses proven in range. Add a source-built check that verifies the valid atomic's old value and bound buffer, and that misaligned/out-of-range inputs cannot change any bound word. Keep this separate from earlier load/store observations.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 01:47 UTC · original · approved these changes

On 423c2e0a, Windows Release passed both spirv_address_window_atomic checks on RTX 4060 Laptop and WARP. Valid, misaligned, out-of-window and wrapped-index cases matched all 16 words, with no debug-layer diagnostics. I separately forced the atomic branch to take invalid addresses, keeping the substitute word inside the UAV. WARP caught the misaligned old value at word 11 (expected 0, observed cba98765). This clears the earlier request. The GPU readback evidence is for atomic add, and the other seven forms have the structural validation recorded in the PR.

**@⁠R0Y00** on GitHub · 2026-11-24 01:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1088#pullrequestreview-6032405808) · **approved these changes** On 423c2e0a, Windows Release passed both spirv_address_window_atomic checks on RTX 4060 Laptop and WARP. Valid, misaligned, out-of-window and wrapped-index cases matched all 16 words, with no debug-layer diagnostics. I separately forced the atomic branch to take invalid addresses, keeping the substitute word inside the UAV. WARP caught the misaligned old value at word 11 (expected 0, observed cba98765). This clears the earlier request. The GPU readback evidence is for atomic add, and the other seven forms have the structural validation recorded in the PR.
This discussion has been locked. Commenting is limited to contributors.
No description provided.