Repository navigation
rdna2spirv: plain LDS loads and stores are Volatile (cs_w64x_lds_raw/war fail on AMD 24.30.46) - #6714
Conversation
RDNA2 runs a wave in lockstep, so a ds_read issued after a ds_write sees every lane's write without an s_barrier. Translated, each lane is one invocation and nothing orders two invocations' plain accesses, so a driver may move a lane's load ahead of the wave's stores or merge two loads. AMD's Windows driver 24.30.46 does that on a Radeon 880M (native 64-wide subgroups): cs_w64x_lds_raw and cs_w64x_lds_war read uninitialized Workgroup memory on every run on main 561b65a. lds_load, lds_store and the two ADDTID forms now emit the Volatile memory operand. Both tests pass on that GPU and driver (run_gpu_tests.py 210 -> 212 of 232, none failing); an RTX 5070 Laptop is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
I’m running the requested retail corpus check on |
|
Tested 58deee3 (merged on
|
|
Tested
|
|
Tested
|
|
Completed the requested full Xbox 1.0.2.1 shader comparison on CachyOS. 26,503/26,503 translated and passed
Across the 489 changed modules, the complete instruction diff consists of 12,099 |
|
Tested on NVIDIA GeForce GTX 1080 (Pascal, subgroup 32), Linux (Ubuntu 26.04.1), driver 580.178.04. No game files.
cs_w64x_lds_raw and cs_w64x_lds_war pass with the same words as main. No regression on this NVIDIA driver. AI-assisted. |
shayderrr
left a comment
There was a problem hiding this comment.
Summary: Plain LDS accesses now carry SPIR-V Volatile. tools/rdna2spirv.py adds the operand in lds_load(), lds_store() and the ds_read_addtid_b32/ds_write_addtid_b32 paths, preserving each invocation's access order against driver reordering. docs/design.md records the rule with the Radeon 880M driver evidence. tests/semantic/test_lds_volatile.py checks every read/write width and ADDTID form on wave32, wave64 and emulated wave64, asserts nothing else is Volatile, and executes round-trip and post-barrier cases on the CPU interpreter.
Why merge: Fixes real hardware failures where a driver hoisted or merged LDS accesses within a lockstep wave.
Verdict: Approve
|
Summary: Plain LDS accesses now carry SPIR-V Volatile. tools/rdna2spirv.py adds the operand in lds_load(), lds_store() and the ds_read_addtid_b32/ds_write_addtid_b32 paths, preserving each invocation's access order against driver reordering. docs/design.md records the rule with the Radeon 880M driver evidence. tests/semantic/test_lds_volatile.py checks every read/write width and ADDTID form on wave32, wave64 and emulated wave64, asserts nothing else is Volatile, and executes round-trip and post-barrier cases on the CPU interpreter. Why merge: Fixes real hardware failures where a driver hoisted or merged LDS accesses within a lockstep wave. Verdict: Approve |
Claimed in the coordination issue as: #6414 (comment) (a new SHADER item, no ID assigned yet)
What and why
cs_w64x_lds_rawandcs_w64x_lds_warfail natively on an AMD Radeon 880M with AMD's Windows driver 24.30.46, on every run, atmain561b65a8. This is the native wave64 path (64-wide compute subgroups), with no emulation involved.cs_w64x_lds_raw132 137 100 108 131 101 149 118584826922 1876221419 61804513 3349970407 3763559323 3425325245 1601035134 2110006689cs_w64x_lds_war1032 1063 1000 1031 2032 2063 2000 20313805932010 1262937919 199952361 4027800506 3805932010 1262937919 199952361 4027800506Both read uninitialized Workgroup memory, and in
cs_w64x_lds_warthe second read returns the same four words as the first, although every lane wrote in between.Cause. RDNA2 runs a wave in lockstep with an in-order LDS queue, so a
ds_readissued after ads_writesees every lane's write without ans_barrier. Translated, each lane is one invocation, and the Vulkan memory model orders nothing between invocations without a barrier or an atomic. A driver's compiler may therefore move an invocation's load ahead of its own earlier store to another address, or merge two loads of one address. The observed failures are consistent with these transformations. The GPU results establish the effect of the workaround. #2345 describes the same race and notes that it had not reproduced on its testers' drivers (among them a Radeon 880M on a newer driver); this is a reproduction, on existing fixtures.Change. The translator's plain LDS
OpLoadandOpStore(lds_load,lds_storeand the two ADDTID forms) carry theVolatilememory operand, which SPIR-V defines as an access that cannot be eliminated, duplicated or combined with other accesses. The atomics are unchanged.tools/rdna2spirv.pychanges by 4 emitted lines.Before writing it, I checked the hypothesis on hand-edited SPIR-V of
cs_w64x_lds_rawon the same GPU and driver:Volatileon the store alone, on the load alone, or on both gives the expected words on 3 of 3 runs each; the unmodified module gives garbage on 4 of 4.Limit. On the Radeon 880M with driver 24.30.46, marking the plain accesses Volatile restored the expected RAW and WAR results. Portable ordering between invocations requires appropriate synchronization; #2345's opt-in subgroup barriers address that, and the two changes don't conflict in intent (both touch
tools/rdna2spirv.py, so whichever lands second needs a rebase).Output change. Default output changes for shaders with plain LDS accesses, by the operand only: 17 of the 238 test shaders differ, and each differing line is an LDS load or store that gained
Volatile. Kev-Ball's independent full corpus check translated and validated 26,503/26,503 shaders at both revisions. Only 484 compute and 5 mesh modules changed, all by the added operands.Tested
Windows 11 Home 10.0.26200, MSVC 14.44, llvm-mc 21.1.8 (
scripts\build_llvm_mc.ps1), Vulkan SDK 1.4.363.0. Synthetic fixtures only, no game files.scripts/run_gpu_tests.py, 238 shaders translated and 238 passspirv-valin every run, before and after:main561b65a8cs_w64x_lds_raw,cs_w64x_lds_war), 20 skippedLEONIDA_W64_EMULATE=1ms_wave_info_s3), 48 skippedLEONIDA_W64_EMULATE=1ms_wave_info_s3), 17 skippedms_wave_info_s3is the known failure onmain(#6172); this PR doesn't touch it.tools/lds_fuzz.py --programs 100 --seed 1 --wave bothon the Radeon 880M with this PR: 200/200 match (native).tests/semantic/test_lds_volatile.py(new, 4 tests): every plain access form (ds_read/ds_write_b32.._b128,read2/write2,st64, the sub-dword reads, ADDTID) on the wave32, wave64 and emulated paths emits only Volatile LDS loads and stores, and nothing else is Volatile; two programs execute the Volatile accesses in the CPU interpreter. Withtools/rdna2spirv.pyfrommain(throughLEONIDA_TOOLS_DIR) it fails with 58 failures; with this PR it passes.tests/semantic, every file: 434 files, 6154 tests, 0 failing.mainbefore the change: 6150 tests OK (23 skipped, 1 expected failure).python -m pytest tests/test_translate.py tests/test_shader_checks.py tests/test_lds_fuzz.py tests/test_spirv_opt.py tests/test_spirv_asm.py tests/test_lane_masks.py: 789 passed.python -m compileall -q make_game.py tools tests, and the docs tests (test_design_contract_rows,test_docs_design_rows,test_docs_table_rows,test_docs_table_ids,test_docs_links,test_docs_repo_paths,test_docs_repeated_lines,test_docs_list_items),test_semantic_translator_useandtest_text_write_line_endings: pass.Outside the original author's test matrix: Intel, Mesa (RADV, ANV, llvmpipe) and MoltenVK; AMD drivers other than 24.30.46; the game's shaders. The CPU interpreter runs a subgroup's invocations one after another between subgroup operations, so it cannot show the lockstep exchange itself; the GPU tests are what show it.
AI-assisted: yes (Claude Code). The numbers above come from runs on this machine.
Checklist
docs/design.md, with how it was confirmed.🤖 Generated with Claude Code