shader: lower bounded 64-bit word loads and stores through the SPIR-V address window #1150

Merged
tedin7 merged 4 commits from upstream-pr/1157 into main 2026-11-24 03:42:38 +00:00
tedin7 commented 2026-11-24 01:56:42 +00:00 (Migrated from github.com)

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


Bounded 64-bit loads and stores through the SPIR-V address window.

A plain 64-bit load or store through a physical pointer becomes two 32-bit accesses inside an explicit branch, taken only for an address that is 8-byte aligned, below 0xfffffff8, and does not wrap on an indexed address. Otherwise a load returns zero and a store changes nothing; the substitute index is never used (same approach as the atomics). Atomics, Volatile, other alignments and other uses of the pointer are rejected.

  • tests/spirv_window/check.py: shape of the lowering, 7 rejection cases and 6 mutations that must each be caught. Fails on main.
  • New GPU readback (qword.spvasm, qword.py, readback.cpp): the 16-word memory is compared with an independent C++ model over 11 cases, including misaligned, above-window, index-wrap and out-of-view ones, which must leave memory intact; six negative controls each fail at a predicted case and word. Not run locally (no Windows or dxc); the Windows jobs are its first run.
  • docs/experiments.md updated; the existing readback function now takes init/apply callables so the new cases reuse it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572846695 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1157). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:56:42Z. --- Bounded 64-bit loads and stores through the SPIR-V address window. A plain 64-bit load or store through a physical pointer becomes two 32-bit accesses inside an explicit branch, taken only for an address that is 8-byte aligned, below 0xfffffff8, and does not wrap on an indexed address. Otherwise a load returns zero and a store changes nothing; the substitute index is never used (same approach as the atomics). Atomics, Volatile, other alignments and other uses of the pointer are rejected. - tests/spirv_window/check.py: shape of the lowering, 7 rejection cases and 6 mutations that must each be caught. Fails on main. - New GPU readback (qword.spvasm, qword.py, readback.cpp): the 16-word memory is compared with an independent C++ model over 11 cases, including misaligned, above-window, index-wrap and out-of-view ones, which must leave memory intact; six negative controls each fail at a predicted case and word. Not run locally (no Windows or dxc); the Windows jobs are its first run. - docs/experiments.md updated; the existing readback function now takes init/apply callables so the new cases reuse it. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:46:35 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:46:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T02:39:46Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f8a40bbc9

ℹ️ 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".

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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6032867554 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1157#pullrequestreview-6032867554). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:39:46Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3f8a40bbc9` <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". 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". </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:50:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T02:35:04Z.


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-24T02:39:48.468194Z 3f8a40b 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:7120287848 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1157#issuecomment-7120287848). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:35:04Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3f8a40bbc918f0baa3aeff53954b66d052b87908","has_any_findings":true,"has_unresolved_findings":true,"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-24T02:39:48.468194Z">2026-11-24T02:39:48.468194Z</relative-time> | `3f8a40b` | 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>
tedin7 commented 2026-11-24 06:50:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T02:42:56Z.


AI-assisted update addressing the P2 finding: a QWORD access that splits a block now rewrites the parent label of OpPhis in successor blocks to the generated *_merge block. tests/spirv_window/check.py gains a module with a successor phi, validated with spirv-as and spirv-val before and after lowering. The check fails on the previous lowering (spirv-val: phi parent is not a predecessor) and passes now. docs/experiments.md notes the rewrite.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7120411160 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1157#issuecomment-7120411160). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T02:42:56Z. --- AI-assisted update addressing the P2 finding: a QWORD access that splits a block now rewrites the parent label of `OpPhi`s in successor blocks to the generated `*_merge` block. `tests/spirv_window/check.py` gains a module with a successor phi, validated with spirv-as and spirv-val before and after lowering. The check fails on the previous lowering (spirv-val: phi parent is not a predecessor) and passes now. `docs/experiments.md` notes the rewrite.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T02:39:46Z.

Code review location: tools/spirv_address_window.py; line 251

@@ -144,9 +223,34 @@ def lower(assembly):
             new, valid_of[dst] = word_pointer(dst, arrays[pointer], index)
             output.extend(new)
             continue
