shader: pin the per-lane heap index at its waterfall mark #3317

Manually merged
github merged 1 commit from github-bot/gh-3315 into gh-pr/3315/base 2026-11-28 19:46:54 +00:00 AGit
Owner

@⁠SimSalabimse on GitHub · 2026-11-28 08:54 UTC · original
SimSalabimse:cursor/heap-record-index-temp-edb4 → main · +114 −13 · 3 files · 1 commits · merged 2026-11-28 19:44 UTC

Closes #3306.

The per-lane heap-record lowering in gfx2hlsl.py (from #2861) read the index SGPR at the s_load, not at the waterfall mark. If that SGPR was written between the mark and the load, the load silently picked record 0 (rh[0]).

What changed

  • tools/startup/gfx2hlsl.py: copy the index SGPR into a temporary when the mark is made, and have the load read that copy. An expression that still names the original SGPR after a write is refused instead of lowered.
  • tests/startup_compute_waterfall_heap_check.py: mark-time pin cases, including a clobber between the mark and the load, v_lshrrev bounds, an unbounded v_mov copy, and a stale-capture refusal. Both mutants from the issue now fail the check.
  • docs/experiments.md: one sentence on the temporary and the refusal.

Tests

  • Linux: startup_compute_waterfall_heap_check.py and the issue's repro.
  • Windows test PC (NVIDIA, 32-lane waves), at 74b4ded9, ctest -j 1 -R "waterfall_heap|startup_gfx2hlsl_" (audio device tests excluded): 391/391 passed, twice. That includes startup_compute_waterfall_heap_{oracle,dispatch}_{warp,hardware}.

AI-assisted (Cursor)

**@⁠SimSalabimse** on GitHub · 2026-11-28 08:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3315) `SimSalabimse:cursor/heap-record-index-temp-edb4` → `main` · +114 −13 · 3 files · 1 commits · merged 2026-11-28 19:44 UTC Closes #3306. The per-lane heap-record lowering in `gfx2hlsl.py` (from #2861) read the index SGPR at the `s_load`, not at the waterfall mark. If that SGPR was written between the mark and the load, the load silently picked record 0 (`rh[0]`). **What changed** - `tools/startup/gfx2hlsl.py`: copy the index SGPR into a temporary when the mark is made, and have the load read that copy. An expression that still names the original SGPR after a write is refused instead of lowered. - `tests/startup_compute_waterfall_heap_check.py`: mark-time pin cases, including a clobber between the mark and the load, `v_lshrrev` bounds, an unbounded `v_mov` copy, and a stale-capture refusal. Both mutants from the issue now fail the check. - `docs/experiments.md`: one sentence on the temporary and the refusal. **Tests** - Linux: `startup_compute_waterfall_heap_check.py` and the issue's repro. - Windows test PC (NVIDIA, 32-lane waves), at `74b4ded9`, `ctest -j 1 -R "waterfall_heap|startup_gfx2hlsl_"` (audio device tests excluded): 391/391 passed, twice. That includes `startup_compute_waterfall_heap_{oracle,dispatch}_{warp,hardware}`. AI-assisted (Cursor)
The waterfall load read the index SGPR at the s_load, so a write between
the mark and the load selected record 0. Copy the index into a temporary
at the mark, and refuse an expression that still names that SGPR.

Closes #3304

Co-authored-by: SimSalabimse <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 09:01:10 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-28 19:39 UTC · original · approved these changes

Review of 74b4ded9.

  • Copying the heap index at the waterfall mark fixes the read of an SGPR that is overwritten between the mark and the load.
  • Run here in Windows Sandbox, network off, vGPU, Windows 11 build 26300 host, release build of main f2972840 with this PR and 17 other open PRs merged locally: startup_compute_waterfall_heap_oracle_{warp,hardware} and startup_compute_waterfall_heap_dispatch_{warp,hardware} pass. Storing the SGPR name instead of the pinned copy (self.per_lane_index[dst[1]] = ('s%d' % dst[1], bound[1])) makes both _dispatch tests fail.

Not covered: _refuse_overwritten_per_lane has no test and looks unreachable with the current callers.

Approve.

**@⁠Leyukaka** on GitHub · 2026-11-28 19:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3315#pullrequestreview-6099789185) · **approved these changes** Review of `74b4ded9`. - Copying the heap index at the waterfall mark fixes the read of an SGPR that is overwritten between the mark and the load. - Run here in Windows Sandbox, network off, vGPU, Windows 11 build 26300 host, release build of `main` `f2972840` with this PR and 17 other open PRs merged locally: `startup_compute_waterfall_heap_oracle_{warp,hardware}` and `startup_compute_waterfall_heap_dispatch_{warp,hardware}` pass. Storing the SGPR name instead of the pinned copy (`self.per_lane_index[dst[1]] = ('s%d' % dst[1], bound[1])`) makes both `_dispatch` tests fail. Not covered: `_refuse_overwritten_per_lane` has no test and looks unreachable with the current callers. Approve.
github-bot changed target branch from main to gh-pr/3315/base 2026-11-28 19:46:52 +00:00
github manually merged commit 74b4ded9a2 into gh-pr/3315/base 2026-11-28 19:46:54 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.