shader: lower vec4 float loads and stores in the address window #1371

Merged
tedin7 merged 1 commit from upstream-pr/1378 into main 2026-11-24 10:33:39 +00:00
tedin7 commented 2026-11-24 09:53:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:53:31Z.


What

The SPIR-V address-window adapter now lowers four-float (%v4float) physical accesses: OpConvertUToPtr %_ptr_PSB_v4float, OpAccessChain into a %rt_v4float array (%_ptr_PSB_arrv4f, ArrayStride 16), and OpLoad / OpStore with Aligned 16.

  • Each access becomes four DWORD accesses on the logical heap, lane 0 first, inside one branch. A load is four word loads, four OpBitcast %float and one OpCompositeConstruct. A store is four OpCompositeExtract, four OpBitcast %uint and four word stores.
  • The branch is taken only for an address that is a multiple of 16 with all 16 bytes below the window end 0xfffffffc (the guard compares against 0xfffffff0), and, for an indexed address, a base plus index that does not wrap. The last valid vector starts at 0xffffffe0; one at 0xfffffff0 straddles the end and is refused whole.
  • Outside the branch a load yields the zero vector (every lane the bit pattern zero) and a store changes nothing, not even one lane.
  • Existing forms and messages are unchanged. %v2float, %v3float, %v4uint and %v4int pointers are still refused with unhandled physical pointer operation; they are not part of this PR.
  • New fixture tests/spirv_window/address_vec4.{spvasm,py}, a CPU model and two modes in readback.cpp / offscreen_check.cpp, and the bridge entry address_window_vec4:address_vec4.

Why

The scalar float form was the template. A vector load or store is the next common shape, and a guard that checked only the first word would let a vector that crosses the window end move partly. The fixture and negative controls pin the all-or-nothing rule.

Tested

Windows (needs the SPIR-V tools; DXC and WARP):

ctest --preset pr --no-tests=error -R spirv_address_window_vec4_warp -V

(spirv_address_window_vec4_hardware is the same test on a physical GPU.) It runs 18 production cases and 5 cases in a second build whose window ends at byte 44, then seven negative controls, each of which must first diverge at its predicted case and word.

Run on Linux (SPIRV-Tools and Debian spirv-cross, no DXC or WARP):

  • python3 -B tests/spirv_window/address_vec4.py spirv-as spirv-val spirv-cross: model, guard-versus-edge-model at every DWORD address near the window end, shape, HLSL (twelve DWORD stores, no Interlocked), 15 rejections, a mixed uint, float and vec4 module, 7 shape-caught mutations that still validate. Also run with the old-release wrapper (it only simulates the missing gather-compare form).
  • address_float.py, address_signed.py and check.py with the same tools: pass. The lowered output of every other SPIR-V fixture in the repository, and every module the three tests above lower, is identical before and after the change; only the new fixture changes (before: unhandled physical pointer operation).
  • The CPU model of readback.cpp compiled on its own with g++ agrees with the Python model word for word on all 23 cases. readback.cpp also passes x86_64-w64-mingw32-g++ -fsyntax-only. offscreen_check.cpp could not be syntax-checked on Linux (it needs generated headers); its edits mirror the existing qword entries.
  • The lowered module, run by a throwaway interpreter outside the repository, matched the model on all 23 cases and on each of the 7 mutations, with the predicted first differences.
  • docs_links_check.py, bidi_controls_check.py, py_compile, git diff --check.

Not run: DXC, WARP, any GPU.