+        if wide := WIDE_ACCESS.fullmatch(line):
+            dst, pointer, index = wide.groups()
+            if pointer not in wide_arrays:
+                raise ValueError("unknown physical array pointer")
+            new, valid_of[dst] = word_pointer(dst, wide_arrays[pointer], index, True)
+            wide_words[dst] = address_name(dst) + "_word"
+            output.extend(new)
+            continue
         if opened := re.fullmatch(rf"({ID}) = OpLabel", line):
             label = opened[1]
-        used = set(re.findall(ID, line)) & physical_words
+        ids = set(re.findall(ID, line))
+        wide_used = ids & physical_qwords
+        if wide_used:
+            fields = line.split()
+            wide_load = fields[1:4] == ["=", "OpLoad", "%ulong"] and fields[4:5] and fields[4] in wide_used
+            wide_store = fields[0] == "OpStore" and fields[1] in wide_used and fields[2] not in wide_used
+            operands = fields[5:] if wide_load else fields[3:]
+            if ids & physical_words or len(wide_used) != 1 or not (wide_load or wide_store) \
+                    or operands not in WIDE_MEMORY_OPERANDS:
+                raise ValueError("unhandled physical word pointer use")
+            wide_accesses += 1
+            kind = "load" if wide_load else "store"
+            pointer = fields[4] if wide_load else fields[1]
+            stem = "%x2w_" + (f"load_{fields[0][1:]}" if wide_load else f"store_{wide_accesses}")
+            new, label = wide_access(kind, stem, valid_of[pointer], label, wide_words[pointer], fields)
+            output.extend(new)

P2 Badge Rewrite successor phi parents when splitting QWORD blocks

When a QWORD access occurs in a block that feeds a successor OpPhi, this moves the original terminator into a generated *_merge block without updating the successor's incoming parent label. In a variant of qword.spvasm that branches from %entry to %exit with %copied = OpPhi %ulong %result %entry, lowering retains %entry in that phi even though %x2w_load_value_merge is now the actual predecessor. The generated SPIR-V is therefore invalid, so output validation rejects an otherwise supported shader. Track each original block's final label and rewrite the original successor phi parents after inserting these guards.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4674843414 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1157#discussion_r4674843414). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:39:46Z. **Code review location:** `tools/spirv_address_window.py`; line 251 ~~~~diff @@ -144,9 +223,34 @@ def lower(assembly): new, valid_of[dst] = word_pointer(dst, arrays[pointer], index) output.extend(new) continue + if wide := WIDE_ACCESS.fullmatch(line): + dst, pointer, index = wide.groups() + if pointer not in wide_arrays: + raise ValueError("unknown physical array pointer") + new, valid_of[dst] = word_pointer(dst, wide_arrays[pointer], index, True) + wide_words[dst] = address_name(dst) + "_word" + output.extend(new) + continue if opened := re.fullmatch(rf"({ID}) = OpLabel", line): label = opened[1] - used = set(re.findall(ID, line)) & physical_words + ids = set(re.findall(ID, line)) + wide_used = ids & physical_qwords + if wide_used: + fields = line.split() + wide_load = fields[1:4] == ["=", "OpLoad", "%ulong"] and fields[4:5] and fields[4] in wide_used + wide_store = fields[0] == "OpStore" and fields[1] in wide_used and fields[2] not in wide_used + operands = fields[5:] if wide_load else fields[3:] + if ids & physical_words or len(wide_used) != 1 or not (wide_load or wide_store) \ + or operands not in WIDE_MEMORY_OPERANDS: + raise ValueError("unhandled physical word pointer use") + wide_accesses += 1 + kind = "load" if wide_load else "store" + pointer = fields[4] if wide_load else fields[1] + stem = "%x2w_" + (f"load_{fields[0][1:]}" if wide_load else f"store_{wide_accesses}") + new, label = wide_access(kind, stem, valid_of[pointer], label, wide_words[pointer], fields) + output.extend(new) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Rewrite successor phi parents when splitting QWORD blocks** When a QWORD access occurs in a block that feeds a successor `OpPhi`, this moves the original terminator into a generated `*_merge` block without updating the successor's incoming parent label. In a variant of `qword.spvasm` that branches from `%entry` to `%exit` with `%copied = OpPhi %ulong %result %entry`, lowering retains `%entry` in that phi even though `%x2w_load_value_merge` is now the actual predecessor. The generated SPIR-V is therefore invalid, so output validation rejects an otherwise supported shader. Track each original block's final label and rewrite the original successor phi parents after inserting these guards. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!1150
No description provided.