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

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

@⁠Moon0755 on GitHub · 2026-11-25 20:48 UTC · original
Moon0755:fix/mesh-psv-shared-bytes → main · +35 −2 · 2 files · 1 commits · open

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 #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

**@⁠Moon0755** on GitHub · 2026-11-25 20:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2798) `Moon0755:fix/mesh-psv-shared-bytes` → `main` · +35 −2 · 2 files · 1 commits · open ### 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](https://github.com/Moon0755/VIctory/actions/runs/45696042514)): the control validates, the program with declared LDS fails with the message above, `270 passed; 1 failed`; - with the change ([run 45696975573](https://github.com/Moon0755/VIctory/actions/runs/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 #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
`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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:30 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:10 UTC · original

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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2798#issuecomment-7174718275) 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`.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:23 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 23:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2798#issuecomment-7177492026) <!-- victory-triage v1 head=1f0061c2a746be408be87d571cf7c6556509a367 verdict=merge-candidate at=2026-11-25T23:23:15Z --> 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](https://claude.ai/code)_
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/2798/head:github-bot/gh-2798'
git switch 'github-bot/gh-2798'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2798'
git switch 'github-bot/gh-2798'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2798'
git switch 'github-bot/gh-2798'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2798'
git switch 'main'
git merge --squash 'github-bot/gh-2798'
git switch 'main'
git merge --ff-only 'github-bot/gh-2798'
git switch 'main'
git merge 'github-bot/gh-2798'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2798
No description provided.