shader: lower signed atomic add, bitwise and compare-exchange in address window #1323

Merged
tedin7 merged 1 commit from upstream-pr/1330 into main 2026-11-24 08:31:26 +00:00
tedin7 commented 2026-11-24 08:17:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:17:14Z.


Change

The SPIR-V address-window adapter now lowers signed (%int) OpAtomicIAdd, OpAtomicExchange, OpAtomicAnd, OpAtomicOr, OpAtomicXor and OpAtomicCompareExchange on %_ptr_PSB_int, which origin/main rejected ("unhandled physical word pointer use"). Each runs in the same guarded branch plus OpPhi shape as the unsigned atomics: operands are bit-cast, the atomic runs on the unsigned word with its scope and semantics, the result is cast back to %int, and a misaligned, out-of-window or wrapping address issues nothing and yields zero. No substitute index is used. OpAtomicUMin/OpAtomicUMax on a signed pointer stay rejected. Builds on the signed access work already merged.

Files: tools/spirv_address_window.py, tests/spirv_window/address_signed.{py,spvasm}, tests/spirv_window/readback.cpp (the fixture's own readback and CPU model), docs/experiments.md.

Verification

Linux, spirv-as/val/cross from the distro:

  • python3 -B tests/spirv_window/address_signed.py spirv-as spirv-val spirv-cross: passes (validates, guards, per-step operation and operand wiring, HLSL has one each of InterlockedAdd/Exchange/And/Or/Xor and four compare-exchanges, 5 rejections, 13 mutations caught by the shape check).
  • python3 -B tests/spirv_window/check.py: passes (unchanged).
  • Negative control: the new address_signed.py against origin/main's tools/ fails with ValueError: unhandled physical word pointer use.
  • The readback CPU model was compiled standalone and compared with a second, separate model for all 12 cases: identical.

GPU: not run (no D3D12 adapter on the Linux author machine). ctest -R '^spirv_address_window_signed_' needs a WARP/hardware run; it covers 12 cases of 16 DWORDs and 13 mutations, each of which must first diverge at a named case and word (values predicted with a separate model, not yet confirmed on an adapter). Part of the existing --preset pr test spirv_address_window_signed_warp.

Evidence and follow-up

The fixture is a synthetic source-built module. The sequence runs on one signed word so each old value feeds the next, with a compare-exchange that misses on the sign bit alone and one that hits. Invalid addresses leave every target and output word unchanged. The diff touches 5 files because the readback harness is the fixture's own.

AI-assisted.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6577550837 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1330). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:17:14Z. --- ## Change The SPIR-V address-window adapter now lowers signed (`%int`) `OpAtomicIAdd`, `OpAtomicExchange`, `OpAtomicAnd`, `OpAtomicOr`, `OpAtomicXor` and `OpAtomicCompareExchange` on `%_ptr_PSB_int`, which origin/main rejected ("unhandled physical word pointer use"). Each runs in the same guarded branch plus `OpPhi` shape as the unsigned atomics: operands are bit-cast, the atomic runs on the unsigned word with its scope and semantics, the result is cast back to `%int`, and a misaligned, out-of-window or wrapping address issues nothing and yields zero. No substitute index is used. `OpAtomicUMin`/`OpAtomicUMax` on a signed pointer stay rejected. Builds on the signed access work already merged. Files: tools/spirv_address_window.py, tests/spirv_window/address_signed.{py,spvasm}, tests/spirv_window/readback.cpp (the fixture's own readback and CPU model), docs/experiments.md. ## Verification Linux, spirv-as/val/cross from the distro: - `python3 -B tests/spirv_window/address_signed.py spirv-as spirv-val spirv-cross`: passes (validates, guards, per-step operation and operand wiring, HLSL has one each of InterlockedAdd/Exchange/And/Or/Xor and four compare-exchanges, 5 rejections, 13 mutations caught by the shape check). - `python3 -B tests/spirv_window/check.py`: passes (unchanged). - Negative control: the new address_signed.py against origin/main's tools/ fails with `ValueError: unhandled physical word pointer use`. - The readback CPU model was compiled standalone and compared with a second, separate model for all 12 cases: identical. GPU: not run (no D3D12 adapter on the Linux author machine). `ctest -R '^spirv_address_window_signed_'` needs a WARP/hardware run; it covers 12 cases of 16 DWORDs and 13 mutations, each of which must first diverge at a named case and word (values predicted with a separate model, not yet confirmed on an adapter). Part of the existing `--preset pr` test `spirv_address_window_signed_warp`. ## Evidence and follow-up The fixture is a synthetic source-built module. The sequence runs on one signed word so each old value feeds the next, with a compare-exchange that misses on the sign bit alone and one that hits. Invalid addresses leave every target and output word unchanged. The diff touches 5 files because the readback harness is the fixture's own. AI-assisted. ## 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.
upstream-sync closed this pull request 2026-11-24 09:04:33 +00:00
tedin7 commented 2026-11-24 09:04:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:23:17Z.


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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 4.81s (configure 1.62s)
    • Test (ctest --preset dev -R '^spirv_address_window_warp$' --no-tests=error --output-on-failure): 1/1 passed (0.41s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 2.51s (configure 1.60s)
    • Test (ctest --preset release -R '^spirv_address_window_warp$' --no-tests=error --output-on-failure): 1/1 passed (0.35s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126072826 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1330#issuecomment-7126072826). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:23:17Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `60ddf53943dada424dde801e679bd58f864cf021`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `4.81s` (configure `1.62s`) - Test (`ctest --preset dev -R '^spirv_address_window_warp$' --no-tests=error --output-on-failure`): **1/1 passed** (`0.41s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `2.51s` (configure `1.60s`) - Test (`ctest --preset release -R '^spirv_address_window_warp$' --no-tests=error --output-on-failure`): **1/1 passed** (`0.35s`)
chatgpt-codex-connector[bot commented 2026-11-24 09:04:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T08:23:27Z.


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-24T08:28:18.565132Z 60ddf53 Draft marked ready
ℹ️ 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:7126075915 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1330#issuecomment-7126075915). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T08:23:27Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"60ddf53943dada424dde801e679bd58f864cf021","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-24T08:28:18.565132Z">2026-11-24T08:28:18.565132Z</relative-time> | `60ddf53` | Draft marked ready | <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>
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!1323
No description provided.