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

Merged
Leyukaka merged 1 commit from upstream-pr/3423 into main 2026-11-29 08:24:31 +00:00
Leyukaka commented 2026-11-29 00:45:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T00:45:09Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5546145089 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3423). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T00:45:09Z. --- ## 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 - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] 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) - [x] No application files, dumps, distribution links or secrets included.
tedin7 commented 2026-11-29 08:24:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-29T08:24:27Z.

Review: COMMENTED


Reviewed c725dc6e1eb7ee900ac234b52a859ada35a7d230:

  • src/gfx1013_direct_mesh.inl: adds after_graphics_write invalidation of vcc_words, vcc_words+1, and vcc_nonempty when r == 106 || r == 107 (including across skip/diamond merges), extracts exec_nonempty_known(), and records vcc_nonempty (and vcc_words when EXEC bits are known) on v_cmp_* writing vcc when both sources are uniform and exec_nonempty_known() holds.
  • tests/native_direct_mesh_check.py: adds root-vcc-branch positive 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6102071539 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3423#pullrequestreview-6102071539). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-29T08:24:27Z. **Review:** COMMENTED --- Reviewed `c725dc6e1eb7ee900ac234b52a859ada35a7d230`: - `src/gfx1013_direct_mesh.inl`: adds `after_graphics_write` invalidation of `vcc_words`, `vcc_words+1`, and `vcc_nonempty` when `r == 106 || r == 107` (including across skip/diamond merges), extracts `exec_nonempty_known()`, and records `vcc_nonempty` (and `vcc_words` when `EXEC` bits are known) on `v_cmp_*` writing `vcc` when both sources are uniform and `exec_nonempty_known()` holds. - `tests/native_direct_mesh_check.py`: adds `root-vcc-branch` positive 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3423
No description provided.