victory-shader: mask mesh primitive vertex indices to 9 bits (drop edge flags) #1718

Manually merged
github merged 1 commit from gh-pr/1718/head into gh-pr/1718/base 2026-11-26 04:42:33 +00:00
Owner

@⁠tjthebigbearcat-hub on GitHub · 2026-11-24 21:14 UTC · original
tjthebigbearcat-hub:fix/third-pr → main · +188 −7 · 3 files · 1 commits · merged 2026-11-25 00:15 UTC

Summary

Fixes mesh primitive export vertex index unpacking in victory-shader (crates/victory-shader/src/emit/lower.rs and io.rs):

  • Masks exported primitive vertex indices to 9 bits (0x1FF) instead of 10 bits (0x3FF) so hardware edge-flag bits (bits 9, 19, and 29) are not mixed into vertex indices.
  • Previously, any mesh triangle with an edge flag set had its vertex index shifted by +512 (past the mesh shader's max vertex count), causing DirectX 12 to drop or corrupt the primitive.
  • Updates the corresponding bit-layout comment in crates/victory-shader/src/io.rs.

Verification (Windows 11 + SDK dxil.dll + WARP)

  • Added hand-encoded synthetic GFX10 mesh shader tests in crates/victory-shader/src/emit/mod.rs (zero game bytes; verified with xtask asset-policy check):
    • primitive_export_indices_drop_the_edge_flags: validates plain, edge-flagged (0x20280600), and culled triangles against dxil.dll.
    • edge_flagged_triangles_draw_as_unflagged_ones: executes on WARP (D3D12), verifying edge-flagged triangles rasterize all 256 texels identically to unflagged triangles (whereas the previous 0x3FF mask rendered 0/256 texels).
  • cargo test --workspace --locked: all crates pass, 0 failures.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings.
**@⁠tjthebigbearcat-hub** on GitHub · 2026-11-24 21:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1718) `tjthebigbearcat-hub:fix/third-pr` → `main` · +188 −7 · 3 files · 1 commits · merged 2026-11-25 00:15 UTC ### Summary Fixes mesh primitive export vertex index unpacking in `victory-shader` (`crates/victory-shader/src/emit/lower.rs` and `io.rs`): - Masks exported primitive vertex indices to 9 bits (`0x1FF`) instead of 10 bits (`0x3FF`) so hardware edge-flag bits (bits 9, 19, and 29) are not mixed into vertex indices. - Previously, any mesh triangle with an edge flag set had its vertex index shifted by +512 (past the mesh shader's max vertex count), causing DirectX 12 to drop or corrupt the primitive. - Updates the corresponding bit-layout comment in `crates/victory-shader/src/io.rs`. ### Verification (Windows 11 + SDK `dxil.dll` + WARP) - Added hand-encoded synthetic GFX10 mesh shader tests in `crates/victory-shader/src/emit/mod.rs` (zero game bytes; verified with `xtask` asset-policy check): - `primitive_export_indices_drop_the_edge_flags`: validates plain, edge-flagged (`0x20280600`), and culled triangles against `dxil.dll`. - `edge_flagged_triangles_draw_as_unflagged_ones`: executes on WARP (`D3D12`), verifying edge-flagged triangles rasterize all 256 texels identically to unflagged triangles (whereas the previous `0x3FF` mask rendered 0/256 texels). - `cargo test --workspace --locked`: all crates pass, 0 failures. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **0 warnings**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:42:30 +00:00
github manually merged commit c0228d939e into gh-pr/1718/base 2026-11-26 04:42:33 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-24 21:37 UTC · original

The edge-flagged triangle matched the unflagged reference pixel for pixel on both the RTX 5080 (driver 621.24) and built-in Windows WARP. I tested PR head c0228d9 on Windows 11 build 26300.10075 and read back the 16 × 16 RGBA target after each draw.

Triangle Primitive export RTX 5080, pixels lit WARP, pixels lit
Unflagged reference 0x00200400 256/256 256/256
All three edge flags set 0x20280600 256/256 256/256
All three edge flags set, with culling 0xa0280600 0/256 0/256

With all three flags set, every pixel matched the reference RGBA value [1.0, 0.5, 0.25, 1.0] bit for bit. I also set bit 9, bit 19, and bit 29 individually. Each single-bit draw produced 0 differing pixels out of 256 on each adapter. With culling enabled, all four channels were zero across the target on both adapters.

