Skip to content

rdna2spirv: use OpAtomicStore for MSG_GS_ALLOC_REQ %ms_counts - #5855

Open
liamhob wants to merge 1 commit into
ItsNotRexed:mainfrom
liamhob:fix/ms-alloc-atomic-store
Open

liamhob wants to merge 1 commit into
ItsNotRexed:mainfrom
liamhob:fix/ms-alloc-atomic-store

Conversation

@liamhob

@liamhob liamhob commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: not claimed (regression fix found running run_gpu_tests.py on Round 44 / 561b65a83)

What and why

SHADER-766 guarded OpStore %ms_counts %m0 in s_sendmsg(MSG_GS_ALLOC_REQ) with local_index == 0 to avoid SharedMemoryDataRace-RaceOnStore.

However, when a non-zero wave sends the mesh allocation — as in runtime/test/shaders/ms_wave_info_s3.asm, where wave 0 (local_index 0..63) skips MSG_GS_ALLOC_REQ and only wave 1 (local_index 64..127) executes it — local_index == 0 is false for every executing thread. %ms_counts is never written and reads uninitialized workgroup memory, causing ms_wave_info_s3 to fail intermittently (8/10 runs failed on AMD Radeon RX 9070 XT, returning the (-1,-1,-1,-1) clear color).

Replacing the local_index == 0 branch + plain OpStore with OpAtomicStore %ms_counts %c2 %c0 %m (Workgroup scope, Relaxed semantics) stays data-race-free even when multiple lanes or waves execute MSG_GS_ALLOC_REQ while ensuring %ms_counts is always written regardless of which wave allocates. Updated tests/test_mesh_alloc_single_writer.py accordingly.

Tested

  • GPU / Driver: AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD proprietary driver 26.10.1 (LLPC), Vulkan API 1.4.359
  • OS / Toolchain: Windows x64, Vulkan SDK 1.4.363.0, LLVM 23.1.6 (conda-forge llvm-tools)
  • python -I tests/test_mesh_alloc_single_writer.py: 1/1 passed
  • python -I tests/test_text_write_line_endings.py: 3/3 passed
  • python -I scripts/run_gpu_tests.py --filter ms_wave_info_s3 (10 consecutive runs): 10/10 passed (was 2/10 passed, 8/10 failed before)
  • python -I scripts/run_gpu_tests.py: 238/238 translated & passed spirv-val; 216/232 passed, 16 skipped, 0 failed

AI-assisted: yes

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. (N/A — fixes existing MSG_GS_ALLOC_REQ workgroup store)

@Kam471 Kam471 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.

Approving. This is the correct SHADER-766 fix. Head 0b094ae8e, one commit on 561b65a83.

What the diff does: it removes the invocation-0 gate and replaces the plain store — both, not one or the other. The OpIEqual/OpSelectionMerge/OpBranchConditional block is deleted and the store becomes:

%t192 = OpLoad %uint %m0
OpAtomicStore %ms_counts %c2 %c0 %t192   ; %c2 = Workgroup scope, %c0 = Relaxed

Disassembled from the wave-1-only fixture: OpAtomicStore %7 %uint_2 %uint_0 %456, spirv-val clean (rc 0). The following OpControlBarrier %uint_2 %uint_2 %uint_264 still orders the store before the counts load, so Relaxed is sufficient.

Tests: python -I -m pytest tests/test_mesh_alloc_single_writer.py -q → 1 passed. The test now asserts no %local_index and no plain OpStore %ms_counts, and assembles both mesh and compute variants.

Wave-1-only fixture (ms_wave_info_s3.asm as committed on main by #5079, send only in wave 1; RTX 5070 Ti, vk_harness, 64x64):

translator pixels
main 561b65a83 (#4272 gate) 0/4096, every pixel (-1,-1,-1,-1)
#5855 4096/4096, exact ((x+.5)/64,(y+.5)/64,0.5,1)

So main's own registered ms_wave_info_s3 GPU test is red today, and this fixes it.

Corpus path not regressed: with the pre-#5079 fixture where every wave/lane sends (the corpus shape), main and #5855 both render 4096/4096 and the two readbacks are byte-identical (sha256 cf7df6a5…). All 9,282 corpus mesh shaders send from invocation 0, so the extra writers write the same uniform m0 value atomically; the corpus keeps its previous image.

Overlap: #4314 (closed 9 s after #4272 merged) carried the same atomic-store fix; this re-lands it on top of #4272. No other open PR in this batch touches %ms_counts. Merge this and main's ms_wave_info_s3 returns to green.

@DenRakEiw

Copy link
Copy Markdown
Contributor

Independent hardware review of 0b094ae8e49dd846abf2abdac7e4b3588d18ee74 (trial-merged onto origin/main 561b65a83) — LGTM.

Environment

  • OS / Toolchain: Windows 11 x64, MSVC 2022 (19.44.35230.0), Ninja, Vulkan SDK 1.4.363.0, Python 3.12.10, llvm-mc (LLVM 21 via WSL)
  • GPU / Driver: NVIDIA GeForce RTX 5090 (32.0.16.1088, LEONIDA_VK_DEVICE="RTX 5090")

Verification

  • git diff --cached --check: clean (0 issues)
  • python -I tests/test_mesh_alloc_single_writer.py -v: 1/1 passed (covers both MESH_COMPUTE=False and MESH_COMPUTE=True)
  • python -I scripts/run_gpu_tests.py --filter ms_ --require-pass (native MeshEXT): 7/7 translated & passed spirv-val; 5/6 passed, 1 skipped (ms_w64x_ballot, wave64-only)
  • python -I scripts/run_gpu_tests.py --filter ms_wave_info_s3 --require-pass (5 consecutive runs): 5/5 passed (4096/4096 pixels exact)
  • LEONIDA_MESH_COMPUTE=1 python -I scripts/run_gpu_tests.py --filter ms_ --require-pass: 7/7 translated & passed spirv-val; 5/6 passed, 1 skipped (ms_w64x_ballot)

Notes

  • Replacing the local_index == 0 guard + plain OpStore with OpAtomicStore %ms_counts %c2 %c0 %m (Workgroup scope, Relaxed semantics) cleanly fixes non-zero-wave allocation while remaining race-free, and both %ms_counts read sites are already synchronized by OpControlBarrier %c2 %c2 0x108 (Workgroup AcquireRelease | WorkgroupMemory).

AI-assisted (Gemini 4 Neon).

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0b094ae8 (merge base 561b65a8) on Windows 11 10.0.26300 with an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56: pass. This PR's tools/rdna2spirv.py ran with the runtime test tools built from main 561b65a8 (MSVC 19.44, Ninja; llvm-mc 21 and spirv-as/val from WSL Ubuntu).

  • ms_wave_info_s3 PASS (4096/4096 pixels exact), 5 of 5 runs each as a mesh stage and with LEONIDA_MESH_COMPUTE=1, and also with LEONIDA_W64_EMULATE=1. On main it fails 0 of 5 in both modes with the (-1,-1,-1,-1) clear colour, the same as in the description. The other ms_ tests pass (ms_w64x_ballot skips: no 64-wide subgroup).
  • Full scripts/run_gpu_tests.py: 184/232 passed, 48 skipped, 0 failed. Against main's 183/232 the only change is ms_wave_info_s3 FAIL → PASS.

For what it's worth, #5741 fixes the same failure here with identical results. I haven't compared the two approaches beyond that. Not run: other GPUs, Linux, the Vulkan validation layer (not installed). No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0b094ae merged with main 561b65a on Linux (WSL2) x86_64, Python 3.12.16 (-I): pass

tests/test_mesh_alloc_single_writer.py: 1 run, 1 passed, 0 failed. Negative control: with tools/rdna2spirv.py from main the test fails (1 run, 1 failed); with the PR's file it passes. Full semantic suite with the #4357 runner (scripts/run_semantic_tests.py --jobs 3): 433 files, 6150 tests, 0 files not ok. Main baseline (561b65a): 433 files, 6150 tests, 0 files not ok. Notes, not failures: the test adds tools to sys.path as a relative path, so it only runs from the repo root (cd /tmp && python -I <repo>/tests/test_mesh_alloc_single_writer.py raises ModuleNotFoundError for rdna2spirv); and tests/semantic/spirv_mini_interp.py has no OpAtomicStore handler, so no CPU test executes the new store, only its text is checked. ms_wave_info_s3 (GPU) and spirv-val were not run here.

@UNYTIX

UNYTIX commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0b094ae8 on AMD Radeon RX 7800 XT (RDNA3, gfx1101, Navi 32), AMD proprietary 26.11.2 (LLPC), Windows driver 32.0.32029.2010, Vulkan 1.4.359, Windows 11 build 26300: pass, with the base failing on the same device 3 of 3 runs.

Your own measurements are on an RX 9070 XT (RDNA4); this adds the RDNA3 desktop case on AMD's Windows driver, with a base-vs-head pair rather than one tree.

Method: test programs built from main 561b65a8 (MSVC 19.44.35230.0, Ninja, Vulkan SDK 1.4.363.0), llvm-mc 21.1.8 native with the AMDGPU target, SPIRV-Tools v2026.4. python -I scripts/run_gpu_tests.py --build <that build> --filter ms_wave_info_s3, a separate work folder per tree, native mesh path, device default subgroup 64 (32..64).

tree ms_wave_info_s3
main 561b65a8 (pristine origin/main worktree) FAIL at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000), want (0.0078,0.0078,0.5,1.0) - 3/3 runs
this PR 0b094ae8 PASS 4096/4096 pixels exact

--filter ms_ at this head: 6/6 passed. On this device main fails every run, so the regression is not intermittent here.

Note for the merge order: #5741 fixes the same %ms_counts write, so one of the two will need to give way.

AI-assisted. No game files; synthetic fixtures only.

@dandasma

Copy link
Copy Markdown
Contributor

Tested 0b094ae8 (on main 561b65a) on an AMD Radeon RX 9070 (RDNA4, discrete), AMD Windows driver 26.10.1, Windows 11: pass, and it fixes ms_wave_info_s3 here too.

ms_wave_info_s3 runs failures
this PR 42 (including the full suite) 0
main's tools/rdna2spirv.py, 14:15-14:35 14 (4 full suites + 10 alone) 1
main's tools/rdna2spirv.py, after 14:45 77 (alone, in the ms_ group, full suites, with and without concurrent GPU load) 76

Every failure is got (-1.0000,-1.0000,-1.0000,-1.0000), want (0.0078,0.0078,0.5,1.0), the clear color. The main failure rate went from about 7% to about 99% within half an hour on the same build, SPIR-V and order. That fits reading never-written workgroup memory (whatever is left in LDS); I couldn't tie it to concurrent load or to test order. The PR changes six mesh modules (ms_clip, ms_f16_pack, ms_tri, ms_v5_workgroup, ms_w64x_ballot, ms_wave_info_s3): all pass, and the full suite is 216/232 with 16 skipped, as on main. tests/test_mesh_alloc_single_writer.py: OK.

AI-assisted (Claude Code).

@gutersohn

Copy link
Copy Markdown

Tested 0b094ae8e on AMD Radeon RX 6600 (RDNA2, Navi 23, gfx1032), AMD Windows driver 26.10.1 (32.0.21045.16010, Vulkan 1.4.315), Windows 11 10.0.26200: pass.

This is the first RDNA2 card on this PR. Here, ms_wave_info_s3 on the base is intermittent (clear colour at every pixel), not deterministic:

ms_wave_info_s3 (run_gpu_tests.py --filter) native W64_EMULATE=1 MESH_COMPUTE=1 both
base 561b65a8 5/10 8/10 1/10 4/10
this PR 0b094ae8 20/20 20/20 20/20 20/20

Full scripts/run_gpu_tests.py, native and with LEONIDA_W64_EMULATE=1: base 214/232 passed, 17 skipped, 1 failed (ms_wave_info_s3). This PR: 215/232 passed, 17 skipped, 0 failed in both modes. 238/238 translated and passed spirv-val. tests/test_mesh_alloc_single_writer.py: OK.

Same RX 6600 and runtime build as my run on #5741: #5741 60c027c4 also passes 20/20 in all four modes, so both fixes behave the same on this card.

Setup: the runtime test programs were built once at the merge base 561b65a8 (MSVC, VS 2022 Build Tools, Windows SDK 10.0.26100). This PR doesn't touch runtime/ or scripts/, so they match its head. llvm-mc 21.1.8 from scripts/build_llvm_mc.ps1, Vulkan SDK 1.4.363.0, Python 3.14.4, LEONIDA_VK_DEVICE=radeon. Counts only, no game files. AI-assisted (Claude Code).

@barredodavid

Copy link
Copy Markdown

Tested 0b094ae on two GPUs of one laptop, selected with VK_LOADER_DRIVERS_SELECT. Full run_gpu_tests.py suite, runtime rebuilt at that commit, no game files. AI-assisted (setup, log reading and this write-up).

It fixes ms_wave_info_s3 on the RTX 5060 Laptop GPU, with no new failure.

GPU Mode main 56e607a this PR (0b094ae) ms_wave_info_s3
NVIDIA RTX 5060 Laptop GPU (Blackwell), 616.56, subgroup 32..32 default 188/237, 48 skipped, 1 failed 184/232, 48 skipped, 0 failed FAIL → PASS (4096/4096 pixels exact)
same LEONIDA_W64_EMULATE=1 219/237, 17 skipped, 1 failed 215/232, 17 skipped, 0 failed FAIL → PASS (4096/4096 pixels exact)
AMD Radeon 780M (RDNA3 iGPU), 26.11.2 LLPC (32.0.32029.2010), subgroup 32..64 default 221/237, 16 skipped, 0 failed 216/232, 16 skipped, 0 failed PASS → PASS

On main the failure was at (0,0): got (-1,-1,-1,-1), want (0.0078,0.0078,0.5,1.0) in both NVIDIA runs (#166 entry). The totals differ only because this head is based on an older main with five fewer tests; 238 shaders: 238 translated, 238 pass spirv-val.

Same result as #5741 (60c027c) on this machine: the translator change is the same line in both.

Windows 11 Pro build 26300, llvm-mc 23.1.6 (conda-forge, native), Vulkan SDK 1.4.363.0, MSVC 19.44.35230.

@carlos-seiffert

Copy link
Copy Markdown

Tested 0b094ae (merged onto main e0816d6) on NVIDIA GeForce RTX 2060 (Turing), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 (10.0.26300): pass

What I ran: python -I scripts/run_gpu_tests.py with the Vulkan tools built from e0816d6 (llvm-mingw + Ninja, -DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF, Vulkan-Headers 6802bb47), llvm-mc 23.1.6 (conda-forge), subgroup size 32.

main e0816d6 this PR on main
full GPU suite 190/239 passed, 48 skipped, 1 fail (ms_wave_info_s3: got (-1,-1,-1,-1) at (0,0), want (0.0078,0.0078,0.5,1.0)) 191/239 passed, 48 skipped, 0 fail
ms_wave_info_s3, 10 runs FAIL 10/10 PASS 10/10

Unit test: tests/test_mesh_alloc_single_writer.py: OK.

On this NVIDIA Windows driver the failure on main is deterministic (10/10), unlike the intermittent RADV report in #6172. For reference, #7136, #5741 and #5855 all fix it here with no other change in the suite. AI-assisted run (Claude Code); numbers are from my machine.

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.

10 participants