startup: accept forward branches outside the slot 57 group-memory exchanges (Part of #2413) #2540

Merged
Leyukaka merged 2 commits from upstream-pr/2548 into main 2026-11-25 21:03:28 +00:00
Leyukaka commented 2026-11-25 20:29:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T20:29:03Z.


Part of #2413 (claim). #2447 refused any branch outside the two group-memory exchanges of a slot 57 mesh program. This accepts forward branches in the code before the first exchange and after the second.

Accepted:

  • s_branch;
  • s_cbranch_scc0/scc1 on SCC proven wave-uniform;
  • s_cbranch_execz.

They are emitted through Stage's existing block dispatch. The group barrier and allocation block stays outside the pc dispatch, so every path runs it.

mesh_skeleton keeps its straight-line proofs, made path-aware:

  • At a join:
    • a VGPR stale or pending on any incoming path is stale;
    • a narrowed EXEC mask is kept only when every path has the same one;
    • the wave index, thread index and SCC facts are kept only when all paths agree.
  • Under s_cbranch_execz: the skipped range may hold only predicated lane writes, because the model skips per lane where the guest skips per wave. An s_branch in it may land at or past the execz target, over s_nop/s_waitcnt/s_clause only. This is the s_branch .else over .empty: s_nop of a compiled if/else.
  • if/else: accepted through s_and_saveexec_b64 of a fresh VCC and its s_andn2_b64 complement.

Still refused: loops, a branch entering or crossing an exchange, s_cbranch_vccz/vccnz, s_setpc/s_call/s_swappc, a branch bypassing an export, an early s_endpgm, other uses of a saved EXEC mask, unreachable code after a branch, and an SCC branch on a value not proven wave-uniform. Each has a control except the non-uniform SCC refusal (in Stage), which has none yet.

Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100), on main 780f3c0 plus this commit:

  • python -B tests/startup_mesh57_skeleton_check.py: ok. New controls:
    • taken and not-taken SCC branches and a lane-masked if/else, which translate;
    • refusals for:
      • a loop;
      • a branch into the count exchange;
      • a branch over the group-index exchange;
      • s_setpc_b64;
      • a VGPR defined on one path;
      • different EXEC masks before an export;
      • a skipped scalar write under s_cbranch_execz, inside the range and past the target;
      • a uniform branch over the primitive export;
      • s_cbranch_vccz and s_cbranch_vccnz, an early s_endpgm, a read of the saved EXEC pair, and unreachable code after an unconditional branch.
  • ... draw <dxc> offscreen_check warp and hardware: ok. 5 draws each, including both SCC branches and the if/else, match the CPU model (1024 pixels, 0 mismatches). WARP: Microsoft Basic Render Driver. Hardware: NVIDIA GeForce RTX 5080.
  • Also ok: startup_gfx2hlsl_watch_check, startup_translator_check, startup_gfx2hlsl_join_symbols_check, startup_gfx2hlsl_loop_constants_check, startup_gfx2hlsl_refusals_check, startup_compute_translate_check, startup_gfx2hlsl_waitcnt_depctr_check and startup_gfx2hlsl_capture_check.

Mutation checks, run by hand. The controls fail on each:

  • loops accepted;
  • a branch crossing an exchange accepted;
  • the join keeping the first path's mask;
  • the execz skipped range unchecked;
  • a branch allowed to bypass an export;
  • stale registers not merged;
  • an s_branch landing past the target over a scalar write.

Measured on a local capture (counts only, inputs private): at main 396e7e2, 279 slot 57 requests stopped at a branch outside the group-memory exchanges. On this branch (main 780f3c0 plus this commit) none of them translates yet. Their next first refusals:

  • a branch enters or crosses a group-memory exchange: 162. In each, an s_cbranch_execz between the two exchanges targets the first instruction of the count exchange, and the range it skips holds ds_write/ds_read: a third group-memory exchange that the accepted shape does not model. Accepting a branch that lands on an exchange start would also need a proof of the EXEC mask the exchange is entered with, so it is left out here.
  • s_cbranch_vccz (76) and s_cbranch_vccnz (1) on a wave-wide condition.
  • The NEG refusal from ce530846 (v_cmp_class_f32_e64, v_fma_f32 with NEG on an integer or literal source): 34.
  • A loop: 6.

