Skip to content

shader: lower a pixel discard written as a compare that writes EXEC - #3615

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Not-Saii:native/pixel-cmpx-discard
Dec 1, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Not-Saii:native/pixel-cmpx-discard

Conversation

@Not-Saii

Copy link
Copy Markdown
Contributor

Change

A pixel stage that removes lanes with a v_cmpx compare (which writes EXEC) and then skips to a valid-mask EXP_NULL when the wave is empty was refused with graphics branch on a wave mask. The native emitter already lowers one discard shape (s_or_b64 / s_andn2_b64 exec / s_cbranch_execz); this adds the direct form:

v_cmpx_<op> ...            ; EXEC &= compare
s_cbranch_execz null
<tail>                     ; registers and exports only
s_endpgm
null: exp null ... done vm
s_endpgm

The compare becomes a discard of the lanes that fail it, and the skip is dropped.

The shape is matched only when the tail cannot observe the difference between a discarded pixel and a lane removed from EXEC. The tail may hold local VGPR arithmetic, lane compares into VCC or an SGPR pair, interpolation, scalar loads and scalar SOP operations, and a colour or depth export. It is left unmatched, so today's refusal stays, when:

  • the tail reads EXEC, or holds anything outside the list above (image operations, lane or wave operations, stores);
  • the compare is a class compare or uses SDWA selection;
  • the skip target is not exp null with DONE and VM;
  • an export precedes the compare.

Refs #3541. This is the second refusal of the depth-only fixed slot 57 pass reported there (comment). That pass needs #3612 as well: its first refusal is the raw depth export. The two changes are independent in code and can land in either order.

Shared interface: lower_graphics in src/gfx1013_direct_graphics.inl. Open PR #3527 touches the same file in an unrelated hunk.

Verification

Commit 085ac6a1 on main 077bff3a. Windows 11 build 26300, MSVC 19.44, Windows SDK 10.0.26100 (DXC from the SDK), release preset. The draw runs on Microsoft WARP (debug_errors=0 debug_warnings=0); no physical GPU is used.

cmake --build --preset release --target compile_dxil native_pixel_ir_dump
ctest --preset release --no-tests=error -R '^native_(pixel_cmpx_discard_warp|graphics_wqm_warp|graphics_wqm_ir|direct_container|fixed_graphics_psi1|graphics_interface_library|compile_dxil_refusals|compile_dxil_watch|compile_dxil_rekey)$'
Test Result
native_pixel_cmpx_discard_warp (new) passed
native_graphics_wqm_warp passed
native_graphics_wqm_ir passed
native_direct_container passed
native_fixed_graphics_psi1 passed
native_graphics_interface_library passed
native_compile_dxil_refusals passed
native_compile_dxil_rekey passed
native_compile_dxil_watch passed

9 of 9 passed, no skips. offscreen_check was not rebuilt for this run; it comes from a full build of main 78261e08. It draws the bytecode compile_dxil produced, so I did not expect the change to reach it, but I have not checked its link inputs.

Before the change, the new check fails at its first compile: native compute +0x8: graphics branch on a wave mask.

