shader: lower pixel SAVEEXEC lane-mask expressions (Part of #3814) #3828

Manually merged
github merged 1 commit from github-bot/gh-3826 into gh-pr/3826/base 2026-12-02 09:10:03 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-02 07:02 UTC · original
timbot103:shader/pixel-saveexec-mask-exprs → main · +372 −21 · 4 files · 1 commits · merged 2026-12-02 09:05 UTC

Part of #3816. Refs #3642, #3643, #3705.

Lowers claimed #3816 pixel-stage items W3 (~370 stages) and W4 (~260 stages) in src/gfx1013_direct_graphics.inl.

Summary

  • Replaces the narrow single v_cmp_* sM; s_and_b64 sM, vcc, sM recognizer in pixel_readonly_arms with a recursive single-block proof (mask_source + straight_mask_chain) feeding s_and_saveexec_b64 sP, sN (both one-armed skips and two-armed THEN/ELSE arms):
    • W3 ("if not"): s_xor_b64 with inline -1 (193) on either operand, and s_not_b64, from vcc (106) or an SGPR compare pair.
    • W4 (combine): s_and_b64, s_or_b64, and s_andn2_b64 (S0 & ~S1, operand order preserved) combining two proven lane masks in either operand order, writing either an aliased operand or a fresh even SGPR pair, chained up to depth 8.
    • Also accepts a direct SGPR compare pair and s_and_saveexec_b64 s[6:7], s[6:7] (saving parent EXEC over the mask pair).
  • Fail-closed guards & intentional tightening:
    • Every leaf must trace back to a plain v_cmp_* (no class, SDWA, omod, clamp, DPP, or DPP8) within the same straight-line run (no branch, branch target, EXEC write/*exec*, v_div_scale, s_*pc_b64, or s_endpgm between earliest definition and s_and_saveexec_b64). (Note: VCC operands in these expressions are now strictly proven back to a plain v_cmp_* in the same straight-line run rather than accepting arbitrary reaching VCC.)
    • Strictly refuses s_xor_b64 with 1, a 32-bit literal, or -1 on both operands; refuses odd pairs, vcc_hi, copied (s_mov_b64), unproven, or half-overwritten pairs.
    • Clears the numeric SGPR pair and SCC at each mask operation so numeric reads after the expression fail closed.

Verification (source-built fixtures only)

Environment: Windows 11 (26200.9974), MSVC 19.44 (C++20 /W4, zero new warnings), Ninja, Windows SDK 10.0.26100.0, D3D12 debug layer unavailable.

  • New test (tests/native_pixel_saveexec_masks_check.py, tests/cmake/native_pixel_saveexec_masks.cmake) — Debug (dev) & Release (release):
    • native_pixel_saveexec_masks_controls: 24 accepted shapes emit branch+merge DXIL with no wave ops; all 19 refusal controls refused.
    • native_pixel_saveexec_masks_warp (Microsoft Basic Render Driver 10.0.26100.9818): all 24 draws match; all inverted, operand-swapped, and single-arm negative references fail as expected.
    • native_pixel_saveexec_masks_hardware (NVIDIA GeForce RTX 5080 32.0.16.2140): all 24 draws match (executed on GPU, not skipped).
    • Mutation check: swapping s_andn2_b64 operands in the emitter failed WARP readback (8/16 pixels differed), confirming the GPU fixture pins operand order.
  • Regression set — 25/25 passed in both Debug and Release (native_direct_container, native_direct_mesh, native_pixel_dxil, native_pixel_cmpx_if_else_{controls,warp}, native_pixel_cmpx_discard_warp, native_pixel_compare_mask_{warp,hardware,container}, native_graphics_*).
  • git diff --check origin/main..HEAD clean.

AI-assisted.

**@⁠timbot103** on GitHub · 2026-12-02 07:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3826) `timbot103:shader/pixel-saveexec-mask-exprs` → `main` · +372 −21 · 4 files · 1 commits · merged 2026-12-02 09:05 UTC Part of #3816. Refs #3642, #3643, #3705. Lowers claimed #3816 pixel-stage items **W3** (~370 stages) and **W4** (~260 stages) in `src/gfx1013_direct_graphics.inl`. ### Summary - Replaces the narrow single `v_cmp_* sM; s_and_b64 sM, vcc, sM` recognizer in `pixel_readonly_arms` with a recursive single-block proof (`mask_source` + `straight_mask_chain`) feeding `s_and_saveexec_b64 sP, sN` (both one-armed skips and two-armed THEN/ELSE arms): - **W3 ("if not"):** `s_xor_b64` with inline `-1` (`193`) on either operand, and `s_not_b64`, from `vcc` (`106`) or an SGPR compare pair. - **W4 (combine):** `s_and_b64`, `s_or_b64`, and `s_andn2_b64` (`S0 & ~S1`, operand order preserved) combining two proven lane masks in either operand order, writing either an aliased operand or a fresh even SGPR pair, chained up to depth 8. - Also accepts a direct SGPR compare pair and `s_and_saveexec_b64 s[6:7], s[6:7]` (saving parent EXEC over the mask pair). - **Fail-closed guards & intentional tightening:** - Every leaf must trace back to a plain `v_cmp_*` (no `class`, SDWA, omod, clamp, DPP, or DPP8) within the same straight-line run (no branch, branch target, EXEC write/`*exec*`, `v_div_scale`, `s_*pc_b64`, or `s_endpgm` between earliest definition and `s_and_saveexec_b64`). *(Note: VCC operands in these expressions are now strictly proven back to a plain `v_cmp_*` in the same straight-line run rather than accepting arbitrary reaching VCC.)* - Strictly refuses `s_xor_b64` with `1`, a 32-bit literal, or `-1` on both operands; refuses odd pairs, `vcc_hi`, copied (`s_mov_b64`), unproven, or half-overwritten pairs. - Clears the numeric SGPR pair and SCC at each mask operation so numeric reads after the expression fail closed. ### Verification (source-built fixtures only) Environment: Windows 11 (`26200.9974`), MSVC `19.44` (C++20 `/W4`, zero new warnings), Ninja, Windows SDK `10.0.26100.0`, D3D12 debug layer unavailable. - **New test (`tests/native_pixel_saveexec_masks_check.py`, `tests/cmake/native_pixel_saveexec_masks.cmake`) — Debug (`dev`) & Release (`release`):** - `native_pixel_saveexec_masks_controls`: 24 accepted shapes emit branch+merge DXIL with no wave ops; all 19 refusal controls refused. - `native_pixel_saveexec_masks_warp` (Microsoft Basic Render Driver `10.0.26100.9818`): all 24 draws match; all inverted, operand-swapped, and single-arm negative references fail as expected. - `native_pixel_saveexec_masks_hardware` (NVIDIA GeForce RTX 5080 `32.0.16.2140`): all 24 draws match (executed on GPU, not skipped). - Mutation check: swapping `s_andn2_b64` operands in the emitter failed WARP readback (8/16 pixels differed), confirming the GPU fixture pins operand order. - **Regression set — 25/25 passed in both Debug and Release** (`native_direct_container`, `native_direct_mesh`, `native_pixel_dxil`, `native_pixel_cmpx_if_else_{controls,warp}`, `native_pixel_cmpx_discard_warp`, `native_pixel_compare_mask_{warp,hardware,container}`, `native_graphics_*`). - `git diff --check origin/main..HEAD` clean. AI-assisted.
A wave64 pixel s_and_saveexec_b64 that opens a read-only EXECZ arm (one
arm or THEN/ELSE) may now take its mask from a lane-mask expression:
s_xor_b64 with inline -1 or s_not_b64 of VCC or a compare pair, and
s_and_b64, s_or_b64 and s_andn2_b64 (S0 & ~S1, order kept) of two such
masks, in either operand order, aliased or to a fresh even pair, and
chained. Each operand must reach back to a plain v_cmp_* in the same
straight-line run, with no branch, branch target or EXEC write in it.
Each pixel branches on its own bit; the numeric pairs and SCC stay
unavailable. This replaces the single v_cmp/s_and_b64 VCC shape.

XOR with 1 or a 32-bit literal, odd pairs, VCC_HI, unproven, copied or
overwritten pairs, class compares, and control flow or EXEC writes
inside the run keep the refusal. The new check draws every accepted
shape on WARP and a physical GPU against the reference and its
complement, operand-swapped and single-arm references.

Part of #3814. Refs #3640, #3641, #3703.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:05:30 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 07:28 UTC · original · approved these changes

Reviewed 0eb75d25 by reading the diff; not built or run.

Verdict: approve. The mask expression lowering matches the guest semantics per invocation, and every gap I looked for fails closed. No MUST.

  • SHOULD No measured stage count. The ~370 / ~260 figures come from the #3816 shape tally (branch site only), not from translating the stages. The new mask_source also tightens the old s_and_b64 sM, vcc, sM path: VCC must now reach a plain v_cmp_* in the same run, where it used to be read as-is. A ps86 census before and after on f365f125 would show the real gain and that no stage which translated on main is now refused. This can come in a follow-up.
  • NIT CI runs only _controls. native_pixel_saveexec_masks_warp is not in the pr preset filter, so the 24 draws and the operand-order references ran only locally.
  • Checked, no finding:
    • ~, - (a & ~b, operand order kept) and |/& on the 0/1 bits (gfx1013_direct_graphics.inl:2457) match s_not_b64, s_xor_b64 -1, s_andn2_b64, s_or_b64 and s_and_b64 for the invocation's own lane. Only inline -1 (193) counts as an inversion, so a 32-bit literal is refused because it is not a pair register.
    • The straight-run guard catches v_cmpx_*: the decoder sets their dst to 126, and writes_pair(op,126) covers that. v_readlane/v_readfirstlane and SMEM partial writes into the pair are caught by scalar_width, and VOP3B v_div_scale explicitly.
    • Each mask op nulls its numeric pair and SCC (:2467), so any later numeric read of an intermediate pair fails closed.

Tests: _controls compiles 24 shapes, checks the branch and merge DXIL, and refuses 19 controls. It reaches mask_source, straight_mask_chain and the new lowering. _warp/_hardware check each pixel's arm against inverted and operand-swapped references. CI ran _controls (green); WARP and hardware ran only in the author's local runs.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 07:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3826#pullrequestreview-6146413079) · **approved these changes** Reviewed `0eb75d25` by reading the diff; not built or run. **Verdict: approve.** The mask expression lowering matches the guest semantics per invocation, and every gap I looked for fails closed. No MUST. - **SHOULD** No measured stage count. The ~370 / ~260 figures come from the #3816 shape tally (branch site only), not from translating the stages. The new `mask_source` also tightens the old `s_and_b64 sM, vcc, sM` path: VCC must now reach a plain `v_cmp_*` in the same run, where it used to be read as-is. A `ps86` census before and after on `f365f125` would show the real gain and that no stage which translated on main is now refused. This can come in a follow-up. - **NIT** CI runs only `_controls`. `native_pixel_saveexec_masks_warp` is not in the `pr` preset filter, so the 24 draws and the operand-order references ran only locally. - Checked, no finding: - `~`, `-` (`a & ~b`, operand order kept) and `|`/`&` on the 0/1 bits (`gfx1013_direct_graphics.inl:2457`) match `s_not_b64`, `s_xor_b64 -1`, `s_andn2_b64`, `s_or_b64` and `s_and_b64` for the invocation's own lane. Only inline `-1` (193) counts as an inversion, so a 32-bit literal is refused because it is not a pair register. - The straight-run guard catches `v_cmpx_*`: the decoder sets their `dst` to 126, and `writes_pair(op,126)` covers that. `v_readlane`/`v_readfirstlane` and SMEM partial writes into the pair are caught by `scalar_width`, and VOP3B `v_div_scale` explicitly. - Each mask op nulls its numeric pair and SCC (`:2467`), so any later numeric read of an intermediate pair fails closed. Tests: `_controls` compiles 24 shapes, checks the branch and merge DXIL, and refuses 19 controls. It reaches `mask_source`, `straight_mask_chain` and the new lowering. `_warp`/`_hardware` check each pixel's arm against inverted and operand-swapped references. CI ran `_controls` (green); WARP and hardware ran only in the author's local runs.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 07:34 UTC · original

@⁠lukaslw-lab Thanks for the thorough review and approval! Understood on the ps86 census before/after f365f125 to verify net stage gain and confirm no regression on the stricter VCC mask_source rule — happy to let that follow up separately.

**@⁠timbot103** on GitHub · 2026-12-02 07:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3826#issuecomment-7338355720) @⁠lukaslw-lab Thanks for the thorough review and approval! Understood on the `ps86` census before/after `f365f125` to verify net stage gain and confirm no regression on the stricter VCC `mask_source` rule — happy to let that follow up separately.
github-bot changed target branch from main to gh-pr/3826/base 2026-12-02 09:10:00 +00:00
github manually merged commit 0eb75d2547 into gh-pr/3826/base 2026-12-02 09:10:03 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 09:04 UTC · original · approved these changes

Independently built compile_dxil and offscreen_check and ran ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_saveexec_masks_(controls|warp|hardware)$' --output-on-failure. All three passed (75.47 s, no skips) at 0eb75d25 on Windows 11 26300.9974 Debug, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. All 24 positive draw cases per backend matched, and the fixture rejected the incorrect arm references. The offscreen harness enables the installed D3D12 debug layer.

**@⁠R0Y00** on GitHub · 2026-12-02 09:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3826#pullrequestreview-6147649064) · **approved these changes** Independently built `compile_dxil` and `offscreen_check` and ran `ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_saveexec_masks_(controls|warp|hardware)$' --output-on-failure`. All three passed (75.47 s, no skips) at `0eb75d25` on Windows 11 26300.9974 Debug, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. All 24 positive draw cases per backend matched, and the fixture rejected the incorrect arm references. The offscreen harness enables the installed D3D12 debug layer.
This discussion has been locked. Commenting is limited to contributors.
No description provided.