Skip to content

rdna2spirv: --max-mesh-shared-memory checks a mesh shader's Workgroup memory (SHADER-MESH-SHARED-LIMIT) - #2155

Open
vinceychu wants to merge 1 commit into
ProjectLeonida:mainfrom
vinceychu:shader-mesh-shared-limit
Open

vinceychu wants to merge 1 commit into
ProjectLeonida:mainfrom
vinceychu:shader-mesh-shared-limit

Conversation

@vinceychu

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-MESH-SHARED-LIMIT (#1608)

What and why

docs/design.md listed "mesh shaders against maxMeshSharedMemorySize" as not covered. The translator already caps a
compute shader's Workgroup memory (--max-shared-memory); a MeshEXT module had no equivalent.

  • New --max-mesh-shared-memory BYTES (MAX_MESH_SHARED_BYTES): a MeshEXT module whose Workgroup memory (the LDS
    array, the 4-byte %ms_counts and, under --wave64-emulate, %x_buf, the same total lds_bytes records) is over
    it is refused (Unsupported) with the needed and allowed byte counts, e.g.
    MS workgroup memory 32772 B (LDS 32768 B + %ms_counts 4 B) over maxMeshSharedMemorySize 28672 B.
  • The default is 0: no check. A full 64 KiB LDS array plus %ms_counts is already 65,540 B, so any non-zero
    default would refuse mesh shaders that translate today. Pass a device's limit (28,672 is the
    VK_EXT_mesh_shader minimum) to refuse at translation what that device can't run; the runtime keeps checking
    lds_bytes against the device it runs on either way.
  • A --mesh-compute module is GLCompute, so it keeps the compute cap.
  • design.md's row and the d3d12_vulkan.md note say the same.

Tested

  • tests/semantic/test_ms_shared_memory_limit.py (new, 7 tests, hand-written fixture ms_shared_limit.asm, PSV0
    written in the test): under the cap; over it with the byte counts; the exact boundary (32,772 passes, 32,771
    refuses); %x_buf counted under --wave64-emulate; --mesh-compute uses the compute cap; the default refuses
    nothing (65,540 B translates and lds_bytes carries it); the CLI flag end to end.
  • python -I scripts/run_semantic_tests.py tests/semantic: 494 files, 6,325 tests, 0 failed.
  • pytest tests/test_translate.py: 712 passed; the 2 failures are cs_dpp_cmp.asm with LLVM 21, which fail on main
    too (tests: the pytest helper takes a text-only sample's lines as its listing, as run_gpu_tests.py does (TEST-TRANSLATE-TEXT-ONLY) #1375 fixes the helper).
  • python -m compileall -q tools tests: clean.

GPUs tested: n/a (translator-side check; no GPU path changes)

AI-assisted: yes (Claude Code, with a Devin draft reviewed and changed: the default went from 28,672 to 0 after
the existing test_ms_lds_need.py showed real mesh LDS sizes over the spec minimum)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RAL8MMXUuNpQAVa1iiyAMP

@qhukz13

qhukz13 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Checked at d94d97f0a on Linux (Python 3).

  • test_ms_shared_memory_limit.py: 7 tests OK. It catches each of these mutants: wg > limit -> wg >= limit (the exact-boundary case), %x_buf left out of wg, and --mesh-compute checked against the mesh cap instead of the compute cap.
  • I wondered whether wg and the lds_bytes that shader_meta records can differ: assemble always adds gen.x_buf_bytes() for a mesh shader, shader_meta only if g.cs or g.emulate. They can't: without --wave64-emulate, x_buf_bytes() is the barrier-round 12 bytes, and needs_barrier_rounds returns False for any stage but cs, so it is 0 for a mesh shader. The two totals agree, as the description says.
  • Default 0 keeps every mesh shader that translates today, and the runtime check on lds_bytes is unchanged.

Looks right to me.

AI-assisted (Claude Code).

@real-rusher

Copy link
Copy Markdown

Verified on main a73a57e (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly into main. python -m unittest discover -s tests/semantic -p test_ms_shared_memory_limit.py: 7 tests OK with this PR; the same file against main's translator: 1 failure and 6 errors, so it fails on main and passes with the change. compileall clean.

Not run: the whole semantic suite and the translated / spirv-val counts over a corpus (no game data here).

Note for review: it conflicts with #2183 in tools/rdna2spirv.py, so whichever lands later needs a rebase.

AI-assisted: yes (Claude Code)

@Tauwni

Tauwni commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tested d94d97f0a on an Apple M3 (macOS 26.5.1). I ran the full scripts/run_gpu_tests.py in auto mode against main a73a57e13, with test programs built from main.

Driver main this PR
MoltenVK 1.4.2 195 pass, 70 skip 195 pass, 70 skip
MoltenVK, LEONIDA_W64_EMULATE=1 229 pass, 36 skip 229 pass, 36 skip
KosmicKrisp (Mesa 26.3.1) 190 pass, 73 skip 190 pass, 73 skip

No mesh fixture runs on these drivers (no VK_EXT_mesh_shader), so this only shows that the compute and graphics results are unchanged. No new failure. The ones left are the same on both sides: cs_fma_fused (#1724), ps_ssharp (#1774) and cs_imgatomic_ext (#1518) on MoltenVK; KosmicKrisp's (NAN)-constant fixtures (#2229) and cs_imgatomic_ext there.

AI-assisted (Claude Code). No game data.

… memory (SHADER-MESH-SHARED-LIMIT)

design.md listed mesh shaders against maxMeshSharedMemorySize as not covered.
A MeshEXT module's Workgroup memory (the LDS array, the 4-byte %ms_counts and,
under --wave64-emulate, %x_buf) can now be capped at translation with
--max-mesh-shared-memory BYTES, refused with the needed and allowed byte
counts. The default is 0 (no check), so every mesh shader that translated
before still does; a --mesh-compute module keeps the compute cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RAL8MMXUuNpQAVa1iiyAMP
@vinceychu
vinceychu force-pushed the shader-mesh-shared-limit branch from d94d97f to c9a480e Compare November 26, 2026 22:36
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.

4 participants