Not run: native_direct_mesh, which fails on unmodified main 077bff3a (reported in #3612); tests driven by d3d12_xs.dll; any _hardware test. The pull request check does not run the native_* tests.

Evidence and follow-up

The fixture is source-built: gfx1013 words assembled in the test, in the synthetic pixel container of tests/native_direct_container_check.py, drawn over an 8x2 target with the harness native_graphics_wqm_check.py uses. MIT, no external inputs.

Cases:

  • pixels with limit < SV_Position.x take the exported colour and the rest keep the clear value: all 16 pixels match;
  • a limit no pixel passes leaves the whole target at the clear value;
  • a second compare and a v_cndmask in the tail give part of the survivors another colour, and the readback follows it;
  • negative controls on the readback: the opposite survivors, no discard at all, and no select each differ;
  • refusal controls: a tail with s_mov_b64 s[20:21], exec, a null export without VM, and an export before the compare are refused with the unchanged reason;
  • a raw fixed VS/PS pair with a PSI1 entry and no container compiles the same shape to a discard.

Assumptions and limits:

  • The lowering rests on one argument: after the discard, a lane's later register values and exports cannot matter, and nothing in the allowed tail reads a neighbouring lane. The drawn cases support it for a move, a float compare and a select; the rest of the allowed list (interpolation, scalar loads, scalar SOP operations) is exercised by compilation only.
  • Only a float v_cmpx_lt_f32 is drawn. Integer compares, the other float predicates and wave32 stages are not covered by the fixture.
  • The export-before-compare control does not isolate its condition: with the condition removed the same program is still refused, by the existing repeated-target check. The condition is defensive.
  • Local-data result, for context only: with this change and shader: admit a depth-only export in the raw graphics front end #3612 applied together, the request for the pass in P0: identify and fix the first GPU blocker for a visible 3D scene draw #3541 compiles offline to vertex and pixel bytecode and a runtime manifest with no refusal; its pixel stage reads position, discards and stores SV_Depth. No package run has been done with them, so nothing here shows that draw being submitted or a depth value written. The public fixture verifies the discard shape, not that request.
  • On the same local request set, this change alone leaves 11 requests refused with graphics branch on a wave mask; I have not examined their shapes.

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. (No README row or documented command changes; the test is registered in tests/cmake/native_pixel_cmpx_discard.cmake.)
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

🤖 Generated with Claude Code

A pixel stage that removes lanes with a v_cmpx compare and then skips to a
valid-mask EXP_NULL when the wave is empty was refused with "graphics
branch on a wave mask". The emitter now takes that shape next to the
s_or/s_andn2 one it already knows: the compare becomes a discard of the
lanes that fail it, and the skip is dropped.

The code after the skip may only compute registers and export: local
arithmetic, lane compares, interpolation, scalar loads and a color or
depth export. A read of the narrowed EXEC, a class compare, or an export
before the compare leaves the shape unmatched, so those stay refused.

Refs R0Y00#3541

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>

@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 085ac6a1 by reading the diff; not built or run.

Verdict: approve. On gfx10 v_cmpx_* writes only EXEC, so lowering it to discard(!cmp) and dropping the wave-empty skip is right for the matched shape. No MUST. The SHOULD can follow.

  • SHOULD The tail filter (src/gfx1013_direct_graphics.inl:1564-1572) enforces "no read of the narrowed EXEC" only for the SOP alternative: reads_exec gates scalar alone and looks at src[0]/src[1] only. local_alu(op) and lane_compare accept ops without that test. For example, v_mov_b32 v1, exec_lo, v_bcnt_u32_b32 v1, exec_lo, 0, a VOP3 src[2] of exec, or a v_cmp_* with an exec_lo source all pass the filter. A SOP op reading a v_cmp result pair (e.g. s_bcnt1_i32_b64 s22, s[20:21]) also passes, and that is a wave operation over lanes the discard removed. I expect the ALU to refuse these later (require_numeric on 126/127, the full-wave-mask refusal), so I am not claiming a wrong result. But the shape's correctness argument then rests on refusals elsewhere that no test pins. Either apply reads_exec to every tail op, including src[2], and refuse SOP reads of compare destinations, or add those two shapes as refusal controls.
  • Checked, no finding:
    • The kill must sit immediately before the s_cbranch_execz to the valid-mask EXP_NULL (skip.op == 8, DONE + VM). Class and SDWA compares are refused. Wave32 is not matched. whole_quad and a graphics predicate are refused at the kill (:1853).
    • Tail exports are MRT0-7 or Z only (target <= 8). An earlier export blocks the match.
    • Implicit-derivative ops (MIMG), DPP, *lane*, mbcnt and _co_ ops are outside the allowed list.
    • The search stops at the first skip to EXP_NULL, so a non-matching shape keeps today's refusal.

Tests: the WARP draw checks survivors pixel by pixel, the all-fail case, and a per-lane select after the kill, with three readback negative controls. Three refusal controls are included, and you already noted that the export-before-compare one is not isolated. A raw PSI1 pair also emits discard. Only v_cmpx_lt_f32 is drawn. native_pixel_cmpx_discard_warp is not in the Windows pr preset filter, so it has only your WARP run on 077bff3a.

@R0Y00
R0Y00 merged commit 7bccb72 into R0Y00:main Dec 1, 2026
5 checks passed
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