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

Manually merged
github merged 3 commits from gh-pr/1131/head into gh-pr/1131/base 2026-11-26 22:44:05 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 01:37 UTC · original
tedin7:x2w-pixel-aot-masked-region-waits-loads → main · +227 −37 · 4 files · 3 commits · merged 2026-11-24 03:16 UTC

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.
**@⁠tedin7** on GitHub · 2026-11-24 01:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1131) `tedin7:x2w-pixel-aot-masked-region-waits-loads` → `main` · +227 −37 · 4 files · 3 commits · merged 2026-11-24 03:16 UTC ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:44:03 +00:00
github manually merged commit 95c4e4200e into gh-pr/1131/base 2026-11-26 22:44:05 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 02:17 UTC · original · edited 2026-11-24 02:24 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 02:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1131#issuecomment-7119985761) · edited 2026-11-24 02:24 UTC <!-- 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>
@ -5254,0 +5277,4 @@
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)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 02:24 UTC · original

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 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 02:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1131#discussion_r4674736508) **<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 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 02:27 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 02:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1131#issuecomment-7120170766) 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.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 02:24 UTC · original · reviewed

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

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 02:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1131#pullrequestreview-6032727684) · **reviewed** <!-- 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>
This discussion has been locked. Commenting is limited to contributors.
No description provided.