shader: lower signed DWORD accesses and SMin/SMax atomics in the SPIR-V address window #1240
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1247"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:11:48Z.
Change
Extends the SPIR-V address-window adapter (
tools/spirv_address_window.py) to signed 32-bit physical accesses:OpConvertUToPtr %_ptr_PSB_int, indexed%rt_intarrays, plain loads and stores,OpAtomicSMinandOpAtomicSMax. Target: shader tooling only, no CPU targets.57e4efcemits the unsignedInterlockedMin/InterlockedMaxon a byte-address buffer, so a negative word would sort above a positive one.Verification
python3 -B tests/spirv_window/address_signed.py spirv-as spirv-val spirv-cross(Linux, SPIRV-Tools and SPIRV-Cross from the distro): lowered module validates for Vulkan 1.2, each access is guarded, the HLSL has two compare-exchange loops and noInterlockedMin/InterlockedMax, four unsupported forms are rejected, seven mutations fail the shape check. Passes.origin/main'stools/: fails withValueError: unhandled physical pointer operation.python3 -B tests/spirv_window/check.pystill passes (unchanged).spirv_address_window_signed_{hardware,warp}(inctest --preset prthroughspirv_.*_warp). 11 cases of 16 DWORDs against a separate CPU model, with negative words so signed and unsigned compares differ; misaligned, window-end, wrapping and out-of-view addresses; seven negative controls (SMin or SMax compared unsigned, direction reversed, atomic wrap guard, load alignment guard, store alignment guard dropped), each expected to first diverge at a named case and word. I could not run the D3D12 readback here (Linux, no dxc or D3D12). I checked that the C++ model matches an independent Python model for all 11 cases and derived the control words from that model. The Windows CI run is the first real GPU run.Evidence and follow-up
The fixture
address_signed.spvasmis hand-written for this repo; no external code or data. This PR is AI-assisted. The diff is larger than a minimal change because the readback model and the documentation had to ship together with the lowering.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:22:25Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
4daa4a814cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:16Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:18Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:19Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:31:42Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
b429d36565ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:32:41Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:32:42Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:21Z.
Fixed in
b429d365: compare-exchange failure semantics drop Release and map AcquireRelease to Acquire; a guarded access in a block with OpLoopMerge is rejected; result-derived and store stems use disjoint prefixes. Each has a case in address_signed.py. @codex reviewImported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:32:44Z.
Fixed in
e6f1a2cd: the compare-exchange loop starts from zero instead of a plain load, and the semantics scan covers only atomics on physical signed pointers (a workgroup signed atomic now passes through, with a case). @codex reviewImported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:39:38Z.
Codex Review: Didn't find any major issues. 🎉
Reviewed commit:
e6f1a2cd6cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:14:16Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
e6f1a2cℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:22:25Z.
Code review location:
tools/spirv_address_window.py; line 165For a signed atomic using
ReleaseorAcquireReleasesemantics, this copies the same semantics into both the success and failure operands ofOpAtomicCompareExchange. SPIR-V forbidsReleaseandAcquireReleasein the failure operand, so otherwise valid input—for example, semantics72(AcquireRelease | UniformMemory)—produces an invalid module that the CLI cannot publish. Derive the failure ordering separately, using relaxed ordering for release and acquire ordering for acquire-release while preserving the applicable memory-class bits.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:22:25Z.
Code review location:
tools/spirv_address_window.py; line 149When a signed load occurs in a loop header before its existing
OpLoopMerge, this inserted selection moves the originalOpLoopMergeinto the generated_mergeblock, but the loop's continue branch still targets the original header. The backedge consequently targets a block that no longer declares the loop, violating SPIR-V's structured-loop requirements and preventing translation of an otherwise valid loop condition. Rewriting successor phi parents does not repair this edge; the access split also needs to preserve the original loop-header structure.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:22:25Z.
Code review location:
tools/spirv_address_window.py; line 341A signed load or atomic result named
%store_1receives exactly the same stem as the first signed store. Renaming%loadedto%store_1throughoutaddress_signed.spvasmreproduces duplicate definitions of%x2w_signed_store_1_issue,%x2w_signed_store_1_ptr, and%x2w_signed_store_1_merge, making the generated module invalid. Such source identifiers are allowed by the input namespace check, which reserves only%x2w_. Use disjoint prefixes for result-derived accesses and numbered stores.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:16Z.
Code review location:
tools/spirv_address_window.py; line 165Fixed in
b429d365Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:18Z.
Code review location:
tools/spirv_address_window.py; line 149Fixed in
b429d365Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:24:19Z.
Code review location:
tools/spirv_address_window.py; line 341Fixed in
b429d365Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:31:42Z.
Code review location:
tools/spirv_address_window.py; line 170When multiple invocations perform signed atomics on the same DWORD, this seed
OpLoadcan overlap with another invocation's compare-exchange write. That introduces a non-atomic/atomic data race into otherwise race-free source operations, so the lowered SPIR-V no longer preserves defined behavior under contention. The later CAS does not make the earlier load atomic, and the single-invocation fixture cannot expose this. Use an atomic read with load-legal semantics, or initialize the expected value to a constant and let the first CAS obtain the actual word.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:31:42Z.
Code review location:
tools/spirv_address_window.py; line 287If the input also contains a workgroup
OpAtomicSMinorOpAtomicSMaxwith a legal semantics constant such as%relaxed = OpConstant %int 0, this unconditional scan raisessigned atomic semantics must be a constant, although that atomic is not being lowered. Adding such a workgroup atomic tosubtract.spvasmreproduces the regression: the parent accepts and preserves it, while this revision rejects it. Restrict this pre-pass to pointers inphysical_intsrather than imposing the physical-lowering constant format on unrelated atomics.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:32:41Z.
Code review location:
tools/spirv_address_window.py; line 170Fixed in
e6f1a2cdImported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:32:42Z.
Code review location:
tools/spirv_address_window.py; line 287Fixed in
e6f1a2cd