Repository navigation
shader: lower complementary pixel EXECZ arms inside whole-quad mode - #3819
Conversation
Flatten a CMPX/EXECZ split inside whole-quad mode whose two arms partition the WQM mask and rejoin at entry coverage, so implicit samples still see all four quad coordinates. Lanes outside each arm keep their previous VGPR values. Speculative reads in the arms are limited to fixed-offset table and buffer loads and to samples with a fixed descriptor and constant sampler.
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed 0d1dad12 by reading the diff; not built or run.
Verdict: approve. The flattening matches the guest's WQM semantics, and the matcher fails closed on everything else. No MUST.
- SHOULD No draw runs the flattened arms. The claim this PR rests on is that implicit derivatives stay right when one quad is split across the two arms: arm-2 coordinates must see arm-1 lanes' arm-1 values and the helper lanes' own arm values.
pixel-wqm-execzchecks only the IR shape (selects,isHelperLane,sample, nobr i1). A WARP draw with a gradient texture, a compare that splits quads, and an implicit sample in each arm would check it against a reference. - NIT
pixel_wqm_armsreturns after the first match (gfx1013_direct_graphics.inl:721), so a stage with two such regions keeps the second one refused. A comment saying so, or acontinue, would make that explicit. - Checked, no finding:
- Predicates: the CMPX arm runs on the compare and the complement on its negation (
:2455), with helper lanes included as under WQM. Only the sample window ANDs entry coverage (:2429), which matchess_and_saveexec_b64 <coverage>. - SALU in a skipped arm: first-arm writes (with SCC) expire at the inverse, and both arms' writes expire at the restore, so the speculative scalars stay unreadable.
- No outside entry: the prefix has no branches, the tail is lane-local, second-arm branches stay inside the arm, and an entry inside a sample window is refused.
- With #3815 on main:
pixel_readonly_armsruns first but cannot take this shape, because it needs the inverse and the restore to name the same pair and here they differ. The branch merges cleanly, and the CI run at this head started after #3815 merged. - The M0 move from the primitive mask now returns before the whole-quad entry bookkeeping.
wqm-numeric-m0,-reads-m0and-after-vector-writekeep the refusals.
- Predicates: the CMPX arm runs on the compare and the complement on its negation (
Tests: pixel-wqm-execz and -scc reach the new matcher and both lowering paths. The eight refusals each break one match condition. Neither native_direct_container nor native_fixed_graphics_psi1 matches the pr preset filter, so CI did not run them. Only the author's run at this head shows them passing.
R0Y00
left a comment
There was a problem hiding this comment.
Independently rebuilt compile_dxil on Windows Debug at 0d1dad12. ctest --preset dev --no-tests=error -j 2 -R '^(native_direct_container|native_fixed_graphics_psi1)$' --output-on-failure passed 2/2. This covers the complementary EXECZ and primitive-mask/WQM entry fixtures and their refusal controls. These checks exercise compiled shader output.
…0Y00#3819) * shader: preserve quad inputs in complementary pixel EXECZ arms Flatten a CMPX/EXECZ split inside whole-quad mode whose two arms partition the WQM mask and rejoin at entry coverage, so implicit samples still see all four quad coordinates. Lanes outside each arm keep their previous VGPR values. Speculative reads in the arms are limited to fixed-offset table and buffer loads and to samples with a fixed descriptor and constant sampler. * shader: preserve WQM entry after primitive mask setup
Problem
The native pixel frontend refuses two shapes that a whole-quad-mode (WQM) pixel stage can legitimately contain.
It is refused with
graphics branch on a wave mask. Lowering the two skips as real branches would not be correct either: an implicit-LOD sample in an arm needs the coordinates of all four pixels of its quad, including lanes that are not in that arm.s_wqm_b64is refused withwhole-quad mode requires an unmodified pixel entry mask, although that move does not change EXEC.Change
Shader translation only, in
src/gfx1013_direct_graphics.inl. Two commits.shader: preserve quad inputs in complementary pixel EXECZ armsaddspixel_wqm_arms. When the region matches, both EXECZ skips are removed and the arms are if-converted:s_and_saveexec_b64 <coverage>/s_or_saveexec_b64window, with a fixed texture descriptor and a constant sampler. Its destination is updated only on covered lanes of its arm.The matcher is strict and falls back to the existing refusal on anything else:
s_wqm_b64must precede the region with no other EXEC write or branch before it;v_readfirstlaneand carry-writing scalars are not accepted in an arm;s_endpgm.Scalars written in the first arm are dropped at the inverse. Scalars written in either arm are dropped at the join.
shader: preserve WQM entry after primitive mask setupmoves the existing rule "s_mov_b32 m0, <proven primitive mask>needs no desktop equivalent" ahead of the pixel prologue check. No rule is added: the move was already accepted, but it ran after the check that marks the entry mask as modified. Loading any other value into M0, reading M0 afterwards, or writing a VGPR befores_wqm_b64is still refused.Related open work:
pixel_readonly_armsin the same file for a two-armed CMPX if/else whose join restores the saved pair, lowered with a per-lane branch. This PR covers a different shape (inside WQM, the join restores entry coverage, and the arms are flattened so implicit samples keep their quad) in a separate function. The behaviours do not overlap; a textual rebase may be needed depending on which lands first.Validation
Windows, MSVC.
compile_dxilneedsDXC_BIN_DIR.Both tests pass on the exact head of this PR.
New cases in
tests/native_direct_container_check.py:pixel-wqm-execz: the IR has nobr i1. The first-arm write is aselecton the compare, the second-arm write is aselecton the inverted compare ANDed with coverage, andisHelperLane,sampleLevelandsampleare all present.pixel-wqm-execz-scc: a fixed table record feeds a uniform SCC diamond in the second arm. The IR has exactly onebr i1, aphi, arawBufferLoadand the implicit sample.branch on a wave maskrefusal: wrong parent mask in the inverse, wrong coverage restore, wrong sample-window restore, coverage pair clobbered, WQM pair clobbered,v_readfirstlanein an arm, dynamic table offset, sample outside a window.New cases in
tests/native_fixed_graphics_psi1_check.py:wqm-primitive-m0compiles;wqm-numeric-m0,wqm-reads-m0andwqm-after-vector-writekeep their refusals.The fixtures are hand-assembled instruction words written for these tests.
Beyond the fixtures: in a run of a guest application, both refusals no longer appeared for the pixel pipelines that had them. That is a local observation. The public fixtures verify the lowering rules and the refusals listed above, not that run.
Checklist