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

Open
Moon0755 wants to merge 1 commit from upstream-pr/2798 into main
Moon0755 commented 2026-11-25 20:48:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-25T20:48:57Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5498936797 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T20:48:57Z. --- ### 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
kotekompotek commented 2026-11-25 21:13:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:13:41Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065066518 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#pullrequestreview-6065066518). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T21:13:41Z. **Review:** COMMENTED --- 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.
fuzeofficlal commented 2026-11-25 22:04:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:10:47Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7174718275 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#issuecomment-7174718275). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T21:10:47Z. --- 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`.
AwsAli05 commented 2026-11-25 23:04:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:04:43Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066188103 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#pullrequestreview-6066188103). Originally posted by [AwsAli05](https://github.com/AwsAli05) on 2026-11-25T23:04:43Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-26 00:03:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:23:21Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177492026 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#issuecomment-7177492026). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:23:21Z. --- <!-- 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)_
DenRakEiw commented 2026-11-26 00:47:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-26T00:47:53Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067046075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#pullrequestreview-6067046075). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-26T00:47:53Z. **Review:** APPROVED --- 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).
fuzeofficlal commented 2026-11-27 00:17:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:17:48Z.

Review: APPROVED


LGTM — verified rustfmt on the changed hunks, cargo xtask policy, cargo clippy (--all-targets and --all-features), and emit::tests:: (18 passed, including unused_mesh_lds_is_not_counted_in_psv0 validated against dxil.dll).

Gating mesh_shared on self.lds.is_some() matches DXC's MSInfo::GroupSharedBytesUsed check (VerifyPSVMatches requires exact equality with the sum of address-space-3 groupshared globals in the DXIL module, so 0 is required when no lds global is materialized). Non-blocking note: adding a mesh test case that actually accesses LDS (lds global present) would cover the nonzero path too.

<!-- greyfinch-sync:Marvisak/VIctory:review:6081908078 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2798#pullrequestreview-6081908078). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T00:17:48Z. **Review:** APPROVED --- LGTM — verified `rustfmt` on the changed hunks, `cargo xtask policy`, `cargo clippy` (`--all-targets` and `--all-features`), and `emit::tests::` (18 passed, including `unused_mesh_lds_is_not_counted_in_psv0` validated against `dxil.dll`). Gating `mesh_shared` on `self.lds.is_some()` matches DXC's `MSInfo::GroupSharedBytesUsed` check (`VerifyPSVMatches` requires exact equality with the sum of address-space-3 groupshared globals in the DXIL module, so `0` is required when no `lds` global is materialized). Non-blocking note: adding a mesh test case that actually accesses LDS (`lds` global present) would cover the nonzero path too.
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/2798:upstream-pr/2798'
git switch 'upstream-pr/2798'

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