shader: lower two-armed CMPX if/else regions in wave64 pixel stages #3815

Merged
lukaslw-lab merged 2 commits from upstream-pr/3815 into main 2026-12-02 03:04:14 +00:00
lukaslw-lab commented 2026-12-02 02:35:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T02:35:27Z.


Change

Wave64 pixel stages can now lower a two-armed if/else on a compare that writes EXEC:

s_mov_b64 s[4:5], exec
v_cmpx_gt_f32 0.5, v14        ; THEN lanes
s_cbranch_execz ELSE
<THEN>
ELSE: s_andn2_b64 exec, s[4:5], exec
s_cbranch_execz JOIN
<ELSE>
JOIN: s_mov_b64 exec, s[4:5]

pixel_readonly_arms (src/gfx1013_direct_graphics.inl) took only the one-armed skip whose target is the restore. It
now also takes a skip that lands on the ELSE mask, if that mask complements the saved pair and is followed by an
EXECZ skip to the matching restore. Each arm follows the same rules as the one-armed body: lane-local ALU, scalar
loads, image loads, waits. Each lane takes one arm. The ELSE skip branches per lane on the same compare bit (a lane
that ran THEN goes to the join), and VGPRs merge per lane at both masks. A scalar written in THEN is dropped at the
ELSE mask, and anything written in either arm is dropped at the restore. An inner SAVEEXEC is not accepted in the
two-armed form.

Two smaller parts, both needed by the real shapes:

  • v_readfirstlane_b32 is allowed inside an arm. The lowering still refuses it unless its source is wave-uniform.
  • The rule that marks VALU results of SGPRs and constants as wave-uniform ran only for vertex stages. It now also runs
    for pixel stages, and only readfirstlane reads that set.

Refs #3814 (census), #3640, #3641.

Verification

Commit c8096e0e on main b7d61632, release build, Windows 10 19045.

Check Result
ctest --preset release -R '^native_pixel_cmpx_if_else_controls$' pass
native_pixel_cmpx_if_else_check.py ... warp with an offscreen_check built against Agility 1.620.2 + WARP 1.0.22 pass
ctest --preset release -R '^native_' (the same change at 3cad3f73 on main 3ecfbad7; RTX 3080 Ti, driver 32.0.16.1047, debug layer) 198 pass, 197 skip (77), 74 fail. The 73 failures other than the new _warp are SM 6.6 draws on the Windows 10 in-box runtime; the same 73 fail with upstream gfx1013_direct_graphics.inl on this build.

The in-box WARP of Windows 10 19041 rejects ps_6_6/vs_6_6, so _warp fails there in the same way as
native_pixel_cmpx_discard_warp. It needs the Agility runtime or a newer WARP.

