shader: lower pixel live-mask alpha kills (Part of #3814) #3849

Manually merged
github merged 4 commits from github-bot/gh-3847 into gh-pr/3847/base 2026-12-03 00:49:28 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-02 08:58 UTC · original
timbot103:shader/pixel-live-mask-kill → main · +638 −13 · 10 files · 4 commits · merged 2026-12-03 00:44 UTC

Part of #3816 (follow-up to #3831's 2 Dec census breakdown).

Summary

Lowers the dominant wave64 live-mask alpha-kill triple identified in #3831's census follow-up (105 of 106 remaining G1 stages, ~566 real pixel stages):

s_mov_b64 sK, exec
...
v_cmpx_<p>_f32 ...                     ; EXEC = lanes to KILL
s_andn2_b64 sK, sK, exec               ; live sK = sK & ~EXEC
s_cbranch_scc0 L                       ; exit if no live lane left
s_and_b64 exec, sC, sK                 ; (or s_and_b64 exec, sK, sC, or s_mov_b64 exec, sK)
exp mrtz / mrt0..7 ... done ; s_endpgm
L: [s_mov_b64 exec, sK ;] exp null done ; s_endpgm
  • Preserves kill polarity (killed = cmp_result, dx.op.discard(killed), lane_alive = lane_alive & ~killed) and strictly rejects inverted s_andn2_b64 operand orders, overwritten/escaped live masks, and revived pre-kill masks.
  • Supports chained live-mask kills, both color (mrt0..7) and depth (mrtz) exports, WQM exact-coverage restoration (s_and_b64 exec, sC, sK with proven entry-coverage tag "0"), resets exact_after_wqm if a later chained kill restores a WQM live mask via s_mov_b64 exec, sK, and gates post-kill buffer_atomic_add through surviving lane_alive coverage.
  • Adds --startup-pixel-atomic to offscreen_check (without altering --startup-pixel-words) to verify real GPU atomic counters after kill, and updates docs/experiments/mesh86-pixel-execz.md + docs/experiments/native-pixel-live-mask-kill.md.

Verification

  • Built compile_dxil, offscreen_check, and native_pixel_ir_dump in Debug (dev) and Release (release) with zero new C++20 /W4 warnings on edited lines.
  • ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_live_mask_kill_controls$': passed (11 validated DXIL cases + 27 refusal controls).
  • Debug (dev) and Release (release): 7/7 passed (native_pixel_live_mask_kill|native_pixel_wqm|native_graphics_wqm|native_direct_container), zero skips, plus offscreen_check --self-test in both builds.
  • Real GPU readbacks on WARP (10.0.26100.9818) and NVIDIA GeForce RTX 5080 (32.0.16.2140) on Windows 11 (26200.9974): verified 126 color pixels (7×3 odd edges exercising WQM helper coverage), two atomic-after-kill counters matching surviving pixel count 12, and wrong-reference failures.
  • tests/bidi_controls_check.py, tests/docs_links_check.py, and git diff --check origin/main..HEAD passed.
  • Opened as Draft under #3514's 5-PR ready cap.
**@⁠timbot103** on GitHub · 2026-12-02 08:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847) `timbot103:shader/pixel-live-mask-kill` → `main` · +638 −13 · 10 files · 4 commits · merged 2026-12-03 00:44 UTC Part of #3816 (follow-up to #3831's 2 Dec census breakdown). ### Summary Lowers the dominant wave64 live-mask alpha-kill triple identified in #3831's census follow-up (105 of 106 remaining G1 stages, ~566 real pixel stages): ```asm s_mov_b64 sK, exec ... v_cmpx_<p>_f32 ... ; EXEC = lanes to KILL s_andn2_b64 sK, sK, exec ; live sK = sK & ~EXEC s_cbranch_scc0 L ; exit if no live lane left s_and_b64 exec, sC, sK ; (or s_and_b64 exec, sK, sC, or s_mov_b64 exec, sK) exp mrtz / mrt0..7 ... done ; s_endpgm L: [s_mov_b64 exec, sK ;] exp null done ; s_endpgm ``` - Preserves kill polarity (`killed = cmp_result`, `dx.op.discard(killed)`, `lane_alive = lane_alive & ~killed`) and strictly rejects inverted `s_andn2_b64` operand orders, overwritten/escaped live masks, and revived pre-kill masks. - Supports chained live-mask kills, both color (`mrt0..7`) and depth (`mrtz`) exports, WQM exact-coverage restoration (`s_and_b64 exec, sC, sK` with proven entry-coverage tag `"0"`), resets `exact_after_wqm` if a later chained kill restores a WQM live mask via `s_mov_b64 exec, sK`, and gates post-kill `buffer_atomic_add` through surviving `lane_alive` coverage. - Adds `--startup-pixel-atomic` to `offscreen_check` (without altering `--startup-pixel-words`) to verify real GPU atomic counters after kill, and updates `docs/experiments/mesh86-pixel-execz.md` + `docs/experiments/native-pixel-live-mask-kill.md`. ### Verification - Built `compile_dxil`, `offscreen_check`, and `native_pixel_ir_dump` in Debug (`dev`) and Release (`release`) with zero new C++20 `/W4` warnings on edited lines. - `ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_live_mask_kill_controls$'`: passed (**11 validated DXIL cases + 27 refusal controls**). - Debug (`dev`) and Release (`release`): 7/7 passed (`native_pixel_live_mask_kill|native_pixel_wqm|native_graphics_wqm|native_direct_container`), zero skips, plus `offscreen_check --self-test` in both builds. - Real GPU readbacks on WARP (`10.0.26100.9818`) and NVIDIA GeForce RTX 5080 (`32.0.16.2140`) on Windows 11 (`26200.9974`): verified 126 color pixels (7×3 odd edges exercising WQM helper coverage), two atomic-after-kill counters matching surviving pixel count `12`, and wrong-reference failures. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, and `git diff --check origin/main..HEAD` passed. - Opened as Draft under `#3514`'s 5-PR ready cap.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 09:03:33 +00:00
Author
Owner

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

