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

Closed
leonida/mandy
vinceychu wants to merge 0 commits from shader-mesh-shared-limit into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

vinceychu commented 2026-11-26 00:21:13 +00:00

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

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
qhukz13 commented 2026-11-26 00:40:44 +00:00

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

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 commented 2026-11-26 10:20:12 +00:00

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)

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)
Tauwni commented 2026-11-26 13:48:57 +00:00

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.

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.
sodove commented 2026-11-28 09:14:24 +00:00

#2155 | head c9a480e374ab47242800f4fec985675bf853c15a | python3 -I tests/semantic/test_ms_shared_memory_limit.py -v | red: 7 tests, 1 assertion failure, 6 errors | green: 7 passed | Red → green

The baseline CLI rejects the new option and the translator lacks the new mesh-memory setting.

Pinned main 4938673668d807bf365b61284bf22b1ff8d02cc4, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. Batch claim.

#2155 | head `c9a480e374ab47242800f4fec985675bf853c15a` | `python3 -I tests/semantic/test_ms_shared_memory_limit.py -v` | red: 7 tests, 1 assertion failure, 6 errors | green: 7 passed | **Red → green** The baseline CLI rejects the new option and the translator lacks the new mesh-memory setting. Pinned main `4938673668d807bf365b61284bf22b1ff8d02cc4`, merged into the PR head. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Full suite: not run. AI-assisted: OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7236982945).
zmasi commented 2026-11-28 12:32:19 +00:00

#2155 | head c9a480e374ab47242800f4fec985675bf853c15a (merged cleanly onto main d48a957bb9988afce424552a3c0c8d01ef12320f) | Windows 11 (10.0.26200), CPython 3.12.10, llvm-mc (gfx1013), spirv-val (1.4.363.1), NVIDIA GeForce RTX 3090 (Vulkan 1.4.341, driver 610.88, VK_EXT_mesh_shader, maxMeshSharedMemorySize = 28672, LEONIDA_VK_VALIDATION=1)

  • Red on main (d48a957bb9988afce424552a3c0c8d01ef12320f):
    • tests/semantic/test_ms_shared_memory_limit.py: FAILED (failures=1, errors=6) (AttributeError: module 'rdna2spirv' has no attribute 'MAX_MESH_SHARED_BYTES', CLI rejects --max-mesh-shared-memory).
  • Green on PR + main:
    • python -I tests/semantic/test_ms_shared_memory_limit.py -v: 7/7 pass (OK); python -I tests/semantic/test_cs_shared_memory_limit.py -v: pass (OK).
    • Live RTX 3090 VK_EXT_mesh_shader check on ms_shared_limit.asm (--wave64-emulate, spirv-val clean): RTX 3090 reports maxMeshSharedMemorySize = 28672 (28 KiB). With default --max-mesh-shared-memory 0, both 16 KiB (lds_bytes = 17488) and 64 KiB (lds_bytes = 66640) modules translate and vk_pipeline_check compiles the 16 KiB MeshEXT pipeline on RTX 3090 (ms pipelines: 1 ok, 0 failed, 0 validation errors) while rejecting the 64 KiB module (workgroup memory 66640 bytes exceeds maxMeshSharedMemorySize 28672); passing --max-mesh-shared-memory 28672 (or 49152) refuses the oversized module up front at translation with exact byte counts (MS workgroup memory 66640 B (LDS 65536 B + wave64 exchange 1100 B + %ms_counts 4 B)).
    • scripts/check_no_game_data.py, test_docs_encoding.py, and test_text_write_line_endings.py: pass (0 CRLF).

AI-assisted.

#2155 | head `c9a480e374ab47242800f4fec985675bf853c15a` (merged cleanly onto `main` `d48a957bb9988afce424552a3c0c8d01ef12320f`) | Windows 11 (`10.0.26200`), CPython `3.12.10`, `llvm-mc` (`gfx1013`), `spirv-val` (`1.4.363.1`), NVIDIA GeForce RTX 3090 (Vulkan `1.4.341`, driver `610.88`, `VK_EXT_mesh_shader`, `maxMeshSharedMemorySize = 28672`, `LEONIDA_VK_VALIDATION=1`) - **Red on `main` (`d48a957bb9988afce424552a3c0c8d01ef12320f`)**: - `tests/semantic/test_ms_shared_memory_limit.py`: `FAILED (failures=1, errors=6)` (`AttributeError: module 'rdna2spirv' has no attribute 'MAX_MESH_SHARED_BYTES'`, CLI rejects `--max-mesh-shared-memory`). - **Green on `PR + main`**: - `python -I tests/semantic/test_ms_shared_memory_limit.py -v`: `7/7` pass (`OK`); `python -I tests/semantic/test_cs_shared_memory_limit.py -v`: pass (`OK`). - Live RTX 3090 `VK_EXT_mesh_shader` check on `ms_shared_limit.asm` (`--wave64-emulate`, `spirv-val` clean): RTX 3090 reports `maxMeshSharedMemorySize = 28672` (`28 KiB`). With default `--max-mesh-shared-memory 0`, both `16 KiB` (`lds_bytes = 17488`) and `64 KiB` (`lds_bytes = 66640`) modules translate and `vk_pipeline_check` compiles the `16 KiB` `MeshEXT` pipeline on RTX 3090 (`ms pipelines: 1 ok, 0 failed`, `0` validation errors) while rejecting the `64 KiB` module (`workgroup memory 66640 bytes exceeds maxMeshSharedMemorySize 28672`); passing `--max-mesh-shared-memory 28672` (or `49152`) refuses the oversized module up front at translation with exact byte counts (`MS workgroup memory 66640 B (LDS 65536 B + wave64 exchange 1100 B + %ms_counts 4 B)`). - `scripts/check_no_game_data.py`, `test_docs_encoding.py`, and `test_text_write_line_endings.py`: pass (`0` CRLF). AI-assisted.
vinceychu commented 2026-11-28 16:35:15 +00:00

Discord: .fountainhead. (for the Contributor role check).


Generated by Claude Code

Discord: `.fountainhead.` (for the Contributor role check). --- _Generated by [Claude Code](https://claude.ai/code)_
timbot103 reviewed 2026-11-29 04:27:59 +00:00
timbot103 left a comment
No description provided.
Static audit of `c9a480e37` only. No builds, tests, or GPU runs. The MeshEXT total agrees with `lds_bytes` for `%lds`, `%ms_counts`, and the optional `%x_buf`. The Workgroup objects use 32-bit scalar elements throughout. Vertex and primitive staging lives in Function storage, and the exported arrays and structs use Output storage. On current main, `--mesh-serial-waves` sizes the exchange for one 64-lane wave and keeps per-pass export copies in Function storage. - [MAJOR] `tools/rdna2spirv.py:16702` — `--mesh-compute` now refuses the 65,540 B module made by the new fixture with 65,536 B of group-shared memory, even with both caps omitted. The base emitted that GLCompute module because the old compute check ran only for source stage `cs`. Please preserve the fallback's default acceptance and apply its cap when explicitly supplied, or document and justify the new hard default. - [MINOR] `docs/design.md:435` — Document passing `min(maxMeshSharedMemorySize, maxMeshPayloadAndSharedMemorySize)` in the CLI help and mesh docs. For a 65,536 B shared limit and 32,768 B combined limit, the current advice accepts the fixture's 32,772 B module at translation, and `runtime/src/vulkan_mesh_limits.h:39` refuses it. VUIDs `08754` and `08755` both apply with a zero-byte task payload. - [MINOR] `tests/semantic/test_ms_shared_memory_limit.py:30` — Please use `support.TOOLS_DIR` for the subprocess. With `LEONIDA_TOOLS_DIR` set to a translator copy missing just the new CLI flag, the subprocess currently exercises the checkout's working CLI and can mask the regression. AI-assisted.
OreoFR commented 2026-11-29 19:17:51 +00:00

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, spirv-tools + llvm-mc, main 7c330c76d (also merges cleanly on current main dd87aa405; does not force a rebase of #2566), PR head c9a480e37 : red 7 failures/errors / green 7 OK, 0 skipped — but open review requests

  • Red: test_ms_shared_memory_limit 0/7 (1 failure, 6 errors: MAX_MESH_SHARED_BYTES missing). Green: 7/7, 0 skipped.
  • Semantic suite (scripts/run_semantic_tests.py, 529+ files, ~6 530 tests) and the CI translator-tests pytest selection: identical to main (main's known failures only: test_interp_computed_ij_fallback x2, test_mesh_serial_waves x6).
  • Rule check: tests/semantic/fixtures/ms_shared_limit.asm and the docs/design.md row are present.
  • Open review requests after the last commit (timbot103, 29/11, on this head), not addressed yet: [MAJOR] --mesh-compute now rejects the 65 540-byte module by default (compute cap applies); [MINOR] document min(maxMeshSharedMemorySize, maxMeshPayloadAndSharedMemorySize); [MINOR] the test still uses support.ROOT instead of support.TOOLS_DIR (line 30).

Verdict: tests READY, not mergeable until those review requests are answered.

AI-assisted: Claude Code

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, spirv-tools + llvm-mc, main 7c330c76d (also merges cleanly on current main dd87aa405; does not force a rebase of #2566), PR head c9a480e37 : red 7 failures/errors / green 7 OK, 0 skipped — but open review requests - **Red**: `test_ms_shared_memory_limit` 0/7 (1 failure, 6 errors: `MAX_MESH_SHARED_BYTES` missing). **Green**: 7/7, 0 skipped. - Semantic suite (`scripts/run_semantic_tests.py`, 529+ files, ~6 530 tests) and the CI translator-tests pytest selection: identical to main (main's known failures only: `test_interp_computed_ij_fallback` x2, `test_mesh_serial_waves` x6). - Rule check: `tests/semantic/fixtures/ms_shared_limit.asm` and the `docs/design.md` row are present. - **Open review requests after the last commit** (timbot103, 29/11, on this head), not addressed yet: [MAJOR] `--mesh-compute` now rejects the 65 540-byte module by default (compute cap applies); [MINOR] document `min(maxMeshSharedMemorySize, maxMeshPayloadAndSharedMemorySize)`; [MINOR] the test still uses `support.ROOT` instead of `support.TOOLS_DIR` (line 30). **Verdict: tests READY, not mergeable until those review requests are answered.** AI-assisted: Claude Code
aslan2142 reviewed 2026-12-01 11:48:44 +00:00
aslan2142 left a comment
No description provided.
This PR cannot merge in its current state: 1. **Regression under `--mesh-compute`**: at `tools/rdna2spirv.py:16702-16703`, `--mesh-compute` now applies `MAX_SHARED_BYTES` (`maxComputeSharedMemorySize`) even when both caps are omitted, refusing the 65,540 B module produced from the 65,536 B group-shared fixture that `main` previously accepted (since `main` only checked source stage `cs`). Please preserve default acceptance when caps are unset or explicitly gate and document this change. 2. **Merge conflict** with `main` and **failing CI** (`linux-gpu-tools`, `macos`, `macos-python`, `windows`, `check`). Please address the `--mesh-compute` default behavior, rebase onto current `main`, and obtain a green CI run. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:42:46 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.