The Linux Python job is also red on main b7d61632: tests/startup_stubs_ci_check.py (#3656) fails after the
workflow change in #3690. This change does not touch either.

Mutations (local, then reverted):

  • ELSE skip branching without the negation (THEN lanes also run ELSE): the both-arms draw fails.
  • No THEN-scalar drop at the ELSE mask: then-scalar-read-in-else translates and the control fails.
  • Pixel stages without the uniform rule: readfirstlane-uniform is refused and the control fails.

Evidence and follow-up

The fixtures are source-built gfx1013 words in a synthetic pixel container, written for this test. _warp draws an
8x2 target with v0 = SV_Position.x, so each pixel shows the value its own arm wrote. A swapped reference, an all-THEN
reference and an all-ELSE reference must all fail. Cases:

  • both arms write; only THEN writes; only ELSE writes; ELSE reads a uniform constant back through readfirstlane;
  • every lane on one side (the guest skips the empty arm as a whole wave).

Refusals:

  • a THEN scalar read in ELSE or after the join;
  • readfirstlane of the position;
  • ELSE mask or restore from another pair;
  • THEN skip past the ELSE mask, or ELSE skip past the restore;
  • a branch inside an arm.

Offline census of the captured slot 86 pixel stages (#3814): 322 of the 3,370 distinct stages at "graphics branch on
a wave mask" move on (574 requests). The pixel stages of the 24 Mesh86 draws selected in one local run pass every CMPX
region. Their next walls are not touched here: 18 stop at an interpolation after a branch in a looping shader, 6 at a
readfirstlane before any region. Nested CMPX inside an arm and uniform branches inside an arm stay refused.

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. (No capability row changes.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5598676279 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3815). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T02:35:27Z. --- ## Change Wave64 pixel stages can now lower a two-armed if/else on a compare that writes EXEC: ``` s_mov_b64 s[4:5], exec v_cmpx_gt_f32 0.5, v14 ; THEN lanes s_cbranch_execz ELSE <THEN> ELSE: s_andn2_b64 exec, s[4:5], exec s_cbranch_execz JOIN <ELSE> JOIN: s_mov_b64 exec, s[4:5] ``` `pixel_readonly_arms` (`src/gfx1013_direct_graphics.inl`) took only the one-armed skip whose target is the restore. It now also takes a skip that lands on the ELSE mask, if that mask complements the saved pair and is followed by an EXECZ skip to the matching restore. Each arm follows the same rules as the one-armed body: lane-local ALU, scalar loads, image loads, waits. Each lane takes one arm. The ELSE skip branches per lane on the same compare bit (a lane that ran THEN goes to the join), and VGPRs merge per lane at both masks. A scalar written in THEN is dropped at the ELSE mask, and anything written in either arm is dropped at the restore. An inner SAVEEXEC is not accepted in the two-armed form. Two smaller parts, both needed by the real shapes: - `v_readfirstlane_b32` is allowed inside an arm. The lowering still refuses it unless its source is wave-uniform. - The rule that marks VALU results of SGPRs and constants as wave-uniform ran only for vertex stages. It now also runs for pixel stages, and only readfirstlane reads that set. Refs #3814 (census), #3640, #3641. ## Verification Commit `c8096e0e` on main `b7d61632`, release build, Windows 10 19045. | Check | Result | |---|---| | `ctest --preset release -R '^native_pixel_cmpx_if_else_controls$'` | pass | | `native_pixel_cmpx_if_else_check.py ... warp` with an `offscreen_check` built against Agility 1.620.2 + WARP 1.0.22 | pass | | `ctest --preset release -R '^native_'` (the same change at `3cad3f73` on main `3ecfbad7`; RTX 3080 Ti, driver 32.0.16.1047, debug layer) | 198 pass, 197 skip (77), 74 fail. The 73 failures other than the new `_warp` are SM 6.6 draws on the Windows 10 in-box runtime; the same 73 fail with upstream `gfx1013_direct_graphics.inl` on this build. | The in-box WARP of Windows 10 19041 rejects `ps_6_6`/`vs_6_6`, so `_warp` fails there in the same way as `native_pixel_cmpx_discard_warp`. It needs the Agility runtime or a newer WARP. The Linux Python job is also red on main `b7d61632`: `tests/startup_stubs_ci_check.py` (#3656) fails after the workflow change in #3690. This change does not touch either. Mutations (local, then reverted): - ELSE skip branching without the negation (THEN lanes also run ELSE): the `both-arms` draw fails. - No THEN-scalar drop at the ELSE mask: `then-scalar-read-in-else` translates and the control fails. - Pixel stages without the uniform rule: `readfirstlane-uniform` is refused and the control fails. ## Evidence and follow-up The fixtures are source-built gfx1013 words in a synthetic pixel container, written for this test. `_warp` draws an 8x2 target with v0 = SV_Position.x, so each pixel shows the value its own arm wrote. A swapped reference, an all-THEN reference and an all-ELSE reference must all fail. Cases: - both arms write; only THEN writes; only ELSE writes; ELSE reads a uniform constant back through readfirstlane; - every lane on one side (the guest skips the empty arm as a whole wave). Refusals: - a THEN scalar read in ELSE or after the join; - readfirstlane of the position; - ELSE mask or restore from another pair; - THEN skip past the ELSE mask, or ELSE skip past the restore; - a branch inside an arm. Offline census of the captured slot 86 pixel stages (#3814): 322 of the 3,370 distinct stages at "graphics branch on a wave mask" move on (574 requests). The pixel stages of the 24 Mesh86 draws selected in one local run pass every CMPX region. Their next walls are not touched here: 18 stop at an interpolation after a branch in a looping shader, 6 at a readfirstlane before any region. Nested CMPX inside an arm and uniform branches inside an arm stay refused. ## 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. (No capability row changes.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
R0Y00 commented 2026-12-02 02:41:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T02:41:34Z.


Confirmed the Linux job fails tests/startup_stubs_ci_check.py on the current base. #3817 fixes the coverage-only false positive and preserves the full-suite guards. Once it lands, please refresh this PR against main to get a clean Linux run.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7333099050 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3815#issuecomment-7333099050). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T02:41:34Z. --- Confirmed the Linux job fails `tests/startup_stubs_ci_check.py` on the current base. #3817 fixes the coverage-only false positive and preserves the full-suite guards. Once it lands, please refresh this PR against main to get a clean Linux run.
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!3815
No description provided.