Shaders: avoid overwriting mesh indices when every slot is exported #3299

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/3299 into main
andrewpozdnakov7-jpg commented 2026-11-26 16:23:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T16:23:49Z.


On app-local WARP 1.0.22, the existing mesh edge-flag test renders 0 of 256 texels even for its unflagged triangle. The generated DXIL writes a degenerate primitive at entry and later writes the exported indices to the same slot.

I confirmed the API behavior with a native HLSL control. Using the same pipeline and DXC -Od, one EmitIndices(0,1,2) per slot draws the expected frame. Adding an earlier EmitIndices(0,0,0) per slot yields a blank frame. DXC disassembly shows one and two writes respectively. The DirectX mesh shader spec says the last write defines the indices. DirectX mesh shader specification

Skip the preliminary write only for a straight-line shader with one unguarded primitive export and exactly one primitive slot per thread. The export overwrites every slot in that case, so the initialization is redundant. Task claim

Verification

  • Same synthetic draw on main 63bcca4 and this revision. With the patch, the two visible variants match all 256 expected colors and the culled variant lights zero texels.
  • Forced WARP shader lib suite with app-local WARP 1.0.22 and Agility 1.620.2 goes from 298 passed / 4 failed / 3 ignored to 299 passed / 3 failed / 3 ignored. The three remaining failures also occur on main (gather adapter selection and two lane-permutation tests).
  • Strict shader Clippy with and without all features, and policy passed.

All fixtures are synthetic. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5513612294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T16:23:49Z. --- On app-local WARP 1.0.22, the existing mesh edge-flag test renders 0 of 256 texels even for its unflagged triangle. The generated DXIL writes a degenerate primitive at entry and later writes the exported indices to the same slot. I confirmed the API behavior with a native HLSL control. Using the same pipeline and DXC `-Od`, one `EmitIndices(0,1,2)` per slot draws the expected frame. Adding an earlier `EmitIndices(0,0,0)` per slot yields a blank frame. DXC disassembly shows one and two writes respectively. The DirectX mesh shader spec says the last write defines the indices. [DirectX mesh shader specification](https://microsoft.github.io/DirectX-Specs/d3d/MeshShader.html#vertex-indices) Skip the preliminary write only for a straight-line shader with one unguarded primitive export and exactly one primitive slot per thread. The export overwrites every slot in that case, so the initialization is redundant. [Task claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7197353908) ## Verification - Same synthetic draw on main `63bcca4` and this revision. With the patch, the two visible variants match all 256 expected colors and the culled variant lights zero texels. - Forced WARP shader lib suite with app-local WARP 1.0.22 and Agility 1.620.2 goes from 298 passed / 4 failed / 3 ignored to 299 passed / 3 failed / 3 ignored. The three remaining failures also occur on main (gather adapter selection and two lane-permutation tests). - Strict shader Clippy with and without all features, and policy passed. All fixtures are synthetic. AI-assisted with Codex.
andrewpozdnakov7-jpg commented 2026-11-26 16:34:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T16:34:54Z.


I merged exact #3299 head 8f01cab with the published #3267 + #2997 integration b1ff815 without conflicts. On app-local WARP 1.0.22 / Agility 1.620.2 with DXIL 1.9.2609.5, two fresh full shader runs each passed 302 tests, with 0 failures and 3 ignored. The mesh draw that failed in both prior full runs now passes. Earlier #3267 + #2997 results

The separate fresh-process series in #2997 still establishes intermittent divergence in its 19-active-lane case. These two full runs confirm the mesh change composes with the gather and permute changes on this host. Intermittent case

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197832033 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#issuecomment-7197832033). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T16:34:54Z. --- I merged exact #3299 head `8f01cab` with the published #3267 + #2997 integration `b1ff815` without conflicts. On app-local WARP 1.0.22 / Agility 1.620.2 with DXIL 1.9.2609.5, two fresh full shader runs each passed **302 tests**, with **0 failures** and **3 ignored**. The mesh draw that failed in both prior full runs now passes. [Earlier #3267 + #2997 results](https://github.com/Marvisak/VIctory/pull/3267#issuecomment-7197535089) The separate fresh-process series in #2997 still establishes intermittent divergence in its 19-active-lane case. These two full runs confirm the mesh change composes with the gather and permute changes on this host. [Intermittent case](https://github.com/Marvisak/VIctory/pull/2997#issuecomment-7197542064) AI-assisted with Codex.
Dukestar69 commented 2026-11-26 16:50:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T16:50:12Z.

Review: APPROVED


Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP):

  • Skipping the preliminary degenerate-triangle index write when threads == mesh.max_primitives and a single-block mesh shader ([LaneExit::End]) has one unguarded Target::Primitive export is tight and sound, avoiding WARP 1.0.22 keeping the preliminary write.
  • cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1: 17 passed, 0 failed (including edge_flagged_triangles_draw_as_unflagged_ones and primitive_export_indices_drop_the_edge_flags).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6077832103 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#pullrequestreview-6077832103). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T16:50:12Z. **Review:** APPROVED --- Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090 + WARP): - Skipping the preliminary degenerate-triangle index write when `threads == mesh.max_primitives` and a single-block mesh shader (`[LaneExit::End]`) has one unguarded `Target::Primitive` export is tight and sound, avoiding WARP 1.0.22 keeping the preliminary write. - `cargo test -p victory-shader --lib emit::tests:: -- --test-threads=1`: 17 passed, 0 failed (including `edge_flagged_triangles_draw_as_unflagged_ones` and `primitive_export_indices_drop_the_edge_flags`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
andrewpozdnakov7-jpg commented 2026-11-26 17:01:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T17:01:45Z.


The edge-flag fix also composes with the direct mesh group-index candidate from #2624. On the exact integration, the edge-flag draw passed on app-local WARP 1.0.22 in three fresh runs. Each 24-group test still visited every index once, and GPU diagnostics passed with 249 tests, 0 failed and 1 ignored. Integration details in #2624. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7198398089 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#issuecomment-7198398089). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T17:01:45Z. --- The edge-flag fix also composes with the direct mesh group-index candidate from #2624. On the exact integration, the edge-flag draw passed on app-local WARP 1.0.22 in three fresh runs. Each 24-group test still visited every index once, and GPU diagnostics passed with 249 tests, 0 failed and 1 ignored. [Integration details in #2624](https://github.com/Marvisak/VIctory/pull/2624#issuecomment-7198384716). AI-assisted with Codex.
fuzeofficlal commented 2026-11-26 21:02:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:02:17Z.

Review: CHANGES_REQUESTED


Requesting a small fix before merge after auditing against origin/main (63bcca43):

  1. Formatting check fails on added code (rustfmt):
    • rustfmt --edition 2024 --check reports a diff on the added line at crates/victory-shader/src/emit/lower.rs:2982 (let mut exports = self.x.io.exports.iter().filter(|e| e.target == Target::Primitive);).
  2. [P2] Fast path drops all emitIndices calls if the exp prim sits inside a wave::sections block:
    • wave::sections (crates/victory-shader/src/emit/wave.rs:131-169) matches s_or_saveexec_b{32,64} ..., -1 / s_nand_saveexec_b{32,64} ..., 0 ... EXEC restore blocks without excluding Fields::Export.
    • Because EXEC is full inside that block, self.x.st.guards[export.site.0][export.site.1] is None, so mesh_prologue (crates/victory-shader/src/emit/lower.rs:2981-2989) skips emitting the preliminary (0, 0, 0) emitIndices.
    • Then Lower::run (lower.rs:1369-1375) advances past i + 1..end using section_inst (lower.rs:1116-1131), which only populates self.vals and never calls self.export(). As a result, setMeshOutputCounts declares primitives with zero emitIndices writes in the emitted DXIL.
    • Checking that the export site is not inside self.sections (or preventing wave::sections from spanning Fields::Export) avoids that regression.

Local verification on Windows x64:

  • emit::tests:: + emit::lower:: (VICTORY_WARP=0): 50 passed, 0 failed; edge_flagged + primitive_export (VICTORY_WARP=1): 2 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean.

Synthetic tests only; no game data used.

<!-- greyfinch-sync:Marvisak/VIctory:review:6080446113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#pullrequestreview-6080446113). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:02:17Z. **Review:** CHANGES_REQUESTED --- Requesting a small fix before merge after auditing against `origin/main` (`63bcca43`): 1. **Formatting check fails on added code (`rustfmt`)**: - `rustfmt --edition 2024 --check` reports a diff on the added line at `crates/victory-shader/src/emit/lower.rs:2982` (`let mut exports = self.x.io.exports.iter().filter(|e| e.target == Target::Primitive);`). 2. **[P2] Fast path drops all `emitIndices` calls if the `exp prim` sits inside a `wave::sections` block**: - `wave::sections` (`crates/victory-shader/src/emit/wave.rs:131-169`) matches `s_or_saveexec_b{32,64} ..., -1` / `s_nand_saveexec_b{32,64} ..., 0` ... `EXEC` restore blocks without excluding `Fields::Export`. - Because `EXEC` is full inside that block, `self.x.st.guards[export.site.0][export.site.1]` is `None`, so `mesh_prologue` (`crates/victory-shader/src/emit/lower.rs:2981-2989`) skips emitting the preliminary `(0, 0, 0)` `emitIndices`. - Then `Lower::run` (`lower.rs:1369-1375`) advances past `i + 1..end` using `section_inst` (`lower.rs:1116-1131`), which only populates `self.vals` and never calls `self.export()`. As a result, `setMeshOutputCounts` declares primitives with zero `emitIndices` writes in the emitted DXIL. - Checking that the export site is not inside `self.sections` (or preventing `wave::sections` from spanning `Fields::Export`) avoids that regression. Local verification on Windows x64: - `emit::tests::` + `emit::lower::` (`VICTORY_WARP=0`): 50 passed, 0 failed; `edge_flagged` + `primitive_export` (`VICTORY_WARP=1`): 2 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): clean. Synthetic tests only; no game data used.
andrewpozdnakov7-jpg commented 2026-11-27 06:31:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T06:31:28Z.


