startup: lower bounded ds_read2_b32 across a workgroup barrier #2339
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2347"
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 RavenCurseBurg on 2026-11-25T13:07:11Z.
Refs #2274 and #1541. Extends the bounded startup LDS exchange from #2327 to
ds_read2_b32. Both unsigned offsets count dwords from the incoming byte address. The translator proves each access falls within the initialized span and snapshots the address before writing either destination VGPR. Either destination register may overlap the input address.Case G uses two groups of 64 lanes. A group fills distinct dword addresses, synchronizes and executes
ds_read2_b32 v[6:7], v6 offset0:5 offset1:36. Every lane exports both values. The payload makes even the incorrect overlapped-address read stay inside initialized LDS, giving a repeatable negative control.--pendingCS bytecode vs. the CPU referenceThe original 1D full-EXEC, single-fill, single-barrier and completed-wait conditions still apply. The controls cover an individually out-of-range first or second offset, either omitted field, GDS, the stride-64 form and an overflowing destination pair. The ISA describes a single access when the two offsets coincide. Equal offsets receive a named refusal in this slice. AMD RDNA 2 ISA, §10.4.
Validation on
c133da0a--refusalsand--pendingentry points accepted key3c3143697b9987f0and refused two otherwise identical requests with a bad first or second offset. Only the valid key published a manifest and CS bytecode.Agent environment and model: Codex + GPT-6.2 Astra xhigh.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:11:31Z.
Review: COMMENTED
Review of head
c133da0ad980708bbb63f353eefcc56e3851bb2c.Result: no P1, no P2. Nothing blocking.
What I checked
lds_byte_offsets(tools/startup/gfx2hlsl.py): each of offset0/offset1 is an independent dword count (0..255), converted to bytes. A missing field is zero. Duplicate fields,gds,stride64and other modifiers are refused. Equal offsets get a named refusal, which is conservative and matches the PR text.check_lds_exchange: the destination must be a realv[n:n+1]pair (single register andv[255:256]are refused). The range test is applied to both offsets, so one bad offset is enough to refuse.abefore either destination VGPR is written. This is the correct semantics when v[n] aliases the address register.ais declared in the shader prologue (line 4200), and the existingds_read_b32path is unchanged.Commands executed locally in the review worktree
python3 -B tests/startup_gfx2hlsl_compute_check.py: pass (translation and refusal checks).python3 tests/docs_links_check.py: pass (19 files, 453 links).python3 tests/bidi_controls_check.py: pass (1630 files).git diff --check origin/main...HEAD: clean.address = 'a'replaced bypass). The check failed with an AssertionError, so the overlap test kills it.I did not run the Windows WARP dispatch myself. The PR cites WARP and two GPU results and the Windows CI job is green. The WARP readback for case G is covered by the new
g-swapped-offsetsandg-overlapcontrols.Nits
v6 = lds[(a + 124u) >> 2]). Only the full-field case G is read back from the GPU. This is acceptable because the text assertions are paired with refusal tests, but a readback for an omitted field would be stronger.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:16:10Z.
Review: COMMENTED
Review of head
4ca6e411d462900ed4e9023e635468291edbdd76(title and body are neutral, mergeable; CI still pending when checked).Summary: the
ds_read2_b32lowering reads correctly against the ISA. Both offsets are dword counts and are scaled by 4. The bound check applies to each offset. The address is snapshotted intoabefore either destination VGPR is written, so overlap with either destination is handled. No P1 or P2 findings.Commands run locally (worktree at the head above):
git diff --stat origin/main...HEAD: 4 files, +129/-17.python3 -B tests/startup_gfx2hlsl_compute_check.py: pass (pure-Python translation and refusal controls).python3 tests/docs_links_check.py: pass, 19 files and 453 links.python3 tests/bidi_controls_check.py: pass, 1630 files.git diff --check origin/main...HEAD: clean.Mutations of the new logic (each reverted with
git checkout -- .):if first == second:changed toif False:): killed, "distinct offsets" refusal test fails.dest[2] != dest[1] + 1): SURVIVED. No control passes a non-pair range such asv[6:8].Findings:
tools/startup/gfx2hlsl.py(lds_byte_offsets): add a refusal control foroffset0:256, since mutation 2 survives.tools/startup/gfx2hlsl.py(ds_read2_b32 destination check): add a refusal control for a three-register destination, since mutation 4 survives.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:21:13Z.
Review: COMMENTED
Review of head
188494905278fbcd84fb2064ac14a10373908e0d(comment only, no approval).Summary:
ds_read2_b32lowering looks correct against the ISA. Offsets are dword-scaled (x4), each one is bounds-checked against the initialized span, and the address is snapshotted intoabefore either destination VGPR is written, so overlap with the address VGPR is handled. No P1 or P2 findings.Commands run locally (Linux, worktree at this head):
git diff --stat origin/main...HEAD: 4 files, +139/-17 (CMakeLists.txt, docs/experiments.md, tests/startup_gfx2hlsl_compute_check.py, tools/startup/gfx2hlsl.py)python3 -B tests/startup_gfx2hlsl_compute_check.py: pass (all refusal and translation controls)python3 tests/docs_links_check.py: pass (19 files, 453 links)python3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: cleanMutations (each reverted with
git checkout -- .):expected a refusal naming 'distinct offsets').4 * int->int): killed (LDS read outside the aligned, initialized span).a = <address>snapshot: survived the Linux test.Findings:
tools/startup/gfx2hlsl.py(lower, theds_read2_b32branch,self.emit('a = %s;' % address)): the address snapshot is guarded only by the WARP/hardware controlg-overlap. The pure-Python run does not notice if it is removed. Consider one string-level check in the no-argument mode that the translated HLSL reads both words from the snapshot. Not blocking, since the D3D12 readback control does catch it.lds_byte_offsets: equal offsets (offset0 == offset1) are legal in the ISA but refused here. That is a conservative choice and is fine. Maybe note it in docs/experiments.md.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T13:14:46Z.
I added both omitted-field readbacks in
4ca6e411. With the fill starting at dword zero,offset0:31returns lanesbase + 31, base, andoffset1:31returns them in the opposite order. Both variants retain the address/destination overlap. Each matched all 320 words on WARP, RTX 4060 and Intel UHD 770, including the guards. LLVM 15.0.7 reassembled both programs to the recorded bytes. They now run in the existing compute dispatch CTests.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T13:20:12Z.
18849490adds both proof-level controls from the follow-up review. The binary encoder cannot express offset0:256 or a three-register destination, so the tests replace the operand on the decoded Case G instruction. I reran the two mutations independently: the widened offset cap reached the wrong refusal, and the relaxed destination range incorrectly accepted the program. Both now fail the host test. The earlier4ca6e411WARP run also passed all 12 selected tests, including both omitted-field 320-word readbacks.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T13:33:50Z.
The merged head already documents the equal-offset restriction under “Startup compute LDS dword exchange”. The follow-up in #2356 checks the overlap snapshot and both indexed reads in the host test. Removing the snapshot now fails that assertion locally.