Shaders: a mesh primitive naming a vertex no lane writes is culled #2926

Open
0xkn0wh3r3 wants to merge 1 commit from upstream-pr/2928 into main
0xkn0wh3r3 commented 2026-11-26 00:18:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T00:18:39Z.


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:

  • one at or past the vertices the program declares;
  • one past its group's threads (each lane writes its own vertex).

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_indices culls indices at or past min(max_vertices, threads)). Credited with Co-authored-by: DexNom.

Open #587 culls only at or past max_vertices, and it masks indices with 0x3FF, 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_ones now also draws:

    • (0, 1, 2) with 64 vertices declared: drawn;
    • (0, 1, 40) with 64 declared: nothing lit;
    • (0, 1, 33) with 32 declared: nothing lit.

    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 (with VICTORY_DXIL = dxil.dll 1.6): 298 passed. The same four tests fail on main on this machine: heap_direct_texture_reads_mark_their_heap_index (skipped, crashes), two stride_tests and gathers_at_a_level_match_the_hardware.

  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Not tested

  • Not run with the title, so I haven't counted how many of its mesh programs export such primitives.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6616549842 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T00:18:39Z. --- ## 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: - one at or past the vertices the program declares; - one past its group's threads (each lane writes its own vertex). 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](https://github.com/DexNom/VIctory/commit/570a941e9b4e945121c26eb30dfc10c126845207) (`emit_indices` culls indices at or past `min(max_vertices, threads)`). Credited with `Co-authored-by: DexNom`. Open #587 culls only at or past `max_vertices`, and it masks indices with `0x3FF`, 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_ones` now also draws: - (0, 1, 2) with 64 vertices declared: drawn; - (0, 1, 40) with 64 declared: nothing lit; - (0, 1, 33) with 32 declared: nothing lit. 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` (with `VICTORY_DXIL` = `dxil.dll` 1.6): 298 passed. The same four tests fail on main on this machine: `heap_direct_texture_reads_mark_their_heap_index` (skipped, crashes), two `stride_tests` and `gathers_at_a_level_match_the_hardware`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. ## Not tested - Not run with the title, so I haven't counted how many of its mesh programs export such primitives.
kotekompotek commented 2026-11-26 01:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:27:21Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066903561 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928#pullrequestreview-6066903561). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:27:21Z. **Review:** COMMENTED --- 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 commented 2026-11-26 01:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:28:23Z.

Review: COMMENTED


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 unsigned pred::IUGE(i, written) across the three 9-bit corner indices into the bit-31 culled predicate 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.rs is 521,268 B (3,020 B below 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 of primitive_export_indices_drop_the_edge_flags and native RTX 5090 + WARP mesh rendering of edge_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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066910524 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928#pullrequestreview-6066910524). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:28:23Z. **Review:** COMMENTED --- 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 unsigned `pred::IUGE(i, written)` across the three 9-bit corner indices into the bit-31 `culled` predicate 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.rs` is `521,268 B` (`3,020 B` below 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 of `primitive_export_indices_drop_the_edge_flags` and native RTX 5090 + WARP mesh rendering of `edge_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.
cloph-dsp commented 2026-11-26 01:04:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T00:33:29Z.


Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup.

  • cargo test --locked -p victory-shader --lib -- emit::tests::edge_flagged_triangles_draw_as_unflagged_ones --exact --quiet -> 1 passed, 0 failed, 304 filtered out (CARGO_BUILD_JOBS=2).
  • Diff against merge-base 842b0cb: 3 files, +34/-14. git diff --check flags trailing whitespace in README.md:17 (displayed. ) — worth fixing.
  • Negative control: edge_flagged_triangles_draw_as_unflagged_ones already exists on the base, so the new risk is the added (0,1,40)/64 and (0,1,33)/32 cases; the extended test passes here.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7178879638 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928#issuecomment-7178879638). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T00:33:29Z. --- Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no clippy/rustup. - `cargo test --locked -p victory-shader --lib -- emit::tests::edge_flagged_triangles_draw_as_unflagged_ones --exact --quiet` -> 1 passed, 0 failed, 304 filtered out (CARGO_BUILD_JOBS=2). - Diff against merge-base 842b0cb: 3 files, +34/-14. `git diff --check` flags trailing whitespace in README.md:17 (`displayed. `) — worth fixing. - Negative control: `edge_flagged_triangles_draw_as_unflagged_ones` already exists on the base, so the new risk is the added `(0,1,40)/64` and `(0,1,33)/32` cases; the extended test passes here. AI-assisted (Hy4 flash).
Marvisak commented 2026-11-26 05:04:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:24:54Z.


Automated triage for the maintainers.

Needs work. emit_indices in emit/lower.rs now culls a mesh primitive when any corner index is at or past min(max_vertices, threads); the code reads correctly and keeps the 9-bit masking. But a corner naming an unwritten vertex is undefined on the console too, the only evidence is the synthetic host-GPU test, and the title was not run, so it is unknown whether any title mesh program exports such primitives; culling them changes emulation behaviour. It also covers only part of the case, since mesh_prologue declares the maximum counts rather than the real allocation. Please show a title draw where this produces a stray triangle, or a hardware or ISA reference for what GFX10 does with such indices.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182574075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928#issuecomment-7182574075). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:24:54Z. --- <!-- victory-triage v1 head=cb22e848853bd858151751a8d928bd9eab04f0ed verdict=needs-work at=2026-11-26T04:24:46Z --> Automated triage for the maintainers. **Needs work.** `emit_indices` in `emit/lower.rs` now culls a mesh primitive when any corner index is at or past `min(max_vertices, threads)`; the code reads correctly and keeps the 9-bit masking. But a corner naming an unwritten vertex is undefined on the console too, the only evidence is the synthetic host-GPU test, and the title was not run, so it is unknown whether any title mesh program exports such primitives; culling them changes emulation behaviour. It also covers only part of the case, since `mesh_prologue` declares the maximum counts rather than the real allocation. Please show a title draw where this produces a stray triangle, or a hardware or ISA reference for what GFX10 does with such indices. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
0xkn0wh3r3 commented 2026-11-26 08:03:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:21:43Z.


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: mesh_prologue declares the maximum counts, so a corner below max_vertices but past the program's own GS_ALLOC_REQ vertex count isn't culled. Covering that would mean culling at the allocated count. It's your call whether the cull belongs in the tree without a console reference. If not, I'll close this.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185373131 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2928#issuecomment-7185373131). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:21:43Z. --- 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: `mesh_prologue` declares the maximum counts, so a corner below `max_vertices` but past the program's own GS_ALLOC_REQ vertex count isn't culled. Covering that would mean culling at the allocated count. It's your call whether the cull belongs in the tree without a console reference. If not, I'll close this.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2928:upstream-pr/2928'
git switch 'upstream-pr/2928'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2928'
git switch 'upstream-pr/2928'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2928'
git switch 'upstream-pr/2928'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2928'
git switch 'main'
git merge --squash 'upstream-pr/2928'
git switch 'main'
git merge --ff-only 'upstream-pr/2928'
git switch 'main'
git merge 'upstream-pr/2928'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2926
No description provided.