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

Merged
tedin7 merged 3 commits from upstream-pr/1088 into main 2026-11-24 01:48:00 +00:00
tedin7 commented 2026-11-24 00:46:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T00:46:54Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572009051 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:46:54Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:46:15 +00:00
R0Y00 commented 2026-11-24 06:46:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T01:01:54Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6032024546 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088#pullrequestreview-6032024546). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T01:01:54Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-24 06:46:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T01:47:46Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6032405808 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088#pullrequestreview-6032405808). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T01:47:46Z. **Review:** APPROVED --- 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.
chatgpt-codex-connector[bot commented 2026-11-24 06:49:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T00:47:05Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7118429396 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118429396). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T00:47:05Z. --- <!-- 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>
tedin7 commented 2026-11-24 06:50:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T01:07:50Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7118785086 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118785086). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:07:50Z. --- 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 commented 2026-11-24 06:50:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T01:12:18Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7118864992 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1088#issuecomment-7118864992). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:12:18Z. --- 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.
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!1081
No description provided.