Reviewed 9074d442 (draft) by reading the diff and running an offline pixel census of this PR alone; not otherwise built or run.

Verdict: approve. The kill polarity is right (the v_cmpx selects lanes to kill), the live mask stays one lane bit, and everything after the kill is lane-local. No MUST.

Census, f365f125 + this PR alone, same capture as #3816 (6,436 pixel stages): 272 → 546 translate (+274), none lost, no validation failures. 274 stages leave graphics wave or control-flow instruction, and 2 move to unsupported live-mask kill suffix.

  • NIT This conflicts with #3831 and #3836 (gfx1013_direct_graphics.inl), with #3830 and #3835 (the same three harness files, a third extension of startup_flat_param), and with #3828 (mesh86-pixel-execz.md). #3831 also adds its own lane_alive and covered_lane() change, so the two PRs need one shared notion of "alive" when they meet.
  • Checked, no finding:
    • Polarity (gfx1013_direct_graphics.inl:2148): killed = cmp, discard(killed), lane_alive &= !killed. Here s_andn2_b64 sK, sK, exec is only a filter (its pair and SCC are cleared), and inverted operand orders are rejected in find.
    • Coverage: lane_alive starts as !IsHelperLane at the save (:2138). covered_lane() returns it afterwards (:2112), so the exact predicate and the post-kill buffer_atomic_add both drop killed lanes. s_and_b64 exec, sC, sK needs sC tagged as entry coverage. s_mov_b64 exec, sK after a WQM save keeps whole-quad mode, and the suffix must then be lane-local (:2177).
    • Shape (gfx1013_graphics_wqm.inl:41): the first branch is the scc0 guard to the EXP_NULL tail, there is no export or s_endpgm before the kill, the live pair is not clobbered, and the final group is exports with DONE only on the last. The skips and the null tail are removed only when the whole shape matches. The suffix (local_tail) allows only loads, explicit-LOD images and lane-local ALU, so nothing reads a discarded lane.

