shader: prove mesh scalar loads uniform inside an entered lane skip (Part of #3703) #3947

Manually merged
github merged 1 commit from github-bot/gh-3945 into gh-pr/3945/base 2026-12-03 16:27:43 +00:00 AGit
Owner

@⁠mumba17 on GitHub · 2026-12-03 16:06 UTC · original
mumba17:shader/mesh-vcc-branch-whole-wave → main · +34 −1 · 2 files · 1 commits · merged 2026-12-03 16:21 UTC

Part of #3705 (row E3, VCC branch without a whole-wave mask, claimed in #3705).

Problem

All 152 E3 programs in our census refuse at s_cbranch_vccnz. In 134 of them the mask is a VOP3 float compare of an SGPR against 0 (v_cmp_*_f32_e64 s[N:N+1], sM, 0), ANDed with EXEC into VCC (s_and_b64 vcc, exec, s[N:N+1]), and sM is a s_buffer_load_dword/_dwordx4 issued inside an entered EXECZ lane skip.

The VCC path already accepts this AND when the compare's inputs are proven uniform for the current lanes (mask_uniform). But a scalar load was recorded as uniform only under whole_wave_execution(), which excludes per-lane skips. So the loaded word stayed unproven, the compare got no uniform predicate, VCC got no nonempty word, and the branch refused.

Change

lower_mesh, scalar memory: a uniform-address scalar load also counts as uniform inside an entered EXECZ skip, i.e. while EXEC is still that skip's guard (exec_skip->guard == lane_active). The host threads that run the load are the guest's active lanes, and the guest wave runs the load once for all of them, so every running thread reads the same word. The value is recorded in active_uniform for the current lane set, as the existing narrowed-EXEC whole-wave case already does. The other conditions are unchanged: root address or buffer load, no open branch or pending forward edge, constant or uniform SGPR offset.

Readers of active_uniform match the lane set, so a value loaded under a narrower EXEC is still not uniform after a restore. VCC nonemptiness still needs exec_nonempty_known(), which holds inside an entered skip.

Tests (native_direct_mesh)

  • scalar-buffer-vcc-under-lane-skip: before allocation, v_cmpx_eq_u32 1, v0 plus EXECZ opens a lane skip. Inside it, s_buffer_load_dword s20, v_cmp_lt_f32_e64 s[4:5], s20, 0, s_and_b64 vcc, exec, s[4:5] and s_cbranch_vccnz over a v_mov_b32 v3, 1.0. Translates and validates. The check requires that the skip body branches on fcmp olt of the loaded word alone.
  • Refusal controls (still VCC branch without a whole-wave mask):
    • scalar-buffer-vcc-narrowed-load: the load runs under a further CMPX narrowing and EXEC is restored to the guard before the compare.
    • scalar-buffer-vcc-open-branch: the load sits under an open scalar branch (s_cmp_eq_u32 s21, 0 + s_cbranch_scc1 to the restore).
  • Mutation: on unmodified main, scalar-buffer-vcc-under-lane-skip fails with VCC branch without a whole-wave mask. Dropping only the guard == lane_active term does not fail a test, because the active_uniform lane-set match already rejects the narrowed form. The term stays as the statement that the skip was entered.

Census

Native Mesh86 capture, 6,685 distinct programs, one compile_dxil … gfx1013-container-ms-texture-heap run each, release build, main b78e10df vs this branch:

main this PR
translate 2,161 2,161
VCC branch without a whole-wave mask 152 33
  • 119 programs move on, and 0 translations are lost. No program outside E3 changes its first refusal.
  • Where the 119 stop next: v_readfirstlane_b32 74, s_load_dwordx4 root mapping 29, mesh SAVEEXEC then arm depends on EXEC 8, v_madak_f32 3, undefined on an incoming path 3, group memory exchange 2.
  • The 33 left in E3: 18 build VCC from per-lane compares (s_or_b64 with VCC, pair ANDs), which needs a cross-lane vote and is not part of this PR; 15 load the scalar under an open scalar branch.

Counts only; request bytes stay local.

Checks

  • ctest --preset pr -j 4 (Windows, RTX 3090, debug): 345/347 passed, native_direct_mesh included. The 2 failures, native_compute_implicit_lod_controls and native_wave_virtual_derivative_controls, also fail on main locally (this SDK's validator is 1.7, the modules declare 1.8). They fail the same way when rerun serially.
  • native_direct_mesh against the release build with and without the change, as above.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-12-03 16:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3945) `mumba17:shader/mesh-vcc-branch-whole-wave` → `main` · +34 −1 · 2 files · 1 commits · merged 2026-12-03 16:21 UTC Part of #3705 (row **E3**, `VCC branch without a whole-wave mask`, claimed in https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/3705). ## Problem All 152 E3 programs in our census refuse at `s_cbranch_vccnz`. In 134 of them the mask is a VOP3 float compare of an SGPR against 0 (`v_cmp_*_f32_e64 s[N:N+1], sM, 0`), ANDed with EXEC into VCC (`s_and_b64 vcc, exec, s[N:N+1]`), and `sM` is a `s_buffer_load_dword`/`_dwordx4` issued inside an entered EXECZ lane skip. The VCC path already accepts this AND when the compare's inputs are proven uniform for the current lanes (`mask_uniform`). But a scalar load was recorded as uniform only under `whole_wave_execution()`, which excludes per-lane skips. So the loaded word stayed unproven, the compare got no uniform predicate, VCC got no nonempty word, and the branch refused. ## Change `lower_mesh`, scalar memory: a uniform-address scalar load also counts as uniform inside an entered EXECZ skip, i.e. while EXEC is still that skip's guard (`exec_skip->guard == lane_active`). The host threads that run the load are the guest's active lanes, and the guest wave runs the load once for all of them, so every running thread reads the same word. The value is recorded in `active_uniform` for the current lane set, as the existing narrowed-EXEC whole-wave case already does. The other conditions are unchanged: root address or buffer load, no open branch or pending forward edge, constant or uniform SGPR offset. Readers of `active_uniform` match the lane set, so a value loaded under a narrower EXEC is still not uniform after a restore. VCC nonemptiness still needs `exec_nonempty_known()`, which holds inside an entered skip. ## Tests (`native_direct_mesh`) - `scalar-buffer-vcc-under-lane-skip`: before allocation, `v_cmpx_eq_u32 1, v0` plus EXECZ opens a lane skip. Inside it, `s_buffer_load_dword s20`, `v_cmp_lt_f32_e64 s[4:5], s20, 0`, `s_and_b64 vcc, exec, s[4:5]` and `s_cbranch_vccnz` over a `v_mov_b32 v3, 1.0`. Translates and validates. The check requires that the skip body branches on `fcmp olt` of the loaded word alone. - Refusal controls (still `VCC branch without a whole-wave mask`): - `scalar-buffer-vcc-narrowed-load`: the load runs under a further CMPX narrowing and EXEC is restored to the guard before the compare. - `scalar-buffer-vcc-open-branch`: the load sits under an open scalar branch (`s_cmp_eq_u32 s21, 0` + `s_cbranch_scc1` to the restore). - Mutation: on unmodified main, `scalar-buffer-vcc-under-lane-skip` fails with `VCC branch without a whole-wave mask`. Dropping only the `guard == lane_active` term does not fail a test, because the `active_uniform` lane-set match already rejects the narrowed form. The term stays as the statement that the skip was entered. ## Census Native Mesh86 capture, 6,685 distinct programs, one `compile_dxil … gfx1013-container-ms-texture-heap` run each, release build, main `b78e10df` vs this branch: | | main | this PR | |---|---:|---:| | translate | 2,161 | 2,161 | | `VCC branch without a whole-wave mask` | 152 | 33 | - 119 programs move on, and 0 translations are lost. No program outside E3 changes its first refusal. - Where the 119 stop next: `v_readfirstlane_b32` 74, `s_load_dwordx4` root mapping 29, `mesh SAVEEXEC then arm depends on EXEC` 8, `v_madak_f32` 3, `undefined on an incoming path` 3, group memory exchange 2. - The 33 left in E3: 18 build VCC from per-lane compares (`s_or_b64` with VCC, pair ANDs), which needs a cross-lane vote and is not part of this PR; 15 load the scalar under an open scalar branch. Counts only; request bytes stay local. ## Checks - `ctest --preset pr -j 4` (Windows, RTX 3090, debug): 345/347 passed, `native_direct_mesh` included. The 2 failures, `native_compute_implicit_lod_controls` and `native_wave_virtual_derivative_controls`, also fail on main locally (this SDK's validator is 1.7, the modules declare 1.8). They fail the same way when rerun serially. - `native_direct_mesh` against the release build with and without the change, as above. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A scalar buffer load inside an entered EXECZ lane skip (EXEC is the skip's
guard) runs in exactly the host threads of the active guest lanes, from a
uniform address, so it has one value for all of them. Record it as uniform
for the current lane set, as under whole-wave execution. A VOP3 compare of
that value ANDed with EXEC into VCC then gets its wave-uniform proof, and
the following s_cbranch_vccnz no longer refuses with "VCC branch without a
whole-wave mask".

