startup: lower DPP quad reads in pixel programs with uniform branches and loops (Part of #1723) #2697

Merged
tedin7 merged 4 commits from upstream-pr/2705 into main 2026-11-26 05:42:48 +00:00
tedin7 commented 2026-11-26 02:54:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:54:55Z.


Part of #1723

What this unblocks: pixel programs that read a DPP quad neighbour (quad swap, quad broadcast, pair broadcast) and also have a uniform branch or loop now translate; today any branch or loop after the first read, or around it, is refused.

Extends #2657 and #2483: #2657 accepts a broadcast in the entry prefix when a loop follows; this PR proves the same property for reads inside branches and loops.

What changed

The one-lane model runs each guest lane as its own HLSL thread through the pc dispatch, and QuadReadLaneAt only sees a neighbour when the four threads of a quad reach the statement together. The old check required straight-line code (or, since #2657, the entry prefix) instead of proving that.

Stage.quad_flow_refusals proves it over the whole program after translation:

  • s_wqm_b64 exec, exec runs before every branch and branch target;
  • no other EXEC write can reach the read (CFG reachability, back edges included);
  • every conditional branch that can reach the read is wave-uniform (SCC proven uniform by the existing pass; execz/execnz under the whole-quad mask).

No wave size is assumed (SM 6.0 quad operations need only the 2x2 quad). The second commit keeps the entry-prefix test for stage objects that never run translate() (unit probes), so #2657's fixtures behave as before.

What stays refused

vccz/vccnz loops, SCC derived from a lane mask, an EXEC write inside the loop, and a late s_wqm, each with the offset that breaks the proof. The vertex stage and any DPP form other than the lowered quad reads.

Tests

New tests/startup_gfx2hlsl_dpp_quad_flow_check.py (registered in CMakeLists.txt, noted in docs/startup-runtime.md): controls for the accepted loop and the four refusal reasons, mutation controls for wrong-lane reads, and a draw mode with a CPU reference for a 16 x 16 readback. On origin/main the controls fail (LOOP translates, and the four refusal reasons are absent); with the change they pass.

Verification

  • python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py: PASS (fails on origin/main)
  • python3 -B tests/startup_gfx2hlsl_dpp_quad_broadcast_check.py, ..._dpp_quad_swap_check.py, ..._dpp_pair_check.py: PASS
  • All tests/startup_gfx2hlsl_*_check.py run with no arguments on this branch and on origin/main: same result per script (export_null_draw and mul24_align_draw need a compiler and renderer and exit 1 on both); the only new script is dpp_quad_flow_check.
  • Win2025 (Windows Server 2025, MSVC 14.44 + D3D12 WARP) on head fc3afb5c0, dev and release: 12/12 passed in each, including startup_gfx2hlsl_dpp_quad_flow, _warp and _hardware (the 16 x 16 draw against the CPU reference, with the wrong-lane control failing as required).

Commands (run per preset dev and release):

cmake --build --preset <preset> --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check
ctest --preset <preset> -R '^startup_gfx2hlsl_dpp_(quad|pair)' --no-tests=error -V

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618478307 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:54:55Z. --- Part of #1723 What this unblocks: pixel programs that read a DPP quad neighbour (quad swap, quad broadcast, pair broadcast) and also have a uniform branch or loop now translate; today any branch or loop after the first read, or around it, is refused. Extends #2657 and #2483: #2657 accepts a broadcast in the entry prefix when a loop follows; this PR proves the same property for reads inside branches and loops. ## What changed The one-lane model runs each guest lane as its own HLSL thread through the pc dispatch, and `QuadReadLaneAt` only sees a neighbour when the four threads of a quad reach the statement together. The old check required straight-line code (or, since #2657, the entry prefix) instead of proving that. `Stage.quad_flow_refusals` proves it over the whole program after translation: - `s_wqm_b64 exec, exec` runs before every branch and branch target; - no other EXEC write can reach the read (CFG reachability, back edges included); - every conditional branch that can reach the read is wave-uniform (SCC proven uniform by the existing pass; `execz`/`execnz` under the whole-quad mask). No wave size is assumed (SM 6.0 quad operations need only the 2x2 quad). The second commit keeps the entry-prefix test for stage objects that never run `translate()` (unit probes), so #2657's fixtures behave as before. ## What stays refused `vccz`/`vccnz` loops, SCC derived from a lane mask, an EXEC write inside the loop, and a late `s_wqm`, each with the offset that breaks the proof. The vertex stage and any DPP form other than the lowered quad reads. ## Tests New `tests/startup_gfx2hlsl_dpp_quad_flow_check.py` (registered in `CMakeLists.txt`, noted in `docs/startup-runtime.md`): controls for the accepted loop and the four refusal reasons, mutation controls for wrong-lane reads, and a `draw` mode with a CPU reference for a 16 x 16 readback. On `origin/main` the controls fail (`LOOP translates`, and the four refusal reasons are absent); with the change they pass. ## Verification - `python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py`: PASS (fails on `origin/main`) - `python3 -B tests/startup_gfx2hlsl_dpp_quad_broadcast_check.py`, `..._dpp_quad_swap_check.py`, `..._dpp_pair_check.py`: PASS - All `tests/startup_gfx2hlsl_*_check.py` run with no arguments on this branch and on `origin/main`: same result per script (`export_null_draw` and `mul24_align_draw` need a compiler and renderer and exit 1 on both); the only new script is `dpp_quad_flow_check`. - Win2025 (Windows Server 2025, MSVC 14.44 + D3D12 WARP) on head fc3afb5c0, dev and release: 12/12 passed in each, including `startup_gfx2hlsl_dpp_quad_flow`, `_warp` and `_hardware` (the 16 x 16 draw against the CPU reference, with the wrong-lane control failing as required). Commands (run per preset `dev` and `release`): ``` cmake --build --preset <preset> --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check ctest --preset <preset> -R '^startup_gfx2hlsl_dpp_(quad|pair)' --no-tests=error -V ``` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:04:29Z.


@MasterDomino Independent Stage-2 gate review of head e9283e3e9: PASS, marked Ready.

  • Fail before, pass after: tests/startup_gfx2hlsl_dpp_quad_flow_check.py exits 1 on origin/main and passes on this head.
  • Negative controls tried: removing the "EXEC write reaches the read" check, and removing the "branch not proven wave-uniform" check, each make the check fail.
  • Break attempts: a per-lane loop (s_andn2 exec) is refused with the EXEC-write reason; a late s_wqm, a vccz loop and SCC from a lane mask are refused; the uniform loop translates.
  • Windows Server 2025, D3D12 WARP, dev and release: 12/12 passed in each (startup_gfx2hlsl_dpp_quad_flow, _warp, _hardware included).

Commands executed:

python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py
x2w_pipe.py win2025 2705 --regex '^startup_gfx2hlsl_dpp_(quad|pair)'

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182270772 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7182270772). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:04:29Z. --- @MasterDomino Independent Stage-2 gate review of head e9283e3e9: PASS, marked Ready. - Fail before, pass after: `tests/startup_gfx2hlsl_dpp_quad_flow_check.py` exits 1 on `origin/main` and passes on this head. - Negative controls tried: removing the "EXEC write reaches the read" check, and removing the "branch not proven wave-uniform" check, each make the check fail. - Break attempts: a per-lane loop (`s_andn2 exec`) is refused with the EXEC-write reason; a late `s_wqm`, a `vccz` loop and SCC from a lane mask are refused; the uniform loop translates. - Windows Server 2025, D3D12 WARP, dev and release: 12/12 passed in each (`startup_gfx2hlsl_dpp_quad_flow`, `_warp`, `_hardware` included). Commands executed: ``` python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py x2w_pipe.py win2025 2705 --regex '^startup_gfx2hlsl_dpp_(quad|pair)' ``` AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 04:04:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T04:04:36Z.


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-26T04:16:51.036343Z e9283e3 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:7182272512 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7182272512). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T04:04:36Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"e9283e3e93ffce5a4c3a14b8ec778e2daafe615a","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-26T04:16:51.036343Z">2026-11-26T04:16:51.036343Z</relative-time> | `e9283e3` | 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>
chatgpt-codex-connector[bot] commented 2026-11-26 04:16:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T04:16:48Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9283e3e93

ℹ️ 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:6068477269 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#pullrequestreview-6068477269). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-26T04:16:48Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `e9283e3e93` <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>
tedin7 commented 2026-11-26 05:02:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:19:39Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068498228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#pullrequestreview-6068498228). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:19:39Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-26 05:02:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:24:47Z.


Re-checked the fix for the empty branch set on head fc3afb5c0 (resolving the thread).

  • The fix is right: min(..., default=inf) leaves a branch-free program with nothing for the s_wqm to precede, and the rest of the proof still runs (a missing s_wqm and any EXEC write that reaches the read are still refused).
  • The new dead-read case in tests/startup_gfx2hlsl_dpp_quad_flow_check.py fails when the fix is removed (exception) and passes with it.
  • The quad flow, swap, broadcast and pair checks pass. The head merges cleanly into current origin/main.
  • Windows Server 2025, D3D12 WARP, ^startup_gfx2hlsl_dpp_(quad|pair): dev 12/12 and release 12/12 passed on this head.

Commands executed:

python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py   (also swap, broadcast, pair)
x2w_pipe.py win2025 2705 --regex '^startup_gfx2hlsl_dpp_(quad|pair)'

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182572188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7182572188). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:24:47Z. --- Re-checked the fix for the empty branch set on head fc3afb5c0 (resolving the thread). - The fix is right: `min(..., default=inf)` leaves a branch-free program with nothing for the `s_wqm` to precede, and the rest of the proof still runs (a missing `s_wqm` and any EXEC write that reaches the read are still refused). - The new dead-read case in `tests/startup_gfx2hlsl_dpp_quad_flow_check.py` fails when the fix is removed (exception) and passes with it. - The quad flow, swap, broadcast and pair checks pass. The head merges cleanly into current `origin/main`. - Windows Server 2025, D3D12 WARP, `^startup_gfx2hlsl_dpp_(quad|pair)`: dev 12/12 and release 12/12 passed on this head. Commands executed: ``` python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py (also swap, broadcast, pair) x2w_pipe.py win2025 2705 --regex '^startup_gfx2hlsl_dpp_(quad|pair)' ``` AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 05:02:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T04:16:48Z.

