shader: lower waits and scalar loads in pixel_aot masked regions #1124

Merged
tedin7 merged 3 commits from upstream-pr/1131 into main 2026-11-24 03:16:45 +00:00
tedin7 commented 2026-11-24 01:37:10 +00:00 (Migrated from github.com)

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


Change

Stage 3 of #987 (Refs #987). In tools/pixel_aot.py, masked regions (s_and_saveexec_b64 and v_cmpx_* openers) now admit:

  • s_waitcnt forms that resolve outstanding vm or lgkm work. Waits ignore EXEC, so the wait runs for every wave that enters the region. For a region with the s_cbranch_execz skip, the restore puts back what was outstanding at the opener, so the first read after the region needs a wait outside it.
  • Scalar loads s_load_dword{,x2,x4,x8} and s_buffer_load_dword{,x2,x4} (already lowered outside regions). Each is checked to change only its destinations, which become outstanding, and may not overwrite the saved execution pair. With the skip, the destinations become conditional like scalar ALU results.

This replaces the earlier refusals (busy-counter wait, scalar load in a region). docs/experiments.md is updated and a new CTest pixel_aot_region_scalar_load_{warp,hardware} is registered.

AI-assisted.

Verification

Linux, LLVM 19 (LLVM 15 packages are not available on this host):

  • python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so: the translation controls pass, including the new check_region_scalar_load_controls and the rewritten check_region_wait_controls. The full binary run stops at a fixture unrelated to this change (v_cvt_f16_i16 literal and s_version UC_VERSION_GFX7 spelling differences with LLVM 19), so I ran the 12 region round-trip fixtures (including the 4 new ones, skip in label form) alone: all pass.
  • Negative control: with tools/pixel_aot.py from origin/main and the new tests, the controls fail at the first wait: Wait would resolve outstanding lgkm work in a masked region: s_waitcnt lgkmcnt(0). With the change they pass.

Not run: the Windows draws (draw-region-scalar-load, WARP and hardware) and the LLVM 15 CI job; they need Windows or the CI runner.

Evidence and follow-up

The draw fixture is built from source. Its expected pixels come from the constants the test writes and the ramp (not from the translator); a reference with the writes on every lane and one with the wrong word of the two-dword load must mismatch on a precise word.

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:6572616917 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1131). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:37:10Z. --- ## Change Stage 3 of #987 (Refs #987). In `tools/pixel_aot.py`, masked regions (`s_and_saveexec_b64` and `v_cmpx_*` openers) now admit: - `s_waitcnt` forms that resolve outstanding `vm` or `lgkm` work. Waits ignore EXEC, so the wait runs for every wave that enters the region. For a region with the `s_cbranch_execz` skip, the restore puts back what was outstanding at the opener, so the first read after the region needs a wait outside it. - Scalar loads `s_load_dword{,x2,x4,x8}` and `s_buffer_load_dword{,x2,x4}` (already lowered outside regions). Each is checked to change only its destinations, which become outstanding, and may not overwrite the saved execution pair. With the skip, the destinations become conditional like scalar ALU results. This replaces the earlier refusals (busy-counter wait, scalar load in a region). `docs/experiments.md` is updated and a new CTest `pixel_aot_region_scalar_load_{warp,hardware}` is registered. AI-assisted. ## Verification Linux, LLVM 19 (LLVM 15 packages are not available on this host): - `python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so`: the translation controls pass, including the new `check_region_scalar_load_controls` and the rewritten `check_region_wait_controls`. The full binary run stops at a fixture unrelated to this change (`v_cvt_f16_i16` literal and `s_version UC_VERSION_GFX7` spelling differences with LLVM 19), so I ran the 12 region round-trip fixtures (including the 4 new ones, skip in label form) alone: all pass. - Negative control: with `tools/pixel_aot.py` from origin/main and the new tests, the controls fail at the first wait: `Wait would resolve outstanding lgkm work in a masked region: s_waitcnt lgkmcnt(0)`. With the change they pass. Not run: the Windows draws (`draw-region-scalar-load`, WARP and hardware) and the LLVM 15 CI job; they need Windows or the CI runner. ## Evidence and follow-up The draw fixture is built from source. Its expected pixels come from the constants the test writes and the ramp (not from the translator); a reference with the writes on every lane and one with the wrong word of the two-dword load must mismatch on a precise word. ## 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 06:46:30 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:46:30 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a76439d10

ℹ️ 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:6032727684 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1131#pullrequestreview-6032727684). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:24:44Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `4a76439d10` <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:10 +00:00 (Migrated from github.com)

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


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:24:46.774851Z 4a76439 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:7119985761 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1131#issuecomment-7119985761). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:17:57Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4a76439d1064791ba2ea5eb8387df25db82c6de3","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:24:46.774851Z">2026-11-24T02:24:46.774851Z</relative-time> | `4a76439` | 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:10 +00:00 (Migrated from github.com)

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