Part of #3703.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 16:09:10 +00:00
github-bot changed target branch from main to gh-pr/3945/base 2026-12-03 16:26:36 +00:00
github manually merged commit 386108a58d into gh-pr/3945/base 2026-12-03 16:27:43 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 16:21 UTC · original · approved these changes

Reviewed 386108a5. The additional uniform-load case requires the current EXEC to equal the entered skip guard, a uniform offset, and no open scalar branch. The new controls still refuse a load under narrower EXEC and a load inside an open branch. Independently rebuilt compile_dxil in MSVC Debug and ran ctest --test-dir out/build/review --no-tests=error -R '^native_direct_mesh$' --output-on-failure (1/1, no skips). Restoring the previous whole-wave-only condition made scalar-buffer-vcc-under-lane-skip fail at +0x34 with VCC branch without a whole-wave mask. This is source-built compile and emitted-DXIL evidence.

**@⁠R0Y00** on GitHub · 2026-12-03 16:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3945#pullrequestreview-6173815243) · **approved these changes** Reviewed 386108a5. The additional uniform-load case requires the current EXEC to equal the entered skip guard, a uniform offset, and no open scalar branch. The new controls still refuse a load under narrower EXEC and a load inside an open branch. Independently rebuilt compile_dxil in MSVC Debug and ran ctest --test-dir out/build/review --no-tests=error -R '^native_direct_mesh$' --output-on-failure (1/1, no skips). Restoring the previous whole-wave-only condition made scalar-buffer-vcc-under-lane-skip fail at +0x34 with VCC branch without a whole-wave mask. This is source-built compile and emitted-DXIL evidence.
This discussion has been locked. Commenting is limited to contributors.
No description provided.