shader: lower a forward SCC if/else diamond over vector ALU in pixel_aot #1618

Merged
MasterDomino merged 2 commits from upstream-pr/1625 into main 2026-11-24 15:59:42 +00:00
MasterDomino commented 2026-11-24 15:14:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T15:14:41Z.


Refs #1413 (stage 2)

pixel_aot now lowers a single structured forward SCC if/else diamond over vector ALU, on top of #1440, as approved on #1413.

s_cmp_* …                  ; tracked scalar compare
s_cbranch_scc0/scc1 ELSE   ; lands on B's first instruction
  <block A>                ; runs when the branch is not taken
  s_branch JOIN            ; A's terminal branch, lands after B
ELSE:
  <block B>                ; runs when the branch is taken
JOIN:

Behaviour (tools/pixel_aot.py)

  • Recognition: when the conditional target is a later boundary and the instruction just before it is a forward s_branch, the branch opens a diamond. The s_branch must land on JOIN, a later boundary after B's first instruction, decoded the same way as the conditional target. A conditional edge that lands elsewhere is refused by the stage-1 rules: onto the s_branch, the s_branch then runs outside any block; onto JOIN, the s_branch sits inside the skipped block.
  • Condition: the same as stage 1, a tracked uniform s_cmp/s_bitcmp SCC. Block A runs under the stage-1 condition (scc for scc0, !scc for scc1) and block B under its negation.
  • Arms: at A's terminal s_branch, the region switches to B through the else-arm state from #1371:
    • B starts from the incoming VGPR state;
    • a register first defined by A is undefined in B until B writes it (Else arm reads a register defined only in the then arm);
    • B's writes are tracked separately.
  • Join: each register merges as condition ? A : B, with the incoming value standing in for a block that did not write it. A register undefined on entry and not written by both blocks stays undefined after JOIN.
  • Gate: both blocks use the stage-1 vector-only gate. SCC, VCC and EXEC are unchanged. Nesting, backward branches, memory, waits and other observable side effects stay out.

Tests

  • check_scc_diamond_controls:
    • The select condition for both polarities on v13 (both blocks), v14 (A only) and v15 (B only), and B reading v14's incoming sample16.z.
    • Malformed targets refused: conditional edge onto the s_branch; conditional edge onto JOIN; s_branch onto B's first instruction, backward, or outside the program; an s_branch that is not last in A.
    • A nested branch in A or B refused, and memory in B refused.
    • Definedness: a B read of an A-only register refused, accepted after a B write; an undefined-on-entry register written by one block refused after JOIN, defined when both write it.
    • SCC kept across the diamond, and an empty A accepted.
  • check_scc_diamond_draw, run by the existing pixel_aot_scc_skip_{warp,hardware}:
    • Forms: s_cmp_eq_u32 s47, 0 + s_cbranch_scc1, and s_cmp_lg_u32 s47, 0 + s_cbranch_scc0.
    • The runtime flag is 0 (B runs) and 1 and 7 (A runs). A writes v13 = 0.25 and v14 = 0.75; B writes v13 = 0.5 and v15 = 0.5 × v14, which reads v14's incoming value.
    • Mutants that must mismatch: flipped polarity (flags 0 and 1), dropped s_branch (flag 1, so A falls through into B), and the correct shader against a stale-A expectation where B reads A's v14 (flag 0).
  • LLVM 15 binary regression: both diamonds with .Lscc_else and .Lscc_join labels.
  • tests/form_coverage_check.py: s_branch is now recorded as an accepted form. The check used it as its example of a form that only reaches rejections; it now asserts s_branch is accepted, keeps s_code_end as the not-accepted example, and adds ("SOPP", "s_branch") to the covered SCC-branch forms.

Results

117ebb8b on 71be6f0f. Windows 11 26H2 (build 26300.9974), dev preset, DXC 1.8.2502.11, Python 3.13.1, LLVM 15.0.7.

python -B tests/pixel_aot_check.py                                   # controls: pass
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>   # pass
ctest --preset dev --no-tests=error -R '^pixel_aot_(scc_skip|exec_regions|cmpx_regions|region_.*)_(warp|hardware)$'   # 14/14 pass

