Skip to content

shader: lower complementary pixel EXECZ arms inside whole-quad mode - #3819

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-execz
Dec 2, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
Leyukaka:scene-pr-execz

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

The native pixel frontend refuses two shapes that a whole-quad-mode (WQM) pixel stage can legitimately contain.

  1. A complementary EXECZ pair inside WQM:
s_mov_b64 s[C:C+1], exec        ; entry coverage
s_wqm_b64 exec, exec
...
s_mov_b64 s[Q:Q+1], exec        ; WQM mask
v_cmpx_* ...                    ; first arm lanes
s_cbranch_execz ELSE
<first arm>
ELSE: s_andn2_b64 exec, s[Q:Q+1], exec
s_cbranch_execz JOIN
<second arm>
JOIN: s_mov_b64 exec, s[C:C+1]  ; back to entry coverage

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.

  1. A stage that initializes M0 from the primitive mask before s_wqm_b64 is refused with whole-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 arms adds pixel_wqm_arms. When the region matches, both EXECZ skips are removed and the arms are if-converted:

  • Every lane executes both arms. A VGPR write in an arm selects the new value on the lanes of that arm and keeps the previous value elsewhere, so the generated DXIL has no control flow on the wave mask.
  • Implicit-LOD samples stay in quad-uniform flow. A sample is accepted only inside an s_and_saveexec_b64 <coverage> / s_or_saveexec_b64 window, with a fixed texture descriptor and a constant sampler. Its destination is updated only on covered lanes of its arm.
  • Because the arms now run speculatively, scalar loads in them are limited to fixed, aligned offsets of the regular table and buffer bindings that the emitter already validates. A dynamic offset is refused.
  • The second arm may contain forward scalar branches that stay inside the arm (a uniform SCC diamond). They remain real branches and rejoin before the sample.

The matcher is strict and falls back to the existing refusal on anything else:

  • the entry-coverage save and s_wqm_b64 must precede the region with no other EXEC write or branch before it;
  • the inverse must use the saved WQM pair, and the join must restore the entry-coverage pair;
  • neither pair may be clobbered in an arm;
  • v_readfirstlane and carry-writing scalars are not accepted in an arm;
  • the code after the join may only be lane-local ALU, waits, colour exports and 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 setup moves 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 before s_wqm_b64 is still refused.

Related open work:

  • shader: lower two-armed CMPX if/else regions in wave64 pixel stages #3815 changes pixel_readonly_arms in 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.
  • shader: preserve complete native frontend cache results #3792 also touches this file (frontend cache results).
  • A follow-up PR (draw-time checks for physical descriptor table reads) is stacked on this one for its test helpers.

Validation

Windows, MSVC. compile_dxil needs DXC_BIN_DIR.

cmake --build --preset dev --target compile_dxil
ctest --preset dev --no-tests=error -R "^(native_direct_container|native_fixed_graphics_psi1)$"

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 no br i1. The first-arm write is a select on the compare, the second-arm write is a select on the inverted compare ANDed with coverage, and isHelperLane, sampleLevel and sample are all present.
  • pixel-wqm-execz-scc: a fixed table record feeds a uniform SCC diamond in the second arm. The IR has exactly one br i1, a phi, a rawBufferLoad and the implicit sample.
  • Eight negative controls keep the branch on a wave mask refusal: wrong parent mask in the inverse, wrong coverage restore, wrong sample-window restore, coverage pair clobbered, WQM pair clobbered, v_readfirstlane in an arm, dynamic table offset, sample outside a window.

New cases in tests/native_fixed_graphics_psi1_check.py: wqm-primitive-m0 compiles; wqm-numeric-m0, wqm-reads-m0 and wqm-after-vector-write keep 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

  • One reviewable behaviour per commit. The M0 move can become its own PR on request.
  • Negative controls are included for the new fixtures.
  • No guest files, dumps, distribution links or secrets.

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 lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-execz checks only the IR shape (selects, isHelperLane, sample, no br 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_arms returns 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 a continue, 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 matches s_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_arms runs 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-m0 and -after-vector-write keep the refusals.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@R0Y00
R0Y00 merged commit c6689e2 into R0Y00:main Dec 2, 2026
5 checks passed
tedin7 added a commit to tedin7/Xbox2Windows that referenced this pull request Dec 2, 2026
…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
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.

3 participants