startup: lower bounded ds_read2_b32 across a workgroup barrier #2339

Merged
RavenCurseBurg merged 3 commits from upstream-pr/2347 into main 2026-11-25 13:30:17 +00:00
RavenCurseBurg commented 2026-11-25 13:07:11 +00:00 (Migrated from github.com)

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.

Test on WARP, RTX 4060 and UHD 770 Result on each
Published --pending CS bytecode vs. the CPU reference 320/320 words matched, including 64 guard words
Swap the offsets 256 wrong words, first at word 0 (expected 4, actual 0)
Use v6 after writing the first result 128 wrong words, first at word 1 (expected 0, actual 4)

The 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

  • LLVM 15.0.7 reassembly and 72 startup, image and documentation host checks passed. The real --refusals and --pending entry points accepted key 3c3143697b9987f0 and refused two otherwise identical requests with a bad first or second offset. Only the valid key published a manifest and CS bytecode.
  • The regular compute dispatch suite, both new mutation CTests' Python entry points and the six masked-bit-count controls passed on all three adapters. Windows 11 24H2 build 26100.9711, DXC 1.9.2609.5, WARP 10.0.26100.9711, RTX 4060 driver 32.0.15.9579, UHD 770 driver 32.0.101.5973. The local debug layer was unavailable. All 12 selected WARP/host CTests passed, with zero skips and zero debug-layer warnings or errors. Pinned run and full output.