Tests: _controls (11 cases, 27 refusals) is in the pr filter. The color and atomic-after-kill draws ran only locally.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 09:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847#pullrequestreview-6148152243) · **approved these changes** Reviewed `9074d442` (draft) by reading the diff and running an offline pixel census of this PR alone; not otherwise built or run. **Verdict: approve.** The kill polarity is right (the `v_cmpx` selects lanes to kill), the live mask stays one lane bit, and everything after the kill is lane-local. No MUST. Census, `f365f125` + this PR alone, same capture as #3816 (6,436 pixel stages): **272 → 546 translate (+274), none lost**, no validation failures. 274 stages leave `graphics wave or control-flow instruction`, and 2 move to `unsupported live-mask kill suffix`. - **NIT** This conflicts with #3831 and #3836 (`gfx1013_direct_graphics.inl`), with #3830 and #3835 (the same three harness files, a third extension of `startup_flat_param`), and with #3828 (`mesh86-pixel-execz.md`). #3831 also adds its own `lane_alive` and `covered_lane()` change, so the two PRs need one shared notion of "alive" when they meet. - Checked, no finding: - Polarity (`gfx1013_direct_graphics.inl:2148`): `killed = cmp`, `discard(killed)`, `lane_alive &= !killed`. Here `s_andn2_b64 sK, sK, exec` is only a filter (its pair and SCC are cleared), and inverted operand orders are rejected in `find`. - Coverage: `lane_alive` starts as `!IsHelperLane` at the save (`:2138`). `covered_lane()` returns it afterwards (`:2112`), so the exact predicate and the post-kill `buffer_atomic_add` both drop killed lanes. `s_and_b64 exec, sC, sK` needs `sC` tagged as entry coverage. `s_mov_b64 exec, sK` after a WQM save keeps whole-quad mode, and the suffix must then be lane-local (`:2177`). - Shape (`gfx1013_graphics_wqm.inl:41`): the first branch is the `scc0` guard to the EXP_NULL tail, there is no export or `s_endpgm` before the kill, the live pair is not clobbered, and the final group is exports with DONE only on the last. The skips and the null tail are removed only when the whole shape matches. The suffix (`local_tail`) allows only loads, explicit-LOD images and lane-local ALU, so nothing reads a discarded lane. Tests: `_controls` (11 cases, 27 refusals) is in the `pr` filter. The color and atomic-after-kill draws ran only locally.
Resolve conflicts with upstream main e143824c:
- docs/experiments/mesh86-pixel-execz.md (#3826): keep both the SAVEEXEC lane-mask expression notes and the live-mask kill notes.
- tests/desktop_gpu.h, tests/offscreen_check.cpp, tests/startup_flat_param.cpp (#3828): combine the optional root SRV parameter at t0 with the optional pixel atomic counter UAV table at u0, assign distinct root slots when either or both are present, and keep both --startup-pixel-words (optional 6th SRV words arg) and --startup-pixel-atomic in kOperations.
github-bot force-pushed github-bot/gh-3847 from 9519b14b8d to 7947b4e9e0 2026-12-02 12:37:36 +00:00 Compare
Author
Owner

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

Re-review on 7947b4e9 (rebased on 5770f14e, filters now clear compare masks and SCC, stale-compare-mask control).

Verdict: approve. It now conflicts with main and needs a rebase.

Census, same capture and method as before (6,436 distinct pixel stages), main 5770f14e vs this head:

Stages
Translate, main / with this PR 272 / 546
Gained (all from graphics wave or control-flow instruction) 274
Lost / first refusal moved 0 / 2 (graphics branch on a wave mask → unsupported live-mask kill suffix)

Same result as the earlier head: this doubles the translating pixel stages on this capture.

Checked:

  • find accepts only the documented shape: the reaching s_mov_b64 sK, exec save, then per guard v_cmpx_*_f32 → s_andn2_b64 sK, sK, exec → s_cbranch_scc0 to the shared dead tail → an AND/MOV restore. Any other branch, export or clobber of sK/EXEC returns without a match.
  • A filter now drops both halves of sK, its compare-mask entries and SCC, so a later v_cndmask on that pair refuses (unproven graphics CNDMASK source).
  • A restore from a pair other than sK needs the saved exact entry coverage, both in find (reaching s_mov_b64 sC, exec) and at emission (tag 0).
  • With WQM helper lanes still live, the suffix allows only local ALU and the final exports. Loads and the raw atomic add need exact coverage, and the atomic is predicated on the surviving coverage bit.

AI-assisted.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 20:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847#pullrequestreview-6158351893) · **approved these changes** Re-review on `7947b4e9` (rebased on `5770f14e`, filters now clear compare masks and SCC, `stale-compare-mask` control). **Verdict: approve.** It now conflicts with main and needs a rebase. Census, same capture and method as before (6,436 distinct pixel stages), main `5770f14e` vs this head: | | Stages | |---|---:| | Translate, main / with this PR | 272 / 546 | | Gained (all from `graphics wave or control-flow instruction`) | 274 | | Lost / first refusal moved | 0 / 2 (`graphics branch on a wave mask` → `unsupported live-mask kill suffix`) | Same result as the earlier head: this doubles the translating pixel stages on this capture. Checked: - `find` accepts only the documented shape: the reaching `s_mov_b64 sK, exec` save, then per guard `v_cmpx_*_f32` → `s_andn2_b64 sK, sK, exec` → `s_cbranch_scc0` to the shared dead tail → an AND/MOV restore. Any other branch, export or clobber of `sK`/EXEC returns without a match. - A filter now drops both halves of `sK`, its compare-mask entries and SCC, so a later `v_cndmask` on that pair refuses (`unproven graphics CNDMASK source`). - A restore from a pair other than `sK` needs the saved exact entry coverage, both in `find` (reaching `s_mov_b64 sC, exec`) and at emission (tag `0`). - With WQM helper lanes still live, the suffix allows only local ALU and the final exports. Loads and the raw atomic add need exact coverage, and the atomic is predicated on the surviving coverage bit. AI-assisted.
A live-mask save already snapshots raster coverage. Reuse that SSA value as each kill narrows it, so atomic guards use the surviving coverage directly. Keep the helper check for unsaved alpha-test kills, whose keep bits do not include raster coverage.

Exercise chained kills with atomic and depth readbacks, including a zero-survivor counter.
The native compute pack refusal fixture compiles a C++17 copy of the shared frontend. The preceding v_cmpx_ prefix match guarantees enough characters for the suffix check.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 23:20 UTC · original

Merged main (67862ee4) into this branch (aa3f2f32); the reviewed commit 7947b4e9 is unchanged. The merge combines the shared kill state with main's exact-mode tracking.

  • fc611e85 fixes an interaction with #3831, which is now on main. After the merge, native_pixel_live_mask_kill_controls failed: the atomic guard queried helper status again after the discard, even though the saved live mask already carries raster coverage. The fix reuses the saved mask after each kill. It keeps main's helper check for alpha-test kills that have no saved mask.
  • fec8b3aa replaces string_view::ends_with. native_compute_pack_refusal_check builds the frontend as C++17, which main CI compiles but PR CI does not, so this would otherwise have broken main's full build after merging.

GPU results:

  • WARP and the RTX 5080 both returned atomic counts of 12, 6, 0 and 12 in Debug and Release.
  • The chained WQM depth draw matched all 1,024 pixels. The reference that omits the second kill differed on 64 pixels, as expected.

Tests, Windows 11 26200 with RTX 5080 and WARP. The filter was native_pixel_|native_graphics_|native_direct_container plus this PR's own tests. There were 0 failures and 0 skips, with 15 WARP and 12 RTX 5080 tests per configuration. A full Debug build of every target, including the C++17 native_compute_pack_refusal_check, succeeded.

  • Debug passed 41/41 and Release 41/41. The PR preset passed 1/1, and offscreen_capability_table_self_test passed.
**@⁠timbot103** on GitHub · 2026-12-02 23:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847#issuecomment-7361878679) Merged `main` (`67862ee4`) into this branch (`aa3f2f32`); the reviewed commit `7947b4e9` is unchanged. The merge combines the shared kill state with main's exact-mode tracking. - `fc611e85` fixes an interaction with #3831, which is now on main. After the merge, `native_pixel_live_mask_kill_controls` failed: the atomic guard queried helper status again after the discard, even though the saved live mask already carries raster coverage. The fix reuses the saved mask after each kill. It keeps main's helper check for alpha-test kills that have no saved mask. - `fec8b3aa` replaces `string_view::ends_with`. `native_compute_pack_refusal_check` builds the frontend as C++17, which main CI compiles but PR CI does not, so this would otherwise have broken main's full build after merging. GPU results: - WARP and the RTX 5080 both returned atomic counts of 12, 6, 0 and 12 in Debug and Release. - The chained WQM depth draw matched all 1,024 pixels. The reference that omits the second kill differed on 64 pixels, as expected. Tests, Windows 11 26200 with RTX 5080 and WARP. The filter was `native_pixel_|native_graphics_|native_direct_container` plus this PR's own tests. There were 0 failures and 0 skips, with 15 WARP and 12 RTX 5080 tests per configuration. A full Debug build of every target, including the C++17 `native_compute_pack_refusal_check`, succeeded. - Debug passed 41/41 and Release 41/41. The PR preset passed 1/1, and `offscreen_capability_table_self_test` passed.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 23:47 UTC · original

Marked Ready for review now that #3829 and #3831 have merged, keeping to 5 non-draft PRs per #3516. CI is green at this head. All 17 open PRs from this batch were also merged together onto main c42b7ce3. That combined tree passes a full build, and the only problems it showed were pre-existing main flakes plus one #3835/#3835 fixture issue that does not involve this PR; the #3837 fix is coming.

**@⁠timbot103** on GitHub · 2026-12-02 23:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847#issuecomment-7362426281) Marked Ready for review now that #3829 and #3831 have merged, keeping to 5 non-draft PRs per #3516. CI is green at this head. All 17 open PRs from this batch were also merged together onto main `c42b7ce3`. That combined tree passes a full build, and the only problems it showed were pre-existing main flakes plus one #3835/#3835 fixture issue that does not involve this PR; the #3837 fix is coming.
github-bot changed target branch from main to gh-pr/3847/base 2026-12-03 00:49:25 +00:00
github manually merged commit fec8b3aa3d into gh-pr/3847/base 2026-12-03 00:49:28 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 00:44 UTC · original · approved these changes

Independently reviewed fec8b3aa. The live-mask proof checks reaching coverage saves, CMPX/filter polarity and exact coverage for atomic side effects. MSVC Debug, Windows build 26300: ctest --preset dev --no-tests=error -j 1 -R "^(native_pixel_live_mask_kill_(controls|warp|hardware)|native_graphics_wqm_(ir|warp|hardware))$" passed 6/6. WARP and RTX 4060 Laptop (616.56), debug layer enabled, each matched 126 color pixels, 1,024 depth pixels and four atomic counts, with three wrong-reference controls caught. Permitting the reversed filter negated the reversed control. The restored head passed.

**@⁠R0Y00** on GitHub · 2026-12-03 00:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3847#pullrequestreview-6161703624) · **approved these changes** Independently reviewed fec8b3aa. The live-mask proof checks reaching coverage saves, CMPX/filter polarity and exact coverage for atomic side effects. MSVC Debug, Windows build 26300: ctest --preset dev --no-tests=error -j 1 -R "^(native_pixel_live_mask_kill_(controls|warp|hardware)|native_graphics_wqm_(ir|warp|hardware))$" passed 6/6. WARP and RTX 4060 Laptop (616.56), debug layer enabled, each matched 126 color pixels, 1,024 depth pixels and four atomic counts, with three wrong-reference controls caught. Permitting the reversed filter negated the reversed control. The restored head passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.