Skip to content

rdna2spirv: GFX10.1 scalar stores (s_store_dword*, s_buffer_store_dword*) - #3589

Open
Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:claude/s-store
Open

Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:claude/s-store

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-SMEM-STORE, #3381 (comment)

What and why

s_store_dword, s_store_dwordx2, s_store_dwordx4 and s_buffer_store_dword, _x2, _x4 raised Unsupported. These scalar stores exist on GFX10.1 only (gfx1010-gfx1013, so the console's gfx1013 has them). llvm-mc rejects them for gfx1030 and gfx1036.

Change (tools/rdna2spirv.py, Gen.scalar_load(..., store=True)): SDATA's N dwords are written as PhysicalStorageBuffer OpStores at the address an s_load / s_buffer_load of the same operands reads. The address and offset rules are the measured ones from the Scalar/buffer memory row:

  • the base is a 64-bit pointer or a V#;
  • the offset is an immediate, an SGPR, or sOFF offset:IMM;
  • the low two bits are dropped.

Other details:

  • An s_buffer_store dword whose end passes the V# limit is not written.
  • SDATA is read before anything is written.
  • Every invocation of the wave writes the same words. A lane-mask source (one bit per invocation in the translator's model) is refused.
  • On hardware the write goes through the scalar data cache and becomes visible to other readers after s_dcache_wb. That instruction becomes a device memory barrier in rdna2spirv: cache invalidate/write-back ops are a device memory barrier (EGEN-MEM-CACHE-INV) #2878. The direct store here is visible at least as early.
  • Scalar atomics (s_atomic_*, s_buffer_atomic_*) stay Unsupported. If every invocation ran them, they would apply once per lane, so they need a one-writer-per-wave design of their own.

tests/semantic/test_scalar_mem_store.py asserted the old Unsupported. That contract test now checks that the store form emits one store per dword. New contract row in docs/design.md.

Not measured natively. The gfx1036 oracle has no scalar stores. The address and bound reuse the measured load rules, assumed shared. An RDNA1 part (gfx1010-gfx1013) can check them natively, for example the V540 farm announced in the coordination issue.

Tested

Windows 11, LLVM llvm-mc (-mcpu=gfx1013), VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time, python -I scripts/run_gpu_tests.py --filter cs_w32_scalar_store. The vk_compute_test device lines read AMD Radeon(TM) Graphics (subgroup 32..64) and NVIDIA GeForce RTX 5080 (subgroup 32..32).

GPU Driver Result
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D 26.10.1 PASS 0x11111111 .. 0x88888888 (8 words)
NVIDIA GeForce RTX 5080 616.92 PASS, same words
  • New fixture runtime/test/shaders/cs_w32_scalar_store.asm: both forms, with immediate, run-time SGPR and SGPR + immediate offsets. The words are derived in its header. It is registered in check.py, run_gpu_tests.py and regen_fixtures.py.
  • New semantic test ScalarStores in test_value_semantics.py checks the words against a plain-Python reference. It also checks the s_buffer_store bound (an x4 at 0x38 with NUM_RECORDS 0x40 writes two dwords) and the lane-mask refusal.
  • Before the fix: ScalarStores errors on main (Unsupported: s_buffer_store_dwordx4).
  • Negative control: I stored dword 0 for every dword of the unbounded path. ScalarStores fails, and the Radeon run fails (... 1431655765 1431655765 ...). Then I reverted it.
  • Passing: python -m unittest discover -s tests/semantic, python tests/semantic/regen_fixtures.py --check (clean), python -I tests/test_shader_checks.py, and pytest tests/test_docs_design_rows.py tests/test_run_gpu_tests.py tests/test_shader_meta.py.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

…rd*)

s_store_dword/x2/x4 and s_buffer_store_dword/x2/x4 exist on gfx1010-gfx1013
(the console) only. They now write SDATA as PhysicalStorageBuffer stores at
the address an s_load / s_buffer_load of the same operands reads, with the
buffer bound; a lane-mask source is refused. Scalar atomics stay
Unsupported. Not measurable on the gfx1036 oracle. GPU fixture
cs_w32_scalar_store, semantic test ScalarStores, design.md row; the old
contract test that expected Unsupported now checks the emitted stores.

AI-assisted.
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 13ce90b on NVIDIA GeForce RTX 4090 (Ada, subgroup 32..32), 621.14, Windows 11 (26200): pass. The new cs_w32_scalar_store fixture gives its eight expected words on this GPU, natively and with wave64 emulation on.

Test programs: MSVC 19.44 RelWithDebInfo build of main f847748, the branch's base (the PR changes no test program). llvm-mc 21.1.8 assembles the six scalar stores for gfx1013. Vulkan SDK 1.4.363.0, Python 3.13.7.

main f847748 13ce90b
python -I scripts/run_gpu_tests.py 153/199 passed, 46 skipped 154/200 passed, 46 skipped, 0 failed
the same with LEONIDA_W64_EMULATE=1 184/199 passed, 15 skipped 185/200 passed, 15 skipped
runtime/test/shaders/build.py 224 translated, 224 pass spirv-val 225 translated, 225 pass spirv-val
runtime/test/shaders/check.py 139 of 174 pass, 35 skipped 140 of 175 pass, 35 skipped (three runs)

run_gpu_tests.py --filter cs_w32_scalar_store --require-pass:

PASS  cs_w32_scalar_store   286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224

That is 0x11111111 through 0x88888888, so all four forms land where the header says: the x4 buffer store at 0, the x2 pointer store at 0x10, the SGPR-offset buffer store at 0x18 and sOFF offset:4 at 0x1c.

One thing to mention for honesty: my very first check.py run printed 139 of 175 with cs_w32_scalar_store ok; I had other D3D12 tests running on the same GPU at that moment and did not keep that run's output, so I can't say which test it was. Three reruns with the GPU to itself were 140 of 175, so I count it as noise from my side, not this PR.

On the branch: tests/semantic/test_scalar_mem_store.py 32 OK, test_value_semantics.py 37 OK, test_scalar_mem_smem.py 41 OK; python -I -m compileall -q make_game.py tools tests exit 0.

Not run: the full tests/semantic suite; an out-of-range s_buffer_store (the fixture has none). No game files. AI-assisted check (Claude Code).

@kacper-serewis kacper-serewis 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.

At 13ce90b a synthetic single s_store_dword wrote 32 times per wave32 and 64 times per wave64 in the CPU interpreter, for empty, lane-1-only and full EXEC. All wrote the same word, so final buffer comparison hides the duplicate stores. Elect one writer per logical guest wave independently of EXEC on a reached scalar store. The buffered lowering shares the unguarded path at rdna2spirv.py:8829. The emulated two-subgroup interpreter stopped at a control barrier; no runtime count for that case. AI-assisted CPU validation.

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested 13ce90b on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass

  • python3 -m pytest tests/semantic/test_scalar_mem_store.py tests/semantic/test_value_semantics.py -q -> 69 passed, 292 subtests passed
  • python3 -I scripts/run_gpu_tests.py --build <build> --filter scalar_store -> 1/1 passed (cs_w32_scalar_store)
  • python3 -I scripts/run_gpu_tests.py --build <build> -> 185/200 passed, 14 skipped, 0 failed (expected D3D12-owned skips)

No runtime C++ changes; GPU suite run from the PR worktree against the existing main runtime build.

AI-assisted (OpenCode).

@crastinator

Copy link
Copy Markdown
Contributor

Tested 13ce90b merged into main f847748c (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_w32_scalar_store (286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224).
  • Whole run_gpu_tests.py: 186/200 native, 186/200 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 41/41.
  • tests/semantic/test_scalar_mem_store.py, tests/semantic/test_value_semantics.py: 69 passed, 292 subtests passed.

No game files. AI-assisted (Claude Code).

@TreXito

TreXito commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested fddc5cef (base f847748c) on NVIDIA GeForce RTX 3060 Ti (Ampere), driver 580.173.02 (Vulkan 1.4.312), Linux (Ubuntu 26.04 container on a TrueNAS 26.0 host, Python 3.14.4): pass.

  • New GPU fixture cs_w32_scalar_store: PASS, words 0x11111111 0x22222222 ... 0x88888888 (286331153 ... 2290649224 in the log), the expected ones.
  • tests/semantic/test_scalar_mem_store.py and test_value_semantics.py: 69 passed (292 subtests) on this head. With tools/ from f847748c, 6 fail as Unsupported: s_store_dword, s_store_dwordx2, s_store_dwordx4, s_buffer_store_dword and s_buffer_store_dwordx4 (2).
  • scripts/run_gpu_tests.py, whole suite: 153/200 passed, 46 skipped, 1 failed. Apart from the new fixture, identical per test to main f847748c on this card. The failure is ps_sdwa_f16_const, the NVIDIA f16 denormal flush on main (rdna2spirv: widen f16 denormal operands without UnpackHalf2x16 (NVIDIA reads them as 0) #3220 / rdna2spirv: declare DenormPreserve 16 so a driver keeps f16 denormals (SHADER-526) #3040), not this PR.
  • ctest on the Linux build (CMake + Ninja, GCC): 41/41 passed.
  • As @kacper-serewis noted, comparing final words can't see the per-invocation duplicate stores, so this pass doesn't settle that point either way.

AI-assisted (Claude Code). Synthetic test shaders only, no game files.

runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tools/rdna2spirv.py

AI-assisted.
@Kev-Ball

Copy link
Copy Markdown

Tested 75e8f53e on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixture through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. The shader translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_w32_scalar_store — 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224.

AI-assisted verification with synthetic inputs.

docs/design.md
tools/rdna2spirv.py

AI-assisted.
@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 / MoltenVK validation of head db664cd4 (hardware reports Apple M2 / Mac14,3, not M1), macOS 26.4, MoltenVK 1.4.2, subgroup range 4..32, llvm-mc 23.1.6. Python/translator-only change; the harness was built from the PR's own base 0db7fed5 and shared for the A/B.

  • New GPU fixture cs_w32_scalar_store PASS: cs_w32_scalar_store 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224
  • Full suite on the PR head: 217 shaders translated, 217 pass spirv-val; 153/218 passed, 58 skipped, 7 failed (the known MoltenVK expected set). Base 0db7fed5 with the identical harness: 152/217, 58 skipped, 7 failed. No common test changed status in either direction.

No code changes, no game data; synthetic fixture and counts only.

AI-assisted.

@junaydirfan

Copy link
Copy Markdown

Tested db664cd4 merged into main 98fa503f on Linux (CachyOS, kernel 7.3.5), llvm-mc 23.1.5, LEONIDA_W64_EMULATE=1, test programs built from main (this PR changes no C++): pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 187/218 passed, 31 skipped, 0 failed 186/217
RTX 4080 Laptop GPU (Ada), subgroup 32 NVIDIA 620.73.04 202/218 passed, 16 skipped, 0 failed 201/217

New in this PR:

  • cs_w32_scalar_store: Intel PASS, 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 …; RTX 4080 PASS, 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 …

Every other test has the same result as on main on both GPUs.

One earlier Intel run of this PR crashed the runner while the machine was busy with other test suites. Three reruns on an idle GPU were clean, as were three main runs alongside, so I don't think it's this PR.

@lunarminus

Copy link
Copy Markdown

Tested db664cd4 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • db664cd4 already contains main up to 0db7fed5, so the merge onto d0835dd9 fast-forwarded. The PR's own change (0db7fed5..db664cd4) is the 9 files listed and none of them is C++. I rebuilt the test programs from this tree anyway (GCC 16.2.1, RelWithDebInfo), because main has changed runtime/ since d0835dd9.
  • run_gpu_tests.py --filter cs_w32_scalar_store --require-pass: 1/1 PASS natively and 1/1 PASS with LEONIDA_W64_EMULATE=1, words 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224 (0x11111111..0x88888888).
  • Whole run_gpu_tests.py: 203/218 passed, 15 skipped, 0 failed, both natively and with LEONIDA_W64_EMULATE=1. main d0835dd9 without the PR gave 196/210 passed, 14 skipped on this machine.
  • Per-test comparison with d0835dd9, in both modes: all 210 baseline result lines have the same result. The 8 new lines are:
    • cs_w32_scalar_store (this PR): PASS.
    • Seven fixtures added on main since d0835dd9: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_cl and ps_texture_b_cl PASS, and ps_m2_literal is SKIP (D3D12-owned).
  • Other tests run:
    • pytest on tests/semantic/test_scalar_mem_store.py, test_value_semantics.py and test_scalar_mem_smem.py: 118 passed, 368 subtests.
    • tests/semantic/regen_fixtures.py --check: clean.
    • pytest on tests/test_docs_design_rows.py, test_run_gpu_tests.py and test_shader_meta.py: 64 passed, 66 subtests.
    • python -I tests/test_shader_checks.py: OK.
  • Not run to completion: the whole tests/semantic suite, which was too slow on this machine within my time limit. A partial unittest run printed a few F/E markers before the timeout, and I didn't identify them or compare them with main, so I make no claim either way. Also not run: an out-of-range s_buffer_store on the GPU. As noted above in this thread, comparing final words cannot see the per-invocation duplicate stores, so this pass doesn't settle that question.

No game files. AI-assisted (Claude Code).

@jimokulou2-ops

Copy link
Copy Markdown

Tested db664cd merged onto main 98fa503 (clean merge) on AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (32.0.32029.2010, LLPC, Vulkan 1.4.359), Windows 11 Pro 26300: pass. A Windows AMD-driver (RDNA4, native wave64) data point next to the runs above.

  • Test programs built from main with llvm-mingw (the PR doesn't touch the runtime C++), llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, LEONIDA_VK_DEVICE=9070.
  • scripts/run_gpu_tests.py, full suite: 203/218 passed, 15 skipped, 0 failed; 222 shaders translated, 222 pass spirv-val. main 98fa503 on the same machine: 202/217, the same 15 skipped. The only difference is the new test:
    • cs_w32_scalar_store: PASS 286331153 572662306 858993459 1145324612 1431655765 1717986918 2004318071 2290649224
  • tests/semantic/test_scalar_mem_store.py: 32 OK; tests/semantic/test_value_semantics.py: 42 OK.
  • tests/semantic/regen_fixtures.py --check: clean.

No game files. AI-assisted (Claude Code).

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.