fix(shader): identify compute loop exits that cross a backward SCC branch #2844

Merged
brainbudt merged 1 commit from upstream-pr/2852 into main 2026-11-26 14:04:21 +00:00
brainbudt commented 2026-11-26 13:57:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by brainbudt on 2026-11-26T13:57:25Z.


Problem

The compute translator reports branch out of the block when an early s_cbranch_scc0 exits an EXEC-zero guarded block past a backward s_cbranch_scc0. The generic message makes this loop shape indistinguishable from an ordinary forward exit. Refs #2645, T2.

Change

Report loop exit crosses a backward s_cbranch_scc0 when the exit jumps over a latch that branches back to the guard or earlier. Add a source-built, 112-byte gfx1013 fixture that reproduces the two-mask loop from the issue.

The wave and singleton models agree on the original eight output words. Reading the scalar counter after restoring EXEC exposes the difference: the wave exits with 3 for every lane, while the singleton counters are [1, 2, 3, 4, 4, 4, 4, 4].

Scope

T2 explicitly permits a named refusal for this case. Covers the translator diagnostic, its controls and the experiment record. The fixture is refused before dispatch, so WARP readback does not apply.

Verification

  • python3 -B tests/startup_gfx2hlsl_compute_check.py passed on macOS ARM64 (including after rebasing onto latest origin/main). The base translator failed the new assertion with branch out of the block; removing only the latch restored that generic refusal, and removing only the EXEC-zero guard allowed translation.
  • python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15 passed on Linux x86-64 with LLVM 15.0.7; the fixture also reassembled byte-for-byte with LLVM 22 on macOS.
  • Full Linux x86-64 python-linux (209/209) and pixel-binary (135/135) suites passed.

