Skip to content

rdna2spirv: --mesh-serial-waves under --mesh-compute too (SHADER-W64-MESH-SERIAL-COMPUTE) - #2506

Open
qhukz13 wants to merge 7 commits into
ProjectLeonida:mainfrom
qhukz13:cont/mesh-serial-compute
Open

qhukz13 wants to merge 7 commits into
ProjectLeonida:mainfrom
qhukz13:cont/mesh-serial-compute

Conversation

@qhukz13

@qhukz13 qhukz13 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-W64-MESH-SERIAL-COMPUTE: #1608 (comment)

Depends on: #2435 (this branch is its head ad1789d7e plus one commit).

What and why

#2435's --mesh-serial-waves runs an emulated mesh program's waves one after the other, one single-wave pass each, instead of side by side under mini-schedulers. It was off under --mesh-compute, the path for GPUs without VK_EXT_mesh_shader (NVIDIA Pascal and older). Those are also 32-wide GPUs, where every mesh program is wave64-emulated, so they are the ones that pay most for the side-by-side form.

With this change the compute program takes the same passes. Its slot writes (mesh_compute_epilogue) go through ms_serial_epilogue like the mesh epilogue:

  • one barrier and one read of %ms_counts, after the passes;
  • then, per pass, the vertex and primitive stores from that pass's copies of the export variables, at the built-in index + 64 * pass;
  • the slot header is written by index 0, which only lane 0 of pass 0 has.

mesh_compute_epilogue now returns its lines, and assemble indents them, as it already does for the mesh epilogue. Without the flag the output is unchanged.

The metadata keeps the program's thread count in local_size, as #2435 does for mesh. The runtime reads it only for the whole-subgroup and invocation-limit checks (READ IN CODE: runtime/src/subgroup_size.h:135 and :142), and 64 passes both. The docs/design.md row of #2435 now covers this case, and docs/testing.md says how to run it.

Tested

GPUs tested: NVIDIA GeForce GTX 1050 Ti 4 GB desktop (profile S), driver 582.66, Windows 10 19045. Every number below is MEASURED on that machine (n=1 per run unless given); no game files were used.

GTX 1050 Ti 4 GB, NVIDIA 582.66, Windows 10 19045; llvm-mc 21.1.8, Vulkan SDK 1.4.363:

Not measured: the frame time in game (no game files on this machine yet), and other vendors on this path.

AI-assisted: yes (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

quartz-heron-58 and others added 7 commits November 27, 2026 10:58
… other in 64 invocations (work in progress)

Under --wave64-emulate a mesh program of more than 64 threads (a multiple
of 64, no LDS instruction, not --mesh-compute) declares 64 invocations and
runs one pass per wave: the invocation's index is the built-in plus 64 x
pass, every initialised Function variable is set again per pass, the
exports of a pass are copied to per-pass twins, and the epilogue sets the
counts once and writes each pass's outputs. Each pass is one wave, so the
plan is the single-wave one and the exchange buffer is one wave's.

Off by default; with the flag off the output is unchanged. Work in
progress for SHADER-W64-MESH-SERIAL-WAVES: no test or docs row yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ory writes in a serial program (work in progress)

ms_w64x_wave_votes: two waves take different branches, each with its own
ballot count (and a v_readfirstlane in the second), and the triangle's
vertices come from threads 0 and 1 of the first wave and thread 64 of the
second, so ms_tri's picture needs both waves to have run their own branch
with their own votes. It passes in the side-by-side form and with
--mesh-serial-waves on an RTX 4080 (NVIDIA 621.24).

A program with a store or an atomic to memory keeps the side-by-side
form, as one with LDS does: its waves could pass each other something.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
tests/test_mesh_serial_waves.py: the module shape of a program that
qualifies (64 invocations, the pass loop, the index from the built-in,
the exchange's own place, per-pass copies of the exports, one
OpSetMeshOutputsEXT), that every initialised Function variable is set
again per pass, and that ms_wave_info_s3 (LDS), a 32-thread program,
native wave64 and --mesh-compute are unchanged by the flag.

LEONIDA_MESH_SERIAL_WAVES=1 is read by scripts/run_gpu_tests.py, like the
other translation switches, and no longer by rdna2spirv.py itself.
docs/design.md and docs/testing.md say what the flag does and how it is
tested; conftest gives ms_w64x_wave_votes its 128-vertex PSV0.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A variant of ms_w64x_wave_votes with an s_endpgm behind a branch in the middle of the program:
the module still qualifies, validates, and main keeps one return, after the loop over the passes
and the output writes. Suggested in review by tiguan26.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nt length

ms_w64x_wave_loops: each wave loops while a wave-wide count is not 0, 5 iterations in wave 0 and 9 in
wave 1, so under --wave64-emulate the waves reach different numbers of workgroup barriers. Written after
stalls were reported with the serial form on an RTX 2070 SUPER (issue 1608). On an RTX 4080 (NVIDIA
621.24) it draws 4096/4096 pixels exact side by side and in series; that does not explain the stalls.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
docs/design.md: keep the new row and take main's text of the row below it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…MESH-SERIAL-COMPUTE)

GPUs without VK_EXT_mesh_shader (NVIDIA Pascal) translate mesh programs with --mesh-compute and are the ones that
need wave64 emulation most, but the switch was off there. The compute program now runs the same passes, and
mesh_compute_epilogue's slot writes go through ms_serial_epilogue: the header from index 0, which only pass 0's
lane 0 has, and each pass's vertices and primitives at the built-in index + 64 * pass, from that pass's copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timbot103

Copy link
Copy Markdown
Contributor

Independently verified head 29361079f on Windows 11 Pro 26200, Vulkan SDK 1.4.363.0, WSL llvm-mc 21.1.8, across both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02), no game files.