Thanks @fuzeofficlal. 0aef5e1 keeps exports in normal lowering and formats the iterator in the mesh prologue.

The new synthetic mesh places exp prim between the full-EXEC save and restore. The same shader disassembles to zero emitIndices calls on 8f01cab and one on the updated head. WARP drew all 256 expected texels with the fix. The draw also succeeded on this WARP build before the fix, so the DXIL call check is what distinguishes the two revisions.

All 18 emit::tests passed with WARP forced. All-features shader Clippy with -D warnings, the asset policy check, and git diff --check passed as well.

AI-assisted with Codex. Synthetic shaders only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211604748 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#issuecomment-7211604748). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T06:31:28Z. --- Thanks @fuzeofficlal. [0aef5e1](https://github.com/Marvisak/VIctory/pull/3299/commits/0aef5e150975bd13ee8bf3bbaabf9f384ae82d22) keeps exports in normal lowering and formats the iterator in the mesh prologue. The new synthetic mesh places `exp prim` between the full-EXEC save and restore. The same shader disassembles to zero `emitIndices` calls on `8f01cab` and one on the updated head. WARP drew all 256 expected texels with the fix. The draw also succeeded on this WARP build before the fix, so the DXIL call check is what distinguishes the two revisions. All 18 `emit::tests` passed with WARP forced. All-features shader Clippy with `-D warnings`, the asset policy check, and `git diff --check` passed as well. AI-assisted with Codex. Synthetic shaders only.
andrewpozdnakov7-jpg commented 2026-11-27 12:09:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:09:08Z.


I restored the mesh depth-bounds coverage from #158 using VIctory's own shader emitter. Test commit 0f017bd is directly on the current 0aef5e1 head. It shares the existing synthetic triangle from c0228d9 with the shader tests, adds the no-colour pixel stage, and calls the normal pipeline-stream, command-list and DispatchMesh entry points.

I tested with app-local WARP 1.0.22 and Agility 1.620.2. The four columns in each readback are fresh list, excluded by bounds, included by bounds, and after reset.

Shader and pipeline path Four depth values
63bcca4 shader sources, same test [0.5, 0.5, 0.5, 0.5]
0f017bd, ordinary primitive export [0.25, 0.5, 0.25, 0.25]
0f017bd, primitive export in the whole-wave region [0.25, 0.5, 0.25, 0.25]
Control with only the host mesh depth-bounds flag disabled [0.25, 0.25, 0.25, 0.25]

The vertex draw returned [0.25, 0.5, 0.25, 0.25] in all configurations. The final commit passed all three depth-bounds tests, all three filtered primitive-export tests with DXIL validation available, all-feature Clippy with warnings denied for both crates, and the asset policy check.

The GPU checks use WARP. A physical-adapter run of cargo test -p victory-gpu --lib --features diagnostics depth_bounds_test -- --nocapture --test-threads=1 would confirm the same readback on hardware. Please retain the Git author if you pick the commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217899914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3299#issuecomment-7217899914). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T12:09:08Z. --- I restored the mesh depth-bounds coverage from #158 using VIctory's own shader emitter. [Test commit `0f017bd`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/0f017bd94479c27470015c3a376e368bea12fddc) is directly on the current `0aef5e1` head. It shares the existing synthetic triangle from `c0228d9` with the shader tests, adds the no-colour pixel stage, and calls the normal pipeline-stream, command-list and `DispatchMesh` entry points. I tested with app-local WARP 1.0.22 and Agility 1.620.2. The four columns in each readback are fresh list, excluded by bounds, included by bounds, and after reset. | Shader and pipeline path | Four depth values | |---|---| | `63bcca4` shader sources, same test | `[0.5, 0.5, 0.5, 0.5]` | | `0f017bd`, ordinary primitive export | `[0.25, 0.5, 0.25, 0.25]` | | `0f017bd`, primitive export in the whole-wave region | `[0.25, 0.5, 0.25, 0.25]` | | Control with only the host mesh depth-bounds flag disabled | `[0.25, 0.25, 0.25, 0.25]` | The vertex draw returned `[0.25, 0.5, 0.25, 0.25]` in all configurations. The final commit passed all three depth-bounds tests, all three filtered primitive-export tests with DXIL validation available, all-feature Clippy with warnings denied for both crates, and the asset policy check. The GPU checks use WARP. A physical-adapter run of `cargo test -p victory-gpu --lib --features diagnostics depth_bounds_test -- --nocapture --test-threads=1` would confirm the same readback on hardware. Please retain the Git author if you pick the commit. AI-assisted with OpenAI Codex.
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/3299:upstream-pr/3299'
git switch 'upstream-pr/3299'

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/3299'
git switch 'upstream-pr/3299'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3299'
git switch 'upstream-pr/3299'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3299'
git switch 'main'
git merge --squash 'upstream-pr/3299'
git switch 'main'
git merge --ff-only 'upstream-pr/3299'
git switch 'main'
git merge 'upstream-pr/3299'
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!3299
No description provided.