Code review location: tools/startup/gfx2hlsl.py; line 3519

@@ -3457,6 +3467,77 @@ def one(self, name, asm):
                                                     expr)
         return term
 
+    def quad_flow_straight(self):
+        """Whether a DPP quad read sits in straight-line code (the quad intrinsics then run in uniform flow)."""
+        return not getattr(self, 'has_branches', True) and not getattr(self, 'blocks', [])
+
+    def quad_flow_allowed(self):
+        """Whether a DPP quad read in a pixel program with branches or loops may be lowered now and proven over the
+        whole program after translation (Stage.quad_flow_refusals). Unit probes without translate() cannot."""
+        return getattr(self, 'kind', None) == 'ps' and getattr(self, 'quad_flow_reads', None) is not None
+
+    def note_quad_flow(self, base):
+        if not self.quad_flow_straight() and getattr(self, 'quad_flow_reads', None) is not None:
+            self.quad_flow_reads.append((self.pc, base))
+
+    def quad_flow_refusals(self, branches, targets):
+        """[(offset, reason)] for DPP quad reads lowered in a pixel program with branches or loops.
+
+        The one-lane model runs each lane as its own HLSL thread through the pc dispatch, so the QuadReadLaneAt /
+        QuadReadAcross* of a lane reads its neighbours only when all four threads of the quad reach that statement
+        together (same block, same pass of the dispatch loop) with the word the guest lanes hold. The guest runs
+        the wave as one: its scalar branches are wave-wide, and the quad is whole when EXEC is the s_wqm mask. A
+        read is kept when, on every path to it:
+        - the s_wqm exec, exec that proved whole-quad EXEC ran first: it sits before every branch and target;
+        - no other instruction that can write EXEC reaches it (so EXEC is still that mask and every VGPR write ran
+          on all four lanes, helper lanes included);
+        - every conditional branch that reaches it is wave-uniform (SCC proven uniform by the translator), or an
+          execz/execnz branch, whose EXEC is the whole-quad mask by the rule above and so never taken. A vccz/vccnz
+          branch, or SCC from lane data, can split a quad, and the read is refused.
+        Then the four threads ran the same branch outcomes, so they are in the same block on the same dispatch
+        pass. No wave size is assumed: the SM 6.0 quad operations need only the 2x2 quad of four lanes."""
+        reads = getattr(self, 'quad_flow_reads', [])
+        if not reads:
+            return []
+        index, block_of, succ, _dom, _writes, _reached = self.flow
+        after = {}
+
+        def reaches(src, dst):
+            a, b = index[src], index[dst]
+            if block_of[a] == block_of[b] and a < b:
+                return True
+            start = block_of[a]
+            if start not in after:
+                seen, todo = set(), list(succ[start])
+                while todo:
+                    blk = todo.pop()
+                    if blk not in seen:
+                        seen.add(blk)
+                        todo += succ[blk]
+                after[start] = seen
+            return block_of[b] in after[start]
+        first = min([off for off, _ in branches] + list(targets))

