shader: lower a mesh CMPX region inside a SAVEEXEC then arm (Part of #3703) #3782

Merged
mumba17 merged 2 commits from upstream-pr/3782 into main 2026-12-02 02:38:55 +00:00
mumba17 commented 2026-12-01 21:05:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T21:05:59Z.


Part of #3703. Covers 158 of the 215 programs the wall mesh SAVEEXEC then arm depends on EXEC stops in my census on the current stack.

Shape

Inside a SAVEEXEC then arm, the compiler often narrows EXEC once more with a CMPX:

s_mov_b64 sX, exec        ; copy the arm's EXEC
...                       ; vector work under the arm's EXEC (optional)
v_cmpx_* a, b             ; EXEC &= compare
s_cbranch_execz L
...                       ; region
L: s_mov_b64 exec, sX     ; restore the copy

Each lane runs the work, then the region only if the compare holds. That is the if-only region s_and_saveexec_b64 sX, cmp would open, except that a CMPX leaves SCC alone. The then-arm scan refused the EXEC copy.

Chain form (second commit): in an if-only SAVEEXEC arm the EXECZ may instead skip to the arm's end, leaving the copy unrestored. The rest of the arm is then the region, and the SAVEEXEC restore ends both. Regions chain the same way.

Change (gfx1013_direct_mesh.inl)

  • match_cmpx_child recognizes the shape inside a then arm. The work between the copy and the CMPX must leave EXEC, the copied register and control flow alone. The EXECZ must land on s_mov_b64 exec, sX with the same register, inside the arm.
  • The then-arm scan registers it as a child region. The work before the CMPX is scanned as part of the enclosing arm, and the region as its own arm under the existing then-arm rules. Its parent gets contains_child, so its lane masks are exact, as for a nested s_and_saveexec_b64.
  • At the CMPX, the frontend opens a nested diamond on the shared comparison(), so every 32-bit VOPC compare is supported. The region's lane mask is the arm's lane mask AND the compare. It joins and restores through the existing nested SAVEEXEC path. SCC is clobbered after the join, as it is for a nested SAVEEXEC.
  • Chain form:
    • It is accepted only when the enclosing arm has no else arm; otherwise the inverse would read the narrowed EXEC.
    • After the region joins, the frontend visits the same address again so the enclosing arm closes there too.
    • A region whose enclosing arm does not end there is refused.
  • Anything else stays refused as before:
    • a restore of another register or outside the arm;
    • an EXECZ that leaves the region;
    • a prefix that writes the copy or branches;
    • a non-32-bit, SDWA or DPP CMPX, which gets its own refusal.

Tests (tests/native_direct_mesh_check.py)

  • saveexec-cmpx-region and -prefix check the whole chain:
    • the DXIL branch takes the icmp ugt i32 3;
    • the region's write selects on the arm's lanes AND the compare;
    • the region's join merges it with the value from before the CMPX (2, or the prefix's 4);
    • that join leaves the then arm.
  • Seven refusals stay at the copy (then arm depends on EXEC): another restore register, no EXECZ, a prefix that writes the copy, a prefix branch, a VOPC without EXEC, and an EXECZ past the restore.
  • Inside the region: an EXEC read and an LDS write are refused under the then-arm rules. A v_cmpx_gt_u16 is refused as unsupported.
  • Chain form:
    • saveexec-cmpx-chain checks the branch on the compare, the region's select and join, and that the join leaves the arm.
    • -twice checks a second copy and v_cmpx_ne_u32 inside the region, with both joins in order at the arm's end.
    • -else keeps the chain refused under an arm with an else arm.
  • Mutations, each failing the suite:
    • the branch ignores the compare;
    • any restore register is accepted;
    • prefix writes to the copy are not checked (the restore check still refuses, with another message);
    • the 32-bit check is dropped;
    • a chain is accepted under an else arm;
    • the second visit of the join address is dropped.

