shader: lower bounded 64-bit LDS exchange across group barrier in gfx2hlsl #2337

Merged
Vladimir-Human merged 1 commit from upstream-pr/2345 into main 2026-11-25 14:09:01 +00:00
Vladimir-Human commented 2026-11-25 13:05:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T13:05:22Z.


Refs #2274, #1541.

Summary

Extend check_lds_exchange and Stage.lower in tools/startup/gfx2hlsl.py (building on #2327) to support bounded 64-bit group-shared LDS exchanges (ds_write_b64 and ds_read_b64) across s_barrier in 1D compute groups:

  • ds_write_b64 addr, v[d0:d1] [offset:k] (RDNA 2 DS opcode 0x4d): requires straight-line full entry EXEC, unchanged v0, a single VGPR address from v_lshlrev_b32 addr, 3, v0, a contiguous 2-VGPR data pair v[d0:d1] in v0..v255, 4-byte aligned offset, and offset + group[0] * 8 <= lds_words * 4 (COMPUTE_PGM_RSRC2.GRANULATED_LDS_SIZE in 128-dword / 512-byte units per LLVM 15 AMDGPUUsage).
  • ds_read_b64 v[r0:r1], addr [offset:k] (RDNA 2 DS opcode 0x76): requires matching 64-bit fill width (mixed b32/b64 exchanges stay refused), completed s_waitcnt lgkmcnt(0) before s_barrier and after each read, an exact v[r0:r1] pair, and a literal (v_mov_b32) or literal-masked (v_and_b32) byte address proving [a + offset, a + offset + 8) stays 4-byte aligned inside [first, first + group[0] * 8).
  • Aliasing & endianness: evaluates a = (address + offset) >> 2 before updating destination registers so overlapping destinations such as ds_read_b64 v[8:9], v8 offset:16 preserve the address while reading little-endian lds[a] / lds[a + 1u].
  • Adds tests/startup_compute_lds_b64_check.py (offline bounds/width/pair/mask/alignment/refusal checks, HLSL parity, llvm-mc binary verification target, Case P peer swap across wave halves + v[8:9], v8 aliasing, Case B tight 512-byte LDS_SIZE=1 allocation + lane-37 broadcast offset:296, and five mutated negative controls) wired into CMakeLists.txt, .github/workflows/windows.yml, and docs/experiments.md.

Verification

  • Adapter 1 (WARP): Microsoft Basic Render Driver (vendor=1414 device=008c, driver 10.0.26100.9818, Windows 11 10.0.26300 build 26300, debug_layer=enabled): Cases P (groups=2x1x1) and B (groups=1x1x1) matched 320/320 words (mismatches=0, debug_errors=0 debug_warnings=0); controls rejected cleanly (p-same-lane: word=0 256 mismatches; p-swap-dwords: word=0 256 mismatches; p-drop-high: word=1 128 mismatches; b-wrong-mask: word=0 64 mismatches; b-wrong-lane: word=2 128 mismatches).
  • Adapter 2 (hardware): NVIDIA GeForce RTX 4070 SUPER (vendor=10de device=2783, driver 32.0.16.2114, Windows 11 10.0.26300 build 26300, debug_layer=enabled): Cases P and B matched 320/320 words (mismatches=0, debug_errors=0 debug_warnings=0); all 5 controls rejected cleanly with matching mismatch counts and zero debug errors/warnings.
  • Commands run:
    • cmake --preset release; cmake --build --preset release --target offscreen_check
    • ctest --preset release --no-tests=error -j 1 -R "^startup_(compute_lds_b64|gfx2hlsl_compute)" -V -> 30/30 passed (0 failed, 0 skipped)
    • Non-GPU startup_* regression subset -> 84/84 passed (0 failed, 0 skipped)
    • Direct checks: tests/startup_compute_lds_b64_check.py, tests/startup_gfx2hlsl_*_check.py, tests/startup_translator_check.py, tests/startup_tools_lint_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py (all 0 failed), tests/rdna2_tools_check.py (156 ran, 19 skipped, 0 failed)
  • Not tested locally: tests/startup_compute_lds_b64_check.py binary llvm-mc-15 (llvm-mc-15 is not installed on Windows; covered in .github/workflows/windows.yml Linux check and cross-checked locally with tools/disasm_rdna2.py).

AI-assisted implementation and verification.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6605143551 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2345). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T13:05:22Z. --- Refs #2274, #1541. ## Summary Extend `check_lds_exchange` and `Stage.lower` in `tools/startup/gfx2hlsl.py` (building on #2327) to support bounded 64-bit group-shared LDS exchanges (`ds_write_b64` and `ds_read_b64`) across `s_barrier` in 1D compute groups: - **`ds_write_b64 addr, v[d0:d1] [offset:k]`** (RDNA 2 DS opcode `0x4d`): requires straight-line full entry `EXEC`, unchanged `v0`, a single VGPR address from `v_lshlrev_b32 addr, 3, v0`, a contiguous 2-VGPR data pair `v[d0:d1]` in `v0..v255`, 4-byte aligned `offset`, and `offset + group[0] * 8 <= lds_words * 4` (`COMPUTE_PGM_RSRC2.GRANULATED_LDS_SIZE` in 128-dword / 512-byte units per LLVM 15 `AMDGPUUsage`). - **`ds_read_b64 v[r0:r1], addr [offset:k]`** (RDNA 2 DS opcode `0x76`): requires matching 64-bit fill width (mixed `b32`/`b64` exchanges stay refused), completed `s_waitcnt lgkmcnt(0)` before `s_barrier` and after each read, an exact `v[r0:r1]` pair, and a literal (`v_mov_b32`) or literal-masked (`v_and_b32`) byte address proving `[a + offset, a + offset + 8)` stays 4-byte aligned inside `[first, first + group[0] * 8)`. - **Aliasing & endianness**: evaluates `a = (address + offset) >> 2` before updating destination registers so overlapping destinations such as `ds_read_b64 v[8:9], v8 offset:16` preserve the address while reading little-endian `lds[a]` / `lds[a + 1u]`. - Adds `tests/startup_compute_lds_b64_check.py` (offline bounds/width/pair/mask/alignment/refusal checks, HLSL parity, `llvm-mc` binary verification target, Case `P` peer swap across wave halves + `v[8:9], v8` aliasing, Case `B` tight 512-byte `LDS_SIZE=1` allocation + lane-37 broadcast `offset:296`, and five mutated negative controls) wired into `CMakeLists.txt`, `.github/workflows/windows.yml`, and `docs/experiments.md`. ## Verification - Adapter 1 (WARP): `Microsoft Basic Render Driver` (`vendor=1414 device=008c`, driver `10.0.26100.9818`, Windows 11 `10.0.26300` build `26300`, `debug_layer=enabled`): Cases `P` (`groups=2x1x1`) and `B` (`groups=1x1x1`) matched `320/320` words (`mismatches=0`, `debug_errors=0 debug_warnings=0`); controls rejected cleanly (`p-same-lane`: `word=0` 256 mismatches; `p-swap-dwords`: `word=0` 256 mismatches; `p-drop-high`: `word=1` 128 mismatches; `b-wrong-mask`: `word=0` 64 mismatches; `b-wrong-lane`: `word=2` 128 mismatches). - Adapter 2 (hardware): `NVIDIA GeForce RTX 4070 SUPER` (`vendor=10de device=2783`, driver `32.0.16.2114`, Windows 11 `10.0.26300` build `26300`, `debug_layer=enabled`): Cases `P` and `B` matched `320/320` words (`mismatches=0`, `debug_errors=0 debug_warnings=0`); all 5 controls rejected cleanly with matching mismatch counts and zero debug errors/warnings. - Commands run: - `cmake --preset release; cmake --build --preset release --target offscreen_check` - `ctest --preset release --no-tests=error -j 1 -R "^startup_(compute_lds_b64|gfx2hlsl_compute)" -V` -> **30/30 passed** (0 failed, 0 skipped) - Non-GPU `startup_*` regression subset -> **84/84 passed** (0 failed, 0 skipped) - Direct checks: `tests/startup_compute_lds_b64_check.py`, `tests/startup_gfx2hlsl_*_check.py`, `tests/startup_translator_check.py`, `tests/startup_tools_lint_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` (all 0 failed), `tests/rdna2_tools_check.py` (156 ran, 19 skipped, 0 failed) - Not tested locally: `tests/startup_compute_lds_b64_check.py binary llvm-mc-15` (`llvm-mc-15` is not installed on Windows; covered in `.github/workflows/windows.yml` Linux check and cross-checked locally with `tools/disasm_rdna2.py`). AI-assisted implementation and verification.
tedin7 commented 2026-11-25 14:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:11:42Z.

Review: COMMENTED


Review of head 8dd26f26df807bd4744a9d7c1c58580c98f2a7cb (comment only, no approval).

Scope read: tools/startup/gfx2hlsl.py (check_lds_exchange, Stage.lower b64 path), tests/startup_compute_lds_b64_check.py, CTest and workflow wiring.

Commands executed locally (worktree at the head SHA):

  • git diff --stat origin/main...HEAD: 5 files, +452/-14
  • python3 tests/startup_compute_lds_b64_check.py: pass ("sizing, pair validation, aligned masks, bounds and refusals pass")
  • python3 tests/docs_links_check.py: pass (19 files, 454 links)
  • python3 tests/bidi_controls_check.py: pass (1628 files)
  • git diff --check origin/main...HEAD: clean
  • gh pr checks: Linux checks, gfx1013 fixtures, and Windows build/test all pass. The /O2 job was skipped.

Mutations of the new logic (each reverted with git checkout -- .):

  1. Write shift 3 changed to 2: refused with "needs one bounded qword per local X ID". Killed.
  2. Read upper bound (width - 4) term removed: the test fails with "accepted, expected a refusal naming 'initialized span'". Killed.
  3. High dword lowering lds[a + 1u] changed to lds[a]: the exact-HLSL assertion fails. Killed.

Findings:

  • P1: none.
  • P2: none.
  • nit: Stage.lower now raises Unsupported('LDS exchange needs pipeline metadata') when pipe is None. That is a sound guard, but no test covers it. A one-line refusal test would pin it.
  • nit: the b64 write only requires offset % 4 == 0. That is correct for LDS dword access and the span bound covers it. A short comment saying "8-byte alignment is not required" would help future readers.
  • Semantics: the high-dword bound high + offset + 4 < first + group*8, the 4-byte-aligned mask and literal checks, the mixed b32/b64 refusal, and evaluating a before the destination write (no aliasing with the address VGPR) all look correct against the RDNA 2 DS description.

Windows proof: I did not run x2w_pipe.py win2025. The PR's CI Windows job passed and the new CTest WARP and hardware dispatch and control tests are wired. The Win2025 WARP gate is left to the normal Stage-2 step.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058232823 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2345#pullrequestreview-6058232823). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:11:42Z. **Review:** COMMENTED --- Review of head `8dd26f26df807bd4744a9d7c1c58580c98f2a7cb` (comment only, no approval). **Scope read:** `tools/startup/gfx2hlsl.py` (`check_lds_exchange`, `Stage.lower` b64 path), `tests/startup_compute_lds_b64_check.py`, CTest and workflow wiring. **Commands executed locally (worktree at the head SHA):** - `git diff --stat origin/main...HEAD`: 5 files, +452/-14 - `python3 tests/startup_compute_lds_b64_check.py`: pass ("sizing, pair validation, aligned masks, bounds and refusals pass") - `python3 tests/docs_links_check.py`: pass (19 files, 454 links) - `python3 tests/bidi_controls_check.py`: pass (1628 files) - `git diff --check origin/main...HEAD`: clean - `gh pr checks`: Linux checks, gfx1013 fixtures, and Windows build/test all pass. The /O2 job was skipped. **Mutations of the new logic (each reverted with `git checkout -- .`):** 1. Write shift `3` changed to `2`: refused with "needs one bounded qword per local X ID". Killed. 2. Read upper bound `(width - 4)` term removed: the test fails with "accepted, expected a refusal naming 'initialized span'". Killed. 3. High dword lowering `lds[a + 1u]` changed to `lds[a]`: the exact-HLSL assertion fails. Killed. **Findings:** - P1: none. - P2: none. - nit: `Stage.lower` now raises `Unsupported('LDS exchange needs pipeline metadata')` when `pipe` is None. That is a sound guard, but no test covers it. A one-line refusal test would pin it. - nit: the b64 write only requires `offset % 4 == 0`. That is correct for LDS dword access and the span bound covers it. A short comment saying "8-byte alignment is not required" would help future readers. - Semantics: the high-dword bound `high + offset + 4 < first + group*8`, the 4-byte-aligned mask and literal checks, the mixed b32/b64 refusal, and evaluating `a` before the destination write (no aliasing with the address VGPR) all look correct against the RDNA 2 DS description. **Windows proof:** I did not run `x2w_pipe.py win2025`. The PR's CI Windows job passed and the new CTest WARP and hardware dispatch and control tests are wired. The Win2025 WARP gate is left to the normal Stage-2 step. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 14:05:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:34:19Z.


@Vladimir-Human could you rebase this branch onto current main and force-push?

GitHub reports head 8dd26f26 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (43608f2e):

  • tools/startup/gfx2hlsl.py

Commands run locally:

git fetch origin main pull/2345/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 2345 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163970815 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2345#issuecomment-7163970815). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:34:19Z. --- @Vladimir-Human could you rebase this branch onto current `main` and force-push? GitHub reports head `8dd26f26` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`43608f2e`): - `tools/startup/gfx2hlsl.py` Commands run locally: ``` git fetch origin main pull/2345/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 2345 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 14:05:11 +00:00 (Migrated from github.com)

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


Since #2347 landed, GitHub reports a conflict in the shared LDS validator. I tried the combination against main at ec519d0c and this PR at 8dd26f26. A tested merge commit is available if it helps resolve the conflict.

The combined validator checks the two independent ds_read2_b32 offsets against the dword fill, and checks both ends of the contiguous ds_read_b64 against the qword fill. Both host suites passed. On WARP and RTX 4060, both dispatch suites passed, including the omitted paired offset cases, and both paired-read plus all five b64 mutation controls failed readback as expected. Example first mismatches on the RTX: address overlap at word 1 (00000000 / 00000004), wrong b64 mask at word 0 (00000020 / 00000000) and wrong lane at word 2 (00000025 / 00000024). Windows 11 build 26100.9711, NVIDIA 32.0.15.9579, local debug layer unavailable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164112305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2345#issuecomment-7164112305). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T13:40:04Z. --- Since #2347 landed, GitHub reports a conflict in the shared LDS validator. I tried the combination against main at ec519d0c and this PR at 8dd26f26. A [tested merge commit](https://github.com/RavenCurseBurg/Xbox2Windows/commit/a43a996e79cb1ba06d7e0f9842143dc24aa36fff) is available if it helps resolve the conflict. The combined validator checks the two independent `ds_read2_b32` offsets against the dword fill, and checks both ends of the contiguous `ds_read_b64` against the qword fill. Both host suites passed. On WARP and RTX 4060, both dispatch suites passed, including the omitted paired offset cases, and both paired-read plus all five b64 mutation controls failed readback as expected. Example first mismatches on the RTX: address overlap at word 1 (`00000000` / `00000004`), wrong b64 mask at word 0 (`00000020` / `00000000`) and wrong lane at word 2 (`00000025` / `00000024`). Windows 11 build 26100.9711, NVIDIA 32.0.15.9579, local debug layer unavailable.
Vladimir-Human commented 2026-11-25 14:05:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T14:02:09Z.


Rebased onto \main\ (\ 489f934, commit \b6bfbc9) to resolve the conflict with #2347\ (\ds_read2_b32), keeping mixed \32/\64/\ds_read2_b32-over-\64\ exchanges refused, and addressed both nits from @tedin7\ (added a refusal test for \pipe is None\ and a comment explaining why 4-byte alignment suffices for \64\ dword-addressed LDS writes). Re-verified \34/34\ \startup_(compute_lds_b64|gfx2hlsl_compute)\ CTests on WARP and RTX 4070 SUPER plus \9/9\ pure-Python checks; thanks @tedin7\ and @RavenCurseBurg!

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164658062 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2345#issuecomment-7164658062). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T14:02:09Z. --- Rebased onto \main\ (\ 489f934\, commit \b6bfbc9\) to resolve the conflict with \#2347\ (\ds_read2_b32\), keeping mixed \32\/\64\/\ds_read2_b32\-over-\64\ exchanges refused, and addressed both nits from \@tedin7\ (added a refusal test for \pipe is None\ and a comment explaining why 4-byte alignment suffices for \64\ dword-addressed LDS writes). Re-verified \34/34\ \startup_(compute_lds_b64|gfx2hlsl_compute)\ CTests on WARP and RTX 4070 SUPER plus \9/9\ pure-Python checks; thanks \@tedin7\ and \@RavenCurseBurg\! AI-assisted.
upstream-sync closed this pull request 2026-11-25 15:01:37 +00:00
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!2337
No description provided.