Repository navigation
rdna2spirv: keep mesh primitive indices below the vertex count (SHADER-MESH-PRIM-INDEX-CLAMP) - #2397
Conversation
A GFX10 mesh epilogue marks a primitive null (bit 31) when an index field is at or past the vertex count and keeps the field, so a null primitive can carry indices up to 511. Vulkan leaves such an index undefined even on a culled primitive. Both mesh finales (MeshEXT and --mesh-compute) now write index k as null ? 0 : umin(field_k, vertex count - 1), as Mesa clamps them, and a primitive count of 0 when the vertex count is 0. CullPrimitiveEXT is unchanged. Test: test_ms_prim_export.py gains MeshNullPrimitiveClamp with a hand-written 128-thread wave64 fixture at vertex counts 0, 10, 100 and 128; it fails on the old translator. docs/design.md moves the Open note into the mesh primitive export row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
|
Independent check on macOS (not the author's Windows run), applying the PR diff to a clean Negative control (main translator, PR's test and fixture only): With the PR: Full translator suite with the PR (macOS 27.2.1 arm64, CPython 3.15.2, 12 jobs):
AI-assisted (verification only; no game files, no GPU). |
lixonik
left a comment
There was a problem hiding this comment.
On Windows 11, all five test_ms_prim_export tests passed. I also adapted the synthetic fixture to clear the null bit while keeping out-of-range indices. At a vertex count of 10, lanes 1 and 65 produced (9, 9, 9) and lanes 2 and 66 produced (9, 0, 1), with the cull flag clear. Both MeshEXT and --mesh-compute passed this check in the interpreter.
AI-assisted.
|
Both shader paths passed synthetic GPU readbacks on PR head Native mesh draws. I varied the final primitive export in Compute output. I adapted
This verifies the index and primitive-count rules on hardware. Whether the change resolves device loss in a game run remains open. |
|
Retail data from profile M (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11,
So on this driver the mesh-section loss looks gone with this PR. AI-assisted (Claude Code, Claude Opus 5.5). |
|
CORRECTION to my comment above: "4 runs" was wrong. 13 runs used the mesh programs translated with this PR, all on the same machine.
The conclusion stands: no mesh-shader hang with this PR. What remains is a compute-program timeout, a separate issue. |
tiguan26
left a comment
There was a problem hiding this comment.
Approving d48d8b3.
Read ms_prim_indices/ms_prim_count in both finales. A null primitive writes index 0, the others umin(field, vertex count - 1), so no written index reaches past the vertex count, which VK_EXT_mesh_shader leaves undefined even on a culled primitive. With a vertex count of 0 the %mvl subtraction wraps, but ms_prim_count makes the primitive count 0 then, so no primitive is written with it. --mesh-compute still stores the null bit as the fourth word, and CullPrimitiveEXT is untouched.
Merged onto main d1dff7949 together with #2416, #2355, #2357, #2360 and #2366 (no conflicts), on Linux with Python 3.13: test_ms_prim_export.py 5 passed (1,168 subtests); the full translator suite (run_semantic_tests.py tests/semantic) has only the 8 failures main has here (7 in test_fspx_dot4_op_sel_disasm, test_int32_to_f64), and tests/test_translate.py only main's ps_sdwa_f16_const.asm (an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).
|
Merging
AI-assisted review (Antigravity, Gemini 4 Neon). |
Claimed in the coordination issue as: #1608 (comment)
Depends on: none.
What and why
A GFX10 mesh shader exports each primitive with
exp prim: three 10-bit index fields and bit 31, "null primitive (skip)". The NGG epilogues compare each index field with the vertex count. When a field is at or past it, they set bit 31 and leave the fields unchanged, so a null primitive can carry indices up to 511. The hardware skips such a primitive. The translator wrote the 9-bit fields straight intoPrimitiveTriangleIndicesEXTand set onlyCullPrimitiveEXT, butVK_EXT_mesh_shaderleaves an index at or past the vertex count undefined even on a culled primitive. Mesa's own mesh lowering clamps the indices (ac_nir_lower_ngg.cline 4112, Mesa 22.3).docs/design.mdalready listed this as Open in the mesh primitive export row. It is a suspected cause of device losses in mesh draws on NVIDIA, which has no null-primitive path like AMD's. That cause is not confirmed.The rule
In both mesh epilogues, the
MeshEXTfinale inassemble()andmesh_compute_epilogue()for--mesh-compute, through one shared helper (ms_prim_indices,ms_prim_countintools/rdna2spirv.py):null ? 0 : umin(field_k, vertex count - 1). The 9-bit fields still leave out the edge flags.vertex count == 0 ? 0 : min(count, PSV0 max), sovertex count - 1never wraps and no primitive points into an empty vertex array.CullPrimitiveEXT(and the--mesh-computeslot's culled word) is unchanged. Normal primitives with in-range indices are unchanged.No other path writes primitive indices (
PrimitiveLineIndicesEXTor point indices are never emitted). The row in thedocs/design.mdcontract table now states the rule and how it was confirmed, in place of the Open note.Tested
tests/semantic/test_ms_prim_export.pygainsMeshNullPrimitiveClampwith a new hand-written fixture,fixtures/ms_prim_null_clamp.asm(no game data). It runs 128 threads in two wave64 waves at vertex counts 0, 10, 100 and 128. Its null primitives carry fields 300, 511, 0x3FF (bit 9 set), and the vertex count itself; its normal primitives have in-range indices, with and without edge flags. On both paths it checks that every written index is below the vertex count, that null primitives write (0, 0, 0), that normal primitives and cull flags are unchanged, and that the counts become (0, 0) with no vertex. The existing fixture's null primitives now expect (0, 0, 0).mainthe new assertions fail (raw fields such as (300, 511, 511) and (V, 0, 1) written, and counts (0, 128) at vertex count 0). With the change,test_ms_*.pyandtest_mesh*.pyall pass.python -I scripts/run_semantic_tests.py tests/semantic: 500 files, 6,375 tests, 0 files failed (122 s, 24 jobs, Windows 11).spirv-val --target-env vulkan1.2accepts the translated fixture asMeshEXTand with--mesh-compute, plain and with--wave64-emulate.python -m compileall -q tools testsandpython -I scripts/check_no_game_data.pyon the changed files: clean.GPU confirmation in the retail game: pending. The change is checked on the CPU only (semantic interpreter); no GPU was used.
AI-assisted: yes (Claude Code, Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr