shader: lower pixel alpha-test kills and coverage re-application #3829

Merged
timbot103 merged 2 commits from upstream-pr/3829 into main 2026-12-02 16:06:52 +00:00
timbot103 commented 2026-12-02 07:26:30 +00:00 (Migrated from github.com)

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


Lowers wave64 pixel alpha-test v_cmpx_* lane kills without a saved EXEC restore, post-interpolation coverage re-application (s_and_b64 exec, exec, sN in either operand order), and combined one-armed CMPX skips with coverage restore/re-application (items G1, G2, and W1 of #3814).

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

Summary

  • G1 (PixelLaneKills in src/gfx1013_direct_graphics.inl):
    • Recognizes an unclaimed wave64 pixel v_cmpx_* as a lane kill when the program is acyclic, no export precedes it, it dominates all code after it (no crossing branch or then_fallthroughs edge, no earlier s_endpgm), and all subsequent instructions are lane-local (no DPP/DPP8, LDS, quad compare, implicit-LOD sample, image store/atomic 0x08..0x1f, quadmask, s_wqm, lane/mbcnt/store/sendmsg/barrier ops, non-buffer_atomic_add atomics, EXEC/EXECZ reads outside recognized arm anchors, or non-narrowing EXEC writes outside restores from pairs saved strictly after the kill).
    • Lowers to dx.op.discard(!keep) in WQM, exact mode, or non-WQM, updating lane_alive (and covered / graphics_predicate when active) so covered_lane() explicitly ANDs in surviving lanes rather than relying on post-discard IsHelperLane.
    • Proves a following s_cbranch_execz skip (with only lane-local quiet ops between and no branch entering the span) to either a later instruction or a terminal EXP_NULL block (dropping EXP_NULL only when every branch targeting it is such a skip).
  • G2 (s_and_b64 exec, exec, sN & enter_exact):
    • Extracts shared exact-mode transition into enter_exact.
    • Accepts s_and_b64 exec, exec, sN (both operand orders) when sN is proven entry coverage (invariant_entry_masks or tag "0"): leaves WQM in the prologue or in the unique post-dominating branch-free tail (exact_tail, disabled on any backward branch or earlier s_endpgm), and acts as a no-op when already in exact mode or outside WQM.
  • W1 (one-armed CMPX skip + coverage restore/re-application):
    • Combines one-armed CMPX skips cleanly with G1 kills before or after and G2 coverage ANDs.
    • Extends pixel_readonly_arms so a one-armed CMPX skip whose restore is the entry coverage saved immediately before s_wqm_b64 exec, exec lowers its join via coverage_restores -> enter_exact.
  • tests/native_pixel_alpha_kill_check.py + tests/cmake/native_pixel_alpha_kill.cmake:
    • 16 accepted shapes covering G1, G2, W1, and their combinations (DXIL structural checks + 8x2 WARP and hardware GPU readback, each with negative wrong-reference mismatch controls, plus 2 all-lanes-killed draws).
    • 16 fail-closed refusal controls (prior export, DPP/quad-swizzle/EXEC-read/WQM after kill, pre-kill EXEC restore, branch into/around kill, class/clamped compare, unproven/clobbered coverage pair, coverage restore before branch, coverage AND inside uniform arm or after an early s_endpgm).

Verification

Host: Windows 11 (10.0.26200.9974), MSVC C++20 /W4 (zero new warnings), inbox WARP (10.0.26100.9818), NVIDIA GeForce RTX 5080 (32.0.16.2140).

  • Debug (dev) & Release (release):
    • native_pixel_alpha_kill_controls: passed in both configs (16 accepted + 16 refusals).
    • native_pixel_alpha_kill_warp: passed in both configs (WARP readback + wrong-reference mismatch controls + all-killed draws).
    • native_pixel_alpha_kill_hardware: passed in both configs (RTX 5080 readback + wrong-reference mismatch controls + all-killed draws).
    • Regression pass (17/17 in both Debug and Release): native_direct_container, native_pixel_dxil, native_graphics_wqm_{warp,hardware,ir}, native_graphics_vertex_vcc_join_{warp,hardware}, native_pixel_cmpx_{discard_warp,if_else_controls,if_else_warp}, native_pixel_compare_mask_{warp,hardware,container,ir}.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5601863927 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:26:30Z. --- Lowers wave64 pixel alpha-test `v_cmpx_*` lane kills without a saved EXEC restore, post-interpolation coverage re-application (`s_and_b64 exec, exec, sN` in either operand order), and combined one-armed CMPX skips with coverage restore/re-application (items **G1**, **G2**, and **W1** of #3814). Part of #3814. Refs #3640, #3641, #3703. ## Summary - **G1 (`PixelLaneKills` in `src/gfx1013_direct_graphics.inl`):** - Recognizes an unclaimed wave64 pixel `v_cmpx_*` as a lane kill when the program is acyclic, no export precedes it, it dominates all code after it (no crossing branch or `then_fallthroughs` edge, no earlier `s_endpgm`), and all subsequent instructions are lane-local (no DPP/DPP8, LDS, quad compare, implicit-LOD sample, image store/atomic `0x08..0x1f`, `quadmask`, `s_wqm`, lane/`mbcnt`/store/sendmsg/barrier ops, non-`buffer_atomic_add` atomics, `EXEC`/`EXECZ` reads outside recognized arm anchors, or non-narrowing `EXEC` writes outside restores from pairs saved strictly after the kill). - Lowers to `dx.op.discard(!keep)` in WQM, exact mode, or non-WQM, updating `lane_alive` (and `covered` / `graphics_predicate` when active) so `covered_lane()` explicitly ANDs in surviving lanes rather than relying on post-discard `IsHelperLane`. - Proves a following `s_cbranch_execz` skip (with only lane-local quiet ops between and no branch entering the span) to either a later instruction or a terminal `EXP_NULL` block (dropping `EXP_NULL` only when every branch targeting it is such a skip). - **G2 (`s_and_b64 exec, exec, sN` & `enter_exact`):** - Extracts shared exact-mode transition into `enter_exact`. - Accepts `s_and_b64 exec, exec, sN` (both operand orders) when `sN` is proven entry coverage (`invariant_entry_masks` or tag `"0"`): leaves WQM in the prologue or in the unique post-dominating branch-free tail (`exact_tail`, disabled on any backward branch or earlier `s_endpgm`), and acts as a no-op when already in exact mode or outside WQM. - **W1 (one-armed CMPX skip + coverage restore/re-application):** - Combines one-armed CMPX skips cleanly with G1 kills before or after and G2 coverage ANDs. - Extends `pixel_readonly_arms` so a one-armed CMPX skip whose restore is the entry coverage saved immediately before `s_wqm_b64 exec, exec` lowers its join via `coverage_restores` -> `enter_exact`. - **`tests/native_pixel_alpha_kill_check.py` + `tests/cmake/native_pixel_alpha_kill.cmake`:** - 16 accepted shapes covering G1, G2, W1, and their combinations (DXIL structural checks + 8x2 WARP and hardware GPU readback, each with negative wrong-reference mismatch controls, plus 2 all-lanes-killed draws). - 16 fail-closed refusal controls (prior export, DPP/quad-swizzle/EXEC-read/WQM after kill, pre-kill EXEC restore, branch into/around kill, class/clamped compare, unproven/clobbered coverage pair, coverage restore before branch, coverage AND inside uniform arm or after an early `s_endpgm`). ## Verification Host: Windows 11 (`10.0.26200.9974`), MSVC C++20 `/W4` (zero new warnings), inbox WARP (`10.0.26100.9818`), NVIDIA GeForce RTX 5080 (`32.0.16.2140`). - **Debug (`dev`) & Release (`release`):** - `native_pixel_alpha_kill_controls`: passed in both configs (16 accepted + 16 refusals). - `native_pixel_alpha_kill_warp`: passed in both configs (WARP readback + wrong-reference mismatch controls + all-killed draws). - `native_pixel_alpha_kill_hardware`: passed in both configs (RTX 5080 readback + wrong-reference mismatch controls + all-killed draws). - Regression pass (17/17 in both Debug and Release): `native_direct_container`, `native_pixel_dxil`, `native_graphics_wqm_{warp,hardware,ir}`, `native_graphics_vertex_vcc_join_{warp,hardware}`, `native_pixel_cmpx_{discard_warp,if_else_controls,if_else_warp}`, `native_pixel_compare_mask_{warp,hardware,container,ir}`. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, `git diff --check origin/main..HEAD`: all clean.
lukaslw-lab commented 2026-12-02 07:35:03 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

Verdict: approve. The discard matches the guest kill wherever lane_local_after accepts the code after it. Every shape it ignores keeps its old refusal. No MUST.

  • SHOULD No fixture pins the one store-like form allowed after a kill. lane_local_after accepts buffer_atomic_add (gfx1013_direct_graphics.inl:1508). Killed lanes skip it only because covered_lane() now ANDs lane_alive (:2287), which the atomic uses as its predicate (:3193). One draw with a kill and then an atomic add, checking the count of surviving pixels only, would keep that from silently regressing.
  • SHOULD No docs update. G1, G2 and W1 change what docs/experiments/mesh86-pixel-execz.md says about CMPX and coverage handling.
  • SHOULD No measured stage count. 566 / 86 / ≈620 is the #3814 shape tally. A ps86 census on f365f125 before and after would give the real gain. This can come in a follow-up.
  • NIT CI runs only _controls: native_pixel_alpha_kill_warp is not in the pr preset filter.
  • NIT #3826, #3828 and this PR all change pixel_readonly_arms. Two of them will need a rebase.
  • Checked, no finding:
    • Killed lanes cannot come back. A restore of a pair saved before the kill is refused (saved_after), and so is an arm anchored before the kill, because the backward anchor search stops at the kill's EXEC write.
    • With implicit-LOD samples, DPP, LDS, quad and lane ops refused, nothing reads a discarded lane. The no-op EXECZ skips and the dropped EXP_NULL block cut only code that runs with EXEC = 0.
    • exact_tail lies after every branch and then_fallthroughs edge, and is disabled by a backward branch or an early s_endpgm.

Tests: _controls compiles 16 shapes and 16 refusals (e.g. a restore that revives killed lanes). _warp/_hardware read back with wrong-reference and all-killed controls. CI runs _controls only (in progress at review time).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146482699 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829#pullrequestreview-6146482699). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:35:03Z. **Review:** APPROVED --- Reviewed `b24a8d8a` by reading the diff; not built or run. **Verdict: approve.** The discard matches the guest kill wherever `lane_local_after` accepts the code after it. Every shape it ignores keeps its old refusal. No MUST. - **SHOULD** No fixture pins the one store-like form allowed after a kill. `lane_local_after` accepts `buffer_atomic_add` (`gfx1013_direct_graphics.inl:1508`). Killed lanes skip it only because `covered_lane()` now ANDs `lane_alive` (`:2287`), which the atomic uses as its predicate (`:3193`). One draw with a kill and then an atomic add, checking the count of surviving pixels only, would keep that from silently regressing. - **SHOULD** No docs update. G1, G2 and W1 change what `docs/experiments/mesh86-pixel-execz.md` says about CMPX and coverage handling. - **SHOULD** No measured stage count. 566 / 86 / ≈620 is the #3814 shape tally. A `ps86` census on `f365f125` before and after would give the real gain. This can come in a follow-up. - **NIT** CI runs only `_controls`: `native_pixel_alpha_kill_warp` is not in the `pr` preset filter. - **NIT** #3826, #3828 and this PR all change `pixel_readonly_arms`. Two of them will need a rebase. - Checked, no finding: - Killed lanes cannot come back. A restore of a pair saved before the kill is refused (`saved_after`), and so is an arm anchored before the kill, because the backward anchor search stops at the kill's EXEC write. - With implicit-LOD samples, DPP, LDS, quad and lane ops refused, nothing reads a discarded lane. The no-op EXECZ skips and the dropped EXP_NULL block cut only code that runs with EXEC = 0. - `exact_tail` lies after every branch and `then_fallthroughs` edge, and is disabled by a backward branch or an early `s_endpgm`. Tests: `_controls` compiles 16 shapes and 16 refusals (e.g. a restore that revives killed lanes). `_warp`/`_hardware` read back with wrong-reference and all-killed controls. CI runs `_controls` only (in progress at review time).
lukaslw-lab commented 2026-12-02 08:17:28 +00:00 (Migrated from github.com)

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


Census follow-up for the SHOULD in my review: on the #3814 capture, this PR does not yet move the G1 stages, because their kill uses a live-mask form that lane_local_after refuses.

Build Pixel stages translated graphics wave or control-flow instruction
f365f125 + #3825 272 728
same + #3826, #3828, #3829 (and the mesh PRs) 272 648

Same capture and method as #3814. 6,436 distinct stages, run through compile_dxil gfx1013-mesh86-ps. Counts only.

In a 120-stage sample of the 648 that remain, 106 still stop at the v_cmpx, and 105 of those have this shape (registers normalized):

s_mov_b64 sK, exec
...                                    ; alpha value, e.g. v_mul_legacy_f32 / v_fract_f32
v_cmpx_lt_f32 sA, vX                   ; kill condition
s_andn2_b64 sK, sK, exec               ; EXEC = lanes to kill; drop them from live sK
s_cbranch_scc0 L                       ; no live lane left
s_and_b64 exec, sC, sK
exp mrtz ... done ; s_endpgm
L: s_mov_b64 exec, sK ; exp null done ; s_endpgm
  • Here the v_cmpx leaves EXEC holding the lanes to kill, not keep. s_andn2_b64 removes them from the live mask sK, scc0 exits when no lane lives, and s_and_b64 exec, sC, sK restores coverage AND live. Per invocation: keep = saved bit AND NOT compare, then discard where the compare holds. The fixtures' keep model (no live mask) would invert this shape.
  • lane_local_after refuses the EXEC read in s_andn2_b64, so these stay refused, which is the safe outcome. Accepting this triple, with sK the save made before the v_cmpx, would cover G1 + G2 for these stages.
  • I measured this on a local stack with #3826 and #3828 merged in (conflicts resolved locally), not on this PR alone. lane_local_after does not depend on those two PRs, so the result should be the same here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7339250916 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829#issuecomment-7339250916). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T08:17:28Z. --- Census follow-up for the SHOULD in my review: on the #3814 capture, this PR does not yet move the G1 stages, because their kill uses a live-mask form that `lane_local_after` refuses. | Build | Pixel stages translated | `graphics wave or control-flow instruction` | |---|---:|---:| | `f365f125` + #3825 | 272 | 728 | | same + #3826, #3828, #3829 (and the mesh PRs) | 272 | 648 | Same capture and method as #3814. 6,436 distinct stages, run through `compile_dxil gfx1013-mesh86-ps`. Counts only. In a 120-stage sample of the 648 that remain, 106 still stop at the `v_cmpx`, and 105 of those have this shape (registers normalized): ``` s_mov_b64 sK, exec ... ; alpha value, e.g. v_mul_legacy_f32 / v_fract_f32 v_cmpx_lt_f32 sA, vX ; kill condition s_andn2_b64 sK, sK, exec ; EXEC = lanes to kill; drop them from live sK s_cbranch_scc0 L ; no live lane left s_and_b64 exec, sC, sK exp mrtz ... done ; s_endpgm L: s_mov_b64 exec, sK ; exp null done ; s_endpgm ``` - Here the `v_cmpx` leaves EXEC holding the lanes to **kill**, not keep. `s_andn2_b64` removes them from the live mask `sK`, `scc0` exits when no lane lives, and `s_and_b64 exec, sC, sK` restores coverage AND live. Per invocation: keep = saved bit AND NOT compare, then discard where the compare holds. The fixtures' keep model (no live mask) would invert this shape. - `lane_local_after` refuses the EXEC read in `s_andn2_b64`, so these stay refused, which is the safe outcome. Accepting this triple, with `sK` the save made before the `v_cmpx`, would cover G1 + G2 for these stages. - I measured this on a local stack with #3826 and #3828 merged in (conflicts resolved locally), not on this PR alone. `lane_local_after` does not depend on those two PRs, so the result should be the same here. AI-assisted.
timbot103 commented 2026-12-02 08:33:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T08:33:19Z.


@lukaslw-lab Thanks for the approval and the exact census breakdown of the live-mask G1+G2 kill form (s_mov_b64 sK, exec -> v_cmpx_* -> s_andn2_b64 sK, sK, exec -> s_cbranch_scc0 L -> s_and_b64 exec, sC, sK) — that is super actionable!

To keep this approved PR clean and ready to land without restarting review, I will follow up in a dedicated PR (staged as Draft under #3514) adding:

  • The live-mask v_cmpx_* + s_andn2_b64 + s_cbranch_scc0 + s_and_b64 exec, sC, sK kill/coverage-restore lowering (with keep = saved & ~cmp and discard where cmp holds)
  • An atomic-after-kill GPU readback draw fixture pinning killed lanes skipping buffer_atomic_add
  • The docs/experiments/mesh86-pixel-execz.md update
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7339609607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829#issuecomment-7339609607). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T08:33:19Z. --- @lukaslw-lab Thanks for the approval and the exact census breakdown of the live-mask G1+G2 kill form (`s_mov_b64 sK, exec` -> `v_cmpx_*` -> `s_andn2_b64 sK, sK, exec` -> `s_cbranch_scc0 L` -> `s_and_b64 exec, sC, sK`) — that is super actionable! To keep this approved PR clean and ready to land without restarting review, I will follow up in a dedicated PR (staged as Draft under #3514) adding: - The live-mask `v_cmpx_*` + `s_andn2_b64` + `s_cbranch_scc0` + `s_and_b64 exec, sC, sK` kill/coverage-restore lowering (with keep = `saved & ~cmp` and discard where `cmp` holds) - An atomic-after-kill GPU readback draw fixture pinning killed lanes skipping `buffer_atomic_add` - The `docs/experiments/mesh86-pixel-execz.md` update
R0Y00 commented 2026-12-02 10:09:47 +00:00 (Migrated from github.com)

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

Review: COMMENTED


The reviewed revision now conflicts with main in the pixel mask state and one-arm matcher in src/gfx1013_direct_graphics.inl. Please preserve #3826's MaskOp/mask_inputs chain handling alongside the new coverage_restores path. After rebasing, please run the alpha-kill and native_pixel_saveexec_masks_ families together so the coverage change and the existing compound-mask cases both have a readback.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148737529 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829#pullrequestreview-6148737529). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T10:09:47Z. **Review:** COMMENTED --- The reviewed revision now conflicts with main in the pixel mask state and one-arm matcher in `src/gfx1013_direct_graphics.inl`. Please preserve #3826's `MaskOp`/`mask_inputs` chain handling alongside the new `coverage_restores` path. After rebasing, please run the alpha-kill and `native_pixel_saveexec_masks_` families together so the coverage change and the existing compound-mask cases both have a readback.
R0Y00 commented 2026-12-02 12:45:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:45:44Z.

Review: APPROVED


I re-reviewed da0d37ed on the current main base. The rebase keeps the compound MaskOp chain and saved-pair clobber check. The new coverage restore is limited to the one-arm path without merge_or, and the merge tree is clean.

On Windows 11 26300.9974 (SDK 10.0.26100), ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pixel_alpha_kill_|pixel_saveexec_masks_|pixel_cmpx_if_else_controls$|graphics_wqm_ir$)' verified all eight selected tests with zero skips. Alpha-kill and compound SAVEEXEC readbacks and their wrong-reference controls passed on WARP 10.0.26100.9818 and RTX 4060 Laptop driver 32.0.16.1656. The renderer requests the D3D12 debug layer and successful draws' debug status is captured internally rather than printed by these Python fixtures. The WQM test initially lacked native_pixel_ir_dump; it passed after building that target and rerunning the same exact head.

Required Windows CI still fails in native_direct_mesh with +0x34: unmapped graphics export, tracked by #3851. Please rerun after the latter lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6150976167 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3829#pullrequestreview-6150976167). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T12:45:44Z. **Review:** APPROVED --- I re-reviewed `da0d37ed` on the current main base. The rebase keeps the compound `MaskOp` chain and saved-pair clobber check. The new coverage restore is limited to the one-arm path without `merge_or`, and the merge tree is clean. On Windows 11 26300.9974 (SDK 10.0.26100), `ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pixel_alpha_kill_|pixel_saveexec_masks_|pixel_cmpx_if_else_controls$|graphics_wqm_ir$)'` verified all eight selected tests with zero skips. Alpha-kill and compound SAVEEXEC readbacks and their wrong-reference controls passed on WARP 10.0.26100.9818 and RTX 4060 Laptop driver 32.0.16.1656. The renderer requests the D3D12 debug layer and successful draws' debug status is captured internally rather than printed by these Python fixtures. The WQM test initially lacked `native_pixel_ir_dump`; it passed after building that target and rerunning the same exact head. Required Windows CI still fails in `native_direct_mesh` with `+0x34: unmapped graphics export`, tracked by #3851. Please rerun after the latter lands.
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!3829
No description provided.