startup: refuse compute branches that decide for the whole wave but are lowered per lane #2764

Closed
tedin7 wants to merge 9 commits from upstream-pr/2772 into main
tedin7 commented 2026-11-26 07:33:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:33:35Z.


Part of #1723

What this unblocks: stops silently wrong compute shader output: a branch that the wave takes as a whole is no longer lowered as a per-lane decision.

What changed

Compute programs are lowered one lane at a time. s_cbranch_vccz, s_cbranch_vccnz, s_cbranch_execnz and an s_cbranch_scc0/scc1 on an SCC that depends on lane data decide once for the whole wave: the wave runs on while any lane's bit is set. The lowering took the branch from its own lane's bit, so a lane whose bit was clear skipped code the wave ran for it (or left a loop early while a scalar counter kept the wave's count). Such programs translated and gave a different value than the wave model.

They are now refused by name: <branch> decides for the whole wave and the one-lane model decides per lane. Still accepted, because an existing proof covers them:

  • an s_cbranch_execnz inside a block that an s_cbranch_execz skips (execz_refusals proves the block's EXEC writes). s_cbranch_vccz/vccnz and lane-data SCC branches inside such a block stay refused: the proof does not cover their condition (the wave runs the code while any lane's bit is set);
  • the closing s_cbranch_scc1 of a readfirstlane waterfall (waterfall_refusal);
  • an s_cbranch_execnz back edge whose loop writes no scalar register except EXEC and VCC, whose EXEC writes can only narrow the mask (v_cmpx, s_and/s_andn2 of EXEC with itself; a restore of a saved mask in the loop sets lanes an earlier round cleared, so it is refused) and whose VCC is not read after it (a lane that left changes nothing; no scalar count escapes; the wave's VCC after the loop holds the last compare, 0 for lanes that left earlier, which a lane running alone would not reproduce, so a later VCC read is refused: fixture with v_cndmask_b32_e32 ... vcc_lo after the loop);
  • an s_cbranch_scc0/scc1 whose SCC is proven wave-uniform.

The refusal is recorded at the branch and raised at the end of lowering, so every other refusal keeps its reason and order.

Tests

tests/startup_gfx2hlsl_compute_check.py: new check_wave_branches (vccz skip, SCC from s_and_saveexec, vccnz loop, execnz loop with a scalar counter, vccz/vccnz inside an execz block, an execnz loop that restores the saved EXEC in its body, an execnz loop with a VCC read after it: translated on main, refused now; a uniform-SCC branch and a vector-only execnz loop still translate). One existing assertion changed: a s_cbranch_vccz after the join of an execz block (s_and_b32 vcc_lo, vcc_lo, exec_lo, then the branch) was expected to translate; it is the same whole-wave decision and is now expected to be refused, the other reads in that loop are unchanged.

What stays open

  • Programs that need the whole-wave loop (scalar counters, vccnz/scc latches) stay refused until the wave-level loop model exists.

Cache revision

The compute lowering now refuses programs it used to translate, so a translation cached under the old revision could still be served. This PR advances the startup shader cache revision to x2w-startup-shader-28 / 28cs (runtime, offline tool, C++ test mirrors, docs, known-answer values recomputed with a separate FNV-1a loop). The C++ targets were not built here.

Verification:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-19: pass; the new shapes translate on main's gfx2hlsl.py and are refused here.
  • python3 -B tests/startup_compute_readfirstlane_check.py: pass.
  • Full tests/*check.py sweep against origin/main: 0 scripts change result (356 pass, 131 fail in both trees; the fails need the Windows toolchain).
  • Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6621786471 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T07:33:35Z. --- Part of #1723 What this unblocks: stops silently wrong compute shader output: a branch that the wave takes as a whole is no longer lowered as a per-lane decision. ## What changed Compute programs are lowered one lane at a time. `s_cbranch_vccz`, `s_cbranch_vccnz`, `s_cbranch_execnz` and an `s_cbranch_scc0`/`scc1` on an SCC that depends on lane data decide once for the whole wave: the wave runs on while any lane's bit is set. The lowering took the branch from its own lane's bit, so a lane whose bit was clear skipped code the wave ran for it (or left a loop early while a scalar counter kept the wave's count). Such programs translated and gave a different value than the wave model. They are now refused by name: `<branch> decides for the whole wave and the one-lane model decides per lane`. Still accepted, because an existing proof covers them: - an `s_cbranch_execnz` inside a block that an `s_cbranch_execz` skips (`execz_refusals` proves the block's EXEC writes). `s_cbranch_vccz`/`vccnz` and lane-data SCC branches inside such a block stay refused: the proof does not cover their condition (the wave runs the code while any lane's bit is set); - the closing `s_cbranch_scc1` of a readfirstlane waterfall (`waterfall_refusal`); - an `s_cbranch_execnz` back edge whose loop writes no scalar register except EXEC and VCC, whose EXEC writes can only narrow the mask (`v_cmpx`, `s_and`/`s_andn2` of EXEC with itself; a restore of a saved mask in the loop sets lanes an earlier round cleared, so it is refused) and whose VCC is not read after it (a lane that left changes nothing; no scalar count escapes; the wave's VCC after the loop holds the last compare, 0 for lanes that left earlier, which a lane running alone would not reproduce, so a later VCC read is refused: fixture with `v_cndmask_b32_e32 ... vcc_lo` after the loop); - an `s_cbranch_scc0`/`scc1` whose SCC is proven wave-uniform. The refusal is recorded at the branch and raised at the end of lowering, so every other refusal keeps its reason and order. ## Tests `tests/startup_gfx2hlsl_compute_check.py`: new `check_wave_branches` (vccz skip, SCC from `s_and_saveexec`, vccnz loop, execnz loop with a scalar counter, vccz/vccnz inside an execz block, an execnz loop that restores the saved EXEC in its body, an execnz loop with a VCC read after it: translated on `main`, refused now; a uniform-SCC branch and a vector-only execnz loop still translate). One existing assertion changed: a `s_cbranch_vccz` after the join of an execz block (`s_and_b32 vcc_lo, vcc_lo, exec_lo`, then the branch) was expected to translate; it is the same whole-wave decision and is now expected to be refused, the other reads in that loop are unchanged. ## What stays open - Programs that need the whole-wave loop (scalar counters, vccnz/scc latches) stay refused until the wave-level loop model exists. ## Cache revision The compute lowering now refuses programs it used to translate, so a translation cached under the old revision could still be served. This PR advances the startup shader cache revision to `x2w-startup-shader-28` / `28cs` (runtime, offline tool, C++ test mirrors, docs, known-answer values recomputed with a separate FNV-1a loop). The C++ targets were not built here. Verification: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-19`: pass; the new shapes translate on `main`'s `gfx2hlsl.py` and are refused here. - `python3 -B tests/startup_compute_readfirstlane_check.py`: pass. - Full `tests/*check.py` sweep against `origin/main`: 0 scripts change result (356 pass, 131 fail in both trees; the fails need the Windows toolchain). - Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-26 08:01:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T07:43:31Z.


I will independently check the accepted vector-only EXECNZ loop and the boundary where an SCC or VCC value escapes the loop. I will use source-built, per-lane readbacks and a separate wave reference, and report any counterexample or confirmation against this PR head here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185765732 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7185765732). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T07:43:31Z. --- I will independently check the accepted vector-only EXECNZ loop and the boundary where an SCC or VCC value escapes the loop. I will use source-built, per-lane readbacks and a separate wave reference, and report any counterexample or confirmation against this PR head here.
R0Y00 commented 2026-11-26 08:01:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:48:09Z.


I found a separate EXECNZ counterexample at d35433de. The loop has no ordinary SGPR writes, but its first instruction widens EXEC from the saved entry mask. The current scalar-free shortcut accepts it. I spliced this before the store in startup_gfx2hlsl_compute_check.py case A:

s_mov_b32 s0, exec_lo
v_mov_b32_e32 v3, v0
loop:
s_mov_b32 exec_lo, s0
v_add_nc_u32_e32 v3, 1, v3
v_cmp_gt_u32_e32 vcc_lo, 2, v3
s_and_b32 exec_lo, exec_lo, vcc_lo
s_cbranch_execnz loop
s_mov_b32 exec_lo, s0
v_mov_b32_e32 v5, v3

The first round leaves local X=0 running. The second round restores the saved mask, so the original wave stores 2 and 3 for the two X lanes. The translated shader stores 2 and 2. Windows Release WARP and RTX 4060 Laptop both report 144/320 mismatches, first word=1 expected=00000003 actual=00000002, with the debug layer enabled and no warnings/errors. The acceptance guard needs to prove that each EXEC write in this span only narrows the current mask. Keep the vector-only monotone loop as the positive control. This is independent of the SCC/VCC values escaping the loop that Raven is checking.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185850188 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7185850188). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T07:48:09Z. --- I found a separate EXECNZ counterexample at d35433de. The loop has no ordinary SGPR writes, but its first instruction widens EXEC from the saved entry mask. The current scalar-free shortcut accepts it. I spliced this before the store in startup_gfx2hlsl_compute_check.py case A: ```asm s_mov_b32 s0, exec_lo v_mov_b32_e32 v3, v0 loop: s_mov_b32 exec_lo, s0 v_add_nc_u32_e32 v3, 1, v3 v_cmp_gt_u32_e32 vcc_lo, 2, v3 s_and_b32 exec_lo, exec_lo, vcc_lo s_cbranch_execnz loop s_mov_b32 exec_lo, s0 v_mov_b32_e32 v5, v3 ``` The first round leaves local X=0 running. The second round restores the saved mask, so the original wave stores 2 and 3 for the two X lanes. The translated shader stores 2 and 2. Windows Release WARP and RTX 4060 Laptop both report 144/320 mismatches, first word=1 expected=00000003 actual=00000002, with the debug layer enabled and no warnings/errors. The acceptance guard needs to prove that each EXEC write in this span only narrows the current mask. Keep the vector-only monotone loop as the positive control. This is independent of the SCC/VCC values escaping the loop that Raven is checking.
tedin7 commented 2026-11-26 08:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:50:43Z.


Thank you for the counterexample (the loop that restores the saved EXEC in its first instruction). Reproduced on d35433de: the one-lane model stores 2 and 2, the wave stores 2 and 3.

Fixed in eb1e369e3 (together with the review of the vccz/vccnz inside an execz block, below):

  • An s_cbranch_execnz back edge is accepted only when every EXEC write in the loop can only narrow the mask (v_cmpx, s_and/s_andn2 of EXEC with itself). A move, an OR or a restore of a saved mask in the loop is refused. New refused fixture in check_wave_branches (your shape, assembled words, translated before this commit). The vector-only monotone loop stays accepted as the positive control.
  • s_cbranch_vccz / vccnz (and lane-data SCC) inside an s_cbranch_execz block are refused again: the block proof covers its EXEC writes, not that condition. Only s_cbranch_execnz stays exempt there. New refused fixtures for both branches.
  • A VCC read after an execnz loop is refused (the wave's VCC holds the last compare, 0 for lanes that left earlier).

Verification:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and ... binary llvm-mc-19: pass; the new shapes translate on main and are refused here.
  • python3 -B tests/startup_compute_readfirstlane_check.py: pass; tests/*check.py sweep against origin/main: no script changes result.
  • Win2025 WARP dev+release: pending Stage-2.

Update for the second report (the restore at the loop head, wave reference [3, 3, 3, 3], translated [1, 1, 2, 3]): this is the same defect, already fixed on the current head eb1e369e3. The loop is refused by name because its head writes EXEC with a move; only v_cmpx and s_and/s_andn2 of EXEC with itself are accepted, so a restore anywhere in the loop is refused. The refused fixture in check_wave_branches has the same shape (saved mask, restore at the head, v_cmp + s_and latch, s_cbranch_execnz). Thank you for the paired readback and for confirming that the monotone loop and the post-loop SCC read stay correct and the post-loop VCC read is refused.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185897193 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7185897193). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T07:50:43Z. --- Thank you for the counterexample (the loop that restores the saved EXEC in its first instruction). Reproduced on d35433de: the one-lane model stores 2 and 2, the wave stores 2 and 3. Fixed in eb1e369e3 (together with the review of the vccz/vccnz inside an execz block, below): - An `s_cbranch_execnz` back edge is accepted only when every EXEC write in the loop can only narrow the mask (`v_cmpx`, `s_and`/`s_andn2` of EXEC with itself). A move, an OR or a restore of a saved mask in the loop is refused. New refused fixture in `check_wave_branches` (your shape, assembled words, translated before this commit). The vector-only monotone loop stays accepted as the positive control. - `s_cbranch_vccz` / `vccnz` (and lane-data SCC) inside an `s_cbranch_execz` block are refused again: the block proof covers its EXEC writes, not that condition. Only `s_cbranch_execnz` stays exempt there. New refused fixtures for both branches. - A VCC read after an execnz loop is refused (the wave's VCC holds the last compare, 0 for lanes that left earlier). Verification: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `... binary llvm-mc-19`: pass; the new shapes translate on `main` and are refused here. - `python3 -B tests/startup_compute_readfirstlane_check.py`: pass; `tests/*check.py` sweep against `origin/main`: no script changes result. - Win2025 WARP dev+release: pending Stage-2. Update for the second report (the restore at the loop head, wave reference [3, 3, 3, 3], translated [1, 1, 2, 3]): this is the same defect, already fixed on the current head eb1e369e3. The loop is refused by name because its head writes EXEC with a move; only `v_cmpx` and `s_and`/`s_andn2` of EXEC with itself are accepted, so a restore anywhere in the loop is refused. The refused fixture in `check_wave_branches` has the same shape (saved mask, restore at the head, `v_cmp` + `s_and` latch, `s_cbranch_execnz`). Thank you for the paired readback and for confirming that the monotone loop and the post-loop SCC read stay correct and the post-loop VCC read is refused. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-26 08:01:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T07:52:20Z.


I found an accepted loop that writes three wrong words at d35433de. The EXECNZ exception in scalar_free_span permits a write to EXEC that reactivates lanes. The wave can run those lanes again while any lane takes the back edge.

Four lanes start with v3=0 and v0=lane_id. Save the incoming EXEC in s20 before the loop. This is the complete body and latch:

loop:
    s_mov_b32 exec_lo, s20
    v_add_nc_u32_e32 v3, 1, v3
    v_cmp_gt_u32_e32 vcc_lo, v0, v3
    s_and_b32 exec_lo, exec_lo, vcc_lo
    s_cbranch_execnz loop

Restore exec_lo from s20 after the latch and store each lane's counter. While lane 3 keeps the wave running, each trip restores all four lanes, so the wave reference is [3, 3, 3, 3]. The translated shader returned [1, 1, 2, 3] on Intel UHD 770, RTX 4060 and WARP. On each device the 320-word comparison had exactly three mismatches against the wave reference and zero against the lane-local vector. Removing the restore at the loop head made all 320 words match. Reading SCC after the monotone loop also passed, and a post-loop VCC select produced the intended named refusal.

Please require a proof that every EXEC write in the accepted loop can only remove lanes. In particular, restoring a saved mask at the head needs the named refusal. The paired source-built fixtures and Python wave model are in this commit.

Command: python -B tests/verify_execnz_loop_readback.py <clang> <llvm-objcopy> <dxc> <offscreen_check> <warp|hardware>. LLVM 15.0.7 gfx1013 wave32, DXC 1.9.2609.5, Windows 11 build 26100.9711. UHD 770 driver 32.0.101.5973, RTX 4060 driver 32.0.15.9579, WARP 10.0.26100.9711. Debug layer unavailable. AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7185927052 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7185927052). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T07:52:20Z. --- I found an accepted loop that writes three wrong words at `d35433de`. The EXECNZ exception in `scalar_free_span` permits a write to EXEC that reactivates lanes. The wave can run those lanes again while any lane takes the back edge. Four lanes start with `v3=0` and `v0=lane_id`. Save the incoming EXEC in `s20` before the loop. This is the complete body and latch: ```asm loop: s_mov_b32 exec_lo, s20 v_add_nc_u32_e32 v3, 1, v3 v_cmp_gt_u32_e32 vcc_lo, v0, v3 s_and_b32 exec_lo, exec_lo, vcc_lo s_cbranch_execnz loop ``` Restore `exec_lo` from `s20` after the latch and store each lane's counter. While lane 3 keeps the wave running, each trip restores all four lanes, so the wave reference is **[3, 3, 3, 3]**. The translated shader returned **[1, 1, 2, 3]** on Intel UHD 770, RTX 4060 and WARP. On each device the 320-word comparison had exactly three mismatches against the wave reference and zero against the lane-local vector. Removing the restore at the loop head made all 320 words match. Reading SCC after the monotone loop also passed, and a post-loop VCC select produced the intended named refusal. Please require a proof that every EXEC write in the accepted loop can only remove lanes. In particular, restoring a saved mask at the head needs the named refusal. The paired source-built fixtures and Python wave model are [in this commit](https://github.com/RavenCurseBurg/Xbox2Windows/blob/9df506e1366e1acc2cf9d6e8ffbfc8a73bcabd45/tests/verify_execnz_loop_readback.py). Command: `python -B tests/verify_execnz_loop_readback.py <clang> <llvm-objcopy> <dxc> <offscreen_check> <warp|hardware>`. LLVM 15.0.7 gfx1013 wave32, DXC 1.9.2609.5, Windows 11 build 26100.9711. UHD 770 driver 32.0.101.5973, RTX 4060 driver 32.0.15.9579, WARP 10.0.26100.9711. Debug layer unavailable. AI-assisted with Codex.
chatgpt-codex-connector[bot commented 2026-11-26 09:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:18:24Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb1e369e3d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070571956 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#pullrequestreview-6070571956). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:18:24Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `eb1e369e3d` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
R0Y00 commented 2026-11-26 09:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T08:20:12Z.

Review: CHANGES_REQUESTED


The original standalone EXECNZ loop now refuses on 2743cc3e. The same loop still translates and writes wrong data if it is inside a forward EXECZ span. Here is the splice for case A of tests/startup_gfx2hlsl_compute_check.py, with case A's original output code at join.

    s_cbranch_execz join
    s_mov_b32 s0, exec_lo
    v_mov_b32_e32 v3, v0
loop:
    s_mov_b32 exec_lo, s0
    v_add_nc_u32_e32 v3, 1, v3
    v_cmp_gt_u32_e32 vcc_lo, 2, v3
    s_and_b32 exec_lo, exec_lo, vcc_lo
    s_cbranch_execnz loop
    s_mov_b32 exec_lo, s0
    v_mov_b32_e32 v5, v3
join:
    ; case A output

The wave reference repeats [2, 3] for 288 words and preserves 32 sentinel words. Using the existing case A DXC dispatch harness, both WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 disagreed at 144/320 words. First mismatch was word 1, expected 3 and received 2. Windows 11 build 26200, D3D12 debug layer enabled, zero debug warnings/errors.

The execz_covered exemption bypasses the EXEC-narrowing proof for this nested backward branch. The outer proof keeps lanes inactive at entry clear. The latch can still re-enable a lane that was active at entry and left an earlier iteration. Please require the loop proof for a backward EXECNZ inside the span as well, add this refusal, and retain the existing monotone-loop positive control.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070592282 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#pullrequestreview-6070592282). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T08:20:12Z. **Review:** CHANGES_REQUESTED --- The original standalone EXECNZ loop now refuses on 2743cc3e. The same loop still translates and writes wrong data if it is inside a forward EXECZ span. Here is the splice for case A of `tests/startup_gfx2hlsl_compute_check.py`, with case A's original output code at `join`. ```asm s_cbranch_execz join s_mov_b32 s0, exec_lo v_mov_b32_e32 v3, v0 loop: s_mov_b32 exec_lo, s0 v_add_nc_u32_e32 v3, 1, v3 v_cmp_gt_u32_e32 vcc_lo, 2, v3 s_and_b32 exec_lo, exec_lo, vcc_lo s_cbranch_execnz loop s_mov_b32 exec_lo, s0 v_mov_b32_e32 v5, v3 join: ; case A output ``` The wave reference repeats [2, 3] for 288 words and preserves 32 sentinel words. Using the existing case A DXC dispatch harness, both WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 disagreed at 144/320 words. First mismatch was word 1, expected 3 and received 2. Windows 11 build 26200, D3D12 debug layer enabled, zero debug warnings/errors. The `execz_covered` exemption bypasses the EXEC-narrowing proof for this nested backward branch. The outer proof keeps lanes inactive at entry clear. The latch can still re-enable a lane that was active at entry and left an earlier iteration. Please require the loop proof for a backward EXECNZ inside the span as well, add this refusal, and retain the existing monotone-loop positive control.
tedin7 commented 2026-11-26 09:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:28:33Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070695099 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#pullrequestreview-6070695099). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:28:33Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-26 09:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:28:37Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070696104 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#pullrequestreview-6070696104). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:28:37Z. **Review:** COMMENTED --- _No description provided._
Ybucaille commented 2026-11-26 09:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-26T08:15:59Z.


Independent GPU confirmation of the compute case, and a note on scope.

  • Source-built compute fixture (8 lanes per group, 4 groups): v_cmp_gt_u32 vcc_lo, 3, v0, then s_cbranch_vccz over a buffer_store. On the wave VCC is non-zero, so no lane skips and all 8 store. main lowers it to pc = ((vcc & 1) == 0) ? ... : ... per lane. Readback on WARP and on an RTX 2070: 20 of 320 words wrong (lanes 3 to 7 of each group lost their store). This shape is in your check_wave_branches, so nothing to add there.

  • Scope: the same per-lane lowering of s_cbranch_vccz/vccnz and of an SCC branch on lane data is used for pixel and vertex programs, and this PR only guards compute. On a sample of 4000 cached graphics requests, 169 translate on main; 5 of them (all pixel) branch with s_cbranch_scc0/scc1 on an SCC computed from VCC/EXEC (s_and_b32 sN, vcc_lo, exec_lo shape). No VCC branch and no vertex program in that sample.

I have a branch that applies an equivalent refusal to the non-mesh graphics path. To avoid two versions of the same proof, I will not open it as is: once this PR lands I would follow up with the pixel/vertex extension reusing your helpers, unless you prefer to widen this PR yourself. I'll take the pixel/vertex part unless you say otherwise.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186386916 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7186386916). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-26T08:15:59Z. --- Independent GPU confirmation of the compute case, and a note on scope. - Source-built compute fixture (8 lanes per group, 4 groups): `v_cmp_gt_u32 vcc_lo, 3, v0`, then `s_cbranch_vccz` over a `buffer_store`. On the wave VCC is non-zero, so no lane skips and all 8 store. `main` lowers it to `pc = ((vcc & 1) == 0) ? ... : ...` per lane. Readback on WARP and on an RTX 2070: 20 of 320 words wrong (lanes 3 to 7 of each group lost their store). This shape is in your `check_wave_branches`, so nothing to add there. - Scope: the same per-lane lowering of `s_cbranch_vccz`/`vccnz` and of an SCC branch on lane data is used for pixel and vertex programs, and this PR only guards compute. On a sample of 4000 cached graphics requests, 169 translate on `main`; 5 of them (all pixel) branch with `s_cbranch_scc0`/`scc1` on an SCC computed from VCC/EXEC (`s_and_b32 sN, vcc_lo, exec_lo` shape). No VCC branch and no vertex program in that sample. I have a branch that applies an equivalent refusal to the non-mesh graphics path. To avoid two versions of the same proof, I will not open it as is: once this PR lands I would follow up with the pixel/vertex extension reusing your helpers, unless you prefer to widen this PR yourself. I'll take the pixel/vertex part unless you say otherwise. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-26 09:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:13:56Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T08:18:27.891577Z eb1e369 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186345931 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7186345931). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:13:56Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"eb1e369e3d8815cb6539c24dd2c9b0d2e2933793","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T08:18:27.891577Z">2026-11-26T08:18:27.891577Z</relative-time> | `eb1e369` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
RavenCurseBurg commented 2026-11-26 09:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T08:20:52Z.


Verified the reopening fix at eb1e369e (includes db8a5ed7) with the same four-lane fixture. The loop that used to return [1, 1, 2, 3] instead of [3, 3, 3, 3] now stops at the named s_cbranch_execnz refusal. Both accepted controls, including the SCC observation, still match [1, 1, 2, 3] and all 316 untouched words on WARP, UHD 770 and RTX 4060. The live-VCC refusal also remains. This addresses my finding.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186484038 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7186484038). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T08:20:52Z. --- Verified the reopening fix at `eb1e369e` (includes `db8a5ed7`) with the same [four-lane fixture](https://github.com/RavenCurseBurg/Xbox2Windows/blob/9df506e1366e1acc2cf9d6e8ffbfc8a73bcabd45/tests/verify_execnz_loop_readback.py). The loop that used to return [1, 1, 2, 3] instead of [3, 3, 3, 3] now stops at the named `s_cbranch_execnz` refusal. Both accepted controls, including the SCC observation, still match [1, 1, 2, 3] and all 316 untouched words on WARP, UHD 770 and RTX 4060. The live-VCC refusal also remains. This addresses my finding.
tedin7 commented 2026-11-26 09:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:13:45Z.


Independent Stage-2 gate of head eb1e369e3: PASS.

Checked:

  • Refusal of whole-wave branches in compute: vccz / vccnz / execnz and an scc on lane data are refused by name, including vccz / vccnz inside a block that s_cbranch_execz skips (the earlier head accepted that shape and decided it per lane).
  • Kept exceptions, each tried to break: uniform SCC (s_cmp on a workgroup id) still translates; an execnz loop translates only when its EXEC writes can only narrow (s_and exec, exec, X in either order, s_andn2 exec, exec, X, v_cmpx); or, xor, mov, orn2, and with a non-EXEC source and s_and_saveexec in the loop are refused; a VCC read after the loop is refused; lane-crossing ops in such a loop were already refused by their own checks.
  • Edited assertion (vccz after the join) is right: a whole-wave decision.

Verification (Win2025, WARP):

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and tests/startup_compute_readfirstlane_check.py: pass on Linux.
  • Python check sweep against origin/main: 0 scripts change result.
  • x2w_pipe.py win2025 2772 --force --keep-release --regex 'gfx2hlsl|startup_compute|startup_.*readfirstlane': dev 444/444 and release 444/444 passed.
  • A wider dev run (--regex 'compute|gfx2hlsl', 649 tests) had one failure, compute_store_aot_mac_f32_hardware (compute_store_check.py, not touched by this PR); it fails the same way in the logs of other PRs that do not touch that file, and its _warp twin passes.

Update, head 2743cc3ee (main merged in): fresh_gate GO (0 behind origin/main); same shapes still refuse or translate as above; python3 -B tests/startup_gfx2hlsl_compute_check.py and tests/startup_compute_readfirstlane_check.py pass; x2w_pipe.py win2025 2772 --force --keep-release --regex "gfx2hlsl|startup_compute|startup_.*readfirstlane": dev 446/446 and release 446/446 passed.

Correction, head 157d06f64: the PASS above is withdrawn for one open shape. The Windows runs are green (x2w_pipe.py win2025 2772 --force --keep-release --regex 'gfx2hlsl|startup_compute|startup_.*readfirstlane|shader_cache_key': dev 453/453, release 453/453) but they do not cover it:

s_cmp_lt_u32 s7, 4 ; s_cbranch_scc1 J ; v_cmp_gt_u32 vcc_lo, 1, v0 ; s_and_b32 exec_lo, exec_lo, vcc_lo ; J: s_cbranch_scc0 K ; s_mov_b32 exec_lo, -1 ; v_mov_b32 v5, 7 ; K:

spliced into case A of tests/startup_gfx2hlsl_compute_check.py it still translates. The SCC written by the s_and_b32 on one arm is lane data (any lane's bit keeps SCC set for the wave) but the branch after the join is lowered from the lane's own bit: the lanes whose EXEC bit is clear skip the EXEC restore and do not store, while the wave would not take the branch. The same shape without the join is refused; at the join scc_verified is false, so the scc_verified and not scc_uniform condition does not fire. Fix idea: at a join make scc_uniform the AND over the paths and refuse an scc0/scc1 branch whenever it is false; add this shape to check_wave_branches as refused. Back to Draft until then.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186342438 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7186342438). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:13:45Z. --- Independent Stage-2 gate of head eb1e369e3: PASS. Checked: - Refusal of whole-wave branches in compute: `vccz` / `vccnz` / `execnz` and an `scc` on lane data are refused by name, including `vccz` / `vccnz` inside a block that `s_cbranch_execz` skips (the earlier head accepted that shape and decided it per lane). - Kept exceptions, each tried to break: uniform SCC (`s_cmp` on a workgroup id) still translates; an `execnz` loop translates only when its EXEC writes can only narrow (`s_and exec, exec, X` in either order, `s_andn2 exec, exec, X`, `v_cmpx`); `or`, `xor`, `mov`, `orn2`, `and` with a non-EXEC source and `s_and_saveexec` in the loop are refused; a VCC read after the loop is refused; lane-crossing ops in such a loop were already refused by their own checks. - Edited assertion (`vccz` after the join) is right: a whole-wave decision. Verification (Win2025, WARP): - `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `tests/startup_compute_readfirstlane_check.py`: pass on Linux. - Python check sweep against `origin/main`: 0 scripts change result. - `x2w_pipe.py win2025 2772 --force --keep-release --regex 'gfx2hlsl|startup_compute|startup_.*readfirstlane'`: dev 444/444 and release 444/444 passed. - A wider dev run (`--regex 'compute|gfx2hlsl'`, 649 tests) had one failure, `compute_store_aot_mac_f32_hardware` (compute_store_check.py, not touched by this PR); it fails the same way in the logs of other PRs that do not touch that file, and its `_warp` twin passes. Update, head 2743cc3ee (main merged in): `fresh_gate` GO (0 behind `origin/main`); same shapes still refuse or translate as above; `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `tests/startup_compute_readfirstlane_check.py` pass; `x2w_pipe.py win2025 2772 --force --keep-release --regex "gfx2hlsl|startup_compute|startup_.*readfirstlane"`: dev 446/446 and release 446/446 passed. Correction, head 157d06f64: the PASS above is withdrawn for one open shape. The Windows runs are green (`x2w_pipe.py win2025 2772 --force --keep-release --regex 'gfx2hlsl|startup_compute|startup_.*readfirstlane|shader_cache_key'`: dev 453/453, release 453/453) but they do not cover it: s_cmp_lt_u32 s7, 4 ; s_cbranch_scc1 J ; v_cmp_gt_u32 vcc_lo, 1, v0 ; s_and_b32 exec_lo, exec_lo, vcc_lo ; J: s_cbranch_scc0 K ; s_mov_b32 exec_lo, -1 ; v_mov_b32 v5, 7 ; K: spliced into case A of `tests/startup_gfx2hlsl_compute_check.py` it still translates. The SCC written by the `s_and_b32` on one arm is lane data (any lane's bit keeps SCC set for the wave) but the branch after the join is lowered from the lane's own bit: the lanes whose EXEC bit is clear skip the EXEC restore and do not store, while the wave would not take the branch. The same shape without the join is refused; at the join `scc_verified` is false, so the `scc_verified and not scc_uniform` condition does not fire. Fix idea: at a join make `scc_uniform` the AND over the paths and refuse an `scc0`/`scc1` branch whenever it is false; add this shape to `check_wave_branches` as refused. Back to Draft until then. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 09:04:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:18:25Z.

Code review location: tools/startup/gfx2hlsl.py; line 4330

@@ -4396,6 +4326,14 @@ def _lower(self, base, asm, ops, mods):
                 self.read_vcc()
             if getattr(self, 'kind', None) == 'ms' and base in ('s_cbranch_scc0', 's_cbranch_scc1') and not self.scc_uniform:
                 raise Unsupported('slot 57 mesh: a branch reads SCC that is not proven wave-uniform')
+            if getattr(self, 'kind', None) == 'cs' and not getattr(self, 'branch_proven', False) and (
+                    base[10:] in ('vccz', 'vccnz', 'execnz') or (base[10:] in ('scc0', 'scc1') and self.scc_verified and not self.scc_uniform)):

P2 Badge Preserve proven uniform SCC at forward joins

For a compute shader that reuses a uniform SCC after a forward join, translate() retains the uniform reaching definition in scc_def and sets scc_verified=True, but resets scc_uniform=False. This new condition therefore rejects a proven-uniform branch. For example, inserting s_cmp_lt_u32 s7, 4 followed by two forward s_cbranch_scc1 1 instructions, each skipping a vector move, into case A now refuses the second branch; the parent translates it successfully. Both branches read the same group-ID comparison, with no intervening SCC write. Consult or preserve the retained uniform reaching-definition proof so these supported compute shaders continue to translate.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705508762 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#discussion_r4705508762). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:18:25Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 4330 ~~~~diff @@ -4396,6 +4326,14 @@ def _lower(self, base, asm, ops, mods): self.read_vcc() if getattr(self, 'kind', None) == 'ms' and base in ('s_cbranch_scc0', 's_cbranch_scc1') and not self.scc_uniform: raise Unsupported('slot 57 mesh: a branch reads SCC that is not proven wave-uniform') + if getattr(self, 'kind', None) == 'cs' and not getattr(self, 'branch_proven', False) and ( + base[10:] in ('vccz', 'vccnz', 'execnz') or (base[10:] in ('scc0', 'scc1') and self.scc_verified and not self.scc_uniform)): ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve proven uniform SCC at forward joins** For a compute shader that reuses a uniform SCC after a forward join, `translate()` retains the uniform reaching definition in `scc_def` and sets `scc_verified=True`, but resets `scc_uniform=False`. This new condition therefore rejects a proven-uniform branch. For example, inserting `s_cmp_lt_u32 s7, 4` followed by two forward `s_cbranch_scc1 1` instructions, each skipping a vector move, into case A now refuses the second branch; the parent translates it successfully. Both branches read the same group-ID comparison, with no intervening SCC write. Consult or preserve the retained uniform reaching-definition proof so these supported compute shaders continue to translate. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-26 09:04:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:18:25Z.

Code review location: tools/startup/gfx2hlsl.py; line 834

@@ -815,6 +815,54 @@ def lane_read(name, asm, word, halves):
         w == ('exec', 'exec_hi')[p] for src in srcs for p, w in enumerate(src) if p in at and w in EXEC_KEYS)
 
 
+def offsets_between(ins, lo, hi):
+    return [off for off, _n, _name, _asm in ins if lo < off < hi]
+
+
+def scalar_free_span(ins, lo, hi):
+    """True when no instruction at an offset in [lo, hi] writes a scalar register (SGPR, M0) other than EXEC and VCC.
+    A loop that only narrows EXEC and changes vector registers is the same for a lane that runs it per lane or with the
+    wave: a lane whose EXEC bit is clear changes nothing, and no scalar value carries the wave's iteration count out."""
+    for off, _n, name, asm in ins:
+        if not lo <= off <= hi:
+            continue
+        if name.startswith('s_movrel'):
+            return False
+        for tok in destinations(name, parse(asm)[1]):
+            r = reg_range(tok)
+            if r and r[0] == 's' and not (r[1] >= 126 and r[2] <= 127) or tok == 'm0':
+                return False

P2 Badge Exclude CMPX sources from scalar-write detection

For an EXEC-narrowing loop containing v_cmpx_gt_u32_e32 s7, v3, destinations() returns the first printed operand, so this code incorrectly treats the read of s7 as a scalar-register write. CMPX prints only source operands and writes EXEC implicitly. Consequently, a vector-only increment/CMPX loop closed by s_cbranch_execnz now fails the scalar-free proof and is refused, although the parent translates it and the equivalent loop using literal 2 instead of s7 still translates. Use the actual scalar write effects or explicitly exclude CMPX sources when checking the loop.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705508767 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#discussion_r4705508767). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:18:25Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 834 ~~~~diff @@ -815,6 +815,54 @@ def lane_read(name, asm, word, halves): w == ('exec', 'exec_hi')[p] for src in srcs for p, w in enumerate(src) if p in at and w in EXEC_KEYS) +def offsets_between(ins, lo, hi): + return [off for off, _n, _name, _asm in ins if lo < off < hi] + + +def scalar_free_span(ins, lo, hi): + """True when no instruction at an offset in [lo, hi] writes a scalar register (SGPR, M0) other than EXEC and VCC. + A loop that only narrows EXEC and changes vector registers is the same for a lane that runs it per lane or with the + wave: a lane whose EXEC bit is clear changes nothing, and no scalar value carries the wave's iteration count out.""" + for off, _n, name, asm in ins: + if not lo <= off <= hi: + continue + if name.startswith('s_movrel'): + return False + for tok in destinations(name, parse(asm)[1]): + r = reg_range(tok) + if r and r[0] == 's' and not (r[1] >= 126 and r[2] <= 127) or tok == 'm0': + return False ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Exclude CMPX sources from scalar-write detection** For an EXEC-narrowing loop containing `v_cmpx_gt_u32_e32 s7, v3`, `destinations()` returns the first printed operand, so this code incorrectly treats the read of `s7` as a scalar-register write. CMPX prints only source operands and writes EXEC implicitly. Consequently, a vector-only increment/CMPX loop closed by `s_cbranch_execnz` now fails the scalar-free proof and is refused, although the parent translates it and the equivalent loop using literal `2` instead of `s7` still translates. Use the actual scalar write effects or explicitly exclude CMPX sources when checking the loop. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-26 09:04:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:28:33Z.

Code review location: tools/startup/gfx2hlsl.py; line 4330

@@ -4396,6 +4326,14 @@ def _lower(self, base, asm, ops, mods):
                 self.read_vcc()
             if getattr(self, 'kind', None) == 'ms' and base in ('s_cbranch_scc0', 's_cbranch_scc1') and not self.scc_uniform:
                 raise Unsupported('slot 57 mesh: a branch reads SCC that is not proven wave-uniform')
+            if getattr(self, 'kind', None) == 'cs' and not getattr(self, 'branch_proven', False) and (
+                    base[10:] in ('vccz', 'vccnz', 'execnz') or (base[10:] in ('scc0', 'scc1') and self.scc_verified and not self.scc_uniform)):

Real, and fixed in the commit that follows this review: after a forward join the retained uniform reaching definition (scc_def) now counts as uniform for the whole-wave branch check, so the second s_cbranch_scc1 of s_cmp_lt_u32 s7, 4 + two forward branches translates again (it was refused on the previous head, translated on main). New assertion in check_wave_branches. Linux: python3 -B tests/startup_gfx2hlsl_compute_check.py passes.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705604642 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#discussion_r4705604642). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:28:33Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 4330 ~~~~diff @@ -4396,6 +4326,14 @@ def _lower(self, base, asm, ops, mods): self.read_vcc() if getattr(self, 'kind', None) == 'ms' and base in ('s_cbranch_scc0', 's_cbranch_scc1') and not self.scc_uniform: raise Unsupported('slot 57 mesh: a branch reads SCC that is not proven wave-uniform') + if getattr(self, 'kind', None) == 'cs' and not getattr(self, 'branch_proven', False) and ( + base[10:] in ('vccz', 'vccnz', 'execnz') or (base[10:] in ('scc0', 'scc1') and self.scc_verified and not self.scc_uniform)): ~~~~ --- Real, and fixed in the commit that follows this review: after a forward join the retained uniform reaching definition (`scc_def`) now counts as uniform for the whole-wave branch check, so the second `s_cbranch_scc1` of `s_cmp_lt_u32 s7, 4` + two forward branches translates again (it was refused on the previous head, translated on `main`). New assertion in `check_wave_branches`. Linux: `python3 -B tests/startup_gfx2hlsl_compute_check.py` passes. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 09:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:28:37Z.

Code review location: tools/startup/gfx2hlsl.py; line 834

@@ -815,6 +815,54 @@ def lane_read(name, asm, word, halves):
         w == ('exec', 'exec_hi')[p] for src in srcs for p, w in enumerate(src) if p in at and w in EXEC_KEYS)
 
 
+def offsets_between(ins, lo, hi):
+    return [off for off, _n, _name, _asm in ins if lo < off < hi]
+
+
+def scalar_free_span(ins, lo, hi):
+    """True when no instruction at an offset in [lo, hi] writes a scalar register (SGPR, M0) other than EXEC and VCC.
+    A loop that only narrows EXEC and changes vector registers is the same for a lane that runs it per lane or with the
+    wave: a lane whose EXEC bit is clear changes nothing, and no scalar value carries the wave's iteration count out."""
+    for off, _n, name, asm in ins:
+        if not lo <= off <= hi:
+            continue
+        if name.startswith('s_movrel'):
+            return False
+        for tok in destinations(name, parse(asm)[1]):
+            r = reg_range(tok)
+            if r and r[0] == 's' and not (r[1] >= 126 and r[2] <= 127) or tok == 'm0':
+                return False

Real, and fixed in the same commit: the scalar-free loop test now skips v_cmpx (it prints only its sources and writes EXEC; the narrowing check judges that write). A v_add_nc_u32 / v_cmpx_gt_u32 s7, v3 loop closed by s_cbranch_execnz translates again (refused on the previous head, translated on main). New assertion in check_wave_branches, with the decoder text of the hand-assembled word checked. Linux: python3 -B tests/startup_gfx2hlsl_compute_check.py passes.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705605471 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#discussion_r4705605471). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:28:37Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 834 ~~~~diff @@ -815,6 +815,54 @@ def lane_read(name, asm, word, halves): w == ('exec', 'exec_hi')[p] for src in srcs for p, w in enumerate(src) if p in at and w in EXEC_KEYS) +def offsets_between(ins, lo, hi): + return [off for off, _n, _name, _asm in ins if lo < off < hi] + + +def scalar_free_span(ins, lo, hi): + """True when no instruction at an offset in [lo, hi] writes a scalar register (SGPR, M0) other than EXEC and VCC. + A loop that only narrows EXEC and changes vector registers is the same for a lane that runs it per lane or with the + wave: a lane whose EXEC bit is clear changes nothing, and no scalar value carries the wave's iteration count out.""" + for off, _n, name, asm in ins: + if not lo <= off <= hi: + continue + if name.startswith('s_movrel'): + return False + for tok in destinations(name, parse(asm)[1]): + r = reg_range(tok) + if r and r[0] == 's' and not (r[1] >= 126 and r[2] <= 127) or tok == 'm0': + return False ~~~~ --- Real, and fixed in the same commit: the scalar-free loop test now skips `v_cmpx` (it prints only its sources and writes EXEC; the narrowing check judges that write). A `v_add_nc_u32` / `v_cmpx_gt_u32 s7, v3` loop closed by `s_cbranch_execnz` translates again (refused on the previous head, translated on `main`). New assertion in `check_wave_branches`, with the decoder text of the hand-assembled word checked. Linux: `python3 -B tests/startup_gfx2hlsl_compute_check.py` passes. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 11:02:46 +00:00
tedin7 commented 2026-11-26 11:02:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:12:48Z.


Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189059695 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2772#issuecomment-7189059695). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:12:48Z. --- Withdrawn: shader translation is moving to the native C++ frontend (see #870), so we are not continuing this change to the Python translator. The branch stays available if any part is useful later. Thank you to everyone who reviewed and tested it.

Pull request closed

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!2764
No description provided.