shader: lower float loads and stores in the SPIR-V address window #1340

Merged
tedin7 merged 1 commit from upstream-pr/1347 into main 2026-11-24 09:07:21 +00:00
tedin7 commented 2026-11-24 08:50:51 +00:00 (Migrated from github.com)

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


What

The SPIR-V address-window adapter now lowers 32-bit float accesses through a physical pointer: OpConvertUToPtr %_ptr_PSB_float, OpAccessChain into a %rt_float array (%_ptr_PSB_arrf, stride 4), and a plain OpLoad %float or OpStore of a float (no memory operand or Aligned 4). It copies the signed-integer pattern: each access runs in a branch taken only for an aligned, in-window address whose index addition does not wrap. A load is an OpBitcast %float of the loaded heap word, and a store is an OpBitcast %uint of the value. Outside the branch a load yields bit pattern zero (0.0) and a store changes nothing. A bit-cast keeps every bit, including a NaN payload and the sign of a zero.

Every existing form and error message is unchanged. Still refused: atomics, Volatile, another alignment, half and double pointers, a multi-index access chain, a float access through an unsigned pointer (all with the existing messages). The lowered output for every existing fixture is byte-identical to origin/main.

Also added: tests/spirv_window/address_float.{spvasm,py}, a --spirv-address-window-float readback in readback.cpp and offscreen_check.cpp, the CMake entry next to the other address-window tests, and a paragraph in docs/experiments.md.

Why

Float loads and stores are the next scalar form after unsigned, signed and 64-bit integers, and a module that touches float data through a physical address could not be lowered at all.

Tested with

Windows (not run by the author):

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

The same name with _hardware runs on a real adapter. It does the D3D12 readback of 11 cases against a CPU model, then 7 mutations that must each diverge at a predicted case and word.

Linux (run by the author, Debian spirv-tools and spirv-cross):

  • python3 -B tests/spirv_window/address_float.py spirv-as spirv-val spirv-cross: validation of source, lowered and mutated modules, shape checks, HLSL check, 11 rejection cases, a mixed unsigned and float module, and a Python model whose predicted first-divergence word for each of the 7 mutations is checked.
  • The same script with a wrapper in place of spirv-cross, as a smoke check of the argument style only.
  • tests/spirv_window/check.py and address_signed.py, tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check.
  • The float CPU model from readback.cpp was compiled on its own and agrees word for word with the Python model on all 11 cases.

Not run: DXC, WARP, hardware, or the Windows build, so readback.cpp and offscreen_check.cpp were not compiled in the real build. Whether a compiled shader keeps a NaN payload on a given GPU is measured only by the readback. SPIRV-Cross 2021.01.15 (the Ubuntu CI version) was not available locally; the HLSL check only counts asuint( and .Store( and looks for asfloat(, which both spellings should satisfy.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6578063711 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1347). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:50:51Z. --- ## What The SPIR-V address-window adapter now lowers 32-bit float accesses through a physical pointer: `OpConvertUToPtr %_ptr_PSB_float`, `OpAccessChain` into a `%rt_float` array (`%_ptr_PSB_arrf`, stride 4), and a plain `OpLoad %float` or `OpStore` of a float (no memory operand or `Aligned 4`). It copies the signed-integer pattern: each access runs in a branch taken only for an aligned, in-window address whose index addition does not wrap. A load is an `OpBitcast %float` of the loaded heap word, and a store is an `OpBitcast %uint` of the value. Outside the branch a load yields bit pattern zero (0.0) and a store changes nothing. A bit-cast keeps every bit, including a NaN payload and the sign of a zero. Every existing form and error message is unchanged. Still refused: atomics, `Volatile`, another alignment, half and double pointers, a multi-index access chain, a float access through an unsigned pointer (all with the existing messages). The lowered output for every existing fixture is byte-identical to origin/main. Also added: `tests/spirv_window/address_float.{spvasm,py}`, a `--spirv-address-window-float` readback in `readback.cpp` and `offscreen_check.cpp`, the CMake entry next to the other address-window tests, and a paragraph in `docs/experiments.md`. ## Why Float loads and stores are the next scalar form after unsigned, signed and 64-bit integers, and a module that touches float data through a physical address could not be lowered at all. ## Tested with Windows (not run by the author): ctest --preset pr --no-tests=error -R spirv_address_window_float_warp -V The same name with `_hardware` runs on a real adapter. It does the D3D12 readback of 11 cases against a CPU model, then 7 mutations that must each diverge at a predicted case and word. Linux (run by the author, Debian spirv-tools and spirv-cross): - `python3 -B tests/spirv_window/address_float.py spirv-as spirv-val spirv-cross`: validation of source, lowered and mutated modules, shape checks, HLSL check, 11 rejection cases, a mixed unsigned and float module, and a Python model whose predicted first-divergence word for each of the 7 mutations is checked. - The same script with a wrapper in place of spirv-cross, as a smoke check of the argument style only. - `tests/spirv_window/check.py` and `address_signed.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`. - The float CPU model from `readback.cpp` was compiled on its own and agrees word for word with the Python model on all 11 cases. Not run: DXC, WARP, hardware, or the Windows build, so `readback.cpp` and `offscreen_check.cpp` were not compiled in the real build. Whether a compiled shader keeps a NaN payload on a given GPU is measured only by the readback. SPIRV-Cross 2021.01.15 (the Ubuntu CI version) was not available locally; the HLSL check only counts `asuint(` and `.Store(` and looks for `asfloat(`, which both spellings should satisfy.
tedin7 commented 2026-11-24 09:04:47 +00:00 (Migrated from github.com)

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


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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 5.13s (configure 1.54s)
    • Test (ctest --preset dev -R '^spirv_address_window_float_warp$' --no-tests=error --output-on-failure): 1/1 passed (1.39s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 3.84s (configure 1.58s)
    • Test (ctest --preset release -R '^spirv_address_window_float_warp$' --no-tests=error --output-on-failure): 1/1 passed (1.38s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126767962 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1347#issuecomment-7126767962). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:57:09Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `b27f4eed77c27f9c3b92d71b5c6ed867e50b8eaf`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `5.13s` (configure `1.54s`) - Test (`ctest --preset dev -R '^spirv_address_window_float_warp$' --no-tests=error --output-on-failure`): **1/1 passed** (`1.39s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `3.84s` (configure `1.58s`) - Test (`ctest --preset release -R '^spirv_address_window_float_warp$' --no-tests=error --output-on-failure`): **1/1 passed** (`1.38s`)
chatgpt-codex-connector[bot commented 2026-11-24 09:04:48 +00:00 (Migrated from github.com)

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


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-24T09:02:02.292970Z b27f4ee 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:7126772493 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1347#issuecomment-7126772493). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T08:57:22Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"b27f4eed77c27f9c3b92d71b5c6ed867e50b8eaf","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-24T09:02:02.292970Z">2026-11-24T09:02:02.292970Z</relative-time> | `b27f4ee` | 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 10:02:25 +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!1340
No description provided.