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

Merged
tjthebigbearcat-hub merged 1 commit from upstream-pr/1718 into main 2026-11-25 00:15:44 +00:00
tjthebigbearcat-hub commented 2026-11-24 21:14:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tjthebigbearcat-hub on 2026-11-24T21:14:58Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6591557101 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718). Originally posted by [tjthebigbearcat-hub](https://github.com/tjthebigbearcat-hub) on 2026-11-24T21:14:58Z. --- ### 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**.
DenRakEiw commented 2026-11-24 21:28:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T21:26:29Z.

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib primitive_export_indices_drop_the_edge_flags — passed
  • cargo test -p victory-shader --lib edge_flagged — edge_flagged_triangles_draw_as_unflagged_ones passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean 9-bit masking of mesh primitive vertex indices to drop edge flags, verified end-to-end on hardware and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047683468 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#pullrequestreview-6047683468). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T21:26:29Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib primitive_export_indices_drop_the_edge_flags` — passed - `cargo test -p victory-shader --lib edge_flagged` — `edge_flagged_triangles_draw_as_unflagged_ones` passed on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean 9-bit masking of mesh primitive vertex indices to drop edge flags, verified end-to-end on hardware and WARP. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-24 22:02:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:00Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Mesh primitive vertex indices are masked to 9 bits with the edge-flag bits (9/19/29) and cull bit (31) dropped; TRIANGLE/EDGE_FLAGS/CULL constants document the layout, with a one-wave triangle mesh test program. +1 macOS test.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047847380 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#pullrequestreview-6047847380). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:40:00Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests. Mesh primitive vertex indices are masked to 9 bits with the edge-flag bits (9/19/29) and cull bit (31) dropped; TRIANGLE/EDGE_FLAGS/CULL constants document the layout, with a one-wave triangle mesh test program. +1 macOS test.
steven-seagull27 commented 2026-11-24 22:02:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-24T21:37:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145180926 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7145180926). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-24T21:37:43Z. --- 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.
mercuryVM commented 2026-11-24 23:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T22:24:51Z.

Review: APPROVED


Tested c0228d93 on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-shader -- --test-threads=1 passes on the head (122 passed, 1 ignored).
  • Merged into our fork: shader tests and clippy -D warnings (default and all features) are clean.

The fix is right. In the GFX10 NGG primitive export, each vertex index is 9 bits, with its edge flag in the bit above (bits 9, 19, 29), and bit 31 marks a null primitive. The old 0x3FF mask folded the edge flag in as +512.

On a full game package, translate --validate --list gives the same result for every program (counts only compared). This changes the index values, not what validates.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6048366428 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#pullrequestreview-6048366428). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T22:24:51Z. **Review:** APPROVED --- Tested c0228d93 on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-shader -- --test-threads=1` passes on the head (122 passed, 1 ignored). - Merged into our fork: shader tests and `clippy -D warnings` (default and all features) are clean. The fix is right. In the GFX10 NGG primitive export, each vertex index is 9 bits, with its edge flag in the bit above (bits 9, 19, 29), and bit 31 marks a null primitive. The old `0x3FF` mask folded the edge flag in as +512. On a full game package, `translate --validate --list` gives the same result for every program (counts only compared). This changes the index values, not what validates. AI-assisted (Claude Code).
kais7654 commented 2026-11-24 23:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kais7654 on 2026-11-24T22:32:48Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146359388 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7146359388). Originally posted by [kais7654](https://github.com/kais7654) on 2026-11-24T22:32:48Z. --- 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.
DeerSilver commented 2026-11-25 00:06:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T23:06:34Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7147023279 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1718#issuecomment-7147023279). Originally posted by [DeerSilver](https://github.com/DeerSilver) on 2026-11-24T23:06:34Z. --- **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).
upstream-sync closed this pull request 2026-11-25 01:07:05 +00:00
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!1717
No description provided.