Skip to content

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

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
tedin7:x2w-spill-wave64
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
tedin7:x2w-spill-wave64

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

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 6c16fcd): dev 28/28 and release 28/28 passed (spill_wave64 controls, warp and hardware, sgpr_spill, mesh57). The review found one regression, fixed in bcb42f9 (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 bcb42f9: 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.

Symptom: the constant-lane spill idiom v_writelane_b32 vN, sM, k /
v_readlane_b32 sD, vN, k was refused for k >= 32 ("lane 40 outside 0..31")
and in every vertex stage ("lowered in pixel stages only"), although a wave64
program spills into lanes 0..63 and a vertex stage uses the same idiom.

Root cause: the slot model (one scalar per (VGPR, lane)) was limited to
wave32 lanes and pixel stages. Neither limit is needed by the model: the two
instructions touch only lane k and ignore EXEC in every stage.

Change: lanes 0..63 and vertex stages are accepted. The translator does not
know the wave size and a wave32 program takes the lane select modulo 32, so a
spill VGPR whose lanes include k and k + 32 (one slot in wave32, two in
wave64) is refused by name. Lane 64+, compute stages, register lanes,
branches (open R0Y00#2524 territory) stay refused.

Test: tests/startup_gfx2hlsl_spill_wave64_check.py (controls fail before:
lanes 32..63 and the vertex stage refused). The existing sgpr_spill controls
now expect lane 64 and the k/k+32 pair refused and the vertex stage accepted.
Win2025 WARP dev and release, DXC and FXC: the pixel draw matches the slot
reference on 256/256 pixels, the vertex draw exports the reference param0,
and all five wrong-lane/ignored-overwrite mutations fail.

(cherry picked from commit c7fe3e44b10ffb4ebdf40caab7d8306926b3a881)
@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 03:35
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Independent Stage-2 review of head bcb42f9: 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

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
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.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the constant-lane spill proof and ran the host spill, branch, wave64 and mesh57 controls with main 651577a 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.

@R0Y00
R0Y00 merged commit e6902a1 into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants