mesh: reload constant-lane scalar spills through v_writelane_b32 / v_readlane_b32 #2119
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2127"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T00:59:03Z.
Part of #1998 (item B, scalar spills through lane writes).
The bounded mesh interpreter in
tools/mesh_entry_aot.pysentv_writelane_b32andv_readlane_b32through the per-lane vector path. There they were refused ("Unsupported lane instruction") when a lane was live, but under EXEC = 0 the loop body never ran, so both were skipped and a reload left its SGPR unwritten. Compilers use these instructions withv_readlane_b32to spill scalar registers, including saved EXEC words, into fixed lanes of a VGPR. This adds the constant-lane form.v_writelane_b32 vD, sS, lanewith a constant lane in 0..63. It stores the exact scalar word or uniform expression in a per-wave slot keyed by (VGPR, lane), regardless of EXEC.exec_lo/exec_hisources store the corresponding EXEC word. The selected lane ofvDis also updated, so ordinary vector reads of that lane after the last reload see the value.v_readlane_b32 sD, vS, lanereturns the slot's value tosD.tools/mesh_dynamic_aot.py(runtime geometry) now refuses both instructions explicitly, even under EXEC = 0, since it inherits the bounded instruction loop. The bounded profile is wave64 only, as before.Tests
tests/mesh_lane_spill_check.pyis a hand-written wave64 program. It writes lanes 3 and 63 ofv10with EXEC cleared, reloads them intos12ands13, reuses lane 63 for the saved high EXEC word and restores EXEC from it, then exportss12ands13. The check covers:v10in between;v10(v[9:11]) counts as ordinary use;RuntimeWaverefusesv_writelane_b32under EXEC = 0;Registered as
mesh_lane_spill_cpuand added to the pure-Python lists.Negative control: with the previous mesh files the program runs to the end without a refusal, and the check fails on the unwritten reload (
KeyError: 12onwave.s[12]). Mutations that drop theRuntimeWaveoverride or the register-range part of the operand scan each make the check fail.The pending-load overlap, non-SGPR destination and pending-SGPR refusals are implemented but not covered by the fixture.
Not measured: the fixture exercises the CPU interpreter only; no DXIL was compiled and nothing was drawn. The program is hand-written, not compiler output.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:02:22Z.
Review: COMMENTED
Review of head
2dc58a8bdf7e6ed8f4ff2ca4a2f5463c2f34c4d0(external PR, comment only).Summary: The constant-lane
v_writelane_b32/v_readlane_b32model looks correct and conservative. I found no P1. One P2 is a test gap on the EXEC-word source path.Commands run locally (Linux worktree of the PR head):
git diff --stat origin/main...HEAD: 7 files, +218.python3 tests/mesh_lane_spill_check.py: pass.tests/mesh_dynamic_aot_check.py,mesh_dynamic_geometry_check.py,mesh_amplification_refusal_check.py,mesh_multi_check.py,mesh_shadow_check.py: pass. The othermesh_*_check.pyneed abinaryargument or a Windows artifact, so I did not count them.python3 tests/docs_links_check.py: pass (395 links).python3 tests/bidi_controls_check.py: pass.git diff --check origin/main...HEAD: clean.Part of #1998.Mutations (each restored with
git checkout -- .):exec_lo/exec_hisource branch attools/mesh_entry_aot.py:271: SURVIVED, and the check still exits 0.Findings:
tests/mesh_lane_spill_check.py: the check only spills EXEC throughs_mov_b64 s[22:23], exec(lines 11 and 30). Thev_writelane_b32 vN, exec_lo/exec_hi, lanepath attools/mesh_entry_aot.py:271-272, including the shift forexec_hi, is never run. The PR body names this case, so please add a positive case that spillsexec_loandexec_hiand reloads them, with a non-zero and a high-half EXEC value.tools/mesh_entry_aot.py(spill_vector_uses): the first ordinary use of a spill VGPR is recorded and never cleared. This only makes the refusal more conservative, which is fine, but a short comment saying that is intended would help.tools/mesh_entry_aot.py(lane_spill): the lane range check useslen(self.v). Please confirm that is always 64, since the message sayswave{len}.I did not run a Win2025 job: the change is limited to the Python interpreter and the Linux checks cover it.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:15:23Z.
Review: COMMENTED
Review of head
9a6fd7ff79433e5a522c177d582ec5cf160a3aa3(the earlier review covered a previous head).Verdict: no P1, no P2. Ready from my side, pending the maintainer's own checks.
Checks:
Build and test on Windows at /O2and the coverage chart job are skipped.Part of #1998.Commands run locally:
python3 tests/mesh_lane_spill_check.py->Self-test passed.python3 tests/docs_links_check.py->Checked 18 Markdown files and 395 links.python3 tests/bidi_controls_check.py->no bidirectional controls.git diff --check origin/main...HEAD-> clean.Mutations (each reverted with
git checkout -- .), all killed bytests/mesh_lane_spill_check.py:exec_hishift removed -> fails "exec word spill".Logic read-through (
tools/mesh_entry_aot.pylane_spill):tools/mesh_dynamic_aot.pyrefuses both ops explicitly, so the runtime-geometry path cannot inherit the slot model.Nits (non-blocking):
spill_vector_usesis never cleared, so an ordinary VGPR use after the final reload still blocks a later spill of the same VGPR. The comment says this is deliberate, and it only over-refuses. A short test pinning that behavior would stop someone "fixing" it into a stale read later.IndexErrorand not the message assertion. Consider asserting the message text for lane 64 and -1 explicitly, if not already covered.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T02:09:43Z.
Thanks @tedin7. Pushed
9a6fd7ff:0xc0000003_80000005and spillsexec_loandexec_hiinto lanes 5 and 6 ofv12. It clears EXEC, reads both lanes back into SGPRs, and asserts0x80000005/0xc0000003. Each of these mutations now makes the check fail:exec_lo/exec_hisource branch:exec_lothen reachesscalar()and raises;exec_hishift: "exec word spill".spill_vector_uses. Added a comment: it is never cleared on purpose, so a later reload of that VGPR is refused. It can only over-refuse.self.vis assigned only inWave.__init__, with 64 lanes (range(64)), solen(self.v)is always 64.RuntimeWaveoverrideslane_spillto refuse, so the check is only reached onWave.AI-assisted.