Reviewed with mistral-loop: APPROVE (1 round, mistral-large-4-0 + deepseek-v4-1-flash-1017).
Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6628209744 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2852). Originally posted by [brainbudt](https://github.com/brainbudt) on 2026-11-26T13:57:25Z. --- ## Problem The compute translator reports `branch out of the block` when an early `s_cbranch_scc0` exits an EXEC-zero guarded block past a backward `s_cbranch_scc0`. The generic message makes this loop shape indistinguishable from an ordinary forward exit. Refs #2645, T2. ## Change Report `loop exit crosses a backward s_cbranch_scc0` when the exit jumps over a latch that branches back to the guard or earlier. Add a source-built, 112-byte gfx1013 fixture that reproduces the two-mask loop from the issue. The wave and singleton models agree on the original eight output words. Reading the scalar counter after restoring EXEC exposes the difference: the wave exits with `3` for every lane, while the singleton counters are `[1, 2, 3, 4, 4, 4, 4, 4]`. ## Scope T2 explicitly permits a named refusal for this case. Covers the translator diagnostic, its controls and the experiment record. The fixture is refused before dispatch, so WARP readback does not apply. ## Verification - `python3 -B tests/startup_gfx2hlsl_compute_check.py` passed on macOS ARM64 (including after rebasing onto latest `origin/main`). The base translator failed the new assertion with `branch out of the block`; removing only the latch restored that generic refusal, and removing only the EXEC-zero guard allowed translation. - `python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15` passed on Linux x86-64 with LLVM 15.0.7; the fixture also reassembled byte-for-byte with LLVM 22 on macOS. - Full Linux x86-64 `python-linux` (209/209) and `pixel-binary` (135/135) suites passed. --- Reviewed with mistral-loop: APPROVE (1 round, `mistral-large-4-0` + `deepseek-v4-1-flash-1017`). Created with gpt-6.2-astra in Codex (orchestrated with Gemini 4 Neon in T3 Code).
upstream-sync closed this pull request 2026-11-26 15:00:51 +00:00
tedin7 commented 2026-11-26 15:00:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:02:56Z.

Review: COMMENTED


Review of head cfb172e6.

Result: no blocking findings.

What the change does: it only picks a more specific refusal reason (loop exit crosses a backward s_cbranch_scc0) for a case that was already refused with branch out of the block. No shape that translated before is refused now, and no refused shape starts translating. The condition (latch between the join and the exit target, same opcode, target at or before the guard) matches the fixture in the issue.

WARP readback: not applicable here, because the fixture is refused before any HLSL is emitted. The CPU model in the test (wave versus per-lane counters, [1, 2, 3, 4, 4, 4, 4, 4] versus 3) is the reason a refusal is the right outcome rather than a lowering.

Checked locally:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py rc 0
  • python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-19 rc 0 (the 112-byte fixture reassembles byte for byte)
  • python3 tests/docs_links_check.py rc 0, python3 tests/bidi_controls_check.py rc 0, git diff --check origin/main...HEAD clean
  • Three mutations of the new condition (latch range, backward-target test, dropping the new branch): each makes the compute check fail. The tree was restored after each.
  • 174 existing shader shapes compared with origin/main: all identical output.
  • Lane-mask differential run on the DPP/spill families: all 4 selected variants refused, no translated variant, so nothing to compare. Expected, this change does not touch those lowerings.

Not covered: no real-GPU run (not available right now).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6075441947 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2852#pullrequestreview-6075441947). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:02:56Z. **Review:** COMMENTED --- Review of head cfb172e6. Result: no blocking findings. What the change does: it only picks a more specific refusal reason (`loop exit crosses a backward s_cbranch_scc0`) for a case that was already refused with `branch out of the block`. No shape that translated before is refused now, and no refused shape starts translating. The condition (latch between the join and the exit target, same opcode, target at or before the guard) matches the fixture in the issue. WARP readback: not applicable here, because the fixture is refused before any HLSL is emitted. The CPU model in the test (wave versus per-lane counters, `[1, 2, 3, 4, 4, 4, 4, 4]` versus 3) is the reason a refusal is the right outcome rather than a lowering. Checked locally: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` rc 0 - `python3 -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-19` rc 0 (the 112-byte fixture reassembles byte for byte) - `python3 tests/docs_links_check.py` rc 0, `python3 tests/bidi_controls_check.py` rc 0, `git diff --check origin/main...HEAD` clean - Three mutations of the new condition (latch range, backward-target test, dropping the new branch): each makes the compute check fail. The tree was restored after each. - 174 existing shader shapes compared with origin/main: all identical output. - Lane-mask differential run on the DPP/spill families: all 4 selected variants refused, no translated variant, so nothing to compare. Expected, this change does not touch those lowerings. Not covered: no real-GPU run (not available right now). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 15:00:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:03:52Z.


Win2025 WARP receipt for head cfb172e6 (2 commits behind main, no update needed). Python-only change: the PR's own check ran on Windows.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit cfb172e6ead4fa73d650ef7951a5b94d1b1ebb3c:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check startup_stream_consumer -- -j 2): 1.75s (configure 1.90s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check startup_stream_consumer -- -j 2): 37.44s (configure 1.87s)
  • Windows Python checks: tests/startup_gfx2hlsl_compute_check.py ok (0.7s)
  • sccache: 14/18 hits; wall 52.6s
    tested: cfb172e6 via fetch (pull/2852/head, no patch)

Real-GPU run not available (RunPod stopped).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7194225118 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2852#issuecomment-7194225118). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:03:52Z. --- Win2025 WARP receipt for head cfb172e6 (2 commits behind main, no update needed). Python-only change: the PR's own check ran on Windows. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `cfb172e6ead4fa73d650ef7951a5b94d1b1ebb3c`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check startup_stream_consumer -- -j 2`): `1.75s` (configure `1.90s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check startup_stream_consumer -- -j 2`): `37.44s` (configure `1.87s`) - **Windows Python checks**: `tests/startup_gfx2hlsl_compute_check.py` ok (`0.7s`) - `sccache`: 14/18 hits; wall `52.6s` tested: cfb172e6 via fetch (pull/2852/head, no patch) Real-GPU run not available (RunPod stopped). 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!2844
No description provided.