Skip to content

shader: branch on VCC from a wave-uniform mesh compare - #3423

Open
Leyukaka wants to merge 1 commit into
R0Y00:mainfrom
Leyukaka:shader-mesh-vcc-uniform
Open

Leyukaka wants to merge 1 commit into
R0Y00:mainfrom
Leyukaka:shader-mesh-vcc-uniform

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Change

lower_mesh refused every s_cbranch_vccz/vccnz on a VCC written by v_cmp: the v_cmp path always cleared the VCC words and vcc_nonempty. On main, a uniform root compare followed by a VCC branch fails with native 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), in src/gfx1013_direct_mesh.inl:741-759:

  • both operands are uniform();
  • EXEC is full, wave_active is known, or the current lane predicate equals the enclosing EXECZ skip guard (exec_nonempty_known(), now shared with the SCC path).

vcc_nonempty is the uniform predicate (ANDed with wave_active when present). The VCC words are pred ? exec_word : 0, written only for known EXEC words.

Invalidation:

  • Any write of 106/107 through alu.write now clears the VCC words and vcc_nonempty in after_graphics_write (:36-38). This replaces the explicit clears in the v_cmp path and at the gather-arm join.
  • The two join loops that clear SGPRs by direct map assignment now call the same hook for 106/107: the end of a per-lane EXECZ skip (:319) and the CMPX lane-diamond join (:360). Without this, a VCC set inside the region survived the clear and merge_edges produced a per-thread phi with 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 to icmp u(gt|le) <cbuffer extractvalue>, 6.
  • Negative controls, each must fail with mesh VCC branch lacks a proven guest whole-wave mask and write no output:
    • lane-vcc-branch: VGPR operand.
    • narrowed-vcc-branch: EXEC narrowed by v_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 over v_cmp_gt_u32 vcc,s20,6, exec=-1, vccz.
    • diamond-known-vcc: s_mov_b64 vcc,-1, CMPX lane diamond with v_cmp_gt_u32 vcc,s20,6 in 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 212d4b5f on the two files is empty, so main 212d4b5f does 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_hardware fails (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 .inl rebuilt, native_direct_mesh fails at run('root-vcc-branch', ...) with native compute +0xc: mesh VCC branch lacks a proven guest whole-wave mask.

  • The join hole, found in the first pass before the :319/:360 hook calls. Probe programs run against compile_dxil.exe:

    program main without join hook this PR
    diamond, initial vcc,-1 (diamond-known-vcc) refused +0x44 accepted refused +0x44
    diamond, no initial VCC refused refused refused +0x40
    per-lane skip, initial vcc,-1 (skip-uniform-vcc) refused +0x24 accepted refused +0x24
    per-lane skip with s_mov_b64 vcc,0 inside accepted accepted refused +0x20
  • Mutations, each rebuilt and run with native_direct_mesh:

    # Mutation Result
    M1 :743 rhs without uniform() fails, lane-vcc-branch accepted
    M2 hook's r==106 || r==107 branch removed (:36-38) fails, overwritten-vcc-branch accepted
    M3 && exec_nonempty_known() dropped from the VCC path fails, narrowed-vcc-branch accepted
    J1 hook call at :319 removed fails at skip-uniform-vcc
    J2 hook call at :360 removed fails at diamond-known-vcc

    M1-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.inl and the same test file, in other functions and cases.

Not covered:

  • The s_mov_b64 vcc,0 inside 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.
  • The effect on the 543 captured requests is not measured. Fixture coverage only.

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 capability or build change)
  • No application files, dumps, distribution links or secrets included.

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.

1 participant