mesh: reload constant-lane scalar spills through v_writelane_b32 / v_readlane_b32 #2119

Merged
Leyukaka merged 3 commits from upstream-pr/2127 into main 2026-11-25 02:35:29 +00:00
Leyukaka commented 2026-11-25 00:59:03 +00:00 (Migrated from github.com)

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.py sent v_writelane_b32 and v_readlane_b32 through 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 with v_readlane_b32 to spill scalar registers, including saved EXEC words, into fixed lanes of a VGPR. This adds the constant-lane form.

  • v_writelane_b32 vD, sS, lane with 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_hi sources store the corresponding EXEC word. The selected lane of vD is also updated, so ordinary vector reads of that lane after the last reload see the value.
  • v_readlane_b32 sD, vS, lane returns the slot's value to sD.
  • Refused:
    • a register-selected or out-of-range lane;
    • a read of a slot not written on the modelled path, including a write skipped by a branch;
    • any ordinary use of the spill VGPR between its first spill write and a later reload;
    • a write overlapping a pending vector load into that VGPR;
    • a non-SGPR reload destination or a pending SGPR.
  • Scope. 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.py is a hand-written wave64 program. It writes lanes 3 and 63 of v10 with EXEC cleared, reloads them into s12 and s13, reuses lane 63 for the saved high EXEC word and restores EXEC from it, then exports s12 and s13. The check covers:

  • the reloaded scalars and the exported positions (only lanes 32..63 active after restoring EXEC);
  • that a uniform buffer expression survives a spill and reload;
  • refusals for a register-selected read lane, lane 64, an unwritten slot, a branch-skipped write and an ALU use of v10 in between;
  • that a register-range operand covering v10 (v[9:11]) counts as ordinary use;
  • that RuntimeWave refuses v_writelane_b32 under EXEC = 0;
  • a control that swaps the two reload lanes and must fail the value check.
python -B tests/mesh_lane_spill_check.py         # passes
python -B tests/mesh_dynamic_aot_check.py         # passes
python -B tests/mesh_dynamic_geometry_check.py    # passes
python -B tests/mesh_amplification_refusal_check.py   # passes

