mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:30:53 +01:00
[PR #2397] rdna2spirv: keep mesh primitive indices below the vertex count (SHADER-MESH-PRIM-INDEX-CLAMP) #2398
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2398
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2397
Author: @DadaCap
Created: 11/26/2026
Status: 🔄 Open
Base:
main← Head:mesh-prim-index-clamp📝 Commits (1)
d48d8b3rdna2spirv: keep mesh primitive indices below the vertex count📊 Changes
4 files changed (+139 additions, -23 deletions)
View changed files
📝
docs/design.md(+1 -1)➕
tests/semantic/fixtures/ms_prim_null_clamp.asm(+37 -0)📝
tests/semantic/test_ms_prim_export.py(+72 -9)📝
tools/rdna2spirv.py(+29 -13)📄 Description
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7201444406
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.