Skip to content

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

Merged
R0Y00 merged 4 commits into
R0Y00:mainfrom
timbot103:shader/pixel-live-mask-kill
Dec 3, 2026
Merged

R0Y00 merged 4 commits into
R0Y00:mainfrom
timbot103:shader/pixel-live-mask-kill

Conversation

@timbot103

Copy link
Copy Markdown
Contributor

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

Summary

Lowers the dominant wave64 live-mask alpha-kill triple identified in #3829'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.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 #3814 (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 #3829 and #3834 (gfx1013_direct_graphics.inl), with #3828 and #3833 (the same three harness files, a third extension of startup_flat_param), and with #3826 (mesh86-pixel-execz.md). #3829 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.

@timbot103
timbot103 force-pushed the shader/pixel-live-mask-kill branch from 9519b14 to 7947b4e Compare December 2, 2026 12:35

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

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 shader: lower pixel alpha-test kills and coverage re-application #3829, 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
timbot103 marked this pull request as ready for review December 2, 2026 23:47
@timbot103

Copy link
Copy Markdown
Contributor Author

Marked Ready for review now that #3827 and #3829 have merged, keeping to 5 non-draft PRs per #3514. 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 #3833/#3835 fixture issue that does not involve this PR; the #3835 fix is coming.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reviewed fec8b3a. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants