Repository navigation
shader: vote a quad-complete EXEC for WQM EXECZ branches in native pixel draws - #2946
Conversation
…xel draws An s_cbranch_execz after s_wqm exec, sM is skipped only when EXEC is zero in the whole guest wave. For the bounded form where sM comes from the filtered coverage or the whole-quad EXEC, the region writes only scalars and the branch lands on the exact coverage restore, lower the condition as WaveActiveAnyTrue of the modelled EXEC bit OR-ed across the quad with QuadReadAcrossX/Y/Diagonal, as decided on R0Y00#2907. Quad reads see helper lanes, so a quad whose bits sit only on helpers or on pixels that did not survive still votes. The vote is over the desktop wave, under the packing contract of R0Y00#2835 and R0Y00#2854. The fixture measures the desktop quads, helpers and waves of each draw and checks eight cases against that layout, with quad-local, no-OR and survivor-only votes as negative controls. On an adapter with no wave holding two quads the hardware entry exits 77; the WARP entry runs everything a 4-lane wave can decide and names the one control it cannot. An IR entry checks that the vote is emitted before any conditional branch. Hardware register access inside the region is refused by name.
MasterDomino
left a comment
There was a problem hiding this comment.
Review of head eee7f839, tested merged onto cpp-migration c2f6d3de. It merges cleanly. Approving and merging. This is the RX 9070 XT run I offered on #2907, possible now that #2932 fixed #2915.
Code: raster_vote claims only the documented shape:
- a save, then
s_wqm, then filters onsE; - one survivor or whole-quad mask write, optionally narrowed;
s_wqm exec, sMwith a forwards_cbranch_execz;- a scalar-only region that does not touch
sE; - a jump to the exact
s_mov exec, sE, then a lane-local colour-export tail, with no other branch.
Everything else in a claimed program is refused by name. The vote is waveAnyTrue of the modelled EXEC bit OR-ed with quadOp 0, 1 and 2, as decided on #2907, and the branch becomes s_cbranch_scc0 on it.
Run on a 64-lane adapter: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release, D3D12 debug layer enabled.
ctest --preset release --no-tests=error -j 1 -V -R '^native_graphics_wqm_(hardware|warp|ir)$'3/3 passed. All 42 draws report debug_errors=0 debug_warnings=0.
- Measured layout: a new topology for this fixture.
- Full draw:
64 lanes, 4 quads in 1 waves, 1 waves with more than one quad, 0 helper lanes. - Diagonal draw:
64 lanes, 3 quads in 1 waves, 1 waves with more than one quad, 3 helper lanes.
- Full draw:
- Controls:
- quad-local: 10, 4 and 8 of 16 pixels on cases 1, 2 and 4, and 8 on each helper case;
- no-OR ("plain") and survivors-only: 9 of 16 on each helper case;
- survivors-only: 8 of 16 on case 4.
- WARP: passes with
SKIPPED cross-quad quad-local control: no desktop wave holds two quads (4 lanes), as described.
Mutation here: dropping QuadReadAcrossDiagonal from the vote (op<3 → op<2) and rebuilding makes native_graphics_wqm_hardware fail. After restoring, all of ctest --preset release -R '^native_' passes: 37/37, including the WARP capability skip.
That gives the fixture three adapters with three layouts: WARP (4 lanes), RTX 3070 (32 lanes, yours) and RX 9070 XT (64 lanes, here). I will close #2907 by hand after the merge.
AI-assisted; the commands above were run locally.
Fixes #2907. Part of #870, refs #2125. Follows the maintainers' decision in #2907 (comment).
Change
An
s_cbranch_execzafters_wqm exec, sMis skipped only when EXEC is zero in the whole guest wave. Until now the direct frontend refused that branch. For the bounded form below,PixelWqm::raster_voteinsrc/gfx1013_graphics_wqm.inlnow lowers the condition asWaveActiveAnyTrueof the modelled EXEC bit, after OR-ing that bit withQuadReadAcrossX,QuadReadAcrossYandQuadReadAcrossDiagonal.Helper lanes: quad reads see them, so a quad whose bits sit only on helpers or on covered pixels that did not survive still votes. Everything is SM 6.0; there is no
[WaveOpsIncludeHelperLanes]and no 6.7 gate.Where the vote is emitted: the quad reads and the vote come before the first conditional branch, where the whole quad still runs. A new IR test checks this, and checks that the declarations carry the attributes DXC gives the HLSL intrinsics (
nounwind).The branch: it becomes a uniform SCC branch on the vote. The varying-condition refusal is waived for that one branch only; its input dependencies still reach the merged values. Wave intrinsics return undefined values on helper lanes, so a helper may take the other path. That is harmless here because nothing after the branch reads another lane: the region is scalar-only and the tail after the restore is lane-local ALU and colour exports, which a helper never writes.
Still refused by name:
s_setreg/s_getreg), a branch, or an EXEC write other than the restore;raster_program(2.5, cross=True)keeps its existing refusal.Contract: this is the packing contract of shader: recognise whole wave32 reductions in gfx2hlsl pixel stages (Part of #2125) #2835 and startup: lower the first active lane of a pixel stage in gfx2hlsl (Refs #2618) #2854: a correct program cannot depend on which quads share a console wave. The fixture builds such a dependency on purpose (a scalar written in the region), so its reference uses the measured desktop layout. This shows the vote over the desktop wave, not console equivalence for an output that depends on another quad. The note in
docs/experiments/native-graphics-wqm-cross-quad.mdsays so.Fixture
tests/native_graphics_wqm_check.py.native_graphics_wqm_hardwarestays where it was inCMakeLists.txt.native_graphics_wqm_warpandnative_graphics_wqm_irare new, intests/cmake/native_graphics_wqm.cmake.Measured layout. Two HLSL pixel stages, drawn with the same vertex stage and target as the guest program, give each covered pixel:
IsHelperLane, SM 6.6).Wave operations leave helpers out, so the helper flags come from quad reads. The fixture checks that every desktop quad is the aligned 2x2 block and that all covered lanes of a quad report the same quad. Quads are per primitive. On WARP the two middle quads of the 8x2 target are each shaded twice, once with each row covered and the other row as helpers, as if the full-screen triangle were drawn as two primitives. The reference follows the measured quads instead of assuming a 2x2 grid. The layout is measured in separate draws from the guest draw, so a different packing would make the test fail, not pass; it was identical in all four runs below.
10de:2484), driver 32.0.16.2101Cases. Each is drawn against the measured-layout reference:
Pixels outside exact coverage keep the clear value -1.0 (sentinels).
Controls. The same program is redrawn against a quad-local vote, a wave vote without the quad OR, and a vote over survivors only. Each must make
--startup-pixel-wordsreport differing pixels.Skips. On WARP no wave holds two quads, so the quad-local control cannot differ.
native_graphics_wqm_warpstill runs every other case and control, printsSKIPPED cross-quad quad-local control: no desktop wave holds two quads (4 lanes)and passes. On a physical adapter that has no wave with two quads,native_graphics_wqm_hardwareruns the same checks and then exits 77, because it has not exercised the cross-quad decision. That path was not exercised here: our physical adapter always had a wave with more than one quad. If you would rather have the WARP entry exit 77 as well, or the quad-local control as its own test, I can split it.Fail-first
Translator unchanged (
e97c5c7c), new fixture: all three tests fail withnative compute +0x10: unbound numeric SGPR s12. That is not the "complete guest vote" refusal:numeric_guardstook the shape for a numeric EXEC region and then could not evaluate the raster mask.raster_votenow claims the shape beforenumeric_guards.Mutants, each built in a scratch copy and run against the fixture (on the previous revision of this commit, which differs only by the 77 exit, the hardware-register refusal and comments):
WaveActiveAnyTrue)QuadReadAcrossXremovedQuadReadAcrossYremovedQuadReadAcrossDiagonalremovedReproduction
Windows 11 25H2 build 26200.9974, MSVC 19.44 (toolset 14.44), DXC 1.9.2602.17 (SDK 10.0.26100.0), Python 3.12. D3D12 debug layer enabled on both adapters; every draw reported
debug_errors=0 debug_warnings=0. Headeee7f839oncpp-migratione97c5c7c./O2), each run twice in series: 3/3 passed every time, with the same counts.ctest --preset dev --no-tests=error -j 1 -R '^native_', with every native target built: 34 tests, 33 passed and 1 skipped. The skip isnative_comparison_pso_warp, "compute requires wave32: WaveOps=1 range=4..4", a capability skip that this change does not touch.Not run
prpreset does not selectnative_graphics_wqm_*.Checklist
docs/experiments/native-graphics-wqm-cross-quad.md).AI-assisted.