startup: lower a bounded LDS dword exchange across a group barrier #2319

Merged
RavenCurseBurg merged 5 commits from upstream-pr/2327 into main 2026-11-25 12:39:06 +00:00
RavenCurseBurg commented 2026-11-25 12:29:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T12:29:18Z.


First startup-compute LDS slice from the Part A claim.

The startup translator can now dispatch a straight-line exchange between workgroup lanes. Each thread in a 1D group fills one distinct LDS dword. A completed LGKM wait and an unconditional s_barrier publish the span. Subsequent ds_read_b32 instructions read a proven, aligned address in that span and wait for completion. The fill address is local X << 2. Each read uses an immediately preceding literal move or a literal mask that bounds its byte address. The translator checks instruction offsets and the allocation from COMPUTE_PGM_RSRC2, and retains named refusals for other shapes. This permits two 32-lane halves to communicate without assuming a guest wave width. AMD RDNA 2 DS instructions · LLVM AMDGPU register fields · HLSL group barrier.

Case F is a 116-byte LLVM 15 gfx1013 program. Two 64-thread groups write distinct values and read both the opposite half's lane and lane 37. The strict CPU oracle checks all 256 output words and 64 sentinels.

Adapter on Windows 26100.9711 Exact readback Read own lane Broadcast lane 36
WARP, 10.0.26100.9711 320/320 128 wrong 128 wrong
RTX 4060, 32.0.15.9579 320/320 128 wrong 128 wrong
Intel UHD 770, 32.0.101.5973 320/320 128 wrong 128 wrong

The real --pending path compiled the accepted request with DXC 1.9.2609.5. All three adapters dispatched that published bytecode. --refusals examined three requests; removing the barrier or declaring zero LDS produced the expected refusal and no manifest. Before this change the valid source was refused at ds_write_b32.

On the final head, all 63 host scripts passed. LLVM 15.0.7 reproduced the recorded bytes. The controls cover bounds, control flow, and the first and last legal allocation sizes. A host assertion checks barrier placement independently of GPU scheduling. After #2325 merged, the normal unfiltered dispatch entry passed all seven programs on each adapter, and its two LDS mutations reported the predicted first bad words on all three. The desktop D3D12 debug layer was unavailable.

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute_(controls|(f-peer_|f-broadcast_)?(warp|hardware))$' -V
python -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15

Refs #2274 and #1541.

The Windows debug-layer run at fff661e0 passed all 10 selected CTests with no skips. WARP matched 320/320 in case F, the two controls failed at words 0 and 1 as predicted, and the D3D12 debug layer reported zero warnings and errors.

