startup: lower constant-lane SGPR spills on wave64 lanes and in vertex stages in gfx2hlsl (Part of #1723) #2704

Merged
tedin7 merged 2 commits from upstream-pr/2712 into main 2026-11-26 05:40:08 +00:00
tedin7 commented 2026-11-26 03:08:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:08:05Z.


Part of #1723

What this unblocks: constant-lane SGPR spills (v_writelane_b32 vN, sM, k / v_readlane_b32 sD, vN, k) in wave64 programs (lanes 32..63) and in vertex stages now translate instead of being refused ("lane 40 outside 0..31", "lowered in pixel stages only").

Extends #2637, #2524 and #2127: they cover pixel lanes 0..31 (with branches) and the slot 57 mesh stage; the lane range and the vertex stage were still refused.

What changed

The slot model (one scalar per (VGPR, lane)) only needs the two instructions to touch lane k and to ignore EXEC, which holds in every stage. So:

  • lanes 0..63 are accepted (SPILL_LANES = 64) and the vertex stage joins pixel and mesh (SPILL_STAGES);
  • the translator does not know the wave size, and a wave32 program takes the lane select modulo 32 (RDNA 2 ISA, v_readlane/v_writelane). So k and k+32 name one slot in wave32 and two in wave64: a spill VGPR whose lanes include such a pair stays refused by name (require_spill_lanes_apart, new in this PR; it applies to pixel and vertex stages only, because slot 57 mesh is always wave64 and keeps lanes k and k+32 as two slots).

What stays refused

Lane 64 and up, register-chosen lanes, compute stages, a VGPR with any non-spill use, and any branches outside the pixel proof of #2524 (vertex stages with branches stay refused).

Tests

New tests/startup_gfx2hlsl_spill_wave64_check.py (registered in CMakeLists.txt, noted in docs/experiments.md): wave64 pixel slots, the vertex stage, two VGPRs holding lanes 8 and 40, the k/k+32 pair refusal, and a draw mode with a CPU reference and wrong-lane / ignored-overwrite mutations. startup_gfx2hlsl_sgpr_spill_check.py now expects lane 64 and the k/k+32 pair refused and the vertex stage accepted. On origin/main the new check fails (wave64 pixel slots translate, vertex stage slots translate, lanes 8 and 40 of two different VGPRs are accepted); with the change it passes.

Verification

  • python3 -B tests/startup_gfx2hlsl_spill_wave64_check.py: PASS (fails on origin/main); ... binary llvm-mc-19: PASS
  • python3 -B of startup_gfx2hlsl_sgpr_spill_check.py, startup_gfx2hlsl_spill_branches_check.py, startup_mesh57_lane_spill_check.py and the other startup_mesh57_*_check.py: PASS
  • All tests/startup_gfx2hlsl_*_check.py run with no arguments on this branch and on origin/main: same result per script (export_null_draw and mul24_align_draw need a compiler and renderer and exit 1 on both); the only new script is spill_wave64_check.
  • Win2025 (Stage-2, head 6c16fcd62): dev 28/28 and release 28/28 passed (spill_wave64 controls, warp and hardware, sgpr_spill, mesh57). The review found one regression, fixed in bcb42f915 (the pair rule no longer runs for the mesh stage; startup_mesh57_lane_spill_check.py now keeps lanes 3 and 35 of one VGPR translating, and fails without the fix). Win2025 (Windows Server 2025) on the fixed head bcb42f9150: dev 28/28 and release 28/28 passed (startup_gfx2hlsl_spill_wave64_controls/_warp/_hardware, startup_mesh57_lane_spill (controls), _warp, hardware, startup_gfx2hlsl_sgpr_spill*; one mesh57 hardware test skipped by design).

Copy-paste (build and run the spill tests):

cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_(sgpr_spill|spill_wave64|spill_branches)|^startup_mesh57' -V

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618627382 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2712). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:08:05Z. --- Part of #1723 What this unblocks: constant-lane SGPR spills (`v_writelane_b32 vN, sM, k` / `v_readlane_b32 sD, vN, k`) in wave64 programs (lanes 32..63) and in vertex stages now translate instead of being refused ("lane 40 outside 0..31", "lowered in pixel stages only"). Extends #2637, #2524 and #2127: they cover pixel lanes 0..31 (with branches) and the slot 57 mesh stage; the lane range and the vertex stage were still refused. ## What changed The slot model (one scalar per (VGPR, lane)) only needs the two instructions to touch lane k and to ignore EXEC, which holds in every stage. So: - lanes 0..63 are accepted (`SPILL_LANES = 64`) and the vertex stage joins pixel and mesh (`SPILL_STAGES`); - the translator does not know the wave size, and a wave32 program takes the lane select modulo 32 (RDNA 2 ISA, `v_readlane`/`v_writelane`). So k and k+32 name one slot in wave32 and two in wave64: a spill VGPR whose lanes include such a pair stays refused by name (`require_spill_lanes_apart`, new in this PR; it applies to pixel and vertex stages only, because slot 57 mesh is always wave64 and keeps lanes k and k+32 as two slots). ## What stays refused Lane 64 and up, register-chosen lanes, compute stages, a VGPR with any non-spill use, and any branches outside the pixel proof of #2524 (vertex stages with branches stay refused). ## Tests New `tests/startup_gfx2hlsl_spill_wave64_check.py` (registered in `CMakeLists.txt`, noted in `docs/experiments.md`): wave64 pixel slots, the vertex stage, two VGPRs holding lanes 8 and 40, the k/k+32 pair refusal, and a `draw` mode with a CPU reference and wrong-lane / ignored-overwrite mutations. `startup_gfx2hlsl_sgpr_spill_check.py` now expects lane 64 and the k/k+32 pair refused and the vertex stage accepted. On `origin/main` the new check fails (`wave64 pixel slots translate`, `vertex stage slots translate`, `lanes 8 and 40 of two different VGPRs are accepted`); with the change it passes. ## Verification - `python3 -B tests/startup_gfx2hlsl_spill_wave64_check.py`: PASS (fails on `origin/main`); `... binary llvm-mc-19`: PASS - `python3 -B` of `startup_gfx2hlsl_sgpr_spill_check.py`, `startup_gfx2hlsl_spill_branches_check.py`, `startup_mesh57_lane_spill_check.py` and the other `startup_mesh57_*_check.py`: PASS - All `tests/startup_gfx2hlsl_*_check.py` run with no arguments on this branch and on `origin/main`: same result per script (`export_null_draw` and `mul24_align_draw` need a compiler and renderer and exit 1 on both); the only new script is `spill_wave64_check`. - Win2025 (Stage-2, head 6c16fcd62): dev 28/28 and release 28/28 passed (spill_wave64 controls, warp and hardware, sgpr_spill, mesh57). The review found one regression, fixed in bcb42f915 (the pair rule no longer runs for the mesh stage; `startup_mesh57_lane_spill_check.py` now keeps lanes 3 and 35 of one VGPR translating, and fails without the fix). Win2025 (Windows Server 2025) on the fixed head bcb42f9150e12dccd87506e3befcd8c2191075e4: dev 28/28 and release 28/28 passed (startup_gfx2hlsl_spill_wave64_controls/_warp/_hardware, startup_mesh57_lane_spill (controls), _warp, _hardware, startup_gfx2hlsl_sgpr_spill_*; one mesh57 hardware test skipped by design). Copy-paste (build and run the spill tests): ``` cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_(sgpr_spill|spill_wave64|spill_branches)|^startup_mesh57' -V ``` AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:39 +00:00 (Migrated from github.com)

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


Independent Stage-2 review of head bcb42f9150: PASS.

  • The k / k+32 pair rule now applies to pixel and vertex stages only; slot 57 mesh (always wave64) keeps lanes 3 and 35 of one VGPR as two slots. With the rule applied to every stage the new mesh case fails (startup_mesh57_lane_spill_check.py: got 'unsupported: ... one slot in wave32 and two in wave64', want 'ok').
  • Probes through the real pipeline (llvm-mc fixtures): lanes 8 and 40 of one VGPR, a register-chosen lane, an unwritten slot, lane 64, a spill VGPR also used as data and a read before the write are all refused; s_mov_b32 exec_lo, 0 before the lane ops still translates (both instructions ignore EXEC).
  • Mutations that fail the new checks: SPILL_LANES 64 -> 32, pair rule removed, vs dropped from SPILL_STAGES, lane + 32 -> lane + 33.
  • Win2025 (Windows Server 2025), default 5-slot pool, --no-skip-build, --targets offscreen_check --regex '^startup_gfx2hlsl_(sgpr_spill|spill_wave64|spill_branches)|^startup_mesh57': dev 28/28 and release 28/28 passed on this head, including startup_gfx2hlsl_spill_wave64_warp/_hardware and startup_mesh57_lane_spill_warp/_hardware.