Registered as mesh_lane_spill_cpu and 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: 12 on wave.s[12]). Mutations that drop the RuntimeWave override 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594660416 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2127). Originally posted by [Leyukaka](https://github.com/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.py` sent `v_writelane_b32` and `v_readlane_b32` through 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 with `v_readlane_b32` to spill scalar registers, including saved EXEC words, into fixed lanes of a VGPR. This adds the constant-lane form. - **`v_writelane_b32 vD, sS, lane`** with 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_hi` sources store the corresponding EXEC word. The selected lane of `vD` is also updated, so ordinary vector reads of that lane after the last reload see the value. - **`v_readlane_b32 sD, vS, lane`** returns the slot's value to `sD`. - **Refused:** - a register-selected or out-of-range lane; - a read of a slot not written on the modelled path, including a write skipped by a branch; - any ordinary use of the spill VGPR between its first spill write and a later reload; - a write overlapping a pending vector load into that VGPR; - a non-SGPR reload destination or a pending SGPR. - **Scope.** `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.py` is a hand-written wave64 program. It writes lanes 3 and 63 of `v10` with EXEC cleared, reloads them into `s12` and `s13`, reuses lane 63 for the saved high EXEC word and restores EXEC from it, then exports `s12` and `s13`. The check covers: - the reloaded scalars and the exported positions (only lanes 32..63 active after restoring EXEC); - that a uniform buffer expression survives a spill and reload; - refusals for a register-selected read lane, lane 64, an unwritten slot, a branch-skipped write and an ALU use of `v10` in between; - that a register-range operand covering `v10` (`v[9:11]`) counts as ordinary use; - that `RuntimeWave` refuses `v_writelane_b32` under EXEC = 0; - a control that swaps the two reload lanes and must fail the value check. ``` python -B tests/mesh_lane_spill_check.py # passes python -B tests/mesh_dynamic_aot_check.py # passes python -B tests/mesh_dynamic_geometry_check.py # passes python -B tests/mesh_amplification_refusal_check.py # passes ``` Registered as `mesh_lane_spill_cpu` and 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: 12` on `wave.s[12]`). Mutations that drop the `RuntimeWave` override 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.
upstream-sync closed this pull request 2026-11-25 03:00:58 +00:00
tedin7 commented 2026-11-25 03:00:58 +00:00 (Migrated from github.com)

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_b32 model 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 other mesh_*_check.py need a binary argument 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.
  • CI: Linux checks, Windows build and test, and gfx1013 fixtures are all green. Mergeable state was reported as UNKNOWN.
  • Title is neutral, and the body starts with Part of #1998.

Mutations (each restored with git checkout -- .):

  • Removing the "read of unwritten slot" refusal: killed (KeyError).
  • Removing the "mixed spill use" refusal: killed ("Expected refusal: Mixed lane spill use of v10").
  • Removing the exec_lo/exec_hi source branch at tools/mesh_entry_aot.py:271: SURVIVED, and the check still exits 0.

Findings:

  • P2 tests/mesh_lane_spill_check.py: the check only spills EXEC through s_mov_b64 s[22:23], exec (lines 11 and 30). The v_writelane_b32 vN, exec_lo/exec_hi, lane path at tools/mesh_entry_aot.py:271-272, including the shift for exec_hi, is never run. The PR body names this case, so please add a positive case that spills exec_lo and exec_hi and reloads them, with a non-zero and a high-half EXEC value.
  • nit 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.
  • nit tools/mesh_entry_aot.py (lane_spill): the lane range check uses len(self.v). Please confirm that is always 64, since the message says wave{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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050516026 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2127#pullrequestreview-6050516026). Originally posted by [tedin7](https://github.com/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_b32` model 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 other `mesh_*_check.py` need a `binary` argument 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. - CI: Linux checks, Windows build and test, and gfx1013 fixtures are all green. Mergeable state was reported as UNKNOWN. - Title is neutral, and the body starts with `Part of #1998`. **Mutations (each restored with `git checkout -- .`):** - Removing the "read of unwritten slot" refusal: killed (KeyError). - Removing the "mixed spill use" refusal: killed ("Expected refusal: Mixed lane spill use of v10"). - Removing the `exec_lo`/`exec_hi` source branch at `tools/mesh_entry_aot.py:271`: SURVIVED, and the check still exits 0. **Findings:** - **P2** `tests/mesh_lane_spill_check.py`: the check only spills EXEC through `s_mov_b64 s[22:23], exec` (lines 11 and 30). The `v_writelane_b32 vN, exec_lo/exec_hi, lane` path at `tools/mesh_entry_aot.py:271-272`, including the shift for `exec_hi`, is never run. The PR body names this case, so please add a positive case that spills `exec_lo` and `exec_hi` and reloads them, with a non-zero and a high-half EXEC value. - **nit** `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. - **nit** `tools/mesh_entry_aot.py` (`lane_spill`): the lane range check uses `len(self.v)`. Please confirm that is always 64, since the message says `wave{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.
tedin7 commented 2026-11-25 03:00:58 +00:00 (Migrated from github.com)

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:

  • CI on this head: Linux checks, gfx1013 fixtures and Windows build/test all pass. Build and test on Windows at /O2 and the coverage chart job are skipped.
  • Mergeable. Title and body are neutral. Body starts with Part of #1998.
  • No Windows run needed: the change is Python-only (mesh interpreter), and the new check runs on Linux.

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 by tests/mesh_lane_spill_check.py:

  • exec_hi shift removed -> fails "exec word spill".
  • Stored slot value masked to 8 bits -> fails "reload values".
  • "Mixed use between write and read" guard disabled -> fails the expected refusal.
  • Lane range check disabled -> fails (IndexError).

Logic read-through (tools/mesh_entry_aot.py lane_spill):

  • Constant-lane parsing, the 0..63 range check, the slot keyed by (VGPR, lane), the pending-vector-load overlap check and the SGPR-only reload destination all match the described semantics.
  • tools/mesh_dynamic_aot.py refuses both ops explicitly, so the runtime-geometry path cannot inherit the slot model.

Nits (non-blocking):

  • spill_vector_uses is 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.
  • The out-of-range lane case: with the check disabled, the failure is an IndexError and 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6050674791 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2127#pullrequestreview-6050674791). Originally posted by [tedin7](https://github.com/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: - CI on this head: Linux checks, gfx1013 fixtures and Windows build/test all pass. `Build and test on Windows at /O2` and the coverage chart job are skipped. - Mergeable. Title and body are neutral. Body starts with `Part of #1998`. - No Windows run needed: the change is Python-only (mesh interpreter), and the new check runs on Linux. 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 by `tests/mesh_lane_spill_check.py`: - `exec_hi` shift removed -> fails "exec word spill". - Stored slot value masked to 8 bits -> fails "reload values". - "Mixed use between write and read" guard disabled -> fails the expected refusal. - Lane range check disabled -> fails (IndexError). Logic read-through (`tools/mesh_entry_aot.py` `lane_spill`): - Constant-lane parsing, the 0..63 range check, the slot keyed by (VGPR, lane), the pending-vector-load overlap check and the SGPR-only reload destination all match the described semantics. - `tools/mesh_dynamic_aot.py` refuses both ops explicitly, so the runtime-geometry path cannot inherit the slot model. Nits (non-blocking): - `spill_vector_uses` is 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. - The out-of-range lane case: with the check disabled, the failure is an `IndexError` and 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.
Leyukaka commented 2026-11-25 03:01:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T02:09:43Z.


Thanks @tedin7. Pushed 9a6fd7ff:

  • P2. The check now sets EXEC to 0xc0000003_80000005 and spills exec_lo and exec_hi into lanes 5 and 6 of v12. It clears EXEC, reads both lanes back into SGPRs, and asserts 0x80000005 / 0xc0000003. Each of these mutations now makes the check fail:
    • removing the exec_lo/exec_hi source branch: exec_lo then reaches scalar() and raises;
    • dropping the exec_hi shift: "exec word spill".
  • nit, 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.
  • nit, lane range. self.v is assigned only in Wave.__init__, with 64 lanes (range(64)), so len(self.v) is always 64. RuntimeWave overrides lane_spill to refuse, so the check is only reached on Wave.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7150389635 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2127#issuecomment-7150389635). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T02:09:43Z. --- Thanks @tedin7. Pushed `9a6fd7ff`: - **P2.** The check now sets EXEC to `0xc0000003_80000005` and spills `exec_lo` and `exec_hi` into lanes 5 and 6 of `v12`. It clears EXEC, reads both lanes back into SGPRs, and asserts `0x80000005` / `0xc0000003`. Each of these mutations now makes the check fail: - removing the `exec_lo`/`exec_hi` source branch: `exec_lo` then reaches `scalar()` and raises; - dropping the `exec_hi` shift: "exec word spill". - **nit, `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. - **nit, lane range.** `self.v` is assigned only in `Wave.__init__`, with 64 lanes (`range(64)`), so `len(self.v)` is always 64. `RuntimeWave` overrides `lane_spill` to refuse, so the check is only reached on `Wave`. AI-assisted.
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!2119
No description provided.