Both original mesh tests passed on the clean PR head. The Windows SDK DXIL validator also accepted the unflagged, flagged, and flagged-and-culled shader variants.

**@⁠steven-seagull27** on GitHub · 2026-11-24 21:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7145180926) The edge-flagged triangle matched the unflagged reference pixel for pixel on both the RTX 5080 (driver 621.24) and built-in Windows WARP. I tested PR head `c0228d9` on Windows 11 build 26300.10075 and read back the 16 × 16 RGBA target after each draw. | Triangle | Primitive export | RTX 5080, pixels lit | WARP, pixels lit | |---|---|---:|---:| | Unflagged reference | `0x00200400` | 256/256 | 256/256 | | All three edge flags set | `0x20280600` | 256/256 | 256/256 | | All three edge flags set, with culling | `0xa0280600` | 0/256 | 0/256 | With all three flags set, every pixel matched the reference RGBA value `[1.0, 0.5, 0.25, 1.0]` bit for bit. I also set **bit 9**, **bit 19**, and **bit 29** individually. Each single-bit draw produced **0 differing pixels out of 256** on each adapter. With culling enabled, all four channels were zero across the target on both adapters. Both original mesh tests passed on the clean PR head. The Windows SDK DXIL validator also accepted the unflagged, flagged, and flagged-and-culled shader variants.
Author
Owner

@⁠kais7654 on GitHub · 2026-11-24 22:32 UTC · original

Reviewed and verified at runtime on a host that caps its heaps
(Windows): cargo check clean, and both new tests pass — the validator
one, and the hardware/WARP draw test (edge-flagged corners drew as
unflagged, the culled export lit nothing). The 9-bit index + edge flag
layout is consistently updated in io.rs; no other 10-bit mesh mask
remains.

**@⁠kais7654** on GitHub · 2026-11-24 22:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7146359388) Reviewed and verified at runtime on a host that caps its heaps (Windows): cargo check clean, and both new tests pass — the validator one, and the hardware/WARP draw test (edge-flagged corners drew as unflagged, the culled export lit nothing). The 9-bit index + edge flag layout is consistently updated in io.rs; no other 10-bit mesh mask remains.
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 23:06 UTC · original

Setup: one laptop with an NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell, 10de:2d59, driver 621.24) and an Intel UHD Graphics (Raptor Lake Xe-LP, 8086:a788, driver 32.0.101.7088), Windows 11 26300, Rust 1.98.1. The PR was merged onto main 70564ae.

  • cargo test --workspace --all-features --locked --no-fail-fast -- --test-threads=1 with the D3D12 debug layer on (VICTORY_D3D12_DEBUG=1, and a local, uncommitted change that also turns the debug layer on in victory-shader's test Host): 477 passed, 5 failed, 7 ignored. The 5 failures are the ones main 70564ae has by itself on NVIDIA (the view-heap cap and the structured-view stride, already reported in #1744); this PR adds none. No new debug-layer messages compared with main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean
  • edge_flagged_triangles_draw_as_unflagged_ones draws on both devices: hardware: edge-flagged triangles drew on the RTX and warp: edge-flagged triangles drew. primitive_export_indices_drop_the_edge_flags passes.

No game data used. AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 23:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7147023279) **Setup:** one laptop with an NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell, `10de:2d59`, driver 621.24) and an Intel UHD Graphics (Raptor Lake Xe-LP, `8086:a788`, driver 32.0.101.7088), Windows 11 26300, Rust 1.98.1. The PR was merged onto `main` `70564ae`. - `cargo test --workspace --all-features --locked --no-fail-fast -- --test-threads=1` with the D3D12 debug layer on (`VICTORY_D3D12_DEBUG=1`, and a local, uncommitted change that also turns the debug layer on in victory-shader's test `Host`): 477 passed, 5 failed, 7 ignored. The 5 failures are the ones `main` `70564ae` has by itself on NVIDIA (the view-heap cap and the structured-view stride, already reported in #1744); this PR adds none. No new debug-layer messages compared with `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, with and without `--all-features`: clean - `edge_flagged_triangles_draw_as_unflagged_ones` draws on both devices: `hardware: edge-flagged triangles drew` on the RTX and `warp: edge-flagged triangles drew`. `primitive_export_indices_drop_the_edge_flags` passes. No game data used. AI-assisted (Claude Code).
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1718
No description provided.