P2 Badge Guard the proof against an empty branch set

In a branch-free pixel shader with entry WQM and a dead DPP pair read after an early s_endpgm, decode() retains the suffix through the final s_endpgm, and note_quad_flow() records the read because self.blocks is already nonempty. Both branches and targets are empty, so this call raises ValueError. A synthetic program containing a quad_perm:[0,0,2,2] pair in that suffix emits HLSL on the parent but now crashes in both normal and refusal-collection mode. Guard the empty branch set or exclude unreachable reads before running the proof.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4703829857 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#discussion_r4703829857). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T04:16:48Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 3519 ~~~~diff @@ -3457,6 +3467,77 @@ def one(self, name, asm): expr) return term + def quad_flow_straight(self): + """Whether a DPP quad read sits in straight-line code (the quad intrinsics then run in uniform flow).""" + return not getattr(self, 'has_branches', True) and not getattr(self, 'blocks', []) + + def quad_flow_allowed(self): + """Whether a DPP quad read in a pixel program with branches or loops may be lowered now and proven over the + whole program after translation (Stage.quad_flow_refusals). Unit probes without translate() cannot.""" + return getattr(self, 'kind', None) == 'ps' and getattr(self, 'quad_flow_reads', None) is not None + + def note_quad_flow(self, base): + if not self.quad_flow_straight() and getattr(self, 'quad_flow_reads', None) is not None: + self.quad_flow_reads.append((self.pc, base)) + + def quad_flow_refusals(self, branches, targets): + """[(offset, reason)] for DPP quad reads lowered in a pixel program with branches or loops. + + The one-lane model runs each lane as its own HLSL thread through the pc dispatch, so the QuadReadLaneAt / + QuadReadAcross* of a lane reads its neighbours only when all four threads of the quad reach that statement + together (same block, same pass of the dispatch loop) with the word the guest lanes hold. The guest runs + the wave as one: its scalar branches are wave-wide, and the quad is whole when EXEC is the s_wqm mask. A + read is kept when, on every path to it: + - the s_wqm exec, exec that proved whole-quad EXEC ran first: it sits before every branch and target; + - no other instruction that can write EXEC reaches it (so EXEC is still that mask and every VGPR write ran + on all four lanes, helper lanes included); + - every conditional branch that reaches it is wave-uniform (SCC proven uniform by the translator), or an + execz/execnz branch, whose EXEC is the whole-quad mask by the rule above and so never taken. A vccz/vccnz + branch, or SCC from lane data, can split a quad, and the read is refused. + Then the four threads ran the same branch outcomes, so they are in the same block on the same dispatch + pass. No wave size is assumed: the SM 6.0 quad operations need only the 2x2 quad of four lanes.""" + reads = getattr(self, 'quad_flow_reads', []) + if not reads: + return [] + index, block_of, succ, _dom, _writes, _reached = self.flow + after = {} + + def reaches(src, dst): + a, b = index[src], index[dst] + if block_of[a] == block_of[b] and a < b: + return True + start = block_of[a] + if start not in after: + seen, todo = set(), list(succ[start]) + while todo: + blk = todo.pop() + if blk not in seen: + seen.add(blk) + todo += succ[blk] + after[start] = seen + return block_of[b] in after[start] + first = min([off for off, _ in branches] + list(targets)) ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Guard the proof against an empty branch set** In a branch-free pixel shader with entry WQM and a dead DPP pair read after an early `s_endpgm`, `decode()` retains the suffix through the final `s_endpgm`, and `note_quad_flow()` records the read because `self.blocks` is already nonempty. Both `branches` and `targets` are empty, so this call raises `ValueError`. A synthetic program containing a `quad_perm:[0,0,2,2]` pair in that suffix emits HLSL on the parent but now crashes in both normal and refusal-collection mode. Guard the empty branch set or exclude unreachable reads before running the proof. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-26 05:02:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:19:39Z.

