rdna2spirv: accept vcc (s[106:107]) as 64-bit base pointer in s_load_dword* (SHADER-SLOAD-VCC-BASE) #647

Manually merged
github merged 1 commit from gh-pr/647/head into gh-pr/647/base 2026-11-26 09:13:44 +00:00
Owner

@⁠TanmaySatyam on GitHub · 2026-11-24 10:52 UTC · original
TanmaySatyam:feat/sload-vcc-base → main · +175 −1 · 3 files · 1 commits · merged 2026-11-24 15:50 UTC

Claimed in the coordination issue as: SHADER-SLOAD-VCC-BASE

AI-assisted.

What and why

In RDNA2 SMEM s_load_dword*, SBASE encodes a 2-SGPR-aligned 64-bit pointer (sbase * 2). When VCC is dead, the compiler allocates sbase = 53 (s[106:107] = vcc, i.e. {vcc_lo, vcc_hi}), emitting instructions such as s_load_dwordx4 s[12:15], vcc, 0x0.

Gen.scalar_load in tools/rdna2spirv.py previously accepted only sgpr and slist base operands, raising Unsupported: s_load_dwordx4 operands sgpr vcc (and s_load_dwordx8 operands sgpr vcc, s_load_dwordx4 operands slist vcc) on 79 pipeline-library compute shaders.

  • Accepts base["k"] == "special" and base["t"] == "vcc" as ["vcc_lo", "vcc_hi"] in Gen.scalar_load (load_slot already loads %vcc / %vcc_hi).
  • s_buffer_load* still requires a 4-dword V# (len(base_slots) != 4) and continues to reject 2-dword vcc.
  • Independent of #596 (OLD-10062, which recovers SGPR > 105 tuple encodings): together with #596 / high-SGPR tuple decoding, this brings the 2,684-shader pipeline library compute corpus to 2,684 / 2,684 (100.0%) translated and spirv-val-valid under --wave64-emulate.

Testing & Verification

  • python -m unittest discover -s tests/semantic -p test_sload_vcc_base.py -v (3/3 OK, including spirv-as + spirv-val validation)
  • python -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py (44/44 OK)
  • python -I tests/test_text_write_line_endings.py (3/3 OK)
  • Corpus check (--wave64-emulate + spirv-val): all 79 / 79 previously failing vcc-base library compute shaders (72 s_load_dwordx4 sgpr, vcc, 6 s_load_dwordx8 sgpr, vcc, 1 s_load_dwordx4 slist, vcc) now translate and pass spirv-val (bringing library CS from 2,605 → 2,684 / 2,684).
  • Clean-room verified: python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_sload_vcc_base.py docs/design.md exited 0.
**@⁠TanmaySatyam** on GitHub · 2026-11-24 10:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647) `TanmaySatyam:feat/sload-vcc-base` → `main` · +175 −1 · 3 files · 1 commits · merged 2026-11-24 15:50 UTC Claimed in the coordination issue as: SHADER-SLOAD-VCC-BASE AI-assisted. ### What and why In RDNA2 SMEM `s_load_dword*`, `SBASE` encodes a 2-SGPR-aligned 64-bit pointer (`sbase * 2`). When `VCC` is dead, the compiler allocates `sbase = 53` (`s[106:107]` = `vcc`, i.e. `{vcc_lo, vcc_hi}`), emitting instructions such as `s_load_dwordx4 s[12:15], vcc, 0x0`. `Gen.scalar_load` in `tools/rdna2spirv.py` previously accepted only `sgpr` and `slist` base operands, raising `Unsupported: s_load_dwordx4 operands sgpr vcc` (and `s_load_dwordx8 operands sgpr vcc`, `s_load_dwordx4 operands slist vcc`) on 79 pipeline-library compute shaders. - Accepts `base["k"] == "special" and base["t"] == "vcc"` as `["vcc_lo", "vcc_hi"]` in `Gen.scalar_load` (`load_slot` already loads `%vcc` / `%vcc_hi`). - `s_buffer_load*` still requires a 4-dword V# (`len(base_slots) != 4`) and continues to reject 2-dword `vcc`. - Independent of #596 (`OLD-10062`, which recovers `SGPR > 105` tuple encodings): together with #596 / high-SGPR tuple decoding, this brings the 2,684-shader pipeline library compute corpus to **2,684 / 2,684 (100.0%)** translated and `spirv-val`-valid under `--wave64-emulate`. ### Testing & Verification - `python -m unittest discover -s tests/semantic -p test_sload_vcc_base.py -v` (3/3 OK, including `spirv-as` + `spirv-val` validation) - `python -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py` (44/44 OK) - `python -I tests/test_text_write_line_endings.py` (3/3 OK) - Corpus check (`--wave64-emulate` + `spirv-val`): all **79 / 79** previously failing `vcc`-base library compute shaders (72 `s_load_dwordx4 sgpr, vcc`, 6 `s_load_dwordx8 sgpr, vcc`, 1 `s_load_dwordx4 slist, vcc`) now translate and pass `spirv-val` (bringing library CS from 2,605 → 2,684 / 2,684). - Clean-room verified: `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_sload_vcc_base.py docs/design.md` exited 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:43 +00:00
github manually merged commit a4c00f4f4d into gh-pr/647/base 2026-11-26 09:13:44 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-24 11:25 UTC · original

Checked 70a5945c on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main d42773d07:

  • tests/semantic/test_sload_vcc_base.py: 3 tests OK at this head; against main's translator it fails (1 failure, 7 errors), the first being AssertionError: 's_buffer_load without V#' not found in 's_buffer_load_dword operands sgpr vcc', so the test does exercise the new path.
  • GPU: cs_smem_sload_neg still passes (1/1) on MoltenVK 1.4.2 with binaries from main. I cannot claim that fixture reaches the vcc-as-base path; it is a regression check only.

llvm-mc 23.1.6. Synthetic fixtures only, no game data. AI-assisted.

**@⁠GeorgiyDemo** on GitHub · 2026-11-24 11:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647#issuecomment-7130073007) Checked `70a5945c` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `d42773d07`: - `tests/semantic/test_sload_vcc_base.py`: 3 tests OK at this head; against `main`'s translator it fails (1 failure, 7 errors), the first being `AssertionError: 's_buffer_load without V#' not found in 's_buffer_load_dword operands sgpr vcc'`, so the test does exercise the new path. - GPU: `cs_smem_sload_neg` still passes (1/1) on MoltenVK 1.4.2 with binaries from `main`. I cannot claim that fixture reaches the vcc-as-base path; it is a regression check only. llvm-mc 23.1.6. Synthetic fixtures only, no game data. AI-assisted.
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-24 11:42 UTC · original · reviewed

Reviewed on head 70a5945c1 (Linux, no GPU: CPU interpreter and unit tests only).

Checked:

  • The change maps vcc to the slots ["vcc_lo", "vcc_hi"], which load_slot already reads as %vcc / %vcc_hi. Both base halves are loaded before any destination store, so [s104,s105,vcc_lo,vcc_hi], vcc reads the old pointer. s_buffer_load with vcc is still refused.
  • Pass: test_sload_vcc_base.py (3), test_scalar_mem_smem.py.
  • Two hand-written mutations of the new line, run against test_sload_vcc_base.py: reading vcc_lo for both halves is caught (6 failures), but swapping the halves (["vcc_hi", "vcc_lo"]) survives. The tests check that OpLoad %uint %vcc and %vcc_hi appear and that the module validates, not which half becomes the low address word.

spirv_mini_interp already runs PhysicalStorageBuffer loads (memory={address: word}), so a value check is short. On this head:

s_mov_b32 vcc_hi, 0x0
s_mov_b32 vcc_lo, 0x2000
s_load_dword s10, vcc, 0x4
s_waitcnt lgkmcnt(0)
v_mov_b32 v4, s10
exp mrt0 v4, v4, v4, v4 done vm
s_endpgm

with support.mrt0_words(spv, memory={0x2004: 0xCAFEBABE}) gives 0xCAFEBABE; with the halves swapped the load goes to 0x200000000004 instead. A case like that (and one for the aliasing form, where the loaded words land in vcc) would pin the address, not just the opcodes.

Looks correct otherwise.

**@⁠qhukz13** on GitHub · 2026-11-24 11:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647#pullrequestreview-6038567895) · **reviewed** Reviewed on head 70a5945c1 (Linux, no GPU: CPU interpreter and unit tests only). Checked: - The change maps `vcc` to the slots `["vcc_lo", "vcc_hi"]`, which `load_slot` already reads as `%vcc` / `%vcc_hi`. Both base halves are loaded before any destination store, so `[s104,s105,vcc_lo,vcc_hi], vcc` reads the old pointer. `s_buffer_load` with `vcc` is still refused. - Pass: `test_sload_vcc_base.py` (3), `test_scalar_mem_smem.py`. - Two hand-written mutations of the new line, run against `test_sload_vcc_base.py`: reading `vcc_lo` for both halves is caught (6 failures), but **swapping the halves (`["vcc_hi", "vcc_lo"]`) survives**. The tests check that `OpLoad %uint %vcc` and `%vcc_hi` appear and that the module validates, not which half becomes the low address word. `spirv_mini_interp` already runs PhysicalStorageBuffer loads (`memory={address: word}`), so a value check is short. On this head: s_mov_b32 vcc_hi, 0x0 s_mov_b32 vcc_lo, 0x2000 s_load_dword s10, vcc, 0x4 s_waitcnt lgkmcnt(0) v_mov_b32 v4, s10 exp mrt0 v4, v4, v4, v4 done vm s_endpgm with `support.mrt0_words(spv, memory={0x2004: 0xCAFEBABE})` gives 0xCAFEBABE; with the halves swapped the load goes to 0x200000000004 instead. A case like that (and one for the aliasing form, where the loaded words land in vcc) would pin the address, not just the opcodes. Looks correct otherwise.
Author
Owner

@⁠Poussistar on GitHub · 2026-11-24 13:48 UTC · original

Independent check: the patch is correct, but the branch no longer merges cleanly.

Applied to a clean worktree at main 2d73c242f, git apply --check fails on docs/design.md:275 (the hunk's context has moved), so the pull request is STALE as it stands.

At your own head 70a5945c (detached worktree, Linux, CPython 3.14.7, synthetic fixtures, no game files):

python -I -m unittest discover -s tests/semantic -p 'test_sload_vcc_base.py'   3 tests OK
python -I tests/test_docs_links.py                                             16 tests OK
python -I tests/test_docs_cli_flags.py                                          4 tests OK

So only a rebase onto current main is needed — nothing in the translator change or the new test needs to change. This is a second, independent data point next to the macOS check above.

**@⁠Poussistar** on GitHub · 2026-11-24 13:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647#issuecomment-7133370883) Independent check: the patch is correct, but the branch no longer merges cleanly. Applied to a clean worktree at `main` `2d73c242f`, `git apply --check` fails on `docs/design.md:275` (the hunk's context has moved), so the pull request is `STALE` as it stands. At your own head `70a5945c` (detached worktree, Linux, CPython 3.14.7, synthetic fixtures, no game files): ``` python -I -m unittest discover -s tests/semantic -p 'test_sload_vcc_base.py' 3 tests OK python -I tests/test_docs_links.py 16 tests OK python -I tests/test_docs_cli_flags.py 4 tests OK ``` So only a rebase onto current `main` is needed — nothing in the translator change or the new test needs to change. This is a second, independent data point next to the macOS check above.
Author
Owner

@⁠TanmaySatyam on GitHub · 2026-11-24 14:29 UTC · original

Rebased onto current \main\ (\d0da7dade, resolving the \docs/design.md\ hunk context drift noted by @⁠Poussistar) and added two \spirv_mini_interp\ value-execution tests per @⁠qhukz13's review:

  • \ est_vcc_base_pointer_half_order_executes: sets non-zero \ cc_hi = 0x3, \ cc_lo = 0x2000, runs \s_load_dword s10, vcc, 0x4, and asserts \mrt0_words\ reads \
**@⁠TanmaySatyam** on GitHub · 2026-11-24 14:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647#issuecomment-7134456771) Rebased onto current \main\ (\d0da7dade\, resolving the \docs/design.md\ hunk context drift noted by @⁠Poussistar) and added two \spirv_mini_interp\ value-execution tests per @⁠qhukz13's review: - \ est_vcc_base_pointer_half_order_executes\: sets non-zero \ cc_hi = 0x3\, \ cc_lo = 0x2000\, runs \s_load_dword s10, vcc, 0x4\, and asserts \mrt0_words\ reads \
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-24 14:54 UTC · original

Thanks — confirmed on a4c00f4f4: test_sload_vcc_base.py passes, and the half-swap mutation (["vcc_hi", "vcc_lo"]) that survived before now fails it (2 failures), as does reading vcc_lo for both halves (8). The address is pinned now.

**@⁠qhukz13** on GitHub · 2026-11-24 14:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/647#issuecomment-7135132597) Thanks — confirmed on a4c00f4f4: `test_sload_vcc_base.py` passes, and the half-swap mutation (`["vcc_hi", "vcc_lo"]`) that survived before now fails it (2 failures), as does reading `vcc_lo` for both halves (8). The address is pinned now.
This discussion has been locked. Commenting is limited to contributors.
No description provided.