shader: thread a constant-flag mesh edge past its VCC test (Part of #3703) #3956

Open
mumba17 wants to merge 1 commit from upstream-pr/3956 into main
mumba17 commented 2026-12-03 17:43:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-03T17:43:19Z.


Part of #3703 (group 1 of unbound numeric SGPR sN, claimed in https://github.com/R0Y00/Xbox2Windows/issues/3703#issuecomment-7385516376).

Problem

A scalar branch skips a block of buffer reads. Both paths then join, and right after the join a VGPR flag decides a VCC branch over the code that reads what the block loaded:

  • skip path: the flag is set to a constant;
  • load path: the flag is set from a scalar compare;
  • after the join: v_cmp_eq_u32 vcc, K, vF, then s_andn2_b64 vcc, exec, vcc, then s_cbranch_vccnz T over the reads.

On the skip path the flag is a constant other than K, so VCC equals EXEC and the branch is always taken: the reads are reached only from the load path. The frontend merged both paths at the join, so a loaded SGPR became a phi with the skip path's unrelated value, and the first numeric read refused with unbound numeric SGPR sN.

Change

lower_mesh, forward joins: when a join with two or more incoming edges is followed directly by exactly that flag test (only v_mov_b32 copies, s_nop and s_waitcnt around it), and EXEC is full or the guard of an entered EXECZ skip, any edge whose flag VGPR holds a known constant (a literal) other than K is sent straight to T. That edge's register file gets the region's VGPR copies applied without emitting IR. VCC words are left unbound on that edge and SCC is set to 1. Every other edge keeps the existing path, and the VCC branch is lowered as before for those edges.

Not threaded:

  • when the flag is written between the join and the compare;
  • when every edge would be threaded;
  • inside a SAVEEXEC diamond, a scalar loop, or after allocation;
  • when T is past an open skip's end;
  • when another branch lands inside the region.

Tests (native_direct_mesh)

  • flag-join-threads-skip-edge: s21 == 0 skips s_buffer_load_dword s20 and v7 = -1, with v7 = 0 set before the skip. After the join, v_cmp_eq_u32 vcc, -1, v7 + s_andn2_b64 + s_cbranch_vccnz jumps over s_cmp_lg_u32 s20, 0 + s_cselect_b32 s22, 1, 2, and the export reads s22. The check requires that the skip edge carries v7 = 0 into the branch target and that s22 is phi [0, …], [select 1/2, …].
  • flag-join-threads-in-lane-skip: the same join inside an entered v_cmpx_eq_u32 + EXECZ lane skip.
  • Refusal controls (unbound numeric SGPR s20):
    • flag-join-unknown-flag: the skip edge's flag is v7 = s21, uniform but not a known constant;
    • flag-join-rewritten-flag: v7 = -1 is written after the join, so the read is reachable from both paths.
  • Mutations: on unmodified main, flag-join-threads-skip-edge fails with unbound numeric SGPR s20. With the after-join rewrite check removed, flag-join-rewritten-flag translates and the test fails.

Census

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

main this PR
translate 2,163 2,186
unbound numeric SGPR sN 102 54
  • 0 translations lost.
  • All 48 programs of this form move: 18 translate, 17 reach unproven packed mesh signature rows, 13 reach unsupported packed vertex export.
  • 15 programs outside the row have the same join and move as well. They were graphics register undefined on an incoming path: 5 translate, 10 reach unsupported packed vertex export. No other program changes its first refusal.
  • Left in the row: 41 read numeric fields of an image descriptor loaded from a descriptor table. These need the runtime to supply those words (cf. #3801), so they're not part of this PR. 13 other forms remain.

Counts only; request bytes stay local.

Checks

  • ctest --preset pr -j 4 (Windows, RTX 3090, debug): 349/351 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5631815780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3956). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-03T17:43:19Z. --- Part of #3703 (group 1 of `unbound numeric SGPR sN`, claimed in https://github.com/R0Y00/Xbox2Windows/issues/3703#issuecomment-7385516376). ## Problem A scalar branch skips a block of buffer reads. Both paths then join, and right after the join a VGPR flag decides a VCC branch over the code that reads what the block loaded: - skip path: the flag is set to a constant; - load path: the flag is set from a scalar compare; - after the join: `v_cmp_eq_u32 vcc, K, vF`, then `s_andn2_b64 vcc, exec, vcc`, then `s_cbranch_vccnz T` over the reads. On the skip path the flag is a constant other than K, so VCC equals EXEC and the branch is always taken: the reads are reached only from the load path. The frontend merged both paths at the join, so a loaded SGPR became a phi with the skip path's unrelated value, and the first numeric read refused with `unbound numeric SGPR sN`. ## Change `lower_mesh`, forward joins: when a join with two or more incoming edges is followed directly by exactly that flag test (only `v_mov_b32` copies, `s_nop` and `s_waitcnt` around it), and EXEC is full or the guard of an entered EXECZ skip, any edge whose flag VGPR holds a known constant (a literal) other than K is sent straight to T. That edge's register file gets the region's VGPR copies applied without emitting IR. VCC words are left unbound on that edge and SCC is set to 1. Every other edge keeps the existing path, and the VCC branch is lowered as before for those edges. Not threaded: - when the flag is written between the join and the compare; - when every edge would be threaded; - inside a SAVEEXEC diamond, a scalar loop, or after allocation; - when T is past an open skip's end; - when another branch lands inside the region. ## Tests (`native_direct_mesh`) - `flag-join-threads-skip-edge`: `s21 == 0` skips `s_buffer_load_dword s20` and `v7 = -1`, with `v7 = 0` set before the skip. After the join, `v_cmp_eq_u32 vcc, -1, v7` + `s_andn2_b64` + `s_cbranch_vccnz` jumps over `s_cmp_lg_u32 s20, 0` + `s_cselect_b32 s22, 1, 2`, and the export reads s22. The check requires that the skip edge carries `v7 = 0` into the branch target and that s22 is `phi [0, …], [select 1/2, …]`. - `flag-join-threads-in-lane-skip`: the same join inside an entered `v_cmpx_eq_u32` + EXECZ lane skip. - Refusal controls (`unbound numeric SGPR s20`): - `flag-join-unknown-flag`: the skip edge's flag is `v7 = s21`, uniform but not a known constant; - `flag-join-rewritten-flag`: `v7 = -1` is written after the join, so the read is reachable from both paths. - Mutations: on unmodified main, `flag-join-threads-skip-edge` fails with `unbound numeric SGPR s20`. With the after-join rewrite check removed, `flag-join-rewritten-flag` translates and the test fails. ## Census Native Mesh86 capture, 6,685 distinct programs, one `compile_dxil … gfx1013-container-ms-texture-heap` run each, release build, main `8cb022db` vs this branch: | | main | this PR | |---|---:|---:| | translate | 2,163 | 2,186 | | `unbound numeric SGPR sN` | 102 | 54 | - 0 translations lost. - All 48 programs of this form move: 18 translate, 17 reach `unproven packed mesh signature rows`, 13 reach `unsupported packed vertex export`. - 15 programs outside the row have the same join and move as well. They were `graphics register undefined on an incoming path`: 5 translate, 10 reach `unsupported packed vertex export`. No other program changes its first refusal. - Left in the row: 41 read numeric fields of an image descriptor loaded from a descriptor table. These need the runtime to supply those words (cf. #3801), so they're not part of this PR. 13 other forms remain. Counts only; request bytes stay local. ## Checks - `ctest --preset pr -j 4` (Windows, RTX 3090, debug): 349/351 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)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3956:upstream-pr/3956'
git switch 'upstream-pr/3956'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3956'
git switch 'upstream-pr/3956'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3956'
git switch 'upstream-pr/3956'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3956'
git switch 'main'
git merge --squash 'upstream-pr/3956'
git switch 'main'
git merge --ff-only 'upstream-pr/3956'
git switch 'main'
git merge 'upstream-pr/3956'
git push origin 'main'
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!3956
No description provided.