Code review location: tools/startup/gfx2hlsl.py; line 3519

@@ -3457,6 +3467,77 @@ def one(self, name, asm):
                                                     expr)
         return term
 
+    def quad_flow_straight(self):
+        """Whether a DPP quad read sits in straight-line code (the quad intrinsics then run in uniform flow)."""
+        return not getattr(self, 'has_branches', True) and not getattr(self, 'blocks', [])
+
+    def quad_flow_allowed(self):
+        """Whether a DPP quad read in a pixel program with branches or loops may be lowered now and proven over the
+        whole program after translation (Stage.quad_flow_refusals). Unit probes without translate() cannot."""
+        return getattr(self, 'kind', None) == 'ps' and getattr(self, 'quad_flow_reads', None) is not None
+
+    def note_quad_flow(self, base):
+        if not self.quad_flow_straight() and getattr(self, 'quad_flow_reads', None) is not None:
+            self.quad_flow_reads.append((self.pc, base))
+
+    def quad_flow_refusals(self, branches, targets):
+        """[(offset, reason)] for DPP quad reads lowered in a pixel program with branches or loops.
+
+        The one-lane model runs each lane as its own HLSL thread through the pc dispatch, so the QuadReadLaneAt /
+        QuadReadAcross* of a lane reads its neighbours only when all four threads of the quad reach that statement
+        together (same block, same pass of the dispatch loop) with the word the guest lanes hold. The guest runs
+        the wave as one: its scalar branches are wave-wide, and the quad is whole when EXEC is the s_wqm mask. A
+        read is kept when, on every path to it:
+        - the s_wqm exec, exec that proved whole-quad EXEC ran first: it sits before every branch and target;
+        - no other instruction that can write EXEC reaches it (so EXEC is still that mask and every VGPR write ran
+          on all four lanes, helper lanes included);
+        - every conditional branch that reaches it is wave-uniform (SCC proven uniform by the translator), or an
+          execz/execnz branch, whose EXEC is the whole-quad mask by the rule above and so never taken. A vccz/vccnz
+          branch, or SCC from lane data, can split a quad, and the read is refused.
+        Then the four threads ran the same branch outcomes, so they are in the same block on the same dispatch
+        pass. No wave size is assumed: the SM 6.0 quad operations need only the 2x2 quad of four lanes."""
+        reads = getattr(self, 'quad_flow_reads', [])
+        if not reads:
+            return []
+        index, block_of, succ, _dom, _writes, _reached = self.flow
+        after = {}
+
+        def reaches(src, dst):
+            a, b = index[src], index[dst]
+            if block_of[a] == block_of[b] and a < b:
+                return True
+            start = block_of[a]
+            if start not in after:
+                seen, todo = set(), list(succ[start])
+                while todo:
+                    blk = todo.pop()
+                    if blk not in seen:
+                        seen.add(blk)
+                        todo += succ[blk]
+                after[start] = seen
+            return block_of[b] in after[start]
+        first = min([off for off, _ in branches] + list(targets))