Dual-GPU Vulkan-validated verification (scripts/run_gpu_tests.py --filter ms_w64x, LEONIDA_W64_EMULATE=1, LEONIDA_VK_VALIDATION=1):

  • Mesh shader path (ms_w64x_ballot, ms_w64x_wave_loops, ms_w64x_wave_votes): 3/3 spirv-val clean; 3/3 PASS (4096/4096 pixels exact) on RTX 5080 and 3/3 PASS (4096/4096 pixels exact) on AMD Radeon, 0 validation errors.
  • LEONIDA_MESH_COMPUTE=1 path (same 3 fixtures): 3/3 spirv-val clean; 3/3 PASS (4096/4096 pixels exact) on RTX 5080 and 3/3 PASS (4096/4096 pixels exact) on AMD Radeon, 0 validation errors.

Static code review notes (3 edge cases worth double-checking):

  1. MUBUF/global DMA-to-LDS (lds modifier): the eligibility filter excludes ds_ instructions, stores, and atomics, but a MUBUF/global load with the lds modifier writes LDS without starting with ds_ — excluding instructions with an lds modifier keeps the no-LDS invariant exact.
  2. Early shader exits inside the pass loop: if an s_endpgm (or OpReturn/OpKill) occurs on a branch inside a pass, returning directly from the loop would skip remaining passes and the shared epilogue (SetMeshOutputs / mesh-compute header writes). Confirming/ensuring early exits branch to %msw_cont (with a unit fixture) guards against this.
  3. Direct built-in reads: verifying that nothing in the ms_serial path reads LocalInvocationID, SubgroupId, or SubgroupLocalInvocationId directly (bypassing the per-pass + 64 * w %local_index) confirms all wave indexing follows the pass variable.

Overall looks very clean and passed both mesh and mesh-compute paths identically on Blackwell and AMD Radeon. AI-assisted.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Fixed-wave64 hardware check at 29361079: gfx906, RADV Mesa 26.0.8, subgroup size 64 only, no VK_EXT_mesh_shader. All eight synthetic mesh-compute fixtures passed in each of four runs: native wave64, native + serial flag, emulated wave64, and emulated + serial flag. Only the last run serialized anything: six modules used two 64-invocation passes. The two ineligible modules were byte-identical with the flag on and off.

The wave-votes and wave-loops fixtures both exported vertices 0, 1 and 64. Their output slots matched the independent expected bytes and all 4,096 pixels matched in every run. Making either wave produce the wrong value in a private control made the pixel check fail. All compute modules and companion vertex modules passed spirv-val; no Khronos validation or synchronization errors in the four hardware runs. This verifies the compute fallback on fixed wave64, not execution on a wave32 device.

AI-assisted.

@ecox982745

ecox982745 commented Nov 28, 2026 •

Copy link
Copy Markdown

I tested this PR at 29361079f together with the updated wave-0 LDS branch at 46995668d. On Windows with a GeForce RTX 4090 (driver 616.64, subgroup 32..32), all 16 synthetic draws matched the expected image bit for bit. This covers native mesh and forced mesh-as-compute, each with serial waves off and on. Wave64 emulation was enabled throughout.

Synthetic shader Serial enabled, native mesh and compute
ms_w64x_lds_wave0 Two 64-invocation passes. The second wave read the first wave’s shared-memory values and supplied the expected vertex color.
ms_w64x_wave_votes, ms_w64x_wave_loops Both selected two passes and drew the expected triangle.
ms_wave_info_s3 Stayed at 128 invocations. Within each backend its module was byte-identical with serial waves off and on.

For each configuration I checked the SPIR-V entry point and local size, then compared all 4,096 RGBA32F pixels with the expected gradient. A second draw of each configuration produced the same bytes. No Vulkan validation errors appeared. The compute checks used the generated vertex shader and the harness reported a compute dispatch on the same GPU.

For the local integration I retained the LDS branch’s eligibility check, removed its compute-mode veto, and applied this PR’s compute epilogue changes. The combined tools/rdna2spirv.py Git blob is 4feddb71bbb959c07937e2d658dc30f3f5e08b9a. These checks cover shader output on the synthetic fixtures. Game stability and frame rate were outside this run.

AI-assisted with OpenAI Codex (GPT-6).

The author has since put the LDS branch on hold. In a separate RTX 4080 game test, the author reported device loss in four of seven comparable serial runs and zero of six side-by-side runs. The shader in that report exercises a case beyond these synthetic draws. See the game-run report and corrected run counts.

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

Reviewed 29361079f and tested the new --mesh-compute --mesh-serial-waves path.

Code audit:

  • ms_serial_passes and ms_serial_epilogue cleanly extend serial wave execution to --mesh-compute: LocalSize 64 1 1, per-pass slot writes, header (prim_count / vert_count / flags) written only by pass 0 lane 0, meta["mesh_serial_waves"] == 2, and non-qualifying shaders left unchanged.

Verification:

  • Executed all 31 parametrized cases in tests/test_mesh_serial_waves.py (using a Python harness driving conftest.make_shader since pytest is not installed locally) with llvm-mc (LLVM 21.1.8), spirv-as, and spirv-val (Vulkan SDK 1.4.363.1): 31/31 passed.
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

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.

6 participants