shader: lower one structured wave64 else arm in pixel_aot masked regions #1364

Merged
MasterDomino merged 2 commits from upstream-pr/1371 into main 2026-11-24 10:13:35 +00:00
MasterDomino commented 2026-11-24 09:32:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T09:32:00Z.


Fixes #1315 (Stage B; Stage A is #1328)

pixel_aot masked regions now accept one structured wave64 else arm: s_andn2_b64 exec, s[a:b], exec on the saved pair. This follows the scope R0Y00 approved on #1315.

Behaviour (tools/pixel_aot.py)

  • Transition: s_andn2_b64 exec, s[a:b], exec naming the open region's exact saved pair, at most once, for both openers (s_and_saveexec_b64 and s_mov_b64 s[a:b], exec + v_cmpx). EXEC becomes saved & ~EXEC, the saved lanes whose condition is false, so the else arm runs on the negated region condition.
  • Pre-region state per arm:
    • At the transition, the then-arm values are recorded and every register the then arm rewrote gets its pre-region value back.
    • A register first defined by the then arm is undefined in the else arm until the else arm writes it (Else arm reads a register defined only in the then arm).
    • Else-arm writes are tracked separately.
  • Join: each register merges as condition ? then : else, with the pre-region value standing in for an arm that did not write it. A register undefined before the region and not written on both reachable arms stays undefined (conditional) after the close, as before.
  • Skips on real instruction boundaries:
    • The optional s_cbranch_execz directly after the opener must land exactly on the transition. Landing on the close of a region that has a transition is refused at the transition.
    • The optional one directly after the transition must land exactly on the close (s_or_b64 or s_mov_b64).
    • seen_skip now allows both arms of the same region to carry a skip. Two regions with skips are still refused.
    • Outstanding waits are restored at the close if either arm could be skipped.
  • SCC: unknown from the transition, since s_andn2_b64 writes it from the new EXEC, until an admitted scalar compare redefines it.
  • Scalars: a scalar written in a then arm the wave may skip is marked conditional before the else arm. Without that skip, it is defined for the else arm.
  • Unchanged: the body gate (memory, sampling, exports, cross-lane, waits). Wave32, nesting and s_andn2_b32 exec_lo stay refused.

Tests (tests/pixel_aot_check.py)

Fixture else_region: the then arm writes v13 and v14. The else arm writes v13 and computes v15 = 0.5 × v14, so it must read v14's pre-region value. v13 merges both arms, v14 only the then arm and v15 only the else arm. It covers both openers, both closes and the skip shapes none/then/else/both, with the displacements computed from real instruction offsets.

check_masked_else_controls:

  • Every skip shape lowers to the same selects (temporaries renumbered).
  • The else arm reads sample16.z, the pre-region v14.
  • A then-only register read in the else arm is refused, but allowed after an else write.
  • A register defined on one arm only is refused after the join; one defined on both is accepted.
  • A transition of another pair, a second transition, a transition before the region or after the close, and s_andn2_b32 exec_lo are refused.
  • A then skip onto the close, an else skip mid-arm or past the close, and an else skip that is not directly after the transition are refused. Skips in two regions are still refused.
  • SCC: tracked through a v_cmpx then arm, unknown in the else arm (Select condition is not a tracked scalar result), and accepted again after s_cmp_lt_i32 redefines it.
  • A scalar from a skippable then arm is refused in the else arm and accepted without the skip.
  • image_sample, exp and v_readfirstlane_b32 are refused in the else arm.

