Repository navigation
Shaders: a mesh primitive naming a vertex no lane writes is culled - #2928
0xkn0wh3r3 wants to merge 1 commit into
Conversation
A mesh program's primitive export names three vertices (9-bit indices); only the culling bit culled it. A corner at or past the vertices the program declares, or past its group's threads (each lane writes its own vertex), names a vertex whose outputs are undefined: the host drew a stray triangle from whatever they held (seen on the hardware adapter with a corner of 40 in a 32-lane program declaring 64 vertices). Such a primitive is now culled, as one with the culling bit; the 9-bit indices and edge flags are as before. Test: edge_flagged_triangles_draw_as_unflagged_ones also draws triangle (0, 1, 2) with 64 vertices declared (drawn), (0, 1, 40) with 64 and (0, 1, 33) with 32 (nothing lit; the first lit texels before the change), on the hardware adapter and WARP. From DexNom/VIctory@570a941 (emit_indices culling indices past min(max_vertices, threads)). Co-authored-by: DexNom <29156494+DexNom@users.noreply.github.com>
kotekompotek
left a comment
There was a problem hiding this comment.
Sound cull rule: written = min(max_vertices, threads) — each lane writes its own vertex index, so a corner naming a vertex at/past what any lane produced reads undefined outputs; folding it into the existing culled OR-chain keeps the select-then-emit path unchanged. LGTM.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head cb22e848 cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 native mesh shaders + D3D12 WARP + VICTORY_D3D12_DEBUG=1 + Windows SDK 10.0.26100.0 dxil.dll).
Code & Semantics Review
- Computing
written = m.max_vertices.min(threads)and ORing unsignedpred::IUGE(i, written)across the three 9-bit corner indices into the bit-31culledpredicate cleanly culls primitives referencing unwritten vertex slots (>= min(max_vertices, threads)) with zero LDS or cross-lane synchronization overhead, while preserving edge-flag masking and existing bit-31 culls. - File size:
crates/victory-shader/src/emit/lower.rsis521,268 B(3,020 Bbelow the 512 KiB policy cap).
Local Verification (RTX 5090 Mesh Shaders + WARP + dxil.dll + VICTORY_D3D12_DEBUG=1)
cargo test --locked -p victory-shader --lib -- emit::lower::tests emit::tests:: emit::flow_tests: 51/51 passed (including DXIL validation ofprimitive_export_indices_drop_the_edge_flagsand native RTX 5090 + WARP mesh rendering ofedge_flagged_triangles_draw_as_unflagged_ones).cargo clippy --locked -p victory-shader --tests -- -D warnings(default and--all-features) &cargo xtask policy(191 files ok): clean.
Looks clean and ready to merge.
|
Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup.
AI-assisted (Hy4 flash). |
…-culled) into demo
|
Automated triage for the maintainers. Needs work. CI: passing. Generated by Claude Code |
|
There's no public hardware reference for this case. The RDNA2 ISA guide covers primitive-shader exports only as far as the allocation request: §11.3 (p.100), and §12.5.1 (p.129) for GS_ALLOC_REQ's vertex and primitive counts in M0. It doesn't give the primitive export's index layout, or what the hardware does with an index past the allocated vertices. I also can't show a title draw here, so on the console side it stays unknown. What is defined is the host side. The D3D12 mesh shader spec makes a primitive whose vertices weren't all written undefined behaviour. That's what the PR's test shows on an RTX 5070 Ti: triangle (0, 1, 40) from a 32-lane program declaring 64 vertices drew texels from whatever vertex 40 held. Whatever the console does with such an index, that vertex has no written outputs there either. So the cull replaces undefined host output with nothing drawn; it doesn't replace a defined console result. Agreed that it covers only part of the case: |
What
A mesh program's primitive export names three vertices (9-bit indices), and on main only the culling bit (bit 31) culled a primitive. A corner can also name a vertex that no lane writes:
That vertex's outputs are undefined, and the host drew a stray triangle from whatever they held. On the RTX 5070 Ti, triangle (0, 1, 40) from a 32-lane program declaring 64 vertices lit texels.
Such a primitive is now culled, the same way as one with the culling bit. The 9-bit indices and edge flags are unchanged.
Where it came from
From DexNom's fork, DexNom/VIctory@570a941 (
emit_indicesculls indices at or pastmin(max_vertices, threads)). Credited withCo-authored-by: DexNom.Open #587 culls only at or past
max_vertices, and it masks indices with0x3FF, which would also cull edge-flagged primitives. That's why this is a separate small PR, not a comment on #587.Tested
emit::tests::edge_flagged_triangles_draw_as_unflagged_onesnow also draws:This ran on the hardware adapter and WARP. Before the change, the (0, 1, 40) case lit texels on hardware.
cargo test -p victory-shader(withVICTORY_DXIL=dxil.dll1.6): 298 passed. The same four tests fail on main on this machine:heap_direct_texture_reads_mark_their_heap_index(skipped, crashes), twostride_testsandgathers_at_a_level_match_the_hardware.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Not tested