Open doubts

  • A GPU may canonicalise a NaN when it moves a float through a register. The fixture uses quiet NaNs (payload and negative) and avoids signalling NaNs and denormals; whether the payload survives is measured only by the readback.
  • The heap buffer is read with raw DWORD accesses. The 16-byte rule is applied to the logical address, so a runtime must also place the heap at a 16-byte aligned allocation for a vector to match its source.
  • The production window cannot show the end-of-window cases (the 64-byte view ends far below it); the narrow build covers them.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579129909 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1378). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:53:31Z. --- ## What The SPIR-V address-window adapter now lowers four-float (`%v4float`) physical accesses: `OpConvertUToPtr %_ptr_PSB_v4float`, `OpAccessChain` into a `%rt_v4float` array (`%_ptr_PSB_arrv4f`, `ArrayStride 16`), and `OpLoad` / `OpStore` with `Aligned 16`. - Each access becomes four DWORD accesses on the logical heap, lane 0 first, inside one branch. A load is four word loads, four `OpBitcast %float` and one `OpCompositeConstruct`. A store is four `OpCompositeExtract`, four `OpBitcast %uint` and four word stores. - The branch is taken only for an address that is a multiple of 16 with all 16 bytes below the window end `0xfffffffc` (the guard compares against `0xfffffff0`), and, for an indexed address, a base plus index that does not wrap. The last valid vector starts at `0xffffffe0`; one at `0xfffffff0` straddles the end and is refused whole. - Outside the branch a load yields the zero vector (every lane the bit pattern zero) and a store changes nothing, not even one lane. - Existing forms and messages are unchanged. `%v2float`, `%v3float`, `%v4uint` and `%v4int` pointers are still refused with `unhandled physical pointer operation`; they are not part of this PR. - New fixture `tests/spirv_window/address_vec4.{spvasm,py}`, a CPU model and two modes in `readback.cpp` / `offscreen_check.cpp`, and the bridge entry `address_window_vec4:address_vec4`. ## Why The scalar float form was the template. A vector load or store is the next common shape, and a guard that checked only the first word would let a vector that crosses the window end move partly. The fixture and negative controls pin the all-or-nothing rule. ## Tested Windows (needs the SPIR-V tools; DXC and WARP): ```powershell ctest --preset pr --no-tests=error -R spirv_address_window_vec4_warp -V ``` (`spirv_address_window_vec4_hardware` is the same test on a physical GPU.) It runs 18 production cases and 5 cases in a second build whose window ends at byte 44, then seven negative controls, each of which must first diverge at its predicted case and word. Run on Linux (SPIRV-Tools and Debian spirv-cross, no DXC or WARP): - `python3 -B tests/spirv_window/address_vec4.py spirv-as spirv-val spirv-cross`: model, guard-versus-edge-model at every DWORD address near the window end, shape, HLSL (twelve DWORD stores, no `Interlocked`), 15 rejections, a mixed uint, float and vec4 module, 7 shape-caught mutations that still validate. Also run with the old-release wrapper (it only simulates the missing gather-compare form). - `address_float.py`, `address_signed.py` and `check.py` with the same tools: pass. The lowered output of every other SPIR-V fixture in the repository, and every module the three tests above lower, is identical before and after the change; only the new fixture changes (before: `unhandled physical pointer operation`). - The CPU model of `readback.cpp` compiled on its own with g++ agrees with the Python model word for word on all 23 cases. `readback.cpp` also passes `x86_64-w64-mingw32-g++ -fsyntax-only`. `offscreen_check.cpp` could not be syntax-checked on Linux (it needs generated headers); its edits mirror the existing qword entries. - The lowered module, run by a throwaway interpreter outside the repository, matched the model on all 23 cases and on each of the 7 mutations, with the predicted first differences. - `docs_links_check.py`, `bidi_controls_check.py`, `py_compile`, `git diff --check`. Not run: DXC, WARP, any GPU. ## Open doubts - A GPU may canonicalise a NaN when it moves a float through a register. The fixture uses quiet NaNs (payload and negative) and avoids signalling NaNs and denormals; whether the payload survives is measured only by the readback. - The heap buffer is read with raw DWORD accesses. The 16-byte rule is applied to the logical address, so a runtime must also place the heap at a 16-byte aligned allocation for a vector to match its source. - The production window cannot show the end-of-window cases (the 64-byte view ends far below it); the narrow build covers them.
tedin7 commented 2026-11-24 10:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:57:15Z.


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

  • Debug (--preset dev): offscreen_check build 23.96s; ctest --preset dev -R '^spirv_address_window_vec4_warp$' --no-tests=error --output-on-failure: 1/1 passed (1.62s)
  • Release /O2 (--preset release): offscreen_check build 35.67s; ctest --preset release -R '^spirv_address_window_vec4_warp$' --no-tests=error --output-on-failure: 1/1 passed (1.53s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128112861 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1378#issuecomment-7128112861). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:57:15Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `7ea035ce295a359bbee412241df65e5629ced6e9`: - **Debug (`--preset dev`)**: `offscreen_check` build `23.96s`; `ctest --preset dev -R '^spirv_address_window_vec4_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`1.62s`) - **Release `/O2` (`--preset release`)**: `offscreen_check` build `35.67s`; `ctest --preset release -R '^spirv_address_window_vec4_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`1.53s`)
chatgpt-codex-connector[bot commented 2026-11-24 10:02:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:57:28Z.


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-24T10:03:32.486833Z 7ea035c 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:7128117824 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1378#issuecomment-7128117824). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:57:28Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7ea035ce295a359bbee412241df65e5629ced6e9","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-24T10:03:32.486833Z">2026-11-24T10:03:32.486833Z</relative-time> | `7ea035c` | 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>
upstream-sync closed this pull request 2026-11-24 11:02:41 +00:00
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!1371
No description provided.