check_masked_else_draw (runs in draw-exec-regions, so in pixel_aot_exec_regions_{warp,hardware}): 16 programs × thresholds 0.5 / 10 / -1. Three mutants must mismatch:

  • the transition removed (the else body overwrites the then lanes);
  • the predicate reversed;
  • the correct shader drawn against a stale-then expectation (else reading the then arm's v14).

Binary regression: the 16 programs, the 12 with skips through labels, are assembled with LLVM 15, disassembled with offsets, and must lower like the computed offset pairs.

Two existing checks changed because they pinned the old refusal of the transition:

  • check_masked_mov_close_controls (#1328): s_andn2_b64 exec, s[60:61], exec before the close is now valid. It now asserts a transition of another pair rejects with Unexpected execution mask else transition. The wave32 copy refusal is kept.
  • check_cmpx_controls: the refused-extra list used the same-pair transition and now uses s_andn2_b64 exec, s[58:59], exec.

Results

Rebased on b9c9f624 (includes #1337). 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_(exec_regions|cmpx_regions|region_.*)_(warp|hardware)$'   # 12/12 pass
backend if/else cases else mutants earlier region cases
WARP 10.0.26100.9818 48/48 match (64/64 pixels each) 3/3 mismatch 18/18 pass, 4/4 mutants mismatch
AMD Radeon RX 9070 XT, driver 32.0.31044.16 48/48 3/3 mismatch 18/18, 4/4

tests/rdna2_tools_check.py (with LLVM, 1 existing skip), form_coverage_check, shader_census_check, shader_corpus_report_check, pso_readiness_check, docs_links_check and bidi_controls_check also pass.

Negative control: with tools/pixel_aot.py restored to main, check_masked_else_controls fails with Instruction cannot run in a masked region: s_andn2_b64 exec, s[60:61], exec.

Not measured

The structural counts on #1315 are shape counts only: 23,603 simple wave64 if/else regions, 15,323 of them with both skips. With #1337 the scan names unbound operands, but it still stops before regions for almost every record, so the number of local records this unblocks is not measured. These 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:6578764171 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1371). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T09:32:00Z. --- Fixes #1315 (Stage B; Stage A is #1328) `pixel_aot` masked regions now accept one structured wave64 else arm: `s_andn2_b64 exec, s[a:b], exec` on the saved pair. This follows the scope R0Y00 approved on #1315. ## Behaviour (`tools/pixel_aot.py`) - **Transition:** `s_andn2_b64 exec, s[a:b], exec` naming the open region's exact saved pair, at most once, for both openers (`s_and_saveexec_b64` and `s_mov_b64 s[a:b], exec` + `v_cmpx`). EXEC becomes saved & ~EXEC, the saved lanes whose condition is false, so the else arm runs on the negated region condition. - **Pre-region state per arm:** - At the transition, the then-arm values are recorded and every register the then arm rewrote gets its pre-region value back. - A register first defined by the then arm is undefined in the else arm until the else arm writes it (`Else arm reads a register defined only in the then arm`). - Else-arm writes are tracked separately. - **Join:** each register merges as `condition ? then : else`, with the pre-region value standing in for an arm that did not write it. A register undefined before the region and not written on both reachable arms stays undefined (conditional) after the close, as before. - **Skips on real instruction boundaries:** - The optional `s_cbranch_execz` directly after the opener must land exactly on the transition. Landing on the close of a region that has a transition is refused at the transition. - The optional one directly after the transition must land exactly on the close (`s_or_b64` or `s_mov_b64`). - `seen_skip` now allows both arms of the same region to carry a skip. Two regions with skips are still refused. - Outstanding waits are restored at the close if either arm could be skipped. - **SCC:** unknown from the transition, since `s_andn2_b64` writes it from the new EXEC, until an admitted scalar compare redefines it. - **Scalars:** a scalar written in a then arm the wave may skip is marked conditional before the else arm. Without that skip, it is defined for the else arm. - **Unchanged:** the body gate (memory, sampling, exports, cross-lane, waits). Wave32, nesting and `s_andn2_b32 exec_lo` stay refused. ## Tests (`tests/pixel_aot_check.py`) **Fixture `else_region`:** the then arm writes v13 and v14. The else arm writes v13 and computes v15 = 0.5 × v14, so it must read v14's pre-region value. v13 merges both arms, v14 only the then arm and v15 only the else arm. It covers both openers, both closes and the skip shapes `none`/`then`/`else`/`both`, with the displacements computed from real instruction offsets. **`check_masked_else_controls`:** - Every skip shape lowers to the same selects (temporaries renumbered). - The else arm reads `sample16.z`, the pre-region v14. - A then-only register read in the else arm is refused, but allowed after an else write. - A register defined on one arm only is refused after the join; one defined on both is accepted. - A transition of another pair, a second transition, a transition before the region or after the close, and `s_andn2_b32 exec_lo` are refused. - A then skip onto the close, an else skip mid-arm or past the close, and an else skip that is not directly after the transition are refused. Skips in two regions are still refused. - SCC: tracked through a `v_cmpx` then arm, unknown in the else arm (`Select condition is not a tracked scalar result`), and accepted again after `s_cmp_lt_i32` redefines it. - A scalar from a skippable then arm is refused in the else arm and accepted without the skip. - `image_sample`, `exp` and `v_readfirstlane_b32` are refused in the else arm. **`check_masked_else_draw`** (runs in `draw-exec-regions`, so in `pixel_aot_exec_regions_{warp,hardware}`): 16 programs × thresholds 0.5 / 10 / -1. Three mutants must mismatch: - the transition removed (the else body overwrites the then lanes); - the predicate reversed; - the correct shader drawn against a stale-then expectation (else reading the then arm's v14). **Binary regression:** the 16 programs, the 12 with skips through labels, are assembled with LLVM 15, disassembled with offsets, and must lower like the computed offset pairs. **Two existing checks changed** because they pinned the old refusal of the transition: - `check_masked_mov_close_controls` (#1328): `s_andn2_b64 exec, s[60:61], exec` before the close is now valid. It now asserts a transition of another pair rejects with `Unexpected execution mask else transition`. The wave32 copy refusal is kept. - `check_cmpx_controls`: the refused-extra list used the same-pair transition and now uses `s_andn2_b64 exec, s[58:59], exec`. ## Results Rebased on `b9c9f624` (includes #1337). 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_(exec_regions|cmpx_regions|region_.*)_(warp|hardware)$' # 12/12 pass ``` | backend | if/else cases | else mutants | earlier region cases | |---|---|---|---| | WARP 10.0.26100.9818 | 48/48 match (64/64 pixels each) | 3/3 mismatch | 18/18 pass, 4/4 mutants mismatch | | AMD Radeon RX 9070 XT, driver 32.0.31044.16 | 48/48 | 3/3 mismatch | 18/18, 4/4 | `tests/rdna2_tools_check.py` (with LLVM, 1 existing skip), `form_coverage_check`, `shader_census_check`, `shader_corpus_report_check`, `pso_readiness_check`, `docs_links_check` and `bidi_controls_check` also pass. **Negative control:** with `tools/pixel_aot.py` restored to main, `check_masked_else_controls` fails with `Instruction cannot run in a masked region: s_andn2_b64 exec, s[60:61], exec`. ## Not measured The structural counts on #1315 are shape counts only: 23,603 simple wave64 if/else regions, 15,323 of them with both skips. With #1337 the scan names unbound operands, but it still stops before regions for almost every record, so the number of local records this unblocks is not measured. These 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)
tedin7 commented 2026-11-24 10:02:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:42:05Z.

Review: COMMENTED


Technical peer-review of commit 6b8ad31cea19cd53f844d9586562393603f8fcd4:

Verification

  • Linux:
    • git diff --check origin/main...HEAD: clean.
    • tests/docs_links_check.py: passed (16 Markdown files, 303 links).
    • tests/bidi_controls_check.py: passed (1,149 files).
    • tests/pixel_aot_check.py: passed.
    • tests/rdna2_tools_check.py: passed (139 tests, 18 skipped).
    • tests/form_coverage_check.py: passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev): offscreen_check built (24.01s); ctest -R '^pixel_aot_(exec|cmpx)_regions_warp$' 2/2 passed (3.63s).
    • Release /O2 (--preset release): offscreen_check built (35.92s); ctest -R '^pixel_aot_(exec|cmpx)_regions_warp$' 2/2 passed (3.50s).
    • Windows Python checks: tests/pixel_aot_check.py (12.0s), tests/rdna2_tools_check.py (4.4s), tests/form_coverage_check.py (42.6s) passed.

Findings (tools/pixel_aot.py)

  • The else-transition handling (s_andn2_b64 exec, s[a:b], exec), pre-region vector state restoration, else_undefined check (correctly evaluated before difference_update(writes)), dual-arm skip tracking, and close_region join are clean and well-tested.
  • Minor edge case: at the s_andn2_b64 transition (tools/pixel_aot.py:3215-3217), when region["skip"] is not None, scalar.conditional is updated from region["scalar_written"], but region["outstanding"] (before_pending, before_samples) is only restored at close_region (tools/pixel_aot.py:2846-2851). If the skipped then arm executed an s_waitcnt, a wave that skipped the then arm would enter the else arm with pending / sample_dest cleared even though it did not run that wait. Restoring pending and sample_dest from region["outstanding"] at s_andn2_b64 when region["skip"] is not None would close that gap.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6036880028 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1371#pullrequestreview-6036880028). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:42:05Z. **Review:** COMMENTED --- Technical peer-review of commit `6b8ad31cea19cd53f844d9586562393603f8fcd4`: ### Verification - **Linux**: - `git diff --check origin/main...HEAD`: clean. - `tests/docs_links_check.py`: passed (16 Markdown files, 303 links). - `tests/bidi_controls_check.py`: passed (1,149 files). - `tests/pixel_aot_check.py`: passed. - `tests/rdna2_tools_check.py`: passed (139 tests, 18 skipped). - `tests/form_coverage_check.py`: passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: `offscreen_check` built (`24.01s`); `ctest -R '^pixel_aot_(exec|cmpx)_regions_warp$'` **2/2 passed** (`3.63s`). - **Release `/O2` (`--preset release`)**: `offscreen_check` built (`35.92s`); `ctest -R '^pixel_aot_(exec|cmpx)_regions_warp$'` **2/2 passed** (`3.50s`). - **Windows Python checks**: `tests/pixel_aot_check.py` (`12.0s`), `tests/rdna2_tools_check.py` (`4.4s`), `tests/form_coverage_check.py` (`42.6s`) passed. ### Findings (`tools/pixel_aot.py`) - The else-transition handling (`s_andn2_b64 exec, s[a:b], exec`), pre-region vector state restoration, `else_undefined` check (correctly evaluated before `difference_update(writes)`), dual-arm skip tracking, and `close_region` join are clean and well-tested. - **Minor edge case**: at the `s_andn2_b64` transition (`tools/pixel_aot.py:3215-3217`), when `region["skip"] is not None`, `scalar.conditional` is updated from `region["scalar_written"]`, but `region["outstanding"]` (`before_pending, before_samples`) is only restored at `close_region` (`tools/pixel_aot.py:2846-2851`). If the skipped then arm executed an `s_waitcnt`, a wave that skipped the then arm would enter the else arm with `pending` / `sample_dest` cleared even though it did not run that wait. Restoring `pending` and `sample_dest` from `region["outstanding"]` at `s_andn2_b64` when `region["skip"] is not None` would close that gap.
MasterDomino commented 2026-11-24 10:02:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T10:02:36Z.


@tedin7 thanks, that gap was real. Before the fix, a then arm with a skip and an s_waitcnt lgkmcnt(0) let the else arm use a descriptor loaded before the region (s_buffer_load_dword s72, s[68:71], 0x20) although a wave that skipped the then arm never ran that wait. Fixed in e4112744: when the then arm can be skipped, the transition restores the opener's outstanding loads and samples, as close_region does for a skipped region. New control in check_masked_else_controls: no skip → accepted; then skip with the wait only in the then arm → Unresolved constant buffer binding; then skip with a wait in both arms → accepted. Without the fix that control fails. Controls, the LLVM 15 binary regression and the 12 region CTests (WARP + RX 9070 XT) pass; the branch still merges cleanly with main.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128234336 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1371#issuecomment-7128234336). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T10:02:36Z. --- @tedin7 thanks, that gap was real. Before the fix, a then arm with a skip and an `s_waitcnt lgkmcnt(0)` let the else arm use a descriptor loaded before the region (`s_buffer_load_dword s72, s[68:71], 0x20`) although a wave that skipped the then arm never ran that wait. Fixed in `e4112744`: when the then arm can be skipped, the transition restores the opener's outstanding loads and samples, as `close_region` does for a skipped region. New control in `check_masked_else_controls`: no skip → accepted; then skip with the wait only in the then arm → `Unresolved constant buffer binding`; then skip with a wait in both arms → accepted. Without the fix that control fails. Controls, the LLVM 15 binary regression and the 12 region CTests (WARP + RX 9070 XT) pass; the branch still merges cleanly with main. AI-assisted.
upstream-sync closed this pull request 2026-11-24 11:02:38 +00:00
tedin7 commented 2026-11-24 11:02:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:18:57Z.

Review: COMMENTED


Technical retest at e41127442c316862c04e0bfaed904518eb0e33e8:

Previous finding verified

  • Commit e4112744 restores region["outstanding"] (pending and sample_dest) at the s_andn2_b64 exec, s[a:b], exec transition when region["skip"] is not None, so an s_waitcnt in a skippable then arm no longer hides pre-region outstanding loads from the else arm.
  • tests/pixel_aot_check.py (check_masked_else_controls) adds the waited(True, False) negative control (rejects with Unresolved constant buffer binding) and waited(True, True) positive control.

Checks run

  • Linux: docs_links_check.py, bidi_controls_check.py, pixel_aot_check.py, form_coverage_check.py, and rdna2_tools_check.py (LLVM_MC=llvm-mc-19, 139 tests, 18 skipped) all passed.
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Python: tests/form_coverage_check.py passed (44.18s).
    • Debug (--preset dev, target offscreen_check): ctest -R '^pixel_aot_(exec_regions|cmpx_regions|region_body|region_waits|region_scalar_alu|region_scalar_load)_warp$' 6/6 passed (4.61s).
    • Release /O2 (--preset release, target offscreen_check): ctest -R '^pixel_aot_(exec_regions|cmpx_regions|region_body|region_waits|region_scalar_alu|region_scalar_load)_warp$' 6/6 passed (4.87s).

All checks pass cleanly.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037413152 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1371#pullrequestreview-6037413152). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:18:57Z. **Review:** COMMENTED --- Technical retest at `e41127442c316862c04e0bfaed904518eb0e33e8`: **Previous finding verified** - Commit `e4112744` restores `region["outstanding"]` (`pending` and `sample_dest`) at the `s_andn2_b64 exec, s[a:b], exec` transition when `region["skip"] is not None`, so an `s_waitcnt` in a skippable `then` arm no longer hides pre-region outstanding loads from the `else` arm. - `tests/pixel_aot_check.py` (`check_masked_else_controls`) adds the `waited(True, False)` negative control (rejects with `Unresolved constant buffer binding`) and `waited(True, True)` positive control. **Checks run** - **Linux**: `docs_links_check.py`, `bidi_controls_check.py`, `pixel_aot_check.py`, `form_coverage_check.py`, and `rdna2_tools_check.py` (`LLVM_MC=llvm-mc-19`, 139 tests, 18 skipped) all passed. - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - Python: `tests/form_coverage_check.py` passed (`44.18s`). - Debug (`--preset dev`, target `offscreen_check`): `ctest -R '^pixel_aot_(exec_regions|cmpx_regions|region_body|region_waits|region_scalar_alu|region_scalar_load)_warp$'` **6/6 passed** (`4.61s`). - Release `/O2` (`--preset release`, target `offscreen_check`): `ctest -R '^pixel_aot_(exec_regions|cmpx_regions|region_body|region_waits|region_scalar_alu|region_scalar_load)_warp$'` **6/6 passed** (`4.87s`). All checks pass cleanly.
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!1364
No description provided.