Fixed the P2 finding: a scalar load in a masked region that no wave can skip (no s_cbranch_execz) now supersedes earlier conditional provenance of its destination SGPRs, both the region-local record and the scalar.conditional set left by an earlier region. When the region can be skipped the conditionality is kept as before. New controls in check_region_scalar_load_controls cover both reproductions from the finding under both openers: before the fix the first one fails with "Read of a register defined only on the masked path", after it both translate. Merged origin/main (no conflicts, no force). The local run reaches the unrelated LLVM 19 encoding check check_f16_cvt_int16_binary after the region controls pass; CI uses LLVM 15. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7120170766 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1131#issuecomment-7120170766). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T02:27:57Z. --- Fixed the P2 finding: a scalar load in a masked region that no wave can skip (no `s_cbranch_execz`) now supersedes earlier conditional provenance of its destination SGPRs, both the region-local record and the `scalar.conditional` set left by an earlier region. When the region can be skipped the conditionality is kept as before. New controls in `check_region_scalar_load_controls` cover both reproductions from the finding under both openers: before the fix the first one fails with "Read of a register defined only on the masked path", after it both translate. Merged origin/main (no conflicts, no force). The local run reaches the unrelated LLVM 19 encoding check `check_f16_cvt_int16_binary` after the region controls pass; CI uses LLVM 15. AI-assisted.
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:24:44Z.

Code review location: tools/pixel_aot.py; line 5187

@@ -5157,7 +5173,19 @@ def sample_coord(reg):
              old_ended, old_mask, old_attribute, old_interpolated, old_quad, old_samples, scalar_alu) = rstate
             writes = {k for k in set(vector) | set(old_vector)
                       if old_vector.get(k, MISSING) != dict.get(vector, k, MISSING)}
-            if scalar_alu:
+            if isinstance(scalar_alu, set):
+                # A scalar load may only add its own destinations: they become outstanding and change nothing else.
+                scalar_writes = {k for k in set(scalar) | set(old_scalar)
+                                 if old_scalar.get(k, MISSING) != dict.get(scalar, k, MISSING)}
+                if (not scalar_writes.issubset(scalar_alu) or writes or scc != old_scc
+                        or pending != old_pending | scalar_alu or sample_dest != old_sample_dest
+                        or exported != old_exported or ended != old_ended or mask != old_mask
+                        or attribute_input != old_attribute or interpolated != old_interpolated
+                        or quad_values != old_quad or samples != old_samples):
+                    raise ValueError(f"Unsupported masked-region scalar load {i}: {line}")
+                if region["skip"] is not None:
+                    region["scalar_written"].update(scalar_alu)

P2 Badge Clear conditional provenance when a scalar load redefines an SGPR

Without an s_cbranch_execz, a scalar load defines its destination on every wave, but this block leaves earlier conditional-write tracking intact. A region containing s_mov_b32 s72, 0, followed by s_buffer_load_dword s72, s[68:71], 0x20 and s_waitcnt lgkmcnt(0), still leaves s72 in region['scalar_written']; consequently, reading it after the restore is incorrectly rejected as defined only on the masked path. Reloading an SGPR marked conditional by an earlier region similarly leaves scalar.conditional set and rejects even an in-region read after the wait. Both cases reproduce under both openers. Clear superseded conditional provenance for loaded destinations, retaining restore-time conditionality only when the load can be skipped.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4674736508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1131#discussion_r4674736508). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T02:24:44Z. **Code review location:** `tools/pixel_aot.py`; line 5187 ~~~~diff @@ -5157,7 +5173,19 @@ def sample_coord(reg): old_ended, old_mask, old_attribute, old_interpolated, old_quad, old_samples, scalar_alu) = rstate writes = {k for k in set(vector) | set(old_vector) if old_vector.get(k, MISSING) != dict.get(vector, k, MISSING)} - if scalar_alu: + if isinstance(scalar_alu, set): + # A scalar load may only add its own destinations: they become outstanding and change nothing else. + scalar_writes = {k for k in set(scalar) | set(old_scalar) + if old_scalar.get(k, MISSING) != dict.get(scalar, k, MISSING)} + if (not scalar_writes.issubset(scalar_alu) or writes or scc != old_scc + or pending != old_pending | scalar_alu or sample_dest != old_sample_dest + or exported != old_exported or ended != old_ended or mask != old_mask + or attribute_input != old_attribute or interpolated != old_interpolated + or quad_values != old_quad or samples != old_samples): + raise ValueError(f"Unsupported masked-region scalar load {i}: {line}") + if region["skip"] is not None: + region["scalar_written"].update(scalar_alu) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Clear conditional provenance when a scalar load redefines an SGPR** Without an `s_cbranch_execz`, a scalar load defines its destination on every wave, but this block leaves earlier conditional-write tracking intact. A region containing `s_mov_b32 s72, 0`, followed by `s_buffer_load_dword s72, s[68:71], 0x20` and `s_waitcnt lgkmcnt(0)`, still leaves `s72` in `region['scalar_written']`; consequently, reading it after the restore is incorrectly rejected as `defined only on the masked path`. Reloading an SGPR marked conditional by an earlier region similarly leaves `scalar.conditional` set and rejects even an in-region read after the wait. Both cases reproduce under both openers. Clear superseded conditional provenance for loaded destinations, retaining restore-time conditionality only when the load can be skipped. 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!1124
No description provided.