Repository navigation
Conversation
… (SHADER-766) - tools/rdna2spirv.py: when emitting s_sendmsg(MSG_GS_ALLOC_REQ) in stage ms/msc, guard OpStore %ms_counts with local_index == 0 to eliminate SharedMemoryDataRace-RaceOnStore. The counts are uniform across the workgroup (from SGPR m0), and all invocations synchronize at the subsequent workgroup barrier before loading %ms_counts. - tests/test_mesh_alloc_single_writer.py: add unit tests verifying the invocation-0 guard and valid SPIR-V assembly for native mesh and --mesh-compute.
|
Automated test:
Same machine and setup as my earlier manual reports. AI-assisted (Claude Code). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 862d3e91 on Windows 11: python -I tests/test_mesh_alloc_single_writer.py -> 1 test, OK; compileall and git diff --check clean.
The MSG_GS_ALLOC_REQ path now guards the %ms_counts store with local_index == 0 using OpSelectionMerge/OpBranchConditional, so only the first invocation writes the counts while every invocation still reaches the post-alloc barrier. The new test checks the emitted block structure and the single writer. No blocking issue.
|
Tested 862d3e9 on NVIDIA GeForce RTX 3070 (VK_EXT_mesh_shader, 32-wide), driver 617.42, Windows 11 24H2: pass, no change in the mesh results against
So guarding the No game files. AI-assisted (Claude). |
|
Tested Windows 11 (26200), test programs built from
The comment in the change says the counts are uniform; that holds for the value, but not for who runs the store. #4314 (SHADER-766, which the coordinator recorded for me as finder) makes the store an Not checked: your new test file on its own, and GPU-assisted validation of this head. AI-assisted; measured on my PC. |
Kam471
left a comment
There was a problem hiding this comment.
This change breaks the second-wave allocation case. I cherry-picked 862d3e91 onto #4298's 5079b487 and ran its ms_wave_info_s3 fixture (the case where only the second wave sends MSG_GS_ALLOC_REQ) on Windows 11, RTX 5070 Ti with LEONIDA_W64_EMULATE=1:
FAIL ms_wave_info_s3 at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000),
want (0.0078,0.0078,0.5,1.0)
The guard local_index == 0 assumes the sending wave contains invocation 0. It does not when the chosen thread is in a later wave (the fixture's whole point), so the store is skipped and the output is uninitialized.
For comparison, #4314 (19bc3599, OpAtomicStore) passes the same fixture 4096/4096 exact, and its test_ms_counts_atomic.py (3 OK) / test_wave64_emulate_opt.py (22 OK) pass. Its argument in the code — "One writer cannot be picked here: which waves send is the program's own control flow" — is the correct one.
Please either change this PR to the atomic store or close it in favor of #4314; as written it is a correctness regression, not just a race fix. The emitted-shape test here (test_mesh_alloc_single_writer.py) cannot catch this.
|
Tested 862d3e9 (merge base main aa2988c) on NVIDIA GeForce RTX 5080, Linux 580.65.06, with GPU-assisted validation (Khronos validation layer, SDK 1.4.363.1): fail Result: on the fixtures that are on Setup. Test programs built once from Mesh fixtures under GPU-AV (the layer's race check is compute-only, so
The six fixtures pass in all of those runs as on the merge base (native: 5 pass, Suite, no validation (
Every one of the 210 result lines is the same before and after (compared after removing the work-folder path). The same change with #4298's fixtures (
The failure line is GPU-AV on #4272 + #4298, mesh as compute: 0 reports natively, 36 emulated (again #4247's Also run: Not tested: other GPUs; the 9,282-shader corpus (zzEmmazz's claim that every one sends behind AI-assisted. No game files. |
Summary
Addresses SHADER-766 (finding on #4084 by @zzEmmazz):
In mesh shaders (both native mesh and
--mesh-compute),s_sendmsg(MSG_GS_ALLOC_REQ)loads the output vertex and primitive counts from scalar registerm0and stores them into the shared Workgroup variable%ms_counts. Previously, every invocation in the workgroup unconditionally executedOpStore %ms_counts %m, causing Vulkan GPU-assisted validation to reportSharedMemoryDataRace-RaceOnStoreon all 6 mesh fixtures.Changes
tools/rdna2spirv.py:s_sendmsg(MSG_GS_ALLOC_REQ)in stagems(including--mesh-compute), restrictOpStore %ms_countstoLocalInvocationIndex == 0via a structured branch (OpSelectionMerge/OpBranchConditional).m0), and all invocations synchronize at the subsequent workgroup barrier (OpControlBarrier) before reading%ms_countsin the epilogue.tests/test_mesh_alloc_single_writer.py:s_sendmsg(MSG_GS_ALLOC_REQ)emits the invocation-0 check and that the resulting SPIR-V forms a valid structured CFG and assembles cleanly withspirv_asmfor both native mesh and--mesh-compute.Verification
python -I tests/test_mesh_alloc_single_writer.py-> 1 test OKpython -I tests/test_mesh_compute_vs.py-> 12 tests OK (skipped=2)python -I tests/test_meshlet_page.py-> 59 tests OKspirv_asmonly; no game data or GPU required.