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

Open
github-bot wants to merge 1 commit from github-bot/gh-2155 into main AGit
Owner

@⁠vinceychu on GitHub · 2026-11-26 00:21 UTC · original
vinceychu:shader-mesh-shared-limit → main · +230 −4 · 5 files · 1 commits · open

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 (#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

**@⁠vinceychu** on GitHub · 2026-11-26 00:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2155) `vinceychu:shader-mesh-shared-limit` → `main` · +230 −4 · 5 files · 1 commits · open 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 (#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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RAL8MMXUuNpQAVa1iiyAMP
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RAL8MMXUuNpQAVa1iiyAMP
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:30 +00:00
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-26 00:40 UTC · original

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

**@⁠qhukz13** on GitHub · 2026-11-26 00:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2155#issuecomment-7179003734) 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).
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 10:20 UTC · original

Verified on main a73a57e1 (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)

**@⁠real-rusher** on GitHub · 2026-11-26 10:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2155#issuecomment-7189229026) Verified on main a73a57e1 (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)
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 13:48 UTC · original

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.

**@⁠Tauwni** on GitHub · 2026-11-26 13:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2155#issuecomment-7193875683) 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.
github-bot force-pushed github-bot/gh-2155 from d94d97f0a6 to c9a480e374 2026-11-27 00:36:13 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2155/head:github-bot/gh-2155'
git switch 'github-bot/gh-2155'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2155'
git switch 'github-bot/gh-2155'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2155'
git switch 'github-bot/gh-2155'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2155'
git switch 'main'
git merge --squash 'github-bot/gh-2155'
git switch 'main'
git merge --ff-only 'github-bot/gh-2155'
git switch 'main'
git merge 'github-bot/gh-2155'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.