Skip to content

Shaders: a mesh program's PSV0 counts shared memory only when it has some - #2798

Open
Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/mesh-psv-shared-bytes
Open

Moon0755 wants to merge 1 commit into
Marvisak:mainfrom
Moon0755:fix/mesh-psv-shared-bytes

Conversation

@Moon0755

Copy link
Copy Markdown

Problem

For a mesh program Shader::finish writes the console's LDS size into PSV0's GroupSharedBytesUsed whenever the mesh state declares one (lds_dwords, set from the program's lds_bytes). DXC fills that field from the module: it adds up the sizes of the globals in the group-shared address space (lib/DxilContainer/DxilPipelineStateValidation.cpp). Here the group-shared global is made lazily, by Shader::lds, when an LDS instruction is lowered.

So a mesh program whose state declares LDS and whose code never touches it has no such global: the validator's rebuilt PSV0 holds 0, ours holds the declared size, and the whole runtime info is compared byte for byte:

error: DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part ...
error: Container part 'Pipeline State Validation' does not match expected for module.

Fix

The size is written only when the global exists.

Test

emit::tests::unused_mesh_lds_is_not_counted_in_psv0: the triangle mesh program of the existing tests, with lds_bytes 0 (a control) and 16, both through dxil.dll. The program has no LDS instruction.

Verification

GitHub Actions on windows-latest, on the fork, with the jobs narrowed to victory-shader and xtask; the validator ran in both (the control prints that it validated):

  • the test without the change (run 45696042514): the control validates, the program with declared LDS fails with the message above, 270 passed; 1 failed;
  • with the change (run 45696975573): both validate, clippy in both profiles passed, 271 passed; 0 failed; 3 ignored.

Not checked: the title's shaders. I do not know how many mesh programs declare LDS without using it, nor whether any of the mesh programs that still fail validation (#201) are this case.

Notes

  • Known limit: the size follows whether the global was made, not whether the writer keeps it. A program whose only LDS accesses are on a path the writer drops (286a00e) would still declare the bytes while the module has no global. That needs the size taken from the globals written, which this does not do.
  • Independent of Shaders: signature rows of one register follow their name offsets #2793 (signature row order): both add a test to emit/mod.rs, in different places; the two merge together without conflict.

Credit

The mismatch came out of comparing emit/shader.rs and emit/container.rs with DXC's PSV0 writer; Devin wrote the test and the change and ran both arms.

— Devin & Fable

…some

`finish` wrote the console's LDS size into PSV0's GroupSharedBytesUsed
whenever the mesh state declared one. DXC counts the bytes of the
group-shared globals in the module, and the global is made only when an
LDS instruction is lowered. A mesh program that declares LDS and never
touches it has no such global, so the validator's rebuilt PSV0 holds 0
and the container is refused ("Container part 'Pipeline State
Validation' does not match expected for module").

The size is now written only when the global exists.

Test: `unused_mesh_lds_is_not_counted_in_psv0`, the triangle mesh
program with and without declared LDS through dxil.dll.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and verified 1f0061c2 on Windows 11 (Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

  • Since Shader::lds() (shader.rs:219-225) is the sole site creating the addrspace(3) "lds" global, gating mesh PSV0 GroupSharedBytesUsed on self.lds.is_some() cleanly matches emitted shared memory (with the documented caveat for DCE'd branches).
  • unused_mesh_lds_is_not_counted_in_psv0 (validated with dxil.dll for both lds_bytes=0 and lds_bytes=16) + translated_mesh_shaders_draw_as_pc_ones: 2/2 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 184 files ok; clean git merge-tree vs 13f91ca, #2793, and #2796.

@kotekompotek kotekompotek 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.

Matches DXC's rule: PSV0 group-shared bytes come from the module's globals, and a mesh program whose code never touches declared LDS has no such global — reporting the console's lds_bytes would make PSV0 inconsistent with the module and fail validation. Gating on self.lds.is_some() (an actual access, not the declared size) is the right signal, and the dxil.dll validation test proves both sides. LGTM.

@AwsAli05 AwsAli05 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.

I compared this with #2857. Both production changes emit zero PSV0 shared bytes when there is no LDS global, and lds_dwords * 4 when the global exists. The current #2857 also has its validation test on the same module path. Please coordinate which branch should carry the fix so the same shader-container change lands once.

AI-assisted static review.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In Shader::finish (crates/victory-shader/src/emit/shader.rs) a mesh program's PSV0 GroupSharedBytesUsed is now lds_dwords * 4 only when self.lds is set, i.e. when Shader::lds actually created the addrspace(3) global; on main it is written from the declared size even when the module has no group-shared global, so the validator's rebuilt PSV0 differs. I checked that Shader::lds is the only place outside tests that creates an address-space-3 global, so the gate matches what DXC counts; the new test unused_mesh_lds_is_not_counted_in_psv0 validates both a 0-byte control and a 16-byte unused declaration through dxil.dll. The PR itself notes the remaining limit (LDS accesses only on a path the writer drops). CI (check) passes.

This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

@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 against origin/main (63bcca4) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Counting shared memory in a mesh shader's PSV0 only when shared memory is actually used passes all emit tests cleanly.
  • cargo test -p victory-shader emit::tests: 18/18 passed on RTX 5090, 18/18 passed on WARP (including unused_mesh_lds_is_not_counted_in_psv0).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

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

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 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.

6 participants