Skip to content

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

Merged
Leyukaka merged 1 commit into
R0Y00:mainfrom
SimSalabimse:cursor/heap-record-index-temp-edb4
Nov 28, 2026
Merged

Leyukaka merged 1 commit into
R0Y00:mainfrom
SimSalabimse:cursor/heap-record-index-temp-edb4

Conversation

@SimSalabimse

Copy link
Copy Markdown
Contributor

Closes #3304.

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 R0Y00#3304

Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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
Leyukaka merged commit 7781a5f into R0Y00:main Nov 28, 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.

shader: heap-record lowering reads rh[0] when the index SGPR is overwritten before the load

3 participants