shader: branch on VCC from a wave-uniform mesh compare #3423
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3423"
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 Leyukaka on 2026-11-29T00:45:09Z.
Change
lower_meshrefused everys_cbranch_vccz/vccnzon a VCC written byv_cmp: the v_cmp path always cleared the VCC words andvcc_nonempty. On main, a uniform root compare followed by a VCC branch fails withnative compute +0xc: mesh VCC branch lacks a proven guest whole-wave mask.This change sets them when the proof is the one the SCC path already uses (
src/gfx1013_direct_mesh.inl:874), insrc/gfx1013_direct_mesh.inl:741-759:uniform();wave_activeis known, or the current lane predicate equals the enclosing EXECZ skip guard (exec_nonempty_known(), now shared with the SCC path).vcc_nonemptyis the uniform predicate (ANDed withwave_activewhen present). The VCC words arepred ? exec_word : 0, written only for known EXEC words.Invalidation:
alu.writenow clears the VCC words andvcc_nonemptyinafter_graphics_write(:36-38). This replaces the explicit clears in the v_cmp path and at the gather-arm join.:319) and the CMPX lane-diamond join (:360). Without this, a VCC set inside the region survived the clear andmerge_edgesproduced a per-threadphiwith the entry value, so lanes of one wave could take different branches. With the hook,merge_edges(:238-241) drops a register empty on either edge, so no such phi remains.Tests (
tests/native_direct_mesh_check.py):root-vcc-branch: uniform root compare into VCC, then a VCC branch. Must translate; the DXIL regex ties the branch toicmp u(gt|le) <cbuffer extractvalue>, 6.mesh VCC branch lacks a proven guest whole-wave maskand write no output:lane-vcc-branch: VGPR operand.narrowed-vcc-branch: EXEC narrowed byv_cmpx_eq_u32, full EXEC restored before the branch.overwritten-vcc-branch: a lane compare writes VCC between the compare and the branch.skip-uniform-vcc:s_mov_b64 vcc,-1,v_cmpx_eq_u32 0,v0, EXECZ skip overv_cmp_gt_u32 vcc,s20,6,exec=-1,vccz.diamond-known-vcc:s_mov_b64 vcc,-1, CMPX lane diamond withv_cmp_gt_u32 vcc,s20,6in the then-arm, join,s_cbranch_vccz.Refs #2413, #3416 (item d of my claim, the VCC item).
Verification
First pass: change applied to main
51472392. Second pass: same checks on the final change;git diff --stat 51472392 212d4b5fon the two files is empty, so main212d4b5fdoes not touch them. Release build.Targeted run:
ctest --test-dir out\build\release --no-tests=error --output-on-failure -R "^(native_direct_mesh|native_compile_dxil_refusals|native_fixed_mesh57.*)$": 21/22 pass, 0 skipped.native_fixed_mesh57_waterfall_fine_hardwarefails (pixels (0,0) (2,0) (1,1) (3,1) got 0xff0000ff/0xff00ff00, expected 0xffff0000). It fails the same way with main's.inl, so it predates this change.Fails on main: with main's
.inlrebuilt,native_direct_meshfails atrun('root-vcc-branch', ...)withnative compute +0xc: mesh VCC branch lacks a proven guest whole-wave mask.The join hole, found in the first pass before the
:319/:360hook calls. Probe programs run againstcompile_dxil.exe:vcc,-1(diamond-known-vcc)vcc,-1(skip-uniform-vcc)s_mov_b64 vcc,0insideMutations, each rebuilt and run with
native_direct_mesh::743rhswithoutuniform()lane-vcc-branchacceptedr==106 || r==107branch removed (:36-38)overwritten-vcc-branchaccepted&& exec_nonempty_known()dropped from the VCC pathnarrowed-vcc-branchaccepted:319removedskip-uniform-vcc:360removeddiamond-known-vccM1-M3 ran in both passes, J1-J2 in the second. After restore, both files are byte-identical to before the mutations (sha256) and the targeted run is 21/22 again.
Evidence and follow-up
The fixtures are hand-encoded instruction words in
tests/native_direct_mesh_check.py.#3420 and #3422 also edit
src/gfx1013_direct_mesh.inland the same test file, in other functions and cases.Not covered:
s_mov_b64 vcc,0inside a per-lane skip case is accepted on main. With this change the probe is refused (+0x20), but no test in the suite covers that variant.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-29T08:24:27Z.
Review: COMMENTED
Reviewed
c725dc6e1eb7ee900ac234b52a859ada35a7d230:src/gfx1013_direct_mesh.inl: addsafter_graphics_writeinvalidation ofvcc_words,vcc_words+1, andvcc_nonemptywhenr == 106 || r == 107(including across skip/diamond merges), extractsexec_nonempty_known(), and recordsvcc_nonempty(andvcc_wordswhenEXECbits are known) onv_cmp_*writingvccwhen both sources are uniform andexec_nonempty_known()holds.tests/native_direct_mesh_check.py: addsroot-vcc-branchpositive test plus 5 negative controls (lane-vcc-branch,narrowed-vcc-branch,overwritten-vcc-branch,skip-uniform-vcc,diamond-known-vcc).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
c725dc6e1eb7ee900ac234b52a859ada35a7d230:ctest --preset dev -R '^native_direct_mesh$' --parallel 5 --no-tests=error --output-on-failure: 1/1 passed (1.67s)ctest --preset release -R '^native_direct_mesh$' --parallel 5 --no-tests=error --output-on-failure: 1/1 passed (1.51s)AI-assisted; commands listed were executed locally.