Skip to content

Shaders: emit mesh primitive indices once per lane - #2245

Closed
andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/emit-mesh-primitive-indices-once
Closed

andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/emit-mesh-primitive-indices-once

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

Change

The mesh lowerer stages the lane's latest packed primitive export and writes the final indices at exit. A lane with no export still emits a degenerate primitive. Edge flags and the guest cull bit retain their existing meanings.

On WARP, the translated test triangle disappeared when its default indices and real indices were both emitted. A native HLSL shader on the same pipeline drew all 256 pixels. Removing the preliminary default write in isolation also restored the translated triangle. The mesh specification assigns the last write when an output element is written more than once. DirectX Mesh Shader specification

Verification

Same extended test on 940d32f69b22265690a0b5a15d6ded572ba33baf, with WARP forced. Before, the first ordinary triangle lit 0/256 pixels. After, all six cases passed. Visible triangles lit 256/256, while culling and absent exports lit zero. Both orders of repeated exports produced the result from the last export.

The full shader suite went from 244 passed / 3 failed / 3 ignored to 245 passed / 2 failed / 3 ignored. Both runs also hit the existing forced-WARP gather-reference and variable lane-shuffle failures discussed in #2225. Strict shader Clippy and the staged asset policy passed.

If you reuse the patch or regression, please preserve its Git author. If you fold it into your own commit, please add:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • cargo test -p victory-shader --lib mesh — 5 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean deferred emission of mesh primitive indices once per lane via save_mesh_primitive / finish_mesh_primitive. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mesh primitive indices emitted once per lane. Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored. Approving.

@MamaLeVrai

Copy link
Copy Markdown

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 2e26c46a into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 701 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

simnJS added a commit to MiamiGame/XTP that referenced this pull request Nov 25, 2026
simnJS added a commit to MiamiGame/XTP that referenced this pull request Nov 25, 2026
@Mericas77

Copy link
Copy Markdown

NVIDIA hardware test report: RTX 4070, driver 621.01, Windows 11, Rust 1.98.1 MSVC. I ran head 2e26c46 against main 940d32f; the head branches from 940d32f and only changes bitcode.rs, lower.rs and mod.rs under emit/.

  • This PR: edge_flagged_triangles_draw_as_unflagged_ones passes all 6 cases, printing hardware: edge-flagged triangles drew and warp: edge-flagged triangles drew. The new alloca local passes the validator, and the pipeline is created on NVIDIA.
  • A/B: I ran the PR's mod.rs tests on top of main's production code. They also pass all 6 cases on this card, both on the hardware pass and on the WARP pass. So I couldn't reproduce the "first ordinary triangle lit 0/256 pixels" failure here. My guess is that the WARP build or adapter differs from yours, or the repeated-export cases need the forced-WARP setup you describe. Either way, the regression test doesn't tell main and this PR apart on this machine.
  • cargo test -p victory-shader --lib --locked gives 244 passed, 3 failed. The 3 failures match main on this card: stride_tests ×2 and gathers_at_a_level_match_the_hardware.

So there's no regression on NVIDIA. Writing the indices once at exit is consistent with the mesh spec's last-write rule either way.

AI-assisted. Synthetic tests only, no game data.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for running the same fixture on the RTX 4070. I replayed the paired executables here with VICTORY_WARP=1, app-local WARP 1.0.22.0.20261027.1 and Agility core 1.620.2.0.20261106.5. That flag also forces WARP for the arm that prints hardware.

  • The PR fixture with 940d32f production code again reported 0 of 256 texels lit on the first triangle and exited 101.
  • On 2e26c46, the same fixture ran all six cases successfully and exited 0. A minimal native DXC mesh shader also lit all 256 texels on the app-local runtime.
  • As a control, I ran both executables with the same Agility core and just the system WARP (10.0.19041.5794). Both explicitly skipped for lack of mesh shader support, so that control couldn't isolate a WARP version difference.

The fixture distinguishes the two trees on this app-local WARP setup. Your matched A/B establishes that it can also pass on both trees on another setup. Thanks for checking compatibility with the real NVIDIA driver.

If the code or fixture is folded into another commit, please preserve the Git author or include:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted. Synthetic tests only.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 2e26c46 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (worth a look). Instead of a default culled emitIndices in mesh_prologue followed by a second one per exp prim, emit/lower.rs now stores the lane's last packed primitive in an entry-block alloca (new Module::local_i32 in bitcode.rs, which passes the validator per the NVIDIA report) and emits once at lane exit, in both the Term::Ret path and the abort block (the only two returns). This removes the double write the DirectX mesh shader spec leaves to the last one, and the cull bit and edge-flag decoding are unchanged. CI check passes. The failure it fixes was reproduced only on an app-local WARP build (the RTX 4070 A/B passes on main too), so the main gain is spec conformance.


Generated by Claude Code

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because main already behaves as the mesh shader specification requires (the last value written to an output element is the one used), and the failure was seen only with one app-local WARP build. With main's lower.rs and bitcode.rs, the extended edge_flagged_triangles_draw_as_unflagged_ones passes all six cases on an RX 6700 XT and on the system WARP. The change rewrites the primitive path of every mesh program and adds a private alloca to each. The extra test cases (no export, repeated exports) pass on main and would be welcome by themselves.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants