Skip to content

test(shader): cover mesh allocation across a wave64 barrier (SHADER-761) - #4298

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
jeremygold02:test/mesh-alloc-barrier
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
jeremygold02:test/mesh-alloc-barrier

Conversation

@jeremygold02

Copy link
Copy Markdown
Contributor

SHADER-761. Depends on #4247. These two synthetic fixtures cover the visible rendering failure fixed by SHADER-708 and the case where only the second wave sends the allocation. Original coordination claim

What and why

ms_tri adds one instruction, an unconditional s_barrier immediately after MSG_GS_ALLOC_REQ. Both logical wave64s send the same allocation of three vertices and one primitive. On main, moving this barrier before the send or omitting it produces the expected triangle. Placing it after the send clears the entire frame.

ms_wave_info_s3 uses the wave ID it already computed. Wave 0 skips the send, wave 1 sends, and both reach the barrier before wave 0 exports the triangle. This exercises structured wave64 emulation. It also gives SHADER-766 a rendering check for a sender outside workgroup invocation zero. Both fixtures use the existing full-frame gradient expectation. The diff changes six lines in two assembly files.

Tested

Fixture commit 5079b487340de84bbb44cd66c544469ba65e52d5. Compared main aa2988cc555bad7ecd508b48a702adbb32fe7c95 with #4247 at 5f16276d12ea9f2c40f0e29733f10f3507d52057, applying the same fixture inputs to both. Native Windows Vulkan ran on an NVIDIA GeForce RTX 5070, driver 621.01, subgroup 32. CPU was an Intel Core Ultra 7 265K on Windows 11 Home 25H2 build 26200.9974. LLVM assembly and Vulkan 1.2 SPIR-V validation ran in WSL.

Emulated wave64, mesh-as-compute Main header Main matching pixels #4247 header #4247 matching pixels
Both waves send, then barrier (0, 0) 0/4,096 (3, 1) 4,096/4,096
Only wave 1 sends, then both reach barrier (3, 1) 4,096/4,096 (3, 1) 4,096/4,096

The 64×64 frames came from the unmodified repository runner and harness. A separate byte comparison checked every RGBA32F component. The count headers came from 16×16 single-workgroup draws with the output header seeded to (2, 2). In a diagnostic build of main, all 128 invocations read packed count 0x1003 at the send and zero at the first instruction resumed after the barrier. Restricting the allocation store alone did not restore the both-sender case.

On #4247 both fixtures also matched all 4,096 pixels through native MeshEXT, with wave64 emulation enabled and with the default translator settings. Seven synthetic mesh programs validated on each revision. All seven rendered the exact 16×16 frame on #4247, including matched controls for wave 0 only, wave 1 only and both waves sending. The two-wave compute control cs_w64x_wg128_branches returned all eight expected words.

With the fixtures applied and the Vulkan test programs built, these commands repeat the two mesh-as-compute comparisons.

LEONIDA_W64_EMULATE=1 LEONIDA_MESH_COMPUTE=1 python -I scripts/run_gpu_tests.py --filter ms_tri.asm --require-pass
LEONIDA_W64_EMULATE=1 LEONIDA_MESH_COMPUTE=1 python -I scripts/run_gpu_tests.py --filter ms_wave_info_s3.asm --require-pass

The coordinating chat independently compared the same two translator revisions on one local authored mesh program. Both translated modules used the same header-selected wave64 listing and passed validation. The base returned (0, 0) for a meshlet expected to return (126, 80). The unmodified #4247 output matched all 14 allocation headers, all 809 index/cull records and all 1,663 referenced position/UV records under identity transforms. The captured geometry was rendered with a diagnostic camera and three diagnostic pixel shaders. Each 320×96 frame matched the independent source-geometry draw on all 30,720 pixels, including 8,062 covered pixels. This comparison verifies mesh output and diagnostic rendering. The original material pixel shader and runtime bindings remain separate work.

Checklist

GPT-6 Luna checked related claims during the investigation. AI-assisted by GPT-6.2 Astra.

Exercise the round scheduler with both waves sending the allocation, and
the structured scheduler with only wave 1 sending before wave 0 exports.
Both fixtures keep the existing full-frame gradient expectation.

Refs: ItsNotRexed#4247, ItsNotRexed#4084

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

Ran the two changed fixtures at 5079b487 on Windows 11, RTX 5070 Ti (32-wide), with run_gpu_tests.py and the branch's own translator/runner:

  • ms_tri -> 4096/4096 pixels exact, translator 1/1 spirv-val.
  • ms_wave_info_s3 (with LEONIDA_W64_EMULATE=1) -> 4096/4096 pixels exact, translator 1/1 spirv-val.

The added lines exercise the second-wave allocation and the barrier case that the rendering failure needed; both still produce the full picture. No blocking issue.

@Kam471

Kam471 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Heads-up from the SHADER-766 review: #4272's \local_index == 0\ guard \ms_counts\ store fails this PR's second-wave fixture. I cherry-picked its commit onto \5079b487\ and ran
un_gpu_tests.py --filter ms_wave_info_s3\ (RTX 5070 Ti, \LEONIDA_W64_EMULATE=1): got (-1,-1,-1,-1)\ where the expected words are (0.0078,0.0078,0.5,1.0); the store is skipped because wave 0 does not contain the sending invocation. #4314's atomic store passes the same fixture 4096/4096. Do not let #4272 land ahead of this fixture.

@TreXito

TreXito commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested fixtures 5079b487 on AMD Radeon RX 7800 XT (RDNA3, gfx1101, subgroup 32..64, requiredSubgroupSizeStages 0xf0 incl. COMPUTE and MESH), AMD Windows driver 26.11.2 (32.0.32029.2010), Windows 10 Pro 22H2 build 19045.7846, MSVC build of main aa2988cc's test programs, VVL 1.4.363.0, llvm-mc 21.1.8. I applied the same two fixture files to main aa2988cc and to #4247 5f16276d. Both changes are translator only, so I used one vk_harness.

On AMD, the fixtures do not go red on main. All 20 runs (2 fixtures × 2 revisions × 5 configurations) are pixel-exact:

mode (LEONIDA_W64_EMULATE=1 unless noted) main + fixtures #4247 + fixtures
native wave64 (no emulation), native MeshEXT both 4096/4096 both 4096/4096
emulated, native MeshEXT (default and VKH_SUBGROUP_SIZE=32) both 4096/4096 both 4096/4096
emulated, LEONIDA_MESH_COMPUTE=1 (default 64-wide, and VKH_SUBGROUP_SIZE=32 → 4 × 32-wide subgroups per 128-thread group, the RTX 5070 condition) both 4096/4096 both 4096/4096

(vk_harness.cpp:781-784 applies VKH_SUBGROUP_SIZE to the mesh-as-compute pipeline, and COMPUTE is requirable here, so the 32-wide case really ran 32-wide.)

So AMD's timing hides the both-senders case; the frame alone can't show the fix here. GPU-assisted validation does show the race (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1, emulated mesh-as-compute, 32-wide):

main + fixtures #4247 + fixtures
ms_tri 6× SharedMemoryDataRace-RaceOnStore: lane 32 vs lane 95 (logical wave 0 vs wave 1), two different stores (OpStore %285 / %286) 6× SharedMemoryDataRace-RaceOnStore, but a different one: lane 33 vs lane 32, "two invocations executing the same instruction" (OpStore %6 %406)
ms_wave_info_s3 6×, lane 33 vs 32 6×, lane 97 vs 96
native MeshEXT (emulated) no race reported no race reported (I didn't check whether GPU-AV's shared-memory check covers the mesh stage)

Reading: #4247 removes the cross-wave race on ms_tri (the 32↔95 pair is gone). What is left is several lanes of one wave storing through the same instruction to one shared word. That is a single-writer issue of the kind #4247's title targets, but at a store it doesn't cover yet. That store may be the ms_counts header store @Kam471 mentions above for #4272. These are message IDs, not VUIDs. No other validation errors.

So on AMD, these fixtures are a GPU-AV regression check rather than a pixel one. If they should also fail visibly on AMD, they would need a check that doesn't depend on timing.

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

@theswiss24

Copy link
Copy Markdown

Ran both fixtures on NVIDIA GeForce RTX 4070 (Ada), driver 621.24, Windows 11 (26300), Vulkan SDK 1.4.363.1, llvm-mc 21.1.8, test programs built from main 03b09a08. On this GPU, ms_tri does not show the bug without #4247.

Trees: this PR at 5079b487 merged onto main 03b09a08 (#4247 not included), and the same plus #4247 at 5f16276d. Command: LEONIDA_W64_EMULATE=1 [LEONIDA_MESH_COMPUTE=1] python -I scripts/run_gpu_tests.py --filter <fixture>.

without #4247 with #4247
ms_tri, mesh-as-compute PASS 4096/4096 PASS 4096/4096
ms_wave_info_s3, mesh-as-compute PASS 4096/4096 PASS 4096/4096
ms_tri, native mesh PASS 4096/4096 PASS 4096/4096
ms_wave_info_s3, native mesh PASS 4096/4096 PASS 4096/4096

The mesh-as-compute runs did take that path (mesh compute VS: ms_tri.mesh_vs.spv), and the tested ms_tri.asm has the new s_barrier right after MSG_GS_ALLOC_REQ. Where your RTX 5070 gives 0/4,096 for "both waves send, then barrier" without #4247, the 4070 renders the full triangle. So the regression check depends on how the race resolves on the GPU and passes on Ada without the fix. The fixtures themselves pass everywhere with #4247. No game files.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit b6d0811 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
darProfitTrailer pushed a commit to darProfitTrailer/Leonida that referenced this pull request Nov 23, 2026
… 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>
(cherry picked from commit b40aa12)
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.

5 participants