Skip to content

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

Merged
ubiquitarianism merged 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:feat/sload-vcc-base
Nov 24, 2026
Merged

ubiquitarianism merged 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:feat/sload-vcc-base

Conversation

@TanmaySatyam

Copy link
Copy Markdown
Contributor

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.

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.

@GeorgiyDemo

Copy link
Copy Markdown
Contributor

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.

@qhukz13 qhukz13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on head 70a5945 (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.

@Poussistar

Copy link
Copy Markdown
Contributor

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.

@TanmaySatyam

Copy link
Copy Markdown
Contributor Author

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 \

@qhukz13

qhukz13 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks — confirmed on a4c00f4: 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants