shader: lower one-armed pixel CMPX skips with scalar loads and SALU #3830

Manually merged
github merged 1 commit from github-bot/gh-3828 into gh-pr/3828/base 2026-12-02 10:15:36 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-02 07:15 UTC · original
timbot103:shader/pixel-cmpx-scalar-tail → main · +371 −23 · 6 files · 1 commits · merged 2026-12-02 10:11 UTC

Lowers wave64 pixel one-armed v_cmpx_* skips with scalar loads and SALU inside the arm, in the scalar tail between the skip target and EXEC restore, and after the restore (item W2 of #3816).

Part of #3816. Refs #3642, #3643, #3705.

Summary

  • src/gfx1013_direct_graphics.inl (pixel_readonly_arms):
    • Added wave_scalar(const Inst&) accepting scalar loads (Encoding::Smem with dst + memory_count <= 106; decoder only admits loads) and ordinary Sop1/Sop2/Sopk/Sopc SALU on SGPRs/constants while rejecting exec, movrel, pc, reg, wqm, rfe, loop, vskip, waitcnt, call, branch, fork, join, and special-register operands (VCC, EXEC, M0, VCCZ, EXECZ, SCC).
    • Generalized arm scalar support from Smem (op >= 8) / s_mov_b32 to wave_scalar; all arm-written scalars and SCC remain expired at the join so arm-conditional scalar writes cannot leak into the tail or post-restore code.
    • Added one-armed v_cmpx_* scalar-tail recognition between the s_cbranch_execz join and restore (wave_scalar, s_waitcnt, s_nop, s_clause), emitting scalar_tail_merges at the join so tail results stay live past the restore while the restore itself is a no-op.
    • Accepted s_or_b64 exec, exec, parent (either operand order) as a one-armed CMPX restore, expiring SCC at the restore.
    • Fail-closed guards: refuses tail or arm clobbers of the saved pair, vector/EXEC writes or EXEC/VCC reads or branches in the tail, non-skip branches entering the arm or tail, and tail/OR-restore forms combined with ELSE arms, inner s_and_saveexec, or s_and_saveexec masks.
  • tests/offscreen_check.cpp, tests/startup_flat_param.cpp, tests/desktop_gpu.h:
    • Extended --startup-pixel-words with an optional 6th argument (1..64 comma-separated hex words) bound as a root SRV at t0 so pixel stages loading from a root address can be read back on WARP and hardware GPUs; added CLI self-test cases.
  • tests/native_pixel_cmpx_scalar_tail_check.py + tests/cmake/native_pixel_cmpx_scalar_tail.cmake:
    • 5 positive shapes (salu-tail, arm-loads, tail-loads, after-restore-loads, or-restore-tail) verified for DXIL structure (br i1, phi, no wave ops, rawBufferLoad placement in arm vs post-join) and GPU readback (including swapped/all-arm/none-arm mismatch controls and whole-wave all-arm/none-arm tail runs).
    • 26 fail-closed refusal controls (arm scalar/load leaks including pre-defined SGPRs, SCC leaks across join and OR restore, saved-pair clobbers, vector/EXEC/VCC/branch in tail, branches into arm or tail, skip past restore, side-effecting arm ops).

Verification

Host: Windows 11 (10.0.26200.9974), MSVC C++20 /W4 (zero warnings on edited targets), inbox WARP (10.0.26100.9818), NVIDIA GeForce RTX 5080 (32.0.16.2140).

  • Debug (dev) & Release (release):
    • native_pixel_cmpx_scalar_tail_controls: passed in both configs (5 positive + 26 refusals).
    • native_pixel_cmpx_scalar_tail_warp: passed in both configs (WARP readback + negative mismatch controls + whole-wave runs).
    • native_pixel_cmpx_scalar_tail_hardware: passed in both configs (RTX 5080 readback + negative mismatch controls + whole-wave runs).
    • offscreen_check --self-test: passed in both configs.
    • Regression pass in both configs: native_direct_container, native_pixel_dxil, native_pixel_cmpx_discard_warp, native_pixel_cmpx_if_else_{controls,warp}, native_pixel_compare_mask_{warp,hardware,container,ir}, native_graphics_wqm_{hardware,warp,ir}, native_graphics_sampler_heap_{warp,hardware}, native_graphics_interface_library, native_graphics_vertex_vcc_join_{warp,hardware}, startup_flat_param_{controls,warp,hardware} (23/23 built pixel/graphics tests passed in both Debug and Release).
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.
**@⁠timbot103** on GitHub · 2026-12-02 07:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3828) `timbot103:shader/pixel-cmpx-scalar-tail` → `main` · +371 −23 · 6 files · 1 commits · merged 2026-12-02 10:11 UTC Lowers wave64 pixel one-armed `v_cmpx_*` skips with scalar loads and SALU inside the arm, in the scalar tail between the skip target and EXEC restore, and after the restore (item **W2** of #3816). Part of #3816. Refs #3642, #3643, #3705. ## Summary - **`src/gfx1013_direct_graphics.inl` (`pixel_readonly_arms`):** - Added `wave_scalar(const Inst&)` accepting scalar loads (`Encoding::Smem` with `dst + memory_count <= 106`; decoder only admits loads) and ordinary `Sop1`/`Sop2`/`Sopk`/`Sopc` SALU on SGPRs/constants while rejecting `exec`, `movrel`, `pc`, `reg`, `wqm`, `rfe`, `loop`, `vskip`, `waitcnt`, `call`, `branch`, `fork`, `join`, and special-register operands (`VCC`, `EXEC`, `M0`, `VCCZ`, `EXECZ`, `SCC`). - Generalized arm scalar support from `Smem (op >= 8)` / `s_mov_b32` to `wave_scalar`; all arm-written scalars and SCC remain expired at the join so arm-conditional scalar writes cannot leak into the tail or post-restore code. - Added one-armed `v_cmpx_*` scalar-tail recognition between the `s_cbranch_execz` join and restore (`wave_scalar`, `s_waitcnt`, `s_nop`, `s_clause`), emitting `scalar_tail_merges` at the join so tail results stay live past the restore while the restore itself is a no-op. - Accepted `s_or_b64 exec, exec, parent` (either operand order) as a one-armed CMPX restore, expiring SCC at the restore. - Fail-closed guards: refuses tail or arm clobbers of the saved pair, vector/EXEC writes or EXEC/VCC reads or branches in the tail, non-skip branches entering the arm or tail, and tail/OR-restore forms combined with ELSE arms, inner `s_and_saveexec`, or `s_and_saveexec` masks. - **`tests/offscreen_check.cpp`, `tests/startup_flat_param.cpp`, `tests/desktop_gpu.h`:** - Extended `--startup-pixel-words` with an optional 6th argument (`1..64` comma-separated hex words) bound as a root SRV at `t0` so pixel stages loading from a root address can be read back on WARP and hardware GPUs; added CLI self-test cases. - **`tests/native_pixel_cmpx_scalar_tail_check.py` + `tests/cmake/native_pixel_cmpx_scalar_tail.cmake`:** - 5 positive shapes (`salu-tail`, `arm-loads`, `tail-loads`, `after-restore-loads`, `or-restore-tail`) verified for DXIL structure (`br i1`, `phi`, no wave ops, `rawBufferLoad` placement in arm vs post-join) and GPU readback (including swapped/all-arm/none-arm mismatch controls and whole-wave all-arm/none-arm tail runs). - 26 fail-closed refusal controls (arm scalar/load leaks including pre-defined SGPRs, SCC leaks across join and OR restore, saved-pair clobbers, vector/EXEC/VCC/branch in tail, branches into arm or tail, skip past restore, side-effecting arm ops). ## Verification Host: Windows 11 (`10.0.26200.9974`), MSVC C++20 `/W4` (zero warnings on edited targets), inbox WARP (`10.0.26100.9818`), NVIDIA GeForce RTX 5080 (`32.0.16.2140`). - **Debug (`dev`) & Release (`release`):** - `native_pixel_cmpx_scalar_tail_controls`: passed in both configs (5 positive + 26 refusals). - `native_pixel_cmpx_scalar_tail_warp`: passed in both configs (WARP readback + negative mismatch controls + whole-wave runs). - `native_pixel_cmpx_scalar_tail_hardware`: passed in both configs (RTX 5080 readback + negative mismatch controls + whole-wave runs). - `offscreen_check --self-test`: passed in both configs. - Regression pass in both configs: `native_direct_container`, `native_pixel_dxil`, `native_pixel_cmpx_discard_warp`, `native_pixel_cmpx_if_else_{controls,warp}`, `native_pixel_compare_mask_{warp,hardware,container,ir}`, `native_graphics_wqm_{hardware,warp,ir}`, `native_graphics_sampler_heap_{warp,hardware}`, `native_graphics_interface_library`, `native_graphics_vertex_vcc_join_{warp,hardware}`, `startup_flat_param_{controls,warp,hardware}` (23/23 built pixel/graphics tests passed in both Debug and Release). - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, `git diff --check origin/main..HEAD`: all clean.
A wave64 pixel CMPX skip over one arm becomes a lane branch when the arm,
the scalar tail between the skip target and the restore, and the code
after the restore hold scalar loads or SALU (#3814 item W2).

- The arm may hold any scalar load and SALU on ordinary SGPRs and
  constants. What it writes is undefined from the join.
- The skip may land on scalar loads, waits and SALU before
  s_mov_b64 exec, parent. The wave runs them on both paths. They follow
  the join's merge, so their results stay live past the restore.
- s_or_b64 exec, exec, parent is accepted as the restore; its SCC is
  undefined after it.
- Refused: a tail or arm that writes the saved pair, a tail with a
  vector or EXEC write, an EXEC/VCC read or a branch, any other entry
  into the region, and SALU that touches EXEC, VCC, M0 or the PC or
  indexes registers.

offscreen_check --startup-pixel-words takes an optional list of words
bound as a root SRV at t0, so a pixel stage that loads from a root
address can be read back.

Part of #3814

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:17:26 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 07:31 UTC · original · approved these changes

Reviewed 733f6b27 by reading the diff; not built or run.

Verdict: approve. The tail is wave-level scalar work that the guest runs on both paths of the skip. Arm results expire at the join, and the OR restore equals the parent. Each guard fails closed. No MUST.

  • SHOULD No docs update. docs/experiments/mesh86-pixel-execz.md describes these read-only arms. The new forms are not mentioned there: scalar loads and SALU in the arm, a scalar tail before the restore, and the s_or_b64 exec, exec, sN restore.
  • SHOULD No measured stage count. The ~550 figure is the #3816 W2 shape tally, not translated stages. A ps86 census on f365f125 before and after would show the real gain. This can come in a follow-up.
  • NIT CI runs only _controls: native_pixel_cmpx_scalar_tail_warp is not in the pr preset filter.
  • NIT This PR and #3828 both change pixel_readonly_arms, around the saved-compare block and the if (!closed || inner…) line (gfx1013_direct_graphics.inl:927). Whichever merges second needs a rebase.
  • NIT scalar_width counts SOPK s_cmpk_* (whose dst is a source) as a write. This refuses more than needed, but nothing is wrong.
  • Checked, no finding:
    • The tail range is covered by the existing branch-target check (:878, through restore.pc). wave_scalar excludes SOPP, so no branch fits in the tail.
    • expired is applied at :2412, before the no-op return at :2470. So SCC really expires at the skipped OR restore, and the tail's first instruction is not expired.
    • Arm clobbers of the saved pair are still refused (:892). The tail gets its own clobber check (:925).

Tests: _controls reaches the tail scan, the OR restore and 26 refusals, including tail reads of arm scalars, SCC across the OR restore and branches into the tail. _warp/_hardware read back arm and tail values with swapped, all-arm and none-arm controls. CI ran _controls only.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 07:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3828#pullrequestreview-6146447708) · **approved these changes** Reviewed `733f6b27` by reading the diff; not built or run. **Verdict: approve.** The tail is wave-level scalar work that the guest runs on both paths of the skip. Arm results expire at the join, and the OR restore equals the parent. Each guard fails closed. No MUST. - **SHOULD** No docs update. `docs/experiments/mesh86-pixel-execz.md` describes these read-only arms. The new forms are not mentioned there: scalar loads and SALU in the arm, a scalar tail before the restore, and the `s_or_b64 exec, exec, sN` restore. - **SHOULD** No measured stage count. The ~550 figure is the #3816 W2 shape tally, not translated stages. A `ps86` census on `f365f125` before and after would show the real gain. This can come in a follow-up. - **NIT** CI runs only `_controls`: `native_pixel_cmpx_scalar_tail_warp` is not in the `pr` preset filter. - **NIT** This PR and #3828 both change `pixel_readonly_arms`, around the saved-compare block and the `if (!closed || inner…)` line (`gfx1013_direct_graphics.inl:927`). Whichever merges second needs a rebase. - **NIT** `scalar_width` counts SOPK `s_cmpk_*` (whose `dst` is a source) as a write. This refuses more than needed, but nothing is wrong. - Checked, no finding: - The tail range is covered by the existing branch-target check (`:878`, through `restore.pc`). `wave_scalar` excludes SOPP, so no branch fits in the tail. - `expired` is applied at `:2412`, before the no-op return at `:2470`. So SCC really expires at the skipped OR restore, and the tail's first instruction is not expired. - Arm clobbers of the saved pair are still refused (`:892`). The tail gets its own clobber check (`:925`). Tests: `_controls` reaches the tail scan, the OR restore and 26 refusals, including tail reads of arm scalars, SCC across the OR restore and branches into the tail. `_warp`/`_hardware` read back arm and tail values with swapped, all-arm and none-arm controls. CI ran `_controls` only.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 08:33 UTC · original

@⁠lukaslw-lab Thanks for the review and approval! Understood on updating docs/experiments/mesh86-pixel-execz.md and the ps86 census follow-up.

**@⁠timbot103** on GitHub · 2026-12-02 08:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3828#issuecomment-7339609099) @⁠lukaslw-lab Thanks for the review and approval! Understood on updating `docs/experiments/mesh86-pixel-execz.md` and the `ps86` census follow-up.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 10:07 UTC · original · approved these changes

Independent Windows Debug result at 733f6b27: ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_cmpx_scalar_tail_(controls|warp|hardware)$' --output-on-failure passed 3/3. The positive scalar tails, refusal controls and both pixel readbacks passed. Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the offscreen fixture's D3D12 debug layer enabled.

**@⁠R0Y00** on GitHub · 2026-12-02 10:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3828#pullrequestreview-6148696423) · **approved these changes** Independent Windows Debug result at `733f6b27`: `ctest --preset dev --no-tests=error -j 1 -R '^native_pixel_cmpx_scalar_tail_(controls|warp|hardware)$' --output-on-failure` passed 3/3. The positive scalar tails, refusal controls and both pixel readbacks passed. Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the offscreen fixture's D3D12 debug layer enabled.
github-bot changed target branch from main to gh-pr/3828/base 2026-12-02 10:15:33 +00:00
github manually merged commit 733f6b27b1 into gh-pr/3828/base 2026-12-02 10:15:36 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.