Marked Ready. @MasterDomino

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181854857 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2712#issuecomment-7181854857). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:35:38Z. --- Independent Stage-2 review of head bcb42f9150e12dccd87506e3befcd8c2191075e4: PASS. - The k / k+32 pair rule now applies to pixel and vertex stages only; slot 57 mesh (always wave64) keeps lanes 3 and 35 of one VGPR as two slots. With the rule applied to every stage the new mesh case fails (`startup_mesh57_lane_spill_check.py`: `got 'unsupported: ... one slot in wave32 and two in wave64', want 'ok'`). - Probes through the real pipeline (llvm-mc fixtures): lanes 8 and 40 of one VGPR, a register-chosen lane, an unwritten slot, lane 64, a spill VGPR also used as data and a read before the write are all refused; `s_mov_b32 exec_lo, 0` before the lane ops still translates (both instructions ignore EXEC). - Mutations that fail the new checks: SPILL_LANES 64 -> 32, pair rule removed, `vs` dropped from SPILL_STAGES, `lane + 32` -> `lane + 33`. - Win2025 (Windows Server 2025), default 5-slot pool, `--no-skip-build`, `--targets offscreen_check --regex '^startup_gfx2hlsl_(sgpr_spill|spill_wave64|spill_branches)|^startup_mesh57'`: dev 28/28 and release 28/28 passed on this head, including `startup_gfx2hlsl_spill_wave64_warp/_hardware` and `startup_mesh57_lane_spill_warp/_hardware`. Marked Ready. @MasterDomino AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 04:04:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:35:42Z.


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-26T03:38:28.678008Z bcb42f9 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:7181855898 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2712#issuecomment-7181855898). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T03:35:42Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"bcb42f9150e12dccd87506e3befcd8c2191075e4","has_any_findings":false,"has_unresolved_findings":false,"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-26T03:38:28.678008Z">2026-11-26T03:38:28.678008Z</relative-time> | `bcb42f9` | 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>
upstream-sync closed this pull request 2026-11-26 06:01:53 +00:00
R0Y00 commented 2026-11-26 06:01:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:39:57Z.

Review: APPROVED


Reviewed the constant-lane spill proof and ran the host spill, branch, wave64 and mesh57 controls with main 651577a0 combined. The synthetic pixel, vertex and mesh draw checks passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, both on Windows 11 build 26200. The lane and overwrite mutants were caught. An unknown-size VS/PS still refuses lane pairs that could alias, and slot 57 retains its two distinct wave64 lanes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069076731 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2712#pullrequestreview-6069076731). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T05:39:57Z. **Review:** APPROVED --- Reviewed the constant-lane spill proof and ran the host spill, branch, wave64 and mesh57 controls with main 651577a0 combined. The synthetic pixel, vertex and mesh draw checks passed on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, both on Windows 11 build 26200. The lane and overwrite mutants were caught. An unknown-size VS/PS still refuses lane pairs that could alias, and slot 57 retains its two distinct wave64 lanes.
tedin7 commented 2026-11-26 06:02:06 +00:00 (Migrated from github.com)

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


Checked the automated review comment from 03:35Z on head bcb42f915. It is only a status summary: code review "Completed", has_any_findings: false, has_unresolved_findings: false. There is no finding to fix and no review thread to resolve, so no code change.

Commands run: gh pr view 2712 --json comments,reviews and a GraphQL reviewThreads query (0 threads).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183273716 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2712#issuecomment-7183273716). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T05:12:15Z. --- Checked the automated review comment from 03:35Z on head `bcb42f915`. It is only a status summary: code review "Completed", `has_any_findings: false`, `has_unresolved_findings: false`. There is no finding to fix and no review thread to resolve, so no code change. Commands run: `gh pr view 2712 --json comments,reviews` and a GraphQL `reviewThreads` query (0 threads). 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!2704
No description provided.