Skip to content

shader: vote a quad-complete EXEC for WQM EXECZ branches in native pixel draws - #2946

Merged
MasterDomino merged 1 commit into
R0Y00:cpp-migrationfrom
roansystemlabs:tests/2907-cross-quad-wqm
Nov 26, 2026
Merged

MasterDomino merged 1 commit into
R0Y00:cpp-migrationfrom
roansystemlabs:tests/2907-cross-quad-wqm

Conversation

@roansystemlabs

Copy link
Copy Markdown
Contributor

Fixes #2907. Part of #870, refs #2125. Follows the maintainers' decision in #2907 (comment).

Change

An s_cbranch_execz after s_wqm exec, sM is 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_vote in src/gfx1013_graphics_wqm.inl now lowers the condition as WaveActiveAnyTrue of the modelled EXEC bit, after OR-ing that bit with QuadReadAcrossX, QuadReadAcrossY and QuadReadAcrossDiagonal.

s_mov sE, exec ; s_wqm exec, exec
v_cmp_* vcc, ... ; s_andn2 sE, sE, vcc          one or more coverage filters
v_cmp_* vcc, ... ; s_andn2 sM, sE|exec, vcc     the mask, from the survivors or the whole-quad EXEC
v_cmp_* vcc, ... ; s_andn2 sM, sM, vcc          optional further terms
s_wqm exec, sM ; s_cbranch_execz J              the region writes only scalars
J: s_mov exec, sE                               then a terminal colour export
  • 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:

    • inside the region: a vector or DPP instruction, an EXEC or VCC read, a hardware register access (s_setreg/s_getreg), a branch, or an EXEC write other than the restore;
    • a restore that is not the branch target;
    • a second branch;
    • anything after the restore other than lane-local ALU and colour exports.

    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.md says so.

Fixture

tests/native_graphics_wqm_check.py. native_graphics_wqm_hardware stays where it was in CMakeLists.txt. native_graphics_wqm_warp and native_graphics_wqm_ir are new, in tests/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:

  • its wave (the smallest covered id in it);
  • the ids of its three quad peers;
  • whether each peer is a helper (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.

Adapter Lanes Full-screen draw Diagonal draw (x + y < 5.5)
NVIDIA GeForce RTX 3070 (10de:2484), driver 32.0.16.2101 32 4 quads, 1 wave, no helpers 3 quads, 1 wave, 3 helpers
Microsoft Basic Render Driver, 10.0.26100.9818 4 6 quads, 6 waves, 8 helpers 5 quads, 5 waves, 11 helpers

Cases. Each is drawn against the measured-layout reference:

  1. survivors with x <= 1: one quad's survivors keep the wave from skipping;
  2. survivors with x <= 4.5;
  3. x <= -1: the empty wave, where every vote agrees;
  4. the whole-quad EXEC with x >= 4.5 and survivors x <= 3.5: bits only on covered pixels that did not survive (WQM before the filter);
  5. survivors with x >= 4.5: no bits;
  6. the bit only on the diagonal helper of the one covered pixel (4,0) of a quad in the diagonal draw;
  7. the bit only on its horizontal helper;
  8. the bit only on its vertical helper.

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-words report differing pixels.

RTX 3070 WARP
controls that differ quad-local 6, no-OR 3, survivors-only 4 no-OR 3, survivors-only 3
pixels per control quad-local 10, 4 and 8 on cases 1, 2 and 4, and 8 on each helper case; no-OR and survivors-only 9 on each helper case; survivors-only 8 on case 4 1 (pixel (4,0)) on each helper case

Skips. On WARP no wave holds two quads, so the quad-local control cannot differ. native_graphics_wqm_warp still runs every other case and control, prints SKIPPED 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_hardware runs 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 with native compute +0x10: unbound numeric SGPR s12. That is not the "complete guest vote" refusal: numeric_guards took the shape for a numeric EXEC region and then could not evaluate the raster mask. raster_vote now claims the shape before numeric_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):

Mutant hardware warp ir
quad-local vote (no WaveActiveAnyTrue) red, 10 px green (one quad per wave: same as the wave vote) red
no quad OR red, 9 px (helper case) red, 1 px red
survivor-only vote red, 8 px (case 4) red, 1 px green
vote always true / always false red, 14 / 14 px red, 10 / 4 px red
exact restore removed red, 2 px (sentinels) red, 2 px green
QuadReadAcrossX removed red, 9 px (case 7) red, 1 px red
QuadReadAcrossY removed red, 9 px (case 8) red, 1 px red
QuadReadAcrossDiagonal removed red, 9 px (case 6) red, 1 px red
region scalar-only guard removed red (DPP-in-region refusal gone) red green

Reproduction

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. Head eee7f839 on cpp-migration e97c5c7c.

cmake --build --preset dev --target compile_dxil offscreen_check native_store_replay native_pixel_ir_dump
ctest --preset dev --no-tests=error -R '^native_graphics_wqm_hardware$' -V
ctest --preset dev --no-tests=error -j 1 -V -R '^native_graphics_wqm_(hardware|warp|ir)$'
  • The issue's command: passed.
  • dev and release (/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 is native_comparison_pso_warp, "compute requires wave32: WaveOps=1 range=4..4", a capability skip that this change does not touch.

Not run

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/experiments/native-graphics-wqm-cross-quad.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

…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 MasterDomino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 on sE;
  • one survivor or whole-quad mask write, optionally narrowed;
  • s_wqm exec, sM with a forward s_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.
  • 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.

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.

2 participants