Repository navigation
Description
The per-lane heap-record lowering from #2861 (merged as 48ca9ab1) can accept a compute waterfall and translate it to the wrong record. The suite stays green. Below are a reproduction with the PR's own fixture helpers, two surviving mutants and a stale doc paragraph.
Commit or build
main bbf4687b. tools/startup/gfx2hlsl.py is byte-identical to the #2861 head 8a133409. Translator only: no build, device or game files.
Reproduction
The program is the fixture's accepted direct form, plus one s_mov_b32 s22, 0 between the shift and the heap load. Run from the repository root:
import sys; sys.path.insert(0, 'tests')
import startup_compute_waterfall_heap_check as W
body = (W.SHIFT5, W.row_pair('s_mov_b32 s22, 0'), W.HEAP_LOAD, W.WAIT_LGKM, W.BODY_LOAD, W.WAIT_VM)
hlsl, manifest = W.translate(W.build_program(body=body))
for line in hlsl.splitlines():
if line.strip().startswith(('s22 =', 's23 =', 'h0 =', 'if (exec & 1) v7 = rh')):
print(line.strip())
print(manifest.splitlines()[-1])Expected behavior
The program loads the record at s23 (key << 5), so h0 must be the key. Taking h0 from the value before the write, or refusing the program, would both be correct.
Observed behavior
The program is accepted (resheap 4 2), and the HLSL reads the overwritten register:
s22 = v5;
s23 = s22 << (0x00000005u & 31);
s22 = 0x00000000u;
h0 = s22;
if (exec & 1) v7 = rh[NonUniformResourceIndex(h0)].Load(a + 0);
Every lane reads rh[0]. The index is kept as the SGPR name ('s22' in the heap_index mark), and _capture_resheap_desc emits h0 = <expr>; only at the s_load. waterfall_heap_check drops s22 from local_idx on the write, but s23 stays in local_off5. The same happens in three more forms:
- the pre-loop form (
v_lshlrev_b32 v5, 5, v5, pointer add +src_scccarry froms22, thens22 = 0) givesh0 = (s22 >> 5);afters22 = 0x00000000u;; - with
s_lshl_b32 s22, s22, 5; s_mov_b32 s24, s22; s_mov_b32 s22, 0; s_load ... s24it ish0 = (s22 >> 5);; - with
s_mov_b32 s24, s22; s_lshl_b32 s23, s24, 5; s_mov_b32 s24, 0it ish0 = s24;.
A pointer pair that reuses the key register (s_add_u32 s22, s8, s23 + carry into s23) still translates correctly, because the resheap add and carry emit no HLSL. Only an emitted write to the source register in between triggers the bug.
Two bound forms the fixture does not pin
Each mutant below was a one-line edit to vgpr_heap_bounds. In both cases tests/startup_compute_waterfall_heap_check.py still prints PASS (translator + 17 refused controls), exit 0:
- M1: in the
v_mov_b32copy branch, takeregs.get(rs[1], ('idx', 0))and droprs[1] in regs. Thenv_mov_b32 v5, v9withv9unbounded (09030a7e) translates withrh[1]/resheap 1 2. Unmutated, it is refused. - M2: change
regs[rs[1]][1] >> shiftto>> (shift + 1). Thenv_and_b32 v5, 3, v5; v_lshrrev_b32 v5, 1, v5(810a0a2c; lanes hold 0..1) declaresrh[1]/resheap 1 2. Unmutated, it declaresrh[2].v_lshrrev_b32is listed as a bounding form in shader: lower bounded per-lane heap record indices in compute waterfalls (#2644 T3) #2861 but appears 0 times in the fixture.
gfx2hlsl's own decoder reads both hand-encoded words as the instruction named. I did not run them through llvm-mc.
Docs
docs/experiments.md, "An input named by a resource heap record", still says gfx2hlsl.py "lowers one form of a load through that pointer". It does not mention the per-lane waterfall form or the space-2 resheap range.
Suggested fix and tests
- Copy the index into a temporary where its mark is made (at the waterfall
v_readfirstlane_b32,s_lshl_b32 ..., 5ors_mov_b32), not at the load. Or refuse a write to the index's source register between the mark and thes_load. - Add the direct and pre-loop forms above as controls. If they are accepted, assert the exact
h0line. - Add a refused control for the unbounded
v_mov_b32copy, and acceptedv_lshrrev_b32cases with an exactrh[N](bounded source, and the0xffffffff >> shiftform). - Update the docs paragraph.
Environment
Debian Linux, Python 3.13.5, on a read-only git archive export of main. I restored each mutant from a pristine copy and checked the sha256 (07ef1574a005…). I did not dispatch anything (no WARP, GPU or --oracle / --dispatch / --dxil runs), so the wrong record is inferred from the HLSL, not read back.
- I reproduced this on a source-built input.
- I did not include game files, dumps, distribution links or credentials.
This comment was AI-assisted.
Activity
SimSalabimse commentedon Nov 28, 2026
I'll take this one.
My plan is to copy the index SGPR into a temp at the waterfall mark, so the per-lane heap-record read uses the value from the mark even if the SGPR gets overwritten before the
s_load. If an in-between write can't be handled safely, the lowering will refuse it instead of quietly readingrh[0]. I'll pin both of your mutants as fixture controls next tostartup_compute_waterfall_heap_check, add a negative case for the overwrite, and add a docs line.AI-Assisted