Repository navigation
rdna2spirv: %ms_counts is stored atomically by whichever wave sends; ms_wave_info_s3 draws nothing on main on most GPUs (SHADER-766) - #5741
Conversation
… store, from whichever wave sends (SHADER-766) s_sendmsg(MSG_GS_ALLOC_REQ) is reached only by the invocations of a wave that sends. Since round 44 the store of M0 to %ms_counts was gated on LocalInvocationIndex == 0 (ItsNotRexed#4272), so it ran only when invocation 0 is in a sending wave. In ms_wave_info_s3 as ItsNotRexed#4298 left it, only wave 1 sends: no invocation stored the counts, and on a 32-wide GPU the fixture drew nothing (RTX 3070: at (0,0): got (-1,-1,-1,-1) in all four modes). The store is now ungated and an OpAtomicStore (Workgroup scope, relaxed): every invocation of a sending wave stores the same M0, which is defined for any number of writers and is not a data race. The counts are still loaded once after the epilogue's barrier. tests/test_mesh_alloc_single_writer.py pinned the gate and is removed; tests/semantic/test_ms_counts_atomic.py takes its place (three hand-written programs, native and emulated, as a mesh stage and as a compute stage). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Independent Windows NVIDIA check, AI-assisted. Head
The failure on base is Separately ran |
|
Tested b40aa12 on Intel UHD Graphics 630 (CFL GT2), Mesa ANV: with LEONIDA_MESH_COMPUTE=1 and native subgroups (8..32), run_gpu_tests.py --filter ms_ gives 5/6 passed, 1 skipped (ms_w64x_ballot, no 64-wide subgroup), with "PASS ms_wave_info_s3 4096/4096 pixels exact". With LEONIDA_W64_EMULATE=1 it gives 6/6, and ms_w64x_ballot also passes 4096/4096 pixels exact. On 561b65a with the same native command, ms_wave_info_s3 fails: "at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000), want (0.0078,0.0078,0.5,1.0)", 4/6 passed. tests/semantic/test_ms_counts_atomic.py runs 3 tests OK. Without LEONIDA_MESH_COMPUTE this device has no VK_EXT_mesh_shader and all 6 ms_ rows skip. The emulated run was not repeated on 561b65a. AI-assisted. |
|
Tested b40aa12 on NVIDIA GeForce RTX 5080, subgroup 32..32: run_gpu_tests.py --filter ms_ gives 5/6 passed, 1 skipped (ms_w64x_ballot, "no 64-wide subgroup on this device") both without LEONIDA_MESH_COMPUTE and with LEONIDA_MESH_COMPUTE=1, and "PASS ms_wave_info_s3 4096/4096 pixels exact" in both runs. ms_clip, ms_f16_pack, ms_tri and ms_v5_workgroup also pass in both. I did not run main on this GPU. AI-assisted. |
|
Tested
|
|
Tested Test programs built with MSVC 19.51 from a tree with #4272 and #4298 (main after round 44), shaders translated by this PR's
(The one-test difference is #5710's new Bisection on the same GPU, agreeing with your diagnosis:
AI-assisted (Claude Code). Synthetic fixtures only; no game files. |
|
Confirmed the base-to-head change on Ampere, CachyOS, RTX 3080 Ti, NVIDIA 620.73.04. I ran On |
|
Tested b40aa12 (on
The same picture as your RTX 3070 and gfx1036: the failure on The whole suite with this PR,
On
Not tested: the validation layer's race check from the description, and the rest of the unit tests. No game files. AI-assisted (Claude Code ran the tests). |
|
Tested
AI-assisted (Claude Code). Synthetic fixtures only, no game files. |
|
Tested
On the AMD iGPU, AI-assisted: runs were done with Claude Code. |
|
@Etr0p thanks, that is a separate failure and worth its own item: please post it as a finding. It is not something this PR's one instruction can reach, and I cannot reproduce it here:
Thanks also @BeegSchmooze, @Kev-Ball, @gertify and @KubickNubick for the runs. With yours the one-sender case is confirmed failing on AI-assisted. |
|
Tested b40aa12 on AMD Radeon RX 7700 XT (RDNA3, Navi 32, gfx1101), AMD Windows driver 32.0.32029.2010, Windows 11 Pro 26300: pass. This is a 64-wide failure on Setup: Vulkan SDK 1.4.363.0, llvm-mc 23.1.6 (conda-forge
On This supports the hypothesis in the description. Here (64-wide, AMD Windows driver) the never-written PR checks: No game files used; every shader here is a repo fixture. |
|
Tested Pass, it fixes the regression here. On |
|
Tested b40aa12 (already on main 561b65a, nothing to merge) on Apple M4 (32-wide subgroups), macOS 27.2.1, MoltenVK 1.4.2, Python 3.15.2 and 3.12.16: pass, with one test gap (below)
AI-assisted. |
|
Tested
For what it's worth, #5855 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). |
|
Tested
AI-assisted. |
|
Tested I ran
|
|
Tested This is the base-vs-head pair the thread was missing on AMD Windows: the checks above are NVIDIA, Intel ANV and an RX 9070 XT (RDNA4). Method: one set of test programs built from
On this device the failure is deterministic rather than intermittent, so the pair reads cleanly. AI-assisted. No game files; synthetic fixtures only. |
|
Tested
AI-assisted (Claude Code). |
|
Tested Worth noting: on Counts and error classes only; no game data. AI-assisted. |
|
Tested
No game files used. AI-assisted (Claude Code). |
|
Tested live on NVIDIA GeForce GTX 1070 8 GB (Pascal, 32-wide subgroups, no Before (clean
|
|
Independent confirmation of the case @PingasMech posted on #7136, on NVIDIA's native mesh stage: this PR draws it correctly, #7136 does not.
Reproduction: PingasMech's case — in AI-assisted run (Claude Code). |
|
Tested
Synthetic project fixtures only. AI-assisted: yes (Codex). |
|
Tested 57cc180 on AMD Radeon RX 7700 XT (RDNA3, gfx1101), AMD Windows driver 32.0.32029.2010, Windows 11: pass. ms_wave_info_s3 3/3 PASS (4096/4096 exact); main dde82f2 fails it 3/3 with the (-1,-1,-1,-1) signature. tests/semantic/test_ms_counts_atomic.py OK. Full run_gpu_tests.py: 223/239 passed, 16 skipped, 0 failed. llvm-mc 23 (conda-forge), test programs built with llvm-mingw. AI-assisted (Claude Code). |
|
Tested A/B with the same test programs (built at the head with
Whole Thread-127 variant: in |
SHADER-766 follow-up (a regression on
mainsince round 44), claimed in the coordination issue: #5581 (comment)What is broken on
mainOn
main561b65a8,ms_wave_info_s3fails on a GPU with 32-wide subgroups. RTX 3070 (NVIDIA 610.74),python -I scripts/run_gpu_tests.py --filter ms_:in all four modes: as a mesh stage and with
LEONIDA_MESH_COMPUTE=1, native and withLEONIDA_W64_EMULATE=1.Two pull requests of round 44 each pass alone and fail together:
%ms_countsrun only in the invocation withLocalInvocationIndex == 0, to have one writer.ms_wave_info_s3so that only wave 1 sendsMSG_GS_ALLOC_REQ.s_sendmsgis reached only by the invocations of a wave that sends. With the gate the store runs only if invocation 0 is one of them. When wave 1 is the sender, invocation 0 never gets to the send, no invocation stores the counts, and the epilogue loads a word nothing wrote: 0 vertices, 0 primitives, nothing drawn. On a Radeon gfx1036 the same tree passes all four modes, which I can only explain as the load returning what the memory already held (hypothesis). The closed #4314 measured this pair before either was merged, and Kam471's review there reads the gate the same way.The fix
The store is ungated and an
OpAtomicStore(Workgroup scope, relaxed); the change intools/rdna2spirv.pyis one block. Every invocation of a sending wave stores the same M0. That is defined for any number of writers and is not a data race, which was the reason for SHADER-766 in the first place. The counts are still loaded once after the epilogue's barrier, in the mesh epilogue and the--mesh-computeone.One writer cannot be named here the way SHADER-708 does for
%x_buf: which waves send is the program's own control flow. Over my copy of the package all 9,282 mesh shaders send exactly once, behindv_cmpx_eq_u32ands_cbranch_execz(the wave holding one chosen thread sends), so any fixed invocation is wrong for some program.tests/test_mesh_alloc_single_writer.py(from #4272) asserts the gate itself, instruction by instruction, so it cannot stay;tests/semantic/test_ms_counts_atomic.pyreplaces it.docs/design.mdgets a contract row, Mesh counts store.Measured
Windows 11 (26200), Vulkan SDK 1.4.363, test programs built from
main561b65a8. Ryzen 7 9700X iGPU (Radeon gfx1036, AMD 32.0.21042.62, subgroup 32..64) and RTX 3070 (NVIDIA 610.74, subgroup 32), picked withLEONIDA_VK_DEVICE.scripts/run_gpu_tests.py --filter ms_, 7 shaders translated andspirv-val-valid in every run:main561b65a8ms_wave_info_s3FAILms_wave_info_s3FAILmain561b65a8The skip is
ms_w64x_ballotnatively on the RTX 3070 (no 64-wide subgroup).Race check. The validation layer's data-race check covers compute shaders only, so the six fixtures are translated with
LEONIDA_MESH_COMPUTE=1and run throughvk_harnesswithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1:LEONIDA_W64_EMULATE=1main561b65a8(gated plain store)SharedMemoryDataRace-RaceOnStoreSharedMemoryDataRace-RaceOnStoreSo natively the atomic store is as clean as the gate was. The 36 in the emulated runs (6 per module, the most the layer gives) are the same before and after: every one is a plain
OpStoreto the exchange buffer, which is SHADER-708 (#4247, reverted onmainand being re-merged), and this PR's modules have no plain store to%ms_countsat all. That run therefore says nothing about this variable; #4314 measured 0 on top of #4247.Tested
python -m unittest discover -s tests/semantic -p "test_ms_counts_atomic.py": 3 tests OK. Three hand-written mesh programs (the send unguarded, behind ans_cbranch_execz, and on two paths), 128 and 40 threads, native and emulated, as a mesh stage and as a compute stage: each send is oneOpAtomicStoreof M0, no plain store names the variable, and its one load comes after a barrier that follows every store. Withmain's translator the test fails (anOpStorebehind the gate).test_barrier_control.py(17),test_lds_atomic_xchg.py(6),test_lds_direct.py(5),test_lds_read_write.py(8),test_wave64_emulate_opt.py(26): OK.python -I tests/test_shader_checks.py: OK.python -m compileall -q tools tests: clean.python -I tests/test_docs_links.py,test_docs_repo_paths.py,test_docs_list_items.py,test_docs_design_rows.py,test_text_write_line_endings.py: OK.Checklist
docs/design.md, with how it was confirmed.Not checked
tests/semanticsuite and the pytest files on this commit; the change is one emitted instruction of mesh shaders.spirv-val-valid, the same as before it), on an oldermain.--mesh-computemodules go through SPIRV-Cross, which has to turn an atomic store on a Workgroup variable into Metal; Linux, RADV, Intel. A run on any 32-wide GPU other than mine would be welcome:ms_wave_info_s3should fail onmainand pass here.AI-assisted.