Repository navigation
shader: lower a pixel discard written as a compare that writes EXEC - #3615
Merged
Merged
Conversation
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>
3 tasks
lukaslw-lab
approved these changes
Nov 30, 2026
lukaslw-lab
left a comment
Contributor
There was a problem hiding this comment.
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_execgatesscalaralone and looks atsrc[0]/src[1]only.local_alu(op)andlane_compareaccept ops without that test. For example,v_mov_b32 v1, exec_lo,v_bcnt_u32_b32 v1, exec_lo, 0, a VOP3src[2]ofexec, or av_cmp_*with anexec_losource all pass the filter. A SOP op reading av_cmpresult 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_numericon 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 applyreads_execto every tail op, includingsrc[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_execzto the valid-maskEXP_NULL(skip.op == 8, DONE + VM). Class and SDWA compares are refused. Wave32 is not matched.whole_quadand 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*,mbcntand_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.
- The kill must sit immediately before the
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
A pixel stage that removes lanes with a
v_cmpxcompare (which writes EXEC) and then skips to a valid-maskEXP_NULLwhen the wave is empty was refused withgraphics 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:The compare becomes a
discardof 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:
exp nullwith DONE and VM;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_graphicsinsrc/gfx1013_direct_graphics.inl. Open PR #3527 touches the same file in an unrelated hunk.Verification
Commit
085ac6a1onmain077bff3a. 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.native_pixel_cmpx_discard_warp(new)native_graphics_wqm_warpnative_graphics_wqm_irnative_direct_containernative_fixed_graphics_psi1native_graphics_interface_librarynative_compile_dxil_refusalsnative_compile_dxil_rekeynative_compile_dxil_watch9 of 9 passed, no skips.
offscreen_checkwas not rebuilt for this run; it comes from a full build ofmain78261e08. It draws the bytecodecompile_dxilproduced, 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 unmodifiedmain077bff3a(reported in #3612); tests driven byd3d12_xs.dll; any_hardwaretest. The pull request check does not run thenative_*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 harnessnative_graphics_wqm_check.pyuses. MIT, no external inputs.Cases:
limit < SV_Position.xtake the exported colour and the rest keep the clear value: all 16 pixels match;v_cndmaskin the tail give part of the survivors another colour, and the readback follows it;s_mov_b64 s[20:21], exec, a null export without VM, and an export before the compare are refused with the unchanged reason;PSI1entry and no container compiles the same shape to adiscard.Assumptions and limits:
v_cmpx_lt_f32is drawn. Integer compares, the other float predicates and wave32 stages are not covered by the fixture.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.graphics branch on a wave mask; I have not examined their shapes.Checklist
tests/cmake/native_pixel_cmpx_discard.cmake.)This change was AI-assisted.
🤖 Generated with Claude Code