Validation (Windows 11, MSVC, Windows SDK 10.0.26100)

  • ctest --test-dir out/build/dev -R "native_direct_mesh|mesh": 210/210 (the two mesh_two_exits hardware tests skip as usual).
  • Census (same capture and method as on #3703) on main + #3708 + #3709 + #3710 + #3729 + #3760 + #3765 + #3770 + this: 975 of 1,569 translate, up from 845. 130 gained, none lost. Of the 215:
    • 130 translate;
    • 13 stop at unproven mesh mask operand (a mask built with s_cselect_b64 sN, exec, 0);
    • 7 stop at v_min_f32;
    • 5 stop at v_cvt_f16_f32;
    • 3 stop at mesh scalar branch crosses a nested SAVEEXEC region;
    • 57 still stop at this wall: s_and_b64 vcc, exec, sN + s_cbranch_vccnz uniform branches, not in scope here.
    • Counts only; request bytes stay local.
  • Not run in the game.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5594539000 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3782). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T21:05:59Z. --- Part of #3703. Covers 158 of the 215 programs the wall `mesh SAVEEXEC then arm depends on EXEC` stops in my census on the current stack. ## Shape Inside a SAVEEXEC then arm, the compiler often narrows EXEC once more with a CMPX: ``` s_mov_b64 sX, exec ; copy the arm's EXEC ... ; vector work under the arm's EXEC (optional) v_cmpx_* a, b ; EXEC &= compare s_cbranch_execz L ... ; region L: s_mov_b64 exec, sX ; restore the copy ``` Each lane runs the work, then the region only if the compare holds. That is the if-only region `s_and_saveexec_b64 sX, cmp` would open, except that a CMPX leaves SCC alone. The then-arm scan refused the EXEC copy. **Chain form** (second commit): in an if-only SAVEEXEC arm the EXECZ may instead skip to the arm's end, leaving the copy unrestored. The rest of the arm is then the region, and the SAVEEXEC restore ends both. Regions chain the same way. ## Change (`gfx1013_direct_mesh.inl`) - `match_cmpx_child` recognizes the shape inside a then arm. The work between the copy and the CMPX must leave EXEC, the copied register and control flow alone. The EXECZ must land on `s_mov_b64 exec, sX` with the same register, inside the arm. - The then-arm scan registers it as a child region. The work before the CMPX is scanned as part of the enclosing arm, and the region as its own arm under the existing then-arm rules. Its parent gets `contains_child`, so its lane masks are exact, as for a nested `s_and_saveexec_b64`. - At the CMPX, the frontend opens a nested diamond on the shared `comparison()`, so every 32-bit VOPC compare is supported. The region's lane mask is the arm's lane mask AND the compare. It joins and restores through the existing nested SAVEEXEC path. SCC is clobbered after the join, as it is for a nested SAVEEXEC. - Chain form: - It is accepted only when the enclosing arm has no else arm; otherwise the inverse would read the narrowed EXEC. - After the region joins, the frontend visits the same address again so the enclosing arm closes there too. - A region whose enclosing arm does not end there is refused. - Anything else stays refused as before: - a restore of another register or outside the arm; - an EXECZ that leaves the region; - a prefix that writes the copy or branches; - a non-32-bit, SDWA or DPP CMPX, which gets its own refusal. ## Tests (`tests/native_direct_mesh_check.py`) - `saveexec-cmpx-region` and `-prefix` check the whole chain: - the DXIL branch takes the `icmp ugt i32 3`; - the region's write selects on the arm's lanes AND the compare; - the region's join merges it with the value from before the CMPX (2, or the prefix's 4); - that join leaves the then arm. - Seven refusals stay at the copy (`then arm depends on EXEC`): another restore register, no EXECZ, a prefix that writes the copy, a prefix branch, a VOPC without EXEC, and an EXECZ past the restore. - Inside the region: an EXEC read and an LDS write are refused under the then-arm rules. A `v_cmpx_gt_u16` is refused as unsupported. - Chain form: - `saveexec-cmpx-chain` checks the branch on the compare, the region's select and join, and that the join leaves the arm. - `-twice` checks a second copy and `v_cmpx_ne_u32` inside the region, with both joins in order at the arm's end. - `-else` keeps the chain refused under an arm with an else arm. - Mutations, each failing the suite: - the branch ignores the compare; - any restore register is accepted; - prefix writes to the copy are not checked (the restore check still refuses, with another message); - the 32-bit check is dropped; - a chain is accepted under an else arm; - the second visit of the join address is dropped. ## Validation (Windows 11, MSVC, Windows SDK 10.0.26100) - `ctest --test-dir out/build/dev -R "native_direct_mesh|mesh"`: 210/210 (the two `mesh_two_exits` hardware tests skip as usual). - **Census** (same capture and method as on #3703) on `main` + #3708 + #3709 + #3710 + #3729 + #3760 + #3765 + #3770 + this: **975 of 1,569** translate, up from 845. 130 gained, none lost. Of the 215: - 130 translate; - 13 stop at `unproven mesh mask operand` (a mask built with `s_cselect_b64 sN, exec, 0`); - 7 stop at `v_min_f32`; - 5 stop at `v_cvt_f16_f32`; - 3 stop at `mesh scalar branch crosses a nested SAVEEXEC region`; - 57 still stop at this wall: `s_and_b64 vcc, exec, sN` + `s_cbranch_vccnz` uniform branches, not in scope here. - Counts only; request bytes stay local. - Not run in the game. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mumba17 commented 2026-12-01 21:34:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T21:34:12Z.


Pushed d1c76a61: the chain form. In an if-only SAVEEXEC arm the EXECZ after the CMPX may skip to the arm's end, so the rest of the arm is the region and the SAVEEXEC restore ends both.

It is accepted only without an else arm, since the inverse would otherwise read the narrowed EXEC. The description has the tests and mutations.

Census on the stack: 975 of 1,569 (was 924 at 7e997a37), none lost. Only the 57 s_cbranch_vccnz uniform branches still stop at this wall. ctest -R "native_direct_mesh|mesh": 210/210.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7326461556 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3782#issuecomment-7326461556). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T21:34:12Z. --- Pushed `d1c76a61`: the chain form. In an if-only SAVEEXEC arm the EXECZ after the CMPX may skip to the arm's end, so the rest of the arm is the region and the SAVEEXEC restore ends both. It is accepted only without an else arm, since the inverse would otherwise read the narrowed EXEC. The description has the tests and mutations. Census on the stack: 975 of 1,569 (was 924 at `7e997a37`), none lost. Only the 57 `s_cbranch_vccnz` uniform branches still stop at this wall. `ctest -R "native_direct_mesh|mesh"`: 210/210. AI-assisted.
lukaslw-lab commented 2026-12-02 02:29:06 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed d1c76a61 by reading the diff; not built or run.

Verdict: approve. The region reuses the nested SAVEEXEC diamond: the copy is lowered by the existing s_mov_b64 sX, exec path, the CMPX checks that the copy is still the arm's EXEC (saved_exec.at(start), same lane), and the branch and lane mask (arm AND compare) match the nested s_and_saveexec_b64 case. No MUST.

  • SHOULD No case reads a scalar written inside the region after its join. SALU in the region runs once for the whole wave whenever any lane passes the compare. In DXIL it runs only for the lanes that pass. So the then_writes loop and the SCC entry in scalar_clobbers (gfx1013_direct_mesh.inl:1816, :1818) are what keep this correct. Dropping either one passes every new case, because the regions write only v1. Two refusals would pin them:
    • s_mov_b32 s30, 1 in the region, then a read of s30 after the restore;
    • an s_cmp in the region, then s_cselect_b32 after the restore.
  • NIT #3797 edits the same then-arm scan and conflicts textually with this head. Whichever lands second needs a rebase. The two shapes don't overlap: an EXEC copy plus CMPX here, a VCC branch there.
  • Checked, no finding:
    • The chain form needs an arm with no else arm (!shape.else_begin), so the inverse never reads the narrowed EXEC. The second visit of the join address is backed by the outlives its enclosing arm refusal.
    • Prefix and region writes to the copy are refused, in the prefix by writes_saved and in the region at the arm close. A nested SAVEEXEC in the prefix fails the match and stays at depends on EXEC.
    • The copy registers join the parent's then_writes, so after the outer join a chain copy that was never restored reads as unbound, not as a stale lane mask.
    • It merges cleanly with main, #3707, #3712 and #3770.

Tests: the 14 new native_direct_mesh cases check the IR order. The branch takes the compare, the region's select uses arm AND compare, and both joins come in order for the region and the chain forms. The refusals cover each match condition. These are IR checks only; no draw runs a region. CI ran native_direct_mesh in the pr preset at this head, green.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6143793010 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3782#pullrequestreview-6143793010). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T02:29:06Z. **Review:** APPROVED --- Reviewed `d1c76a61` by reading the diff; not built or run. **Verdict: approve.** The region reuses the nested SAVEEXEC diamond: the copy is lowered by the existing `s_mov_b64 sX, exec` path, the CMPX checks that the copy is still the arm's EXEC (`saved_exec.at(start)`, same lane), and the branch and lane mask (`arm AND compare`) match the nested `s_and_saveexec_b64` case. No MUST. - **SHOULD** No case reads a scalar written inside the region after its join. SALU in the region runs once for the whole wave whenever any lane passes the compare. In DXIL it runs only for the lanes that pass. So the `then_writes` loop and the SCC entry in `scalar_clobbers` (`gfx1013_direct_mesh.inl:1816`, `:1818`) are what keep this correct. Dropping either one passes every new case, because the regions write only `v1`. Two refusals would pin them: - `s_mov_b32 s30, 1` in the region, then a read of `s30` after the restore; - an `s_cmp` in the region, then `s_cselect_b32` after the restore. - **NIT** #3797 edits the same then-arm scan and conflicts textually with this head. Whichever lands second needs a rebase. The two shapes don't overlap: an EXEC copy plus CMPX here, a VCC branch there. - Checked, no finding: - The chain form needs an arm with no else arm (`!shape.else_begin`), so the inverse never reads the narrowed EXEC. The second visit of the join address is backed by the `outlives its enclosing arm` refusal. - Prefix and region writes to the copy are refused, in the prefix by `writes_saved` and in the region at the arm close. A nested SAVEEXEC in the prefix fails the match and stays at `depends on EXEC`. - The copy registers join the parent's `then_writes`, so after the outer join a chain copy that was never restored reads as unbound, not as a stale lane mask. - It merges cleanly with main, #3707, #3712 and #3770. Tests: the 14 new `native_direct_mesh` cases check the IR order. The branch takes the compare, the region's select uses `arm AND compare`, and both joins come in order for the region and the chain forms. The refusals cover each match condition. These are IR checks only; no draw runs a region. CI ran `native_direct_mesh` in the `pr` preset at this head, green.
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!3782
No description provided.