shader: lower a pixel discard written as a compare that writes EXEC #3615
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3615"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-30T14:31:41Z.
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
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:35:12Z.
Review: APPROVED
Reviewed
085ac6a1by reading the diff; not built or run.Verdict: approve. On gfx10
v_cmpx_*writes only EXEC, so lowering it todiscard(!cmp)and dropping the wave-empty skip is right for the matched shape. No MUST. The SHOULD can follow.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.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).target <= 8). An earlier export blocks the match.*lane*,mbcntand_co_ops are outside the allowed list.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. Onlyv_cmpx_lt_f32is drawn.native_pixel_cmpx_discard_warpis not in the Windowsprpreset filter, so it has only your WARP run on077bff3a.