Agent environment and model: Codex + GPT-6.2 Astra xhigh.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6605178662 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347). Originally posted by [RavenCurseBurg](https://github.com/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. | Test on WARP, RTX 4060 and UHD 770 | Result on each | | --- | --- | | Published `--pending` CS bytecode vs. the CPU reference | 320/320 words matched, including 64 guard words | | Swap the offsets | 256 wrong words, first at word 0 (expected 4, actual 0) | | Use v6 after writing the first result | 128 wrong words, first at word 1 (expected 0, actual 4) | The 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](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf). **Validation on c133da0a** - LLVM 15.0.7 reassembly and 72 startup, image and documentation host checks passed. The real `--refusals` and `--pending` entry points accepted key `3c3143697b9987f0` and refused two otherwise identical requests with a bad first or second offset. Only the valid key published a manifest and CS bytecode. - The regular compute dispatch suite, both new mutation CTests' Python entry points and the six masked-bit-count controls passed on all three adapters. Windows 11 24H2 build 26100.9711, DXC 1.9.2609.5, WARP 10.0.26100.9711, RTX 4060 driver 32.0.15.9579, UHD 770 driver 32.0.101.5973. The local debug layer was unavailable. All 12 selected WARP/host CTests passed, with zero skips and zero debug-layer warnings or errors. [Pinned run and full output](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45620150360). Agent environment and model: Codex + GPT-6.2 Astra xhigh.
upstream-sync closed this pull request 2026-11-25 14:04:54 +00:00
tedin7 commented 2026-11-25 14:04:55 +00:00 (Migrated from github.com)

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, stride64 and 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 real v[n:n+1] pair (single register and v[255:256] are refused). The range test is applied to both offsets, so one bad offset is enough to refuse.
  • Lowering: the address is snapshotted into a before either destination VGPR is written. This is the correct semantics when v[n] aliases the address register. a is declared in the shader prologue (line 4200), and the existing ds_read_b32 path is unchanged.
  • The CMake control list and the control mismatch table are extended consistently. The test extends the existing compute check (case G) instead of adding a new file.
  • Title is neutral, mergeable, and CI is green: Linux checks, gfx1013 fixtures and Windows build/test passed. The /O2 and chart jobs were skipped.

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.
  • Mutation 1: dropped the address snapshot (address = 'a' replaced by pass). The check failed with an AssertionError, so the overlap test kills it.
  • Mutation 2: disabled the upper-bound term of the range check. The check failed with "accepted, expected a refusal naming 'initialized span'", so the refusal test kills it. Both mutations were reverted.

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-offsets and g-overlap controls.

Nits

  • nit: the Linux assertions for the omitted-field forms check HLSL text (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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058230013 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#pullrequestreview-6058230013). Originally posted by [tedin7](https://github.com/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`, `stride64` and 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 real `v[n:n+1]` pair (single register and `v[255:256]` are refused). The range test is applied to both offsets, so one bad offset is enough to refuse. - Lowering: the address is snapshotted into `a` before either destination VGPR is written. This is the correct semantics when v[n] aliases the address register. `a` is declared in the shader prologue (line 4200), and the existing `ds_read_b32` path is unchanged. - The CMake control list and the control mismatch table are extended consistently. The test extends the existing compute check (case G) instead of adding a new file. - Title is neutral, mergeable, and CI is green: Linux checks, gfx1013 fixtures and Windows build/test passed. The /O2 and chart jobs were skipped. 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. - Mutation 1: dropped the address snapshot (`address = 'a'` replaced by `pass`). The check failed with an AssertionError, so the overlap test kills it. - Mutation 2: disabled the upper-bound term of the range check. The check failed with "accepted, expected a refusal naming 'initialized span'", so the refusal test kills it. Both mutations were reverted. 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-offsets` and `g-overlap` controls. Nits - nit: the Linux assertions for the omitted-field forms check HLSL text (`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.
tedin7 commented 2026-11-25 14:04:55 +00:00 (Migrated from github.com)

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_b32 lowering 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 into a before 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 -- .):

  1. Allow equal offsets (if first == second: changed to if False:): killed, "distinct offsets" refusal test fails.
  2. Widen the per-field cap from 255 to 65535: SURVIVED. No Linux control passes an offset above 255.
  3. Loosen the upper bound of the initialized-span check (x10): killed, "initialized span" refusal test fails.
  4. Drop the consecutive-pair check on the destination (dest[2] != dest[1] + 1): SURVIVED. No control passes a non-pair range such as v[6:8].

Findings:

  • nit, tools/startup/gfx2hlsl.py (lds_byte_offsets): add a refusal control for offset0:256, since mutation 2 survives.
  • nit, tools/startup/gfx2hlsl.py (ds_read2_b32 destination check): add a refusal control for a three-register destination, since mutation 4 survives.
  • Not run: the WARP readback (case G, and the swapped-offsets and overlap negative controls) needs the Windows runner. The PR body reports it; I did not reproduce it here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058296686 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#pullrequestreview-6058296686). Originally posted by [tedin7](https://github.com/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_b32` lowering 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 into `a` before 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 -- .`): 1. Allow equal offsets (`if first == second:` changed to `if False:`): killed, "distinct offsets" refusal test fails. 2. Widen the per-field cap from 255 to 65535: SURVIVED. No Linux control passes an offset above 255. 3. Loosen the upper bound of the initialized-span check (x10): killed, "initialized span" refusal test fails. 4. Drop the consecutive-pair check on the destination (`dest[2] != dest[1] + 1`): SURVIVED. No control passes a non-pair range such as `v[6:8]`. Findings: - nit, `tools/startup/gfx2hlsl.py` (`lds_byte_offsets`): add a refusal control for `offset0:256`, since mutation 2 survives. - nit, `tools/startup/gfx2hlsl.py` (ds_read2_b32 destination check): add a refusal control for a three-register destination, since mutation 4 survives. - Not run: the WARP readback (case G, and the swapped-offsets and overlap negative controls) needs the Windows runner. The PR body reports it; I did not reproduce it here. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 14:04:55 +00:00 (Migrated from github.com)

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_b32 lowering looks correct against the ISA. Offsets are dword-scaled (x4), each one is bounds-checked against the initialized span, and the address is snapshotted into a before 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: pass
  • git diff --check origin/main...HEAD: clean
  • PR is mergeable, title and body are neutral. At review time the Linux CI job passed and the Windows jobs were still pending. I did not run the Windows WARP suite; the PR's WARP results are the author's.

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

  1. Disable the "two distinct offsets" refusal: killed by the pure-Python test (expected a refusal naming 'distinct offsets').
  2. Drop the dword-to-byte scaling (4 * int -> int): killed (LDS read outside the aligned, initialized span).
  3. Remove the a = <address> snapshot: survived the Linux test.

Findings:

  • P1=0, P2=0
  • nit, tools/startup/gfx2hlsl.py (lower, the ds_read2_b32 branch, self.emit('a = %s;' % address)): the address snapshot is guarded only by the WARP/hardware control g-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.
  • nit, 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058374208 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#pullrequestreview-6058374208). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:21:13Z. **Review:** COMMENTED --- Review of head `188494905278fbcd84fb2064ac14a10373908e0d` (comment only, no approval). **Summary:** `ds_read2_b32` lowering looks correct against the ISA. Offsets are dword-scaled (x4), each one is bounds-checked against the initialized span, and the address is snapshotted into `a` before 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`: pass - `git diff --check origin/main...HEAD`: clean - PR is mergeable, title and body are neutral. At review time the Linux CI job passed and the Windows jobs were still pending. I did not run the Windows WARP suite; the PR's WARP results are the author's. **Mutations (each reverted with `git checkout -- .`):** 1. Disable the "two distinct offsets" refusal: killed by the pure-Python test (`expected a refusal naming 'distinct offsets'`). 2. Drop the dword-to-byte scaling (`4 * int` -> `int`): killed (`LDS read outside the aligned, initialized span`). 3. Remove the `a = <address>` snapshot: **survived** the Linux test. **Findings:** - P1=0, P2=0 - nit, `tools/startup/gfx2hlsl.py` (`lower`, the `ds_read2_b32` branch, `self.emit('a = %s;' % address)`): the address snapshot is guarded only by the WARP/hardware control `g-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. - nit, `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.
RavenCurseBurg commented 2026-11-25 14:05:08 +00:00 (Migrated from github.com)

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:31 returns lanes base + 31, base, and offset1:31 returns 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163497897 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#issuecomment-7163497897). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T13:14:46Z. --- I added both omitted-field readbacks in 4ca6e411. With the fill starting at dword zero, `offset0:31` returns lanes `base + 31, base`, and `offset1:31` returns 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.
RavenCurseBurg commented 2026-11-25 14:05:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T13:20:12Z.


18849490 adds 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 earlier 4ca6e411 WARP run also passed all 12 selected tests, including both omitted-field 320-word readbacks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163629119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#issuecomment-7163629119). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T13:20:12Z. --- 18849490 adds 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 earlier 4ca6e411 WARP run also passed all 12 selected tests, including both omitted-field 320-word readbacks.
RavenCurseBurg commented 2026-11-25 14:05:10 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163958289 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2347#issuecomment-7163958289). Originally posted by [RavenCurseBurg](https://github.com/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.
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!2339
No description provided.