Repository navigation
shader: lower pixel compare masks composed with VCC in a whole-quad tail (Part of #3309) - #3401
Conversation
Leyukaka
left a comment
There was a problem hiding this comment.
Request changes at ed447c29. Reviewed by reading the diff and the sources at that head; one mutant result from a local run is noted below.
Blocking:
- A stale tracked pair gives a wrong select where
mainrefuses.compare_masks/broken_compare_masksare only updated byv_cmp_*(src/gfx1013_direct_graphics.inl:2126-2129), bys_mov_b64from a tracked or tagged pair (:2187-2203), bys_mov_b32(:2204-2209) and by a combine (:2224-2225). No other SGPR writer inlower_graphicstouches them, andv_cndmask_b32takes the map entry beforegraphics_lane_mask(:2143-2149). - Smallest case, all in whole-quad mode:
s_mov_b64 s[20:21], exec;s_wqm_b64 exec, exec;v_cmp_gt_f32 s[4:5], v1, 1.0;s_mov_b64 s[4:5], 0;v_cndmask_b32 v4, 0, 1.0, s[4:5]. The literal source is operand 128, so the move skips:2187(i.src[0] <= 104) and is lowered as a numeric move that leavescompare_masks[4]. The select then uses the old compare bit, while the guest mask is 0 on every lane. Onmainthe select goes throughgraphics_lane_mask(main:2115), sees a constant in the analysisstateand refuses withunproven graphics CNDMASK source. The fixture tail has the same hole: adds_mov_b64 s[8:9], 0after the copy. - Same for a
s_mov_b64from an untagged numeric pair (knownis false at:2188-2190), fors_movk_i32, SOP2 arithmetic and SMEM loads into either half, and fors_cselect_b64into a tracked pair (:2265-2277). In the last casemainselects with the new full mask, and the head selects with the old compare bit. So "a later 32-bit write to either half refuses" holds only fors_mov_b32. - In the tracked
s_mov_b64path, whencompare_mask_bitreturns nothing (:2195, tagged source with an offset or a mismatched high half), the destination keeps its old entry. - Suggested fix: before the generic lowering, drop (or mark broken) any tracked pair overlapped by the destination of an instruction the tracker did not handle itself, using the width computation already at
:1991-1992. Alternatively use the map entry inv_cndmask_b32only whenstate[src]is still the tagged pair. Add a container control withs_mov_b64 s[8:9], 0after the copy that expects a refusal.
Non-blocking:
compare_masksis not part of the per-edge state (graphics_registersis restored per edge at:1127and merged at:1182), so an entry made in one block is visible in a sibling block. All fixtures are straight-line.compare_scc_unknownis cleared only by a uniform combine (:2231). After a laters_cmp_*defines SCC,s_cselectstill refuses at:2026.- The branch refusal at
:2424-2425is redundant while SCC is still undefined (alu.read(128)already refuses withgraphics register undefined on an incoming path: 128), and once SCC is redefined it is the same false refusal as above. - Not covered by any case, so deleting them passes the tests: the broken check in
compare_mask_bit(:2167-2168), broken propagation throughs_mov_b64(:2192-2194), the refusal at:2242-2243, and:2424-2425. - The fixed-mesh shader uses a uniform-true mask and reads one pixel, (2,0), where VCC is also 1. AND, OR, the mask alone and VCC alone all give the same result there.
Checked:
- Combine semantics (
:2220-2222): OR, AND, and ANDN2 asS0 & ~S1withxor bit, 1on 0/1 values. SCC is written only for a uniform result (:2229-2235). - Fixture references:
(4,0)is covered (4.5 + 0.5 < 5.5),(4,1)and(5,0)are not; the mask at(4,0)is 0 and the quad read from(4,1)is 1; the two ANDN2 orders give different images. The fixed-mesh words decode tos_and_b64 s[6:7], s[4:5], vcc,s_mov_b64 s[8:9], s[6:7],v_cndmask_b32 v0, 0, 1.0, s[8:9]. - In a local run (this head merged onto
212d4b5ftogether with other open PRs), removing thexorfrom the ANDN2 lowering (:2222) failednative_pixel_compare_mask_warp,_hardwareand_ir;_container,native_direct_containerandnative_fixed_mesh57_compare_vcc_warpstill passed. - CI passes but does not run these tests on a PR: none match the
prpreset filter (CMakePresets.json), and the new script is not intests/checks/python-linux. The evidence is the author's run in the PR body. - CMake changes are
add_test/set_tests_propertiesonly.git merge-treeagainstmain(212d4b5f) is clean.
A whole-quad pixel tail can AND, OR, or ANDN2 a two-SGPR compare with VCC, keep that pair across a 64-bit move, and refuse a half overwrite or an SCC read whose wave-wide result is not uniform. Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
A vertex class-mask high-half overwrite must still refuse as an unproven CNDMASK source. The pair tracker was recording every graphics compare. Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
A literal or numeric s_mov_b64, s_movk_i32, scalar arithmetic, a scalar load, or a copy of a pair that is no longer a mask left the old compare bit for v_cndmask. s_cselect_b64 into that pair keeps the new full mask. Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
ed447c2 to
53a8f2a
Compare
|
Fixed at Windows test PC (MSVC,
Not done in this head: the mask map is still not stored per edge, and a later AI-Assisted |
|
Review of head Checked:
MUST
SHOULD
NIT
AI-assisted. |
Leyukaka
left a comment
There was a problem hiding this comment.
Review at 53a8f2ab. My changes request on ed447c29 is resolved by UnclaimedMaskRelease (src/gfx1013_direct_graphics.inl:1683-1702). Not approving yet: item 1 below is a regression against main. I will approve once it is fixed. Reviewed by reading the diff and the sources at that head and at main 4b0586d4; nothing was built or run for this pass.
Blocking point from ed447c29: fixed (code reading).
src/gfx1013_direct_graphics.inl:1683-1702:UnclaimedMaskReleaseruns on every exit ofinstruction(return or refusal). In the tail it erases each tracked or broken pair overlapped byscalar_width(i)dwords fromi.dst, unless the tracker setclaimed.claimedis set only where the tracker rewrites the entry itself::2159,:2226,:2230,:2242,:2261.- After the erase,
v_cndmask_b32falls through tographics_lane_mask(:2180), which is themainbehavior. So a literal or numerics_mov_b64,s_movk_i32, SOP2 arithmetic and an SMEM load refuse as onmain, ands_cselect_b64selects with the new full mask. - The tracked
s_mov_b64whose source gives no bit (:2227returns nothing) no longer setsclaimed, so the destination entry is erased too. - SOP1/SOP2/SOPK writes to VCC are still refused (
:2314-2318), so register 106 read at:2213is always a 0/1 lane bit. - Requested control is present:
compare-literal-copy-zero(tests/native_pixel_compare_mask_check.py:92-94), plus-literal-zero,-numeric-mov,-movk-high,-add-high,-smem-low,-mismatched-copy, andcompare-cselect-maskwith the IR check at:303-305.
MUST
- Wave32 pixel program that
mainlowers is refused (code reading).src/gfx1013_direct_graphics.inl:2237-2243computesbase = i.dst & ~1uwithout looking atstage.wave32, and:2156records the compare on wave32 as well. On a wave32 pixel stage in whole-quad mode, before the exact restore:v_cmp_gt_f32 s4, ..;s_mov_b32 s5, 0;v_cndmask_b32 .., s4. The move marks pair 4 broken and the select refuses at:2175-2176withcompare mask half overwritten. Onmainthe compare tags onlys4(src/gfx1013_compute_native.cpp:714-715), the move changes onlys5, andgraphics_lane_maskaccepts a wave32 mask from its low word alone (src/gfx1013_direct_compute.inl:2962-2964at4b0586d4), so the select lowers. The result is a refusal, not a wrong value. On wave32s5is an ordinary register, so the sequence is plausible. Fix: gate thes_mov_b32pair-break branch at:2237-2243on!stage.wave32. A wave32 container case with that sequence expecting success would pin it; no fixture in this PR is wave32.
Non-blocking:
SHOULD
- Control flow, unchanged from the earlier review:
compare_masksis not part of the per-edge state, so an entry recorded in one block is visible in a sibling block or at a join. All fixtures are straight-line. A refusal when a tracked entry reaches a block boundary, or a follow-up issue, would bound it. compare_scc_unknownis cleared only by a uniform combine (:2265-2267). After a laters_cmp_*defines SCC,s_cselect(:2056-2057) and a scalar branch (:2460-2461) still refuse.
NIT
compare-broken-copydoes not pin the propagation at:2223-2226(code reading). With that branch removed,s_mov_b64 s[8:9], s[4:5]reachescompare_mask_bit(4)at:2227, which refuses at:2198-2199with the same message, so the case still passes. The branch only changes behavior when the broken copy is never read as a mask (then it lowers instead of refusing), and no case covers that.- SCC of a uniform combine is only tested when true.
scc_program(varying=False)(tests/native_pixel_compare_mask_check.py:61-70) iss_or_b64of a true and a false compare, read bys_cselect_b32with expected value 1.0. Writing a constant 1, or the left operand's bit, to SCC at:2266would pass. A second uniform case with a false result (for examples_and_b64of the same two compares, expecting 0.0) would catch both. - The release at
:1692tests the tail state after the instruction, so entries recorded in the tail outlive it. They are only read inside the tail, and I found no way to re-enter whole-quad mode after a compare (:2045requiresscalar_entry, which a compare clears at:2051-2055).
Checked:
git merge-treeof the head againstmain4b0586d4is clean. The four later commits onmaindo not touchsrc/gfx1013_direct_graphics.inl.- CI passes at the head. As before, the new tests are not in the
prpreset; the 7/7 result is the author's run in the PR body. - CMake changes are
add_test/set_tests_propertiesonly.
pigalot
left a comment
There was a problem hiding this comment.
Request changes at 53a8f2ab, reviewed integrated over main 4b0586d4 (tree d8bfbb92, clean merge, git diff --check clean).
What the earlier review at ed447c29 asked for. The straight-line stale pair is fixed. With the release body disabled, compare-literal-zero, -literal-copy-zero, -numeric-mov, -movk-high, -add-high, -smem-low and -mismatched-copy stop refusing and three tests fail (mutant M1 below). v_add_co_u32-style carry-outs are not a hole: gfx1013_direct_compute.inl:3535 refuses them for a pixel stage.
Blocking
-
A tracked pair crosses a control-flow edge and gives a wrong select where
mainrefuses.compare_masksis one map for the whole function, filled and erased in emission order, andin_compare_tail()is true for the whole-quad region before coverage returns, where branches are allowed (the edge refusal at:1975covers onlyexact_after_wqm). Program, using the helpers intests/native_pixel_compare_mask_check.py:SCMP = 0xBF000000 | (6 << 16) | (129 << 8) | 129 # s_cmp_eq_u32 1, 1 br = lambda op, off: 0xBF800000 | (op << 16) | off with_exports(whole_quad_compare() + [ # v_cmp_gt_f32 s[4:5], y, 1.0 SCMP, br(4, 2), # s_cbranch_scc0 else sop1(4, 4, 128), br(2, 1), # then: s_mov_b64 s[4:5], 0; s_branch join sop1(4, 4, 4), # else: s_mov_b64 s[4:5], s[4:5] *cndmask(0, 128, 242, 4)]) # join: v_cndmask_b32 v0, 0, 1.0, s[4:5]
SCC is 1, so the guest always takes the
thenpath andv0is 0 on every lane. At this headcompile_dxil ... gfx1013-container-psexits 0, the DXIL validates, and the join selects on they > 1compare (%t9 = icmp ne i32 %t5, 0with%t5the compare from the entry block). Drawn with the fixture's vertex shader on WARP,offscreen_check warp --startup-pixel-wordsagainst the all-zero reference reportspixel mismatch (0,1): expected 00000000,... actual 3f800000,...,4 of 16 pixels differ, and it matches they > 1image exactly. Onmain4b0586d4the same blob refuses withnative compute +0x24: unproven graphics CNDMASK source. Thethenblock erases the entry, theelseblock is emitted later and puts it back from the tagged state, and the join then finds an entry that only holds on one path. -
Same cause, invalid IR instead of a refusal. Replace the two arms with a
thenblock that redefines the pair:with_exports(whole_quad_compare() + [SCMP, br(4, 2), *cmp_gt(4, 256, 244), *cndmask(0, 128, 242, 4)])
native_pixel_ir_dumpexits 0 at this head and the join reads a value defined only in thethenblock.compile_dxilthen fails in DXC withInstruction does not dominate all uses! %t14 = zext i1 %t13 to i32.mainrefuses withnative compute +0x20: unproven graphics CNDMASK source.Suggested direction (not tried): use a map entry in
v_cndmask_b32and incompare_mask_bitonly when it was recorded in the current block, and clear the map at every block entry, so anything that crosses an edge falls back tographics_lane_maskand the per-edgestate, as onmain. Or refuse when the whole-quad region is not straight-line. Please add both programs as container controls that expect the refusal. -
The title run of this head failed twice. prwatch built
53a8f2abmerged onto the baseline commitaf1cab5c:[fail] judgement: Judged worse than the baseline: black-frame (at before-1, after-1, before-2, after-2, before-3, after-3, before-4, after-4). Confidence medium.[fail] repeat: Failed again on a re-run (job 44).
I have not tied this to finding 1 or 2.
Non-blocking
compare_scc_unknownis still cleared only by a uniform combine, so a laters_cmp_*followed bys_cselector an SCC branch is refused although SCC is defined again. The PR body says so.- The fixed-mesh shader still reads one pixel where the mask and VCC are both 1, so it cannot tell AND from OR or from either operand alone. The 8x2 fixture does.
- CI does not run any of the new tests on a pull request: none match the
prpreset filter, and the script is not intests/checks/python-linux. The results below are from my machine.
What I ran
Built dev (full build), then
ctest --test-dir out/build/dev --no-tests=error -j 4 -R '^(native_pixel_compare_mask_(warp|container|ir)|native_fixed_mesh57_compare_vcc_warp|native_direct_container|native_fixed_mesh57_mask_warp)$': 6 of 6 passed.
native_pixel_compare_mask_hardware and native_fixed_mesh57_compare_vcc_hardware with -j 1 and the debug layer on: 2 of 2 passed, no skips. Release was not built, because the findings above already decide the verdict.
Mutants in src/gfx1013_direct_graphics.inl, each rebuilt and run against the five non-hardware tests of this PR:
- Killed (13): M1 release body disabled; M2 ANDN2 operands swapped (
_warponly); M3 OR lowered as AND; M4 combine always uniform; M5 broken check incompare_mask_bitoff; M6 broken check inv_cndmask_b32off; M8compare mask is not a 64-bit lane maskrefusal off; M9in_compare_tail()always true (native_direct_containeronly); M10s_cselectSCC refusal off; M12v_cndmask_b32dropped fromexact_mask_select; M13 release erases the odd register number instead of the pair base; M14s_mov_b32break not claimed; M16 trackeds_mov_b64does not record the copy. - Survived (2): M7
s_mov_b64no longer propagates a broken source (the copy itself then refuses with the same message, so no case tells a broken pair that is copied and never selected from one that is selected); M11 the SCC refusal on a two-way branch removed (no case has a branch after a varying combine). - Equivalent for every covered case (1): M15
v_cmp_*does not record or claim. The select and the combine then reach the same bit through the taggedstate, so this entry is only a second route to it.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10, DXC from Windows SDK 10.0.28000.0, debug layer on for the hardware tests.
CI: Build and test on Windows passes on 53a8f2ab.
This reply was AI-assisted.
|
@SimSalabimse Taking this over since there has been no activity for 2 h; will hand back if you resume. Last movement here: head Plan:
|
|
@Leyukaka I can take the remaining review fixes on this branch if you haven't started the follow-up. If you have, I'll leave it with you. AI-Assisted |
|
@SimSalabimse Handing back: the PR stays with you, and I will not open a separate one. I had started.
At |
|
Fixed at Windows test PC (MSVC,
Not done in this head: mutation checks for both commits, pigalot's point 3, and AI-Assisted |
|
Re-review of the delta Delta:
Checks at SHOULD
AI-assisted review. |
Leyukaka
left a comment
There was a problem hiding this comment.
Approve at 2211dac0. Diff reading only; nothing built or run for this pass.
- My blocking point at
53a8f2abis resolved: thes_mov_b32pair-break is gated on!stage.wave32(src/gfx1013_direct_graphics.inl:2245), withcompare-wave32-high-writeexpecting success. pigalot's points 1-2 are resolved by the block-entry clear ofcompare_masks/broken_compare_masks(:1683-1686), withcompare-join-after-clearandcompare-join-after-redefineexpecting a refusal. 61df3c5fand2211dac0are the two commits I handed back (9193f9c4,76b760c0):git range-diffreports both pairs as identical.- Still open, not mine: pigalot's point 3 (the black-frame result on
53a8f2ab, no run at this head yet), andcompare_scc_unknownbeing cleared only by a uniform combine (it only adds refusals).
|
Status at
This can merge once pigalot's review is updated or dismissed. AI-assisted review. |
|
Mutations at Windows test PC (MSVC, Unmutated head, before and after the mutants: 5/5 passed, none skipped. Container:
Not done: pigalot's point 3 (the black-frame title run), and AI-Assisted |
pigalot
left a comment
There was a problem hiding this comment.
Approve at 2211dac0. Retested integrated over main 26df1826 (tree de514147, clean merge, git diff --check clean). This supersedes my changes-requested review on 53a8f2ab.
Earlier blocking findings
- Tracked pair across a control-flow edge, wrong select: addressed. The map and the broken set are cleared at every block leader (
src/gfx1013_direct_graphics.inl:1683-1686), so a join reads the pair through the per-edge state as onmain. My program is nowcompare-join-after-clear;native_pixel_ir_dumprefuses it withnative compute +0x24: unproven graphics CNDMASK source, the same refusal asmain. - Same cause, invalid IR: addressed.
compare-join-after-redefinerefuses withnative compute +0x20: unproven graphics CNDMASK source. - Title run: addressed. prwatch ran
2211dac0merged onto the baseline commitaf1cab5c(job 52): pass, judged no worse than the baseline.
The wave32 gate on the s_mov_b32 pair-break (:2245) is right as far as I traced it: on wave32 the odd register is released as an ordinary scalar write, and the select goes back through graphics_lane_mask. compare-wave32-high-write lowers.
I also checked whether compare_scc_unknown, which is still one flag for the whole function, can let a wrong SCC read through across blocks. It cannot in the cases I tried: with a varying combine in the arm emitted first and a uniform combine in the other, a s_cselect_b32 at the join refuses with graphics register undefined on an incoming path: 128, because a varying combine also leaves register 128 empty on its edge. With the arms swapped, or both varying, it refuses with the SCC message. With both uniform it lowers.
Non-blocking
- Mutant D below survives: no case has a broken pair that crosses an edge. As far as I can see, leaving the broken set uncleared would only add refusals.
- Still open from the last review:
compare_scc_unknownis not cleared by a laters_cmp_*(extra refusals only), the fixed-mesh shader reads a single pixel, and CI does not run the new tests on a pull request.
What I ran
Built dev (full) and release (compile_dxil, offscreen_check, native_pixel_ir_dump, startup_indirect_draw_indexed), then
ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(native_pixel_compare_mask_(warp|container|ir)|native_fixed_mesh57_compare_vcc_warp|native_direct_container|native_fixed_mesh57_mask_warp)$': 6 of 6 passed in Debug and in Release /O2.
native_pixel_compare_mask_hardware and native_fixed_mesh57_compare_vcc_hardware with -j 1 and the debug layer on: 2 of 2 passed in Debug and in Release, no skips.
Mutants of the two new commits in src/gfx1013_direct_graphics.inl, each rebuilt in dev and run against the five non-hardware tests of this PR. The file was restored afterwards, the five tests pass again and git diff --quiet is clean.
- Killed (6): A
!stage.wave32dropped (_container,native_direct_container); B block-entry clear removed (_ir,_container,native_direct_container); C only the broken set cleared (same three); Eblock_entriesnever filled (same three); F clear on every pc that is not a leader (those three and_warp); G wave32 gate inverted (_ir,_container,native_direct_container). - Survived (1): D only the mask map cleared, the broken set kept.
- Equivalent: none.
Mutants A and B are also the negative controls for the three new cases: without each fix the case behaves as it did at 53a8f2ab. The 13 killed and 2 surviving mutants from my review at 53a8f2ab cover lines these two commits do not touch; I did not rerun them.
Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10, DXC from Windows SDK 10.0.28000.0, debug layer on for the hardware tests.
CI: Build and test on Windows passes on 2211dac0.
This reply was AI-assisted.
Change
Part of #3309. Refs #2413, #3210, #870, #3308. The work sits on the pixel path added in #3091.
A gfx1013 pixel tail in whole-quad mode can now combine a named two-SGPR compare mask with VCC. It handles
s_and_b64,s_or_b64ands_andn2_b64(S0 & ~S1), ands_mov_b64keeps the lane bit when the pair is copied. Some cases are still refused:s_mov_b32of either half refuses withcompare mask half overwritten.s_mov_b64,s_movk_i32, scalar arithmetic, a scalar load, or a copy whose source is no longer a 64-bit mask, drops the tracked bit. A later select then refuses withunproven graphics CNDMASK source.s_cselect_b64into the same pair keeps the new full mask instead.SCC read without an established wave-wide nonzero result.This tracking runs only in the pixel whole-quad tail (
whole_quadorexact_after_wqm). A vertex class-mask high-half overwrite still refuses asunproven graphics CNDMASK source, the same as on main.Verification
All results below are for commit
53a8f2ab5fe80af837958bd9caee4700e7e9ce8a, rebased onto main77d1ba4d63ba31abaf4ca3635d4159189a423201.Windows test PC (MSVC,
--preset dev,-j 1). The command was:It passed 7 of 7 with ctest exit 0.
native_pixel_compare_mask_warp,_hardware,_containerand_irall passed. Container and IR refused the new scalar-write cases and validatedcompare-cselect-mask.native_fixed_mesh57_compare_vcc_warpand_hardwarepassed. The reviewed stage pair links and creates a color PSO. Target zero(2,0)packed RGBA was0xffff00ff, with 1/8 non-clear pixels and argument guards intact.native_direct_containerpassed.An earlier commit,
30f6606b, failednative_direct_containeronvertex-class-mask-high-overwritebecause the tracker also ran on vertex compares.ed447c29limits it to the pixel whole-quad tail.53a8f2abdrops a tracked pair when a later scalar write the tracker does not itself rewrite overlaps it.On Linux, at
53a8f2ab:g++andclang++-std=c++20 -Wall -Wextra -Werror=narrowingof the lowering exited 0.python3 -B tests/native_pixel_compare_mask_check.pyand the same script inirmode exited 0.python3 -B tests/docs_links_check.pyexited 0.Evidence and follow-up
The fixture words are written by hand in
tests/native_pixel_compare_mask_check.py, with no game files or dumps. The diagonal draw coversx + y < 5.5, so pixel(4,0)is covered and(4,1)is a helper lane. The mask isy > 1under whole-quad execution, and VCC isx > 2after exact coverage returns. Uncovered pixels stay at the clear value, -1.Each negative control was shown to fail when its check was removed:
v_cndmaskguard let the container lower with the stale bit.s_andn2_b64 s[6:7], s[4:5], vccasvcc & ~mask, and the draw test expectspixels differ.s_mov_b64,s_movk_i32,s_add_u32, a scalar load, and a mismatched copy all compiled. They now refuse.The mask map is still not stored per edge, and a later
s_cmp_*does not clear an unknown SCC from a varying combine. The fixed-mesh readback is the slot 57 target, not the 8×2 fixture. Reproduction notes are indocs/experiments/pixel-compare-mask-vcc.md.Checklist
AI-assisted (Cursor)