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

Merged
timbot103 merged 1 commit from upstream-pr/3826 into main 2026-12-02 09:05:02 +00:00
timbot103 commented 2026-12-02 07:02:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T07:02:47Z.


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

Lowers claimed #3814 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5601559770 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3826). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:02:47Z. --- Part of #3814. Refs #3640, #3641, #3703. Lowers claimed #3814 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.
lukaslw-lab commented 2026-12-02 07:28:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T07:28:30Z.

Review: APPROVED


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 #3814 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146413079 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3826#pullrequestreview-6146413079). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:28:30Z. **Review:** APPROVED --- 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 #3814 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.
timbot103 commented 2026-12-02 07:34:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T07:34:52Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7338355720 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3826#issuecomment-7338355720). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:34:52Z. --- @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.
R0Y00 commented 2026-12-02 09:04:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T09:04:49Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6147649064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3826#pullrequestreview-6147649064). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T09:04:49Z. **Review:** APPROVED --- 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.
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!3826
No description provided.