Agent environment: Codex + GPT-6.2 Astra xhigh.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6604493451 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2327). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T12:29:18Z. --- First startup-compute LDS slice from [the Part A claim](https://github.com/R0Y00/Xbox2Windows/issues/2274#issuecomment-7162051740). The startup translator can now dispatch a straight-line exchange between workgroup lanes. Each thread in a 1D group fills one distinct LDS dword. A completed LGKM wait and an unconditional `s_barrier` publish the span. Subsequent `ds_read_b32` instructions read a proven, aligned address in that span and wait for completion. The fill address is `local X << 2`. Each read uses an immediately preceding literal move or a literal mask that bounds its byte address. The translator checks instruction offsets and the allocation from `COMPUTE_PGM_RSRC2`, and retains named refusals for other shapes. This permits two 32-lane halves to communicate without assuming a guest wave width. [AMD RDNA 2 DS instructions](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [LLVM AMDGPU register fields](https://releases.llvm.org/15.0.0/docs/AMDGPUUsage.html) · [HLSL group barrier](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync). Case F is a 116-byte LLVM 15 gfx1013 program. Two 64-thread groups write distinct values and read both the opposite half's lane and lane 37. The strict CPU oracle checks all 256 output words and 64 sentinels. | Adapter on Windows 26100.9711 | Exact readback | Read own lane | Broadcast lane 36 | | --- | --- | --- | --- | | WARP, 10.0.26100.9711 | 320/320 | 128 wrong | 128 wrong | | RTX 4060, 32.0.15.9579 | 320/320 | 128 wrong | 128 wrong | | Intel UHD 770, 32.0.101.5973 | 320/320 | 128 wrong | 128 wrong | The real `--pending` path compiled the accepted request with DXC 1.9.2609.5. All three adapters dispatched that published bytecode. `--refusals` examined three requests; removing the barrier or declaring zero LDS produced the expected refusal and no manifest. Before this change the valid source was refused at `ds_write_b32`. On the final head, all 63 host scripts passed. LLVM 15.0.7 reproduced the recorded bytes. The controls cover bounds, control flow, and the first and last legal allocation sizes. A host assertion checks barrier placement independently of GPU scheduling. After #2325 merged, the normal unfiltered dispatch entry passed all seven programs on each adapter, and its two LDS mutations reported the predicted first bad words on all three. The desktop D3D12 debug layer was unavailable. ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_compute_(controls|(f-peer_|f-broadcast_)?(warp|hardware))$' -V python -B tests/startup_gfx2hlsl_compute_check.py binary llvm-mc-15 ``` Refs #2274 and #1541. The [Windows debug-layer run at fff661e0](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45614205486) passed all 10 selected CTests with no skips. WARP matched 320/320 in case F, the two controls failed at words 0 and 1 as predicted, and the D3D12 debug layer reported zero warnings and errors. Agent environment: Codex + GPT-6.2 Astra xhigh.
upstream-sync closed this pull request 2026-11-25 13:00:49 +00:00
tedin7 commented 2026-11-25 13:00:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:31:51Z.

Review: COMMENTED


Review of head fff661e062e5716edf2e799e357a99b5c4964c9f (comment only, not an approval).

Scope: tools/startup/gfx2hlsl.py (check_lds_exchange, DS/barrier lowering, lds_words from RSRC2), CMakeLists.txt (two new controls), tests/startup_gfx2hlsl_compute_check.py (case F), docs/experiments.md.

Commands executed locally (Linux):

  • git diff --stat origin/main...HEAD -> 4 files, +199/-2
  • python3 -B tests/startup_gfx2hlsl_compute_check.py -> pass (includes the new check_lds() refusal matrix)
  • python3 tests/docs_links_check.py -> pass (18 files, 451 links)
  • python3 tests/bidi_controls_check.py -> pass
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: removed the high % 4 alignment guard on the masked read -> the suite fails (expected a refusal naming 'aligned'). Killed.
  • Mutation 2: removed the "completed LGKM wait before barrier" requirement -> the suite fails (expected a refusal naming 'completed fill'). Killed.
  • Both mutations reverted with git checkout -- ..

Logic read-through:

  • RSRC2 LDS size: bits 23:15 times 128 dwords matches the gfx10 granularity. The 0 and 65-unit cases are covered.
  • Fill proof: v_lshlrev_b32 vN, 2, v0 directly before a single ds_write_b32, with no earlier VALU that can write v0 (v_swap and 64-bit forms are refused). One write per lane and a bounded span look correct.
  • Read proof: a literal v_mov or a literal v_and mask directly before the read, an aligned span check, and a following lgkmcnt(0). I could not construct an accepted program that reads outside the span.
  • The refusal is computed once per program and replayed per instruction, which is consistent with the refusal census.

Findings: P1 = 0, P2 = 0.

  • nit: check_lds_exchange runs the scalar/VALU guard only before the first write. This is fine because later reads are address-proven from literals, but a short comment saying so would help the next opcode extension.
  • nit: s_barrier is matched by the exact text s_barrier 0x0. A different assembler spelling is refused, not mis-translated. That is safe, just narrow.

Not run: the Windows WARP readback (case F f-peer and f-broadcast controls). The PR body reports it, and CI Windows jobs were still pending at review time. I did not re-run it myself.

Checks / hygiene: title is neutral, the PR is not Draft, mergeable state was UNKNOWN (CI pending).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057640136 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2327#pullrequestreview-6057640136). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:31:51Z. **Review:** COMMENTED --- Review of head `fff661e062e5716edf2e799e357a99b5c4964c9f` (comment only, not an approval). **Scope:** `tools/startup/gfx2hlsl.py` (`check_lds_exchange`, DS/barrier lowering, `lds_words` from RSRC2), `CMakeLists.txt` (two new controls), `tests/startup_gfx2hlsl_compute_check.py` (case F), `docs/experiments.md`. **Commands executed locally (Linux):** - `git diff --stat origin/main...HEAD` -> 4 files, +199/-2 - `python3 -B tests/startup_gfx2hlsl_compute_check.py` -> pass (includes the new `check_lds()` refusal matrix) - `python3 tests/docs_links_check.py` -> pass (18 files, 451 links) - `python3 tests/bidi_controls_check.py` -> pass - `git diff --check origin/main...HEAD` -> clean - Mutation 1: removed the `high % 4` alignment guard on the masked read -> the suite fails (`expected a refusal naming 'aligned'`). Killed. - Mutation 2: removed the "completed LGKM wait before barrier" requirement -> the suite fails (`expected a refusal naming 'completed fill'`). Killed. - Both mutations reverted with `git checkout -- .`. **Logic read-through:** - RSRC2 LDS size: bits 23:15 times 128 dwords matches the gfx10 granularity. The 0 and 65-unit cases are covered. - Fill proof: `v_lshlrev_b32 vN, 2, v0` directly before a single `ds_write_b32`, with no earlier VALU that can write v0 (v_swap and 64-bit forms are refused). One write per lane and a bounded span look correct. - Read proof: a literal `v_mov` or a literal `v_and` mask directly before the read, an aligned span check, and a following `lgkmcnt(0)`. I could not construct an accepted program that reads outside the span. - The refusal is computed once per program and replayed per instruction, which is consistent with the refusal census. **Findings:** P1 = 0, P2 = 0. - nit: `check_lds_exchange` runs the scalar/VALU guard only before the first write. This is fine because later reads are address-proven from literals, but a short comment saying so would help the next opcode extension. - nit: `s_barrier` is matched by the exact text `s_barrier 0x0`. A different assembler spelling is refused, not mis-translated. That is safe, just narrow. **Not run:** the Windows WARP readback (case F `f-peer` and `f-broadcast` controls). The PR body reports it, and CI Windows jobs were still pending at review time. I did not re-run it myself. **Checks / hygiene:** title is neutral, the PR is not Draft, mergeable state was UNKNOWN (CI pending). AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 13:00:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T12:36:17Z.


Addressed the two notes in a0122ece. The prefix comment explains why later reads no longer depend on the entry X ID. The barrier now checks its parsed operand and accepts zero or an omitted immediate; a source-word control checks rejection of a nonzero reserved immediate. The host refusal matrix and the real offline request plus WARP/RTX/UHD readbacks passed again. The original Windows WARP debug-layer run passed 10/10, and the new run pins this reviewed head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162603113 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2327#issuecomment-7162603113). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T12:36:17Z. --- Addressed the two notes in a0122ece. The prefix comment explains why later reads no longer depend on the entry X ID. The barrier now checks its parsed operand and accepts zero or an omitted immediate; a source-word control checks rejection of a nonzero reserved immediate. The host refusal matrix and the real offline request plus WARP/RTX/UHD readbacks passed again. The [original Windows WARP debug-layer run](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45614205486) passed 10/10, and the [new run](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45615218980) pins this reviewed head.
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!2319
No description provided.