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

Manually merged
github merged 4 commits from gh-pr/2705/head into gh-pr/2705/base 2026-11-27 01:16:47 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-26 02:54 UTC · original
tedin7:x2w-dpp-quad-flow → main · +411 −6 · 4 files · 4 commits · merged 2026-11-26 05:42 UTC

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** on GitHub · 2026-11-26 02:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705) `tedin7:x2w-dpp-quad-flow` → `main` · +411 −6 · 4 files · 4 commits · merged 2026-11-26 05:42 UTC 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.
Symptom: a DPP16 quad read (quad swap, quad broadcast, pair broadcast) in a
pixel program with any branch or loop was refused ("requires a straight-line
pixel shader with entry EXEC" / "outside straight-line pixel code"), so every
program that also has a loop failed even when the loop is a plain scalar
counter.

Root cause: the one-lane model runs each guest lane as its own HLSL thread
through the pc dispatch, and the quad intrinsics only see a neighbour when
the four threads of a quad reach them together. The old check required
straight-line code instead of proving that.

Change: Stage.quad_flow_refusals proves it over the whole program after
translation: the s_wqm exec, exec runs before every branch and target, no
other EXEC write can reach the read (CFG reachability, back edges included),
and 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).
vccz/vccnz loops, SCC from a lane mask, an EXEC write inside the loop and a
late s_wqm are refused with the offset that breaks the proof. No wave size is
assumed (SM 6.0 quad operations need only the 2x2 quad).

Test: tests/startup_gfx2hlsl_dpp_quad_flow_check.py (controls fail before:
LOOP refused, the four refusal reasons absent). Win2025 WARP (DXC ps_6_0)
dev and release: LOOP draws 256/256 pixels equal to the CPU reference, the
three wrong-lane mutations each fail; dpp_pair draws still pass.

(cherry picked from commit 82d1b1d7786e8012494782d13eeefafd88b6a4c8)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:16:46 +00:00
github manually merged commit fc3afb5c0e into gh-pr/2705/base 2026-11-27 01:16:47 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 04:04 UTC · original

@⁠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.

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

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 04:04 UTC · original · edited 2026-11-26 04:16 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-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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 04:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7182272512) · edited 2026-11-26 04:16 UTC <!-- 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 04:16 UTC · original · reviewed

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

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 04:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705#pullrequestreview-6068477269) · **reviewed** <!-- 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 04:16 UTC · original

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

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

@⁠tedin7 on GitHub · 2026-11-26 04:19 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-26 04:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705#discussion_r4703845517) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 04:24 UTC · original

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.

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

@⁠R0Y00 on GitHub · 2026-11-26 05:42 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-26 05:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705#pullrequestreview-6069100204) · **approved these changes** 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.
Author
Owner

@⁠RonLogic on GitHub · 2026-11-26 16:13 UTC · original

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.

**@⁠RonLogic** on GitHub · 2026-11-26 16:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2705#issuecomment-7197346314) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.