Confirmed and fixed in fc3afb5c0.

  • Cause: quad_flow_refusals took min() of an empty branch and target list when a dead DPP read sits behind an early s_endpgm in a branch-free program.
  • Fix: min(..., default=inf). With nothing to precede, the rest of the proof (EXEC writers, uniform branches) still runs.
  • Test: tests/startup_gfx2hlsl_dpp_quad_flow_check.py gets a dead-read fixture. It fails on the previous head (exception) and passes now.

Commands executed:

python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py   (FAIL on e9283e3e9 logic, PASS on fc3afb5c0)
python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py
python3 -B tests/startup_gfx2hlsl_dpp_quad_broadcast_check.py
python3 -B tests/startup_gfx2hlsl_dpp_quad_swap_check.py

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4703845517 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#discussion_r4703845517). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:19:39Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 3519 ~~~~diff @@ -3457,6 +3467,77 @@ def one(self, name, asm): expr) return term + def quad_flow_straight(self): + """Whether a DPP quad read sits in straight-line code (the quad intrinsics then run in uniform flow).""" + return not getattr(self, 'has_branches', True) and not getattr(self, 'blocks', []) + + def quad_flow_allowed(self): + """Whether a DPP quad read in a pixel program with branches or loops may be lowered now and proven over the + whole program after translation (Stage.quad_flow_refusals). Unit probes without translate() cannot.""" + return getattr(self, 'kind', None) == 'ps' and getattr(self, 'quad_flow_reads', None) is not None + + def note_quad_flow(self, base): + if not self.quad_flow_straight() and getattr(self, 'quad_flow_reads', None) is not None: + self.quad_flow_reads.append((self.pc, base)) + + def quad_flow_refusals(self, branches, targets): + """[(offset, reason)] for DPP quad reads lowered in a pixel program with branches or loops. + + The one-lane model runs each lane as its own HLSL thread through the pc dispatch, so the QuadReadLaneAt / + QuadReadAcross* of a lane reads its neighbours only when all four threads of the quad reach that statement + together (same block, same pass of the dispatch loop) with the word the guest lanes hold. The guest runs + the wave as one: its scalar branches are wave-wide, and the quad is whole when EXEC is the s_wqm mask. A + read is kept when, on every path to it: + - the s_wqm exec, exec that proved whole-quad EXEC ran first: it sits before every branch and target; + - no other instruction that can write EXEC reaches it (so EXEC is still that mask and every VGPR write ran + on all four lanes, helper lanes included); + - every conditional branch that reaches it is wave-uniform (SCC proven uniform by the translator), or an + execz/execnz branch, whose EXEC is the whole-quad mask by the rule above and so never taken. A vccz/vccnz + branch, or SCC from lane data, can split a quad, and the read is refused. + Then the four threads ran the same branch outcomes, so they are in the same block on the same dispatch + pass. No wave size is assumed: the SM 6.0 quad operations need only the 2x2 quad of four lanes.""" + reads = getattr(self, 'quad_flow_reads', []) + if not reads: + return [] + index, block_of, succ, _dom, _writes, _reached = self.flow + after = {} + + def reaches(src, dst): + a, b = index[src], index[dst] + if block_of[a] == block_of[b] and a < b: + return True + start = block_of[a] + if start not in after: + seen, todo = set(), list(succ[start]) + while todo: + blk = todo.pop() + if blk not in seen: + seen.add(blk) + todo += succ[blk] + after[start] = seen + return block_of[b] in after[start] + first = min([off for off, _ in branches] + list(targets)) ~~~~ --- Confirmed and fixed in fc3afb5c0. - Cause: `quad_flow_refusals` took `min()` of an empty branch and target list when a dead DPP read sits behind an early `s_endpgm` in a branch-free program. - Fix: `min(..., default=inf)`. With nothing to precede, the rest of the proof (EXEC writers, uniform branches) still runs. - Test: `tests/startup_gfx2hlsl_dpp_quad_flow_check.py` gets a dead-read fixture. It fails on the previous head (exception) and passes now. Commands executed: ``` python3 -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py (FAIL on e9283e3e9 logic, PASS on fc3afb5c0) python3 -B tests/startup_gfx2hlsl_dpp_pair_check.py python3 -B tests/startup_gfx2hlsl_dpp_quad_broadcast_check.py python3 -B tests/startup_gfx2hlsl_dpp_quad_swap_check.py ``` AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-26 05:42:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:42:41Z.

Review: APPROVED


Reviewed the whole-quad flow proof and ran the new controls plus the existing DPP broadcast, swap and pair checks with main e6902a11 combined. The uniform loop matched all 256 pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 (Windows 11 build 26200). The three wrong-lane mutations changed 256, 256 and 128 pixels respectively on each adapter. Missing WQM, a reaching EXEC write and unproved SCC flow stayed refused.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069100204 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#pullrequestreview-6069100204). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T05:42:41Z. **Review:** APPROVED --- Reviewed the whole-quad flow proof and ran the new controls plus the existing DPP broadcast, swap and pair checks with main e6902a11 combined. The uniform loop matched all 256 pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 (Windows 11 build 26200). The three wrong-lane mutations changed 256, 256 and 128 pixels respectively on each adapter. Missing WQM, a reaching EXEC write and unproved SCC flow stayed refused.
upstream-sync closed this pull request 2026-11-26 06:01:51 +00:00
RonLogic commented 2026-11-26 16:13:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-26T16:13:13Z.


Independent physical-GPU check of the merged fc3afb5c0eb327edcbeb4d26eeeba60b75a3a9e3: python -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py draw <dxc> <offscreen_check> <backend> matched all 256 pixels on both in-box WARP 10.0.26100.10068 and the physical RTX 4070 32.0.16.2124. Both caught the three wrong-lane mutations, which changed 256, 256 and 128 pixels. Translation/refusal controls passed as well. Windows 26300.10075, SDK DXC 1.9.2602.17, D3D12 debug layer enabled, zero errors or warnings, zero skips. I reused the Release offscreen runner after checking its pixel readback sources matched.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7197346314 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7197346314). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-26T16:13:13Z. --- Independent physical-GPU check of the merged `fc3afb5c0eb327edcbeb4d26eeeba60b75a3a9e3`: `python -B tests/startup_gfx2hlsl_dpp_quad_flow_check.py draw <dxc> <offscreen_check> <backend>` matched all 256 pixels on both in-box WARP `10.0.26100.10068` and the physical RTX 4070 `32.0.16.2124`. Both caught the three wrong-lane mutations, which changed 256, 256 and 128 pixels. Translation/refusal controls passed as well. Windows `26300.10075`, SDK DXC `1.9.2602.17`, D3D12 debug layer enabled, zero errors or warnings, zero skips. I reused the Release offscreen runner after checking its pixel readback sources matched.
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!2697
No description provided.