Repository navigation
gfx2hlsl: accept mask-preserving lane-mask writes in an execz block - #2723
Conversation
…ecz block phi_mask_ok now also accepts s_andn2 M,M,exec_lo and s_or M,M,T with T exec-masked (any M), a v_cmp into M when M was zeroed, and s_orn2 M,X,exec_lo when M was all ones before the branch. Adds partial-wave dispatch cases P and Q, controls, refusal controls and an exhaustive 4-lane check.
|
@MasterDomino Ready for review on head 27ad219. Independent gate review: Verification:
AI-assisted; commands listed were executed locally. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27ad219ce0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
Full-suite Win2025 run (dev + release, default pool) on the same head passed earlier: no failure other than a one-off AI-assisted; commands listed were executed locally. |
|
@MasterDomino #2723 is ready for review and merge. Head AI-assisted; commands listed were executed locally. |
MasterDomino
left a comment
There was a problem hiding this comment.
Reviewed 9ab28289.
The accepted forms look exact:
s_andn2 M, M, exec_lo, ands_or M, M, Twith T exec-masked in the block, leave a skipped lane's bit unchanged.- A compare, an
execcopy, or ans_andwith a lane mask needs M zeroed first. s_orn2 M, X, exec_loneeds M set to all ones.- Other writes stay refused, and the EXEC-clear proof is still checked on its own for every
execwrite in the block.
Two requests before merge:
- Compute cache revision. This change refuses a form
maintranslated:s_mov_b32 M, 0, thens_and_b32 M, s7, exec_lowith s7 a group id, whose cached HLSL reads the wrong bit. The existing compute test that accepted it is flipped here.mainis now atx2w-startup-shader-19cs(since #2708), so please move to20cs, so that stale cache entries are re-keyed:compute_keyingfx2hlsl.py;compute_revisionind3d12_draw.inl;tests/startup_compute_request_offline_check.py.
- Two controls. Two one-line mutants pass
startup_gfx2hlsl_compute_check.pyand the WARP dispatch: one that letszeroandoneswrites mix, and one that acceptss_andn2_b32 M, M, Xfor any X. The existing mixed-class control uses s7, so it's refused for the lane-bit reason instead. Please add:- one mixed case with a compare-derived operand, for example
v_cmp_gt_u32 vcc_lo, 3, v0; s_mov_b32 s20, exec_lo; s_orn2_b32 s20, vcc_lo, exec_lo, afters_mov_b32 s20, 0and again after-1; - one
s_andn2_b32 s20, s20, vcc_lorefusal.
- one mixed case with a compare-derived operand, for example
Smaller points:
- Lane-mask check:
lane_bit_keystreats anys_and_b32 M, X, exec_lobefore the branch as lane bits, without the lane-mask check that the block's writes now get. The generic lowering ofs_and_b32 s20, s7, exec_lohas the same gap onmain, so that can be its own issue. - Formatting: there's a collapsed line continuation in
phi_mask_ok(or any(). - Docs: they list "
s_orn2outside the lane mask above" among exec writes, but the new form writes M, notexec. They also mention onlys_mov_b32 M, 0/-1, while the code acceptss_movk_i32too.
Runs: Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818.
- Targeted:
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute'45/45, with cases P/Q and the five new controls on WARP and hardware. - Neighbours:
ctest -R 'startup_gfx2hlsl|startup_compute_translate|startup_compute_request_offline'277/278. The only failure isstartup_gfx2hlsl_fma_mix_dispatch_hardware, as onmainon this GPU (#2746). - Merged onto
main: the controls and the dispatch pass (320 words, 0 mismatches on WARP and hardware), and each new dispatch control is rejected.
AI-assisted; commands listed were executed locally.
R0Y00
left a comment
There was a problem hiding this comment.
The original head accepted s_and_b32 s20, s7, exec_lo before a preserving execz block, even though the ordinary group ID is not a projected lane mask. The new control reproduces this on the old code and refuses it now. A proven VCC source still translates. Host mask/descriptor controls and the full WARP and RTX compute dispatch suites pass.
|
@R0Y00, thanks. My change request at
AI-assisted. |
…rols for execz mask writes The change refuses a compute form main translated, so cached compute HLSL must be re-keyed. Adds a zero+ones mix control and an s_andn2 M, M, vcc_lo refusal (both mutants now fail), docs wording and a line continuation fix.
MasterDomino
left a comment
There was a problem hiding this comment.
Approving 129fc835. Both points from my change request are addressed.
-
Cache revision: both keys move to
x2w-startup-shader-21/21cs. Against1f0c65d3, the only other translator change is the line-continuation fix.startup_shader_cache_rekey_check.pyandstartup_shader_cache_key_check.pypass. -
Controls: both mutants that survived before are now caught by
startup_gfx2hlsl_compute_check.py:- letting
zeroandoneswrites mix (if stale or (...)→if stale:) fails on the new compare-derived mixed case; - accepting
s_andn2_b32 M, M, Xfor any X fails on the newvcc_lorefusals.
The new
s_andn2_b32 s20, s20, vcc_loword,146a148a, matches llvm-mc 15 (binarymode: "fixture words match llvm-mc"). - letting
The head merges cleanly onto current main, and CI is green at the head.
Commands, on Windows 11 build 26300: python -B tests/startup_gfx2hlsl_compute_check.py (plus binary <llvm-mc 15>), startup_shader_cache_rekey_check.py, startup_shader_cache_key_check.py, startup_compute_request_offline_check.py and startup_gfx2hlsl_mask_overwrite_check.py: all exit 0.
Note for #2768, which also takes 21/21cs: once this lands, it needs 22/22cs.
AI-assisted; commands listed were executed locally.
|
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
|
|
@MasterDomino both requests and the smaller points are done at head
Commands run:
AI-assisted; commands listed were executed locally. |
Part of #1723
What this unblocks: compute shaders whose compiler-made i1 phi (a lane mask with a per-lane old value,
s_andn2+ exec-masked compare +s_or) is defined in ans_cbranch_execzblock and read per lane after the join now translate instead of being refused withdefinition of <M>, live where the block joins.What changed
phi_mask_ok(extends the i1-phi rule from #2505) now accepts, for a 32-bit lane mask M (vcc_lo or one sN) written inside an execz block:s_andn2_b32 M, M, exec_lo, ands_or_b32 M, M, Twhere T was written in the block bys_and_b32 T, X, exec_loor av_cmp;v_cmp(notv_cmpx) into M only when M was zeroed before the branch;s_orn2_b32 M, X, exec_loonly when M was set to all ones (s_mov_b32 M, -1) before the branch.Why it is exact: the model skips a lane when its exec bit is clear, and the exec proof (#2509) keeps that bit clear through the block. The wave runs the block when any lane is active. So the model equals the wave iff the block leaves a skipped lane's mask bit unchanged. Preserving writes always do; compare/exec-copy writes only after zeroing;
s_orn2only after all ones. Zeroing and all-ones writes are never mixed, any other write of M (including an offsets_movkinto M) stays refused, and whole-mask reads after the join stay refused. The exhaustive 4-lane check is in the test file.No overlap with #2557: it covers absorbed reads and an andn2-only narrowed mask; this PR covers the blend and the compare/orn2 set-up forms and does not touch those two rules.
Tests
tests/startup_gfx2hlsl_compute_check.py: acceptance of the blend, andn2-only, vcc blend, zeroed compare and all-ones orn2; refusals for each missing set-up, an unmasked term, M not the first source, mixed classes, and whole-mask reads; exhaustive 4-lane checkcheck_execz_mask_exact.p-dropped-andn2,p-dropped-or,p-block-entered,q-block-entered,q-not-all-ones(registered in CMake for warp and hardware).Verification
Linux (this is Stage-1, no Windows run):
python3 -I tests/startup_gfx2hlsl_compute_check.py-> pass (new checks fail on origin/main withs_andn2_b32 inside a block s_cbranch_execz skips per lane: definition of s20, live where the block joins)python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-19->fixture words match llvm-mcs_cbranch_execzis emitted): blend andtruenow translate, the others unchangedWin2025 (dev + release, head 27ad219, merged with current main):
x2w_pipe.py win2025 2723 --py-checks tests/startup_gfx2hlsl_compute_check.py --targets offscreen_check --regex startup_gfx2hlsl_compute: 45/45 passed, including dispatch cases P and Q on warp and hardware and the five new controls (p-dropped-andn2, p-dropped-or, p-block-entered, q-block-entered, q-not-all-ones), each rejected at its first bad word.Build and run:
cmake --build --preset dev --target offscreen_checkthenctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute' -V.AI-assisted; commands listed were executed locally.