WARP 10.0.26100.9818: the 6 diamond cases (2 forms × flag 0/1/7) match at 64/64 pixels. All 8 mutant cases mismatch: 2 stale-A, 4 polarity, 2 dropped-branch. The stage-1 skip cases still pass.

AMD Radeon RX 9070 XT, driver 32.0.31044.16: the 6 diamond cases match. All 8 mutant cases mismatch. The stage-1 skip cases still pass.

All 37 pure-Python checks listed in AGENTS.md pass.

Negative control: with tools/pixel_aot.py restored to main, check_scc_diamond_controls fails with Instruction cannot run in a uniform skip block: s_branch 2.

Not measured

The #1413 counts are shapes only: 9,004 diamond branches in 3,201 records. The number of local records this unblocks is not measurable while the scan's translator verdict stops at unbound operands (#1314). The draws pin the translator's model on desktop adapters; they are not evidence for gfx1013 hardware.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6585031733 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1625). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T15:14:41Z. --- Refs #1413 (stage 2) `pixel_aot` now lowers a single structured forward SCC if/else diamond over vector ALU, on top of #1440, as approved on #1413. ``` s_cmp_* … ; tracked scalar compare s_cbranch_scc0/scc1 ELSE ; lands on B's first instruction <block A> ; runs when the branch is not taken s_branch JOIN ; A's terminal branch, lands after B ELSE: <block B> ; runs when the branch is taken JOIN: ``` ## Behaviour (`tools/pixel_aot.py`) - **Recognition:** when the conditional target is a later boundary and the instruction just before it is a forward `s_branch`, the branch opens a diamond. The `s_branch` must land on JOIN, a later boundary after B's first instruction, decoded the same way as the conditional target. A conditional edge that lands elsewhere is refused by the stage-1 rules: onto the `s_branch`, the `s_branch` then runs outside any block; onto JOIN, the `s_branch` sits inside the skipped block. - **Condition:** the same as stage 1, a tracked uniform `s_cmp`/`s_bitcmp` SCC. Block A runs under the stage-1 condition (`scc` for `scc0`, `!scc` for `scc1`) and block B under its negation. - **Arms:** at A's terminal `s_branch`, the region switches to B through the else-arm state from #1371: - B starts from the incoming VGPR state; - a register first defined by A is undefined in B until B writes it (`Else arm reads a register defined only in the then arm`); - B's writes are tracked separately. - **Join:** each register merges as `condition ? A : B`, with the incoming value standing in for a block that did not write it. A register undefined on entry and not written by both blocks stays undefined after JOIN. - **Gate:** both blocks use the stage-1 vector-only gate. SCC, VCC and EXEC are unchanged. Nesting, backward branches, memory, waits and other observable side effects stay out. ## Tests - **`check_scc_diamond_controls`:** - The select condition for both polarities on v13 (both blocks), v14 (A only) and v15 (B only), and B reading v14's incoming `sample16.z`. - Malformed targets refused: conditional edge onto the `s_branch`; conditional edge onto JOIN; `s_branch` onto B's first instruction, backward, or outside the program; an `s_branch` that is not last in A. - A nested branch in A or B refused, and memory in B refused. - Definedness: a B read of an A-only register refused, accepted after a B write; an undefined-on-entry register written by one block refused after JOIN, defined when both write it. - SCC kept across the diamond, and an empty A accepted. - **`check_scc_diamond_draw`**, run by the existing `pixel_aot_scc_skip_{warp,hardware}`: - Forms: `s_cmp_eq_u32 s47, 0` + `s_cbranch_scc1`, and `s_cmp_lg_u32 s47, 0` + `s_cbranch_scc0`. - The runtime flag is 0 (B runs) and 1 and 7 (A runs). A writes v13 = 0.25 and v14 = 0.75; B writes v13 = 0.5 and v15 = 0.5 × v14, which reads v14's incoming value. - Mutants that must mismatch: flipped polarity (flags 0 and 1), dropped `s_branch` (flag 1, so A falls through into B), and the correct shader against a stale-A expectation where B reads A's v14 (flag 0). - **LLVM 15 binary regression:** both diamonds with `.Lscc_else` and `.Lscc_join` labels. - **`tests/form_coverage_check.py`:** `s_branch` is now recorded as an accepted form. The check used it as its example of a form that only reaches rejections; it now asserts `s_branch` is accepted, keeps `s_code_end` as the not-accepted example, and adds `("SOPP", "s_branch")` to the covered SCC-branch forms. ## Results `117ebb8b` on `71be6f0f`. Windows 11 26H2 (build 26300.9974), `dev` preset, DXC 1.8.2502.11, Python 3.13.1, LLVM 15.0.7. ``` python -B tests/pixel_aot_check.py # controls: pass python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> # pass ctest --preset dev --no-tests=error -R '^pixel_aot_(scc_skip|exec_regions|cmpx_regions|region_.*)_(warp|hardware)$' # 14/14 pass ``` WARP `10.0.26100.9818`: the 6 diamond cases (2 forms × flag 0/1/7) match at 64/64 pixels. All 8 mutant cases mismatch: 2 stale-A, 4 polarity, 2 dropped-branch. The stage-1 skip cases still pass. AMD Radeon RX 9070 XT, driver `32.0.31044.16`: the 6 diamond cases match. All 8 mutant cases mismatch. The stage-1 skip cases still pass. All 37 pure-Python checks listed in `AGENTS.md` pass. **Negative control:** with `tools/pixel_aot.py` restored to main, `check_scc_diamond_controls` fails with `Instruction cannot run in a uniform skip block: s_branch 2`. ## Not measured The #1413 counts are shapes only: 9,004 diamond branches in 3,201 records. The number of local records this unblocks is not measurable while the scan's translator verdict stops at unbound operands (#1314). The draws pin the translator's model on desktop adapters; they are not evidence for gfx1013 hardware. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 16:03:22 +00:00
tedin7 commented 2026-11-24 16:03:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:45:10Z.

Review: COMMENTED


Technical review (Linux only; no Windows, WARP or GPU run). The draw results in docs/experiments.md (six cases, eight mutant cases on WARP and a hardware adapter) are therefore not reproduced here.

Checked out the PR head in a clean tree.

What I ran:

  • tests/pixel_aot_check.py (default controls, includes the new check_scc_diamond_controls): passes.
  • tests/form_coverage_check.py: passes with the updated s_branch expectation.
  • The new diamond and the existing skip fixtures, assembled with llvm-mc-19/llvm-objcopy-19 for gfx1013 and disassembled with LLVM 19: the translation of the real machine bytes (scc_diamond_asm, with labels) equals the translation of the hand-offset fixture, for both eq/scc1 and lg/scc0. (pixel_aot_check.py binary as a whole stops earlier with LLVM 19 in check_f16_cvt_int16_binary, code this PR does not touch, so I ran the scc fixtures separately.)
  • Extra translations through scc_diamond(): A writes then reads its own value, B reading a register A wrote with an incoming value, a register written by both arms and read after JOIN, one written by A only. All merge as cond ? A : B with the incoming value standing in for an arm that did not write it, and B reads the incoming value, not A's. A v_cmp writing VCC in either arm is refused.
  • Reading of the lowering: A runs when the branch is not taken, so cond = SCC for scc0 and !SCC for scc1, matching the merge order; join <= end rejects a JOIN on B's first instruction and backward targets; the skip path is unchanged.

Local mutation check on tools/pixel_aot.py (each reverted afterwards; tree clean), running the Linux controls (check_scc_diamond_controls and check_scc_skip_controls):

  • join <= end weakened to join < end, or the join check removed: caught.
  • B not restored to the incoming state, or else_undefined not recorded: caught.
  • the s_branch match widened to any branch, or the JOIN offset computed without the + 4: caught.
  • A's snapshot taken from the outer values instead of A's results (region["then"] = {dst: region["written"][dst] ...}): not caught. The translation changes for the worse (for example v13 becomes (!scc) ? sample16.y : ... and v14 becomes (!scc) ? sample16.z : sample16.z, i.e. A's writes are lost), but the Linux controls only assert that _v13, _v14 and _v15 merge lines exist and that B contains (0.5f * sample16.z). Only the Windows draw would see it.
  • the -0x8000 <= jimm <= 0x7fff range test removed: not caught (cosmetic; the decoder only yields a 16-bit immediate).

Suggestion (non-blocking): in check_scc_diamond_controls, assert the full merge expressions for the default diamond, for example alu27_v13 = ((!scc20) ? alu22 : alu25) for scc1 (or build the strings from the A and B operands), so the A arm is pinned without a Windows machine. As written, the Linux-visible controls would still pass if the lowering dropped A's results.

Nothing else found. No conflict with other open work in tools/pixel_aot.py seen in the diff.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042524057 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1625#pullrequestreview-6042524057). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:45:10Z. **Review:** COMMENTED --- Technical review (Linux only; no Windows, WARP or GPU run). The draw results in `docs/experiments.md` (six cases, eight mutant cases on WARP and a hardware adapter) are therefore not reproduced here. Checked out the PR head in a clean tree. What I ran: - `tests/pixel_aot_check.py` (default controls, includes the new `check_scc_diamond_controls`): passes. - `tests/form_coverage_check.py`: passes with the updated `s_branch` expectation. - The new diamond and the existing skip fixtures, assembled with `llvm-mc-19`/`llvm-objcopy-19` for gfx1013 and disassembled with LLVM 19: the translation of the real machine bytes (`scc_diamond_asm`, with labels) equals the translation of the hand-offset fixture, for both `eq/scc1` and `lg/scc0`. (`pixel_aot_check.py binary` as a whole stops earlier with LLVM 19 in `check_f16_cvt_int16_binary`, code this PR does not touch, so I ran the scc fixtures separately.) - Extra translations through `scc_diamond()`: A writes then reads its own value, B reading a register A wrote with an incoming value, a register written by both arms and read after JOIN, one written by A only. All merge as `cond ? A : B` with the incoming value standing in for an arm that did not write it, and B reads the incoming value, not A's. A `v_cmp` writing VCC in either arm is refused. - Reading of the lowering: A runs when the branch is not taken, so `cond` = SCC for `scc0` and `!SCC` for `scc1`, matching the merge order; `join <= end` rejects a JOIN on B's first instruction and backward targets; the skip path is unchanged. Local mutation check on `tools/pixel_aot.py` (each reverted afterwards; tree clean), running the Linux controls (`check_scc_diamond_controls` and `check_scc_skip_controls`): - `join <= end` weakened to `join < end`, or the join check removed: caught. - B not restored to the incoming state, or `else_undefined` not recorded: caught. - the `s_branch` match widened to any branch, or the JOIN offset computed without the `+ 4`: caught. - **A's snapshot taken from the outer values instead of A's results** (`region["then"] = {dst: region["written"][dst] ...}`): **not caught**. The translation changes for the worse (for example `v13` becomes `(!scc) ? sample16.y : ...` and `v14` becomes `(!scc) ? sample16.z : sample16.z`, i.e. A's writes are lost), but the Linux controls only assert that `_v13`, `_v14` and `_v15` merge lines exist and that B contains `(0.5f * sample16.z)`. Only the Windows draw would see it. - the `-0x8000 <= jimm <= 0x7fff` range test removed: not caught (cosmetic; the decoder only yields a 16-bit immediate). Suggestion (non-blocking): in `check_scc_diamond_controls`, assert the full merge expressions for the default diamond, for example `alu27_v13 = ((!scc20) ? alu22 : alu25)` for `scc1` (or build the strings from the A and B operands), so the A arm is pinned without a Windows machine. As written, the Linux-visible controls would still pass if the lowering dropped A's results. Nothing else found. No conflict with other open work in `tools/pixel_aot.py` seen in the diff. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 16:03:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T15:55:56Z.


Resolved the conflict with #1527 in 7355cc6e. The diamond controls are registered in the same table for serial and parallel runs, and the Windows form coverage check plus RTX and WARP SCC draws passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7136851998 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1625#issuecomment-7136851998). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T15:55:56Z. --- Resolved the conflict with #1527 in 7355cc6e. The diamond controls are registered in the same table for serial and parallel runs, and the Windows form coverage check plus RTX and WARP SCC draws passed.
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!1618
No description provided.