So this removes the branch refusal itself. The third exchange and VCC branches are the next steps for these programs.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6613127888 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2548). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T20:29:03Z. --- Part of #2413 ([claim](https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7173092035)). #2447 refused any branch outside the two group-memory exchanges of a slot 57 mesh program. This accepts forward branches in the code before the first exchange and after the second. **Accepted:** - `s_branch`; - `s_cbranch_scc0`/`scc1` on SCC proven wave-uniform; - `s_cbranch_execz`. They are emitted through `Stage`'s existing block dispatch. The group barrier and allocation block stays outside the pc dispatch, so every path runs it. `mesh_skeleton` keeps its straight-line proofs, made path-aware: - **At a join:** - a VGPR stale or pending on any incoming path is stale; - a narrowed EXEC mask is kept only when every path has the same one; - the wave index, thread index and SCC facts are kept only when all paths agree. - **Under `s_cbranch_execz`:** the skipped range may hold only predicated lane writes, because the model skips per lane where the guest skips per wave. An `s_branch` in it may land at or past the execz target, over `s_nop`/`s_waitcnt`/`s_clause` only. This is the `s_branch .else` over `.empty: s_nop` of a compiled if/else. - **if/else:** accepted through `s_and_saveexec_b64` of a fresh VCC and its `s_andn2_b64` complement. **Still refused:** loops, a branch entering or crossing an exchange, `s_cbranch_vccz`/`vccnz`, `s_setpc`/`s_call`/`s_swappc`, a branch bypassing an export, an early `s_endpgm`, other uses of a saved EXEC mask, unreachable code after a branch, and an SCC branch on a value not proven wave-uniform. Each has a control except the non-uniform SCC refusal (in `Stage`), which has none yet. **Tests** (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100), on main `780f3c0` plus this commit: - `python -B tests/startup_mesh57_skeleton_check.py`: ok. New controls: - taken and not-taken SCC branches and a lane-masked if/else, which translate; - refusals for: - a loop; - a branch into the count exchange; - a branch over the group-index exchange; - `s_setpc_b64`; - a VGPR defined on one path; - different EXEC masks before an export; - a skipped scalar write under `s_cbranch_execz`, inside the range and past the target; - a uniform branch over the primitive export; - `s_cbranch_vccz` and `s_cbranch_vccnz`, an early `s_endpgm`, a read of the saved EXEC pair, and unreachable code after an unconditional branch. - `... draw <dxc> offscreen_check warp` and `hardware`: ok. 5 draws each, including both SCC branches and the if/else, match the CPU model (1024 pixels, 0 mismatches). WARP: Microsoft Basic Render Driver. Hardware: NVIDIA GeForce RTX 5080. - Also ok: `startup_gfx2hlsl_watch_check`, `startup_translator_check`, `startup_gfx2hlsl_join_symbols_check`, `startup_gfx2hlsl_loop_constants_check`, `startup_gfx2hlsl_refusals_check`, `startup_compute_translate_check`, `startup_gfx2hlsl_waitcnt_depctr_check` and `startup_gfx2hlsl_capture_check`. **Mutation checks**, run by hand. The controls fail on each: - loops accepted; - a branch crossing an exchange accepted; - the join keeping the first path's mask; - the execz skipped range unchecked; - a branch allowed to bypass an export; - stale registers not merged; - an `s_branch` landing past the target over a scalar write. **Measured on a local capture** (counts only, inputs private): at main `396e7e2`, 279 slot 57 requests stopped at `a branch outside the group-memory exchanges`. On this branch (main `780f3c0` plus this commit) none of them translates yet. Their next first refusals: - `a branch enters or crosses a group-memory exchange`: 162. In each, an `s_cbranch_execz` between the two exchanges targets the first instruction of the count exchange, and the range it skips holds `ds_write`/`ds_read`: a third group-memory exchange that the accepted shape does not model. Accepting a branch that lands on an exchange start would also need a proof of the EXEC mask the exchange is entered with, so it is left out here. - `s_cbranch_vccz` (76) and `s_cbranch_vccnz` (1) on a wave-wide condition. - The NEG refusal from ce530846 (`v_cmp_class_f32_e64`, `v_fma_f32` with NEG on an integer or literal source): 34. - A loop: 6. So this removes the branch refusal itself. The third exchange and VCC branches are the next steps for these programs. AI-assisted.
tedin7 commented 2026-11-25 21:01:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T20:31:42Z.

Review: COMMENTED


Review of head a7fe4e4f (comment only, no approval).

Verdict: code and fixture tests look sound. I found no bug. No other open or merged PR covers this slice (#2447 is the base it extends).

Checked

  • python3 -B tests/startup_mesh57_skeleton_check.py: ok.
  • python3 tests/docs_links_check.py: ok. python3 tests/bidi_controls_check.py: ok. git diff --check origin/main...HEAD: clean.
  • Mutations of tools/startup/gfx2hlsl.py, each makes the new test fail (then reverted):
    • the "a branch bypasses an export" refusal removed: fails;
    • the backward-branch (loop) check disabled: fails (KeyError in the checker);
    • the s_cbranch_execz skipped-range refusal removed: fails.
  • Branch targets, forward-only edges, join merging of stale/pending VGPRs and EXEC masks read consistently with the PR text.

Notes

  • As the PR says, the vccz/vccnz, early s_endpgm, saved-mask, unreachable-code and non-uniform SCC refusals have no control yet. A small follow-up would close that.
  • The PR is a startup change and reports counts from a capture we do not have. I reviewed code and fixture tests only and did not run any executable. I did not run Win2025.
  • Merge stays with MasterDomino or @R0Y00, who can verify the startup claim. CI on Windows was still pending when I looked.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6064550867 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2548#pullrequestreview-6064550867). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T20:31:42Z. **Review:** COMMENTED --- Review of head a7fe4e4f (comment only, no approval). **Verdict:** code and fixture tests look sound. I found no bug. No other open or merged PR covers this slice (#2447 is the base it extends). **Checked** - `python3 -B tests/startup_mesh57_skeleton_check.py`: ok. - `python3 tests/docs_links_check.py`: ok. `python3 tests/bidi_controls_check.py`: ok. `git diff --check origin/main...HEAD`: clean. - Mutations of `tools/startup/gfx2hlsl.py`, each makes the new test fail (then reverted): - the "a branch bypasses an export" refusal removed: fails; - the backward-branch (loop) check disabled: fails (KeyError in the checker); - the `s_cbranch_execz` skipped-range refusal removed: fails. - Branch targets, forward-only edges, join merging of stale/pending VGPRs and EXEC masks read consistently with the PR text. **Notes** - As the PR says, the `vccz`/`vccnz`, early `s_endpgm`, saved-mask, unreachable-code and non-uniform SCC refusals have no control yet. A small follow-up would close that. - The PR is a startup change and reports counts from a capture we do not have. I reviewed code and fixture tests only and did not run any executable. I did not run Win2025. - Merge stays with MasterDomino or @R0Y00, who can verify the startup claim. CI on Windows was still pending when I looked. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 22:02:00 +00:00
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!2540
No description provided.