Skip to content

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

Merged
R0Y00 merged 4 commits into
R0Y00:mainfrom
tedin7:x2w-dpp-quad-flow
Nov 26, 2026
Merged

R0Y00 merged 4 commits into
R0Y00:mainfrom
tedin7:x2w-dpp-quad-flow

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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 fc3afb5, 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.

…d loops

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)
…f DPP quad reads, keep unit probes on the entry prefix
@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 04:04
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@MasterDomino Independent Stage-2 gate review of head e9283e3: 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

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tools/startup/gfx2hlsl.py Resolved
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Re-checked the fix for the empty branch set on head fc3afb5 (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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the whole-quad flow proof and ran the new controls plus the existing DPP broadcast, swap and pair checks with main e6902a1 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
R0Y00 merged commit 1ec01d7 into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants