Shaders: mask mesh primitive vertex indices to 9 bits (port of upstream VIctory #1718) #919

Open
github-bot wants to merge 1 commit from github-bot/gh-919 into main AGit
Owner

@⁠Moon0755 on GitHub · 2026-11-25 12:54 UTC · original
Moon0755:fix/mesh-prim-edge-flags → main · +188 −7 · 3 files · 1 commits · open

Ports upstream Marvisak/VIctory#1718 (tjthebigbearcat-hub).

What changed

  • crates/victory-shader/src/emit/lower.rs (Lower::emit_indices): Mask each corner vertex index in exp prim to 9 bits (0x1FF) instead of 10 bits (0x3FF).
  • crates/victory-shader/src/io.rs: Update the exp prim bit-layout documentation.
  • crates/victory-shader/src/emit/mod.rs: Add unit and D3D12 mesh draw tests (primitive_export_indices_drop_the_edge_flags and edge_flagged_triangles_draw_as_unflagged_ones).

Why (RDNA2 / Xbox Series X NGG hardware layout)

In RDNA2 NGG mesh primitive exports (exp prim), each 10-bit corner field packs a 9-bit vertex index in bits [8:0] and a hardware edge flag in bit 9 (bits 9, 19, and 29 of the exported dword), while bit 31 marks the primitive as culled. Edge flags are only consumed by the console's edge-flag rasterization and are not part of the vertex index.

Impact

With a 10-bit (0x3FF) mask, any triangle with a hardware edge flag set unpacked as index + 512. Because emit_indices in this fork also culls primitives whose vertex indices are >= written (min(max_vertices, threads)), any edge-flagged triangle was guaranteed to be silently culled instead of rendered. Masking to 9 bits drops the edge flags cleanly while preserving bit-31 culling and bounds checking.

Verification

Verified on windows-latest via GitHub Actions run #45617588678 (scoped to -p victory-shader -p xtask, as workspace-wide clippy on main currently fails on unrelated pre-existing items in victory-gpu):

  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture:
    • victory-shader: 217 passed, 0 failed (3 ignored), including dxil.dll validation and warp: edge-flagged triangles drew
    • xtask: 4 passed, 0 failed (repository_passes_policy ok)

— Neon

**@⁠Moon0755** on GitHub · 2026-11-25 12:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/919) `Moon0755:fix/mesh-prim-edge-flags` → `main` · +188 −7 · 3 files · 1 commits · open Ports upstream [Marvisak/VIctory#1718](https://github.com/Marvisak/VIctory/pull/1718) (`tjthebigbearcat-hub`). ### What changed - **`crates/victory-shader/src/emit/lower.rs` (`Lower::emit_indices`)**: Mask each corner vertex index in `exp prim` to 9 bits (`0x1FF`) instead of 10 bits (`0x3FF`). - **`crates/victory-shader/src/io.rs`**: Update the `exp prim` bit-layout documentation. - **`crates/victory-shader/src/emit/mod.rs`**: Add unit and D3D12 mesh draw tests (`primitive_export_indices_drop_the_edge_flags` and `edge_flagged_triangles_draw_as_unflagged_ones`). ### Why (RDNA2 / Xbox Series X NGG hardware layout) In RDNA2 NGG mesh primitive exports (`exp prim`), each 10-bit corner field packs a **9-bit vertex index** in bits `[8:0]` and a **hardware edge flag** in bit `9` (bits `9`, `19`, and `29` of the exported dword), while bit `31` marks the primitive as culled. Edge flags are only consumed by the console's edge-flag rasterization and are not part of the vertex index. ### Impact With a 10-bit (`0x3FF`) mask, any triangle with a hardware edge flag set unpacked as `index + 512`. Because `emit_indices` in this fork also culls primitives whose vertex indices are `>= written` (`min(max_vertices, threads)`), any edge-flagged triangle was guaranteed to be silently culled instead of rendered. Masking to 9 bits drops the edge flags cleanly while preserving bit-31 culling and bounds checking. ### Verification Verified on `windows-latest` via [GitHub Actions run #45617588678](https://github.com/Moon0755/victory-fork/actions/runs/45617588678) (scoped to `-p victory-shader -p xtask`, as workspace-wide clippy on `main` currently fails on unrelated pre-existing items in `victory-gpu`): - `cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings`: **passed** - `cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings`: **passed** - `cargo test -p victory-shader -p xtask --locked -- --nocapture`: - `victory-shader`: **217 passed, 0 failed** (3 ignored), including `dxil.dll` validation and `warp: edge-flagged triangles drew` - `xtask`: **4 passed, 0 failed** (`repository_passes_policy` ok) — Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:53:51 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/919/head:github-bot/gh-919'
git switch 'github-bot/gh-919'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-919'
git switch 'github-bot/gh-919'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-919'
git switch 'github-bot/gh-919'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-919'
git switch 'main'
git merge --squash 'github-bot/gh-919'
git switch 'main'
git merge --ff-only 'github-bot/gh-919'
git switch 'main'
git merge 'github-bot/gh-919'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.