Shaders: refuse a mesh program over the output budget #1961

Closed
github-bot wants to merge 2 commits from gh-pr/1961/head into gh-pr/1961/base
Owner

@⁠Luislariosss on GitHub · 2026-11-25 01:46 UTC · original
Luislariosss:shaders/mesh-output-budget → main · +83 −4 · 2 files · 2 commits · closed without merging

Why

DXC's validator rejects a mesh shader whose outputs exceed DXIL's kMaxMSOutputTotalBytes (32768):

4 * ( Σ vertex rows*cols * ALIGN32(maxVertexCount)
    + Σ primitive rows*cols * ALIGN32(maxPrimitiveCount) ) > 32768

The translated programs that hit this are console vertex programs wrapped as mesh shaders: they keep the console's own output signatures and the console's vertex/primitive maxima, and the console has no such budget. On one title's shader pack that is 72 programs, all with "For shader 'main', vertex plus primitive output size is greater than 32768."

The existing limit check in mesh_prologue only tests threads ≤ 128 and vertices/primitives ≤ 256, so those programs were translated, and only the validator (or the driver) complained later.

What

mesh_prologue now applies DXC's budget next to the existing limits, with MAX_MS_OUTPUT_BYTES = 32 * 1024 and the sum exactly as the validator computes it (per element, rows × columns times the declared maximum rounded up to 32, over both signatures; our elements are one row each, and component width is ignored as DXC ignores it). Over budget, it refuses with "a mesh shader whose outputs exceed the host's 32 KiB budget", the same refusal path as the other mesh limits.

This does not make those programs render. Trimming outputs that nothing reads needs the paired pixel shader, so that would be a follow-up; the point here is a precise reason instead of invalid DXIL reaching the driver.

Verification

Boundary confirmed against DXC itself (dxc -T ms_6_6, synthetic HLSL): with 100 vertices and 40 primitives, 44 vertex and 40 primitive scalars is 32768 bytes and is accepted; one more primitive scalar (33024) is rejected with the same message. The ALIGN32 rounding is confirmed by (96/96, 44/41 → 32640 accepted), (128/128, 32/33 → 33280 rejected) and (33/33, 128 → 32768 accepted). HLSL-written shaders can hit a 128-scalar/32-row limit first, but the title's signatures already have their registers assigned, so the byte budget is what triggers there.

Against the real pack, translate --validate --list on this branch: the 72 "vertex plus primitive output size" errors become 0, replaced by 72 refusals with the new reason (808 validator errors → 736, the rest being the compute sampling class addressed separately).

  • cargo test -p victory-shader --locked: 247 passed, 3 ignored (246 baseline + 1 new).
  • cargo build --release -p victory --locked: clean.
  • New test: a mesh program at exactly 32768 bytes translates (and validates when dxil.dll is present); one byte-class over is refused. No existing test changed; triangle_mesh became a wrapper over a sized variant with identical values.

No game data, hashes or program names are included (asset policy).

**@⁠Luislariosss** on GitHub · 2026-11-25 01:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1961) `Luislariosss:shaders/mesh-output-budget` → `main` · +83 −4 · 2 files · 2 commits · closed without merging ### Why DXC's validator rejects a mesh shader whose outputs exceed DXIL's `kMaxMSOutputTotalBytes` (32768): ``` 4 * ( Σ vertex rows*cols * ALIGN32(maxVertexCount) + Σ primitive rows*cols * ALIGN32(maxPrimitiveCount) ) > 32768 ``` The translated programs that hit this are console vertex programs wrapped as mesh shaders: they keep the console's own output signatures and the console's vertex/primitive maxima, and the console has no such budget. On one title's shader pack that is 72 programs, all with "For shader 'main', vertex plus primitive output size is greater than 32768." The existing limit check in `mesh_prologue` only tests threads ≤ 128 and vertices/primitives ≤ 256, so those programs were translated, and only the validator (or the driver) complained later. ### What `mesh_prologue` now applies DXC's budget next to the existing limits, with `MAX_MS_OUTPUT_BYTES = 32 * 1024` and the sum exactly as the validator computes it (per element, rows × columns times the declared maximum rounded up to 32, over both signatures; our elements are one row each, and component width is ignored as DXC ignores it). Over budget, it refuses with "a mesh shader whose outputs exceed the host's 32 KiB budget", the same refusal path as the other mesh limits. This does not make those programs render. Trimming outputs that nothing reads needs the paired pixel shader, so that would be a follow-up; the point here is a precise reason instead of invalid DXIL reaching the driver. ### Verification Boundary confirmed against DXC itself (`dxc -T ms_6_6`, synthetic HLSL): with 100 vertices and 40 primitives, 44 vertex and 40 primitive scalars is 32768 bytes and is accepted; one more primitive scalar (33024) is rejected with the same message. The ALIGN32 rounding is confirmed by (96/96, 44/41 → 32640 accepted), (128/128, 32/33 → 33280 rejected) and (33/33, 128 → 32768 accepted). HLSL-written shaders can hit a 128-scalar/32-row limit first, but the title's signatures already have their registers assigned, so the byte budget is what triggers there. Against the real pack, `translate --validate --list` on this branch: the 72 "vertex plus primitive output size" errors become 0, replaced by 72 refusals with the new reason (808 validator errors → 736, the rest being the compute sampling class addressed separately). - `cargo test -p victory-shader --locked`: 247 passed, 3 ignored (246 baseline + 1 new). - `cargo build --release -p victory --locked`: clean. - New test: a mesh program at exactly 32768 bytes translates (and validates when `dxil.dll` is present); one byte-class over is refused. No existing test changed; `triangle_mesh` became a wrapper over a sized variant with identical values. No game data, hashes or program names are included (asset policy).
DXIL caps a mesh shader's output at kMaxMSOutputTotalBytes (32768)
bytes. DXC's validator computes it as
4 * (sum over vertex output elements of rows * columns * ALIGN32(maxVertices)
  + sum over primitive output elements of rows * columns * ALIGN32(maxPrimitives)),
whatever the component width, and rejects a shader over it with "vertex plus
primitive output size is greater than 32768".

We copy the title's own output signatures and declare the console's maxima,
so a console vertex program wrapped as a mesh shader can land over it. The
validator would refuse such a module anyway; the check in mesh_prologue
gives the translation a precise reason instead. Our signature elements are
one row each, so an element's scalars are its columns.

The new test measures the boundary against the validator (when dxil.dll is
present): an exactly full 32768 passes and translates, one scalar more is
refused. No existing test changed.
The program at the budget is read only by the validator check, which is Windows-only, so on other targets the binding was an unused variable (clippy -D warnings). Name it used there; nothing changes on Windows.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:11 +00:00
github-bot closed this pull request 2026-11-26 04:50:11 +00:00
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 01:47 UTC · original

Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head f37c644 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 145 passed, 0 failed, 2 ignored. All tests pass, including the new mesh output budget test.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 5 errors (4 pre-existing on main + 1 new: unused variable at in test code). The new error is in a test, not production code.

Not tested: Windows MSVC build, the title itself. AI-assisted.

**@⁠Headache3318** on GitHub · 2026-11-25 01:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1961#issuecomment-7149968771) Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `f37c644` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 145 passed, 0 failed, 2 ignored. All tests pass, including the new mesh output budget test. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 5 errors (4 pre-existing on main + 1 new: unused variable `at` in test code). The new error is in a test, not production code. Not tested: Windows MSVC build, the title itself. AI-assisted.
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-25 03:37 UTC · original

A full-corpus run of this PR (merged cleanly onto main 940d32f): offline translate --validate over the title 1.0.2.1's shader pack, release build, Windows 11 26300, validator DXC 1.9.2602.

mesh programs emitted validated over-budget refusals
main 8,765 of 8,765 8,694 71 at the validator (vertex plus primitive output size is greater than 32768)
this PR 8,694 of 8,765 8,694 71 at translation (emit: a mesh shader whose outputs exceed the host's 32 KiB budget)

It does what it says: the same 71 programs, now refused by the translator with a reason instead of emitted as invalid DXIL. Nothing else changes (vertex + pixel and compute counts are identical to main).

AI use: Claude Code (Claude Opus 5.5) ran the builds and wrote this; counts only, no game data.

**@⁠AgneyaK** on GitHub · 2026-11-25 03:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1961#issuecomment-7152085646) A full-corpus run of this PR (merged cleanly onto `main` `940d32f`): offline `translate --validate` over the title 1.0.2.1's shader pack, release build, Windows 11 26300, validator DXC 1.9.2602. | mesh programs | emitted | validated | over-budget refusals | |---|---|---|---| | `main` | 8,765 of 8,765 | 8,694 | 71 at the validator (`vertex plus primitive output size is greater than 32768`) | | this PR | 8,694 of 8,765 | 8,694 | **71 at translation** (`emit: a mesh shader whose outputs exceed the host's 32 KiB budget`) | It does what it says: the same 71 programs, now refused by the translator with a reason instead of emitted as invalid DXIL. Nothing else changes (vertex + pixel and compute counts are identical to `main`). AI use: Claude Code (Claude Opus 5.5) ran the builds and wrote this; counts only, no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:21 UTC · original · edited 2026-11-25 20:20 UTC

Automated triage for the maintainers.

Merge candidate (unchanged). mesh_prologue (crates/victory-shader/src/emit/lower.rs) refuses a mesh program whose outputs exceed DXIL's 32 KiB mesh output limit. It computes the size the way the validator does: 4 × columns per element × the declared maximum rounded up to 32, summed over the vertex and primitive signatures. The refusal goes through the same path as the existing mesh limits. The formula is backed by the PR's DXC boundary measurements, and two independent corpus runs show the same ~71 programs moving from validator errors to this refusal, with nothing else changing. I rechecked the test's numbers: 44 vertex scalars × 128 × 4 plus 40 primitive scalars × 64 × 4 is exactly 32768, and the extra scalar puts the second case over the limit.

What changed since the last verdict: the only new commit, 8d9b91b, fixes the unused-variable warning raised earlier. In a_mesh_program_over_the_output_budget_is_refused, the program at the limit is now marked used under cfg(not(windows)). Nothing else changed.

The question from before remains for the maintainer: these programs are now refused rather than passed to the driver.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1961#issuecomment-7156928860) · edited 2026-11-25 20:20 UTC <!-- victory-triage v1 head=8d9b91bebb01aece0efe00592a076af658451425 verdict=merge-candidate at=2026-11-25T20:18:54Z --> Automated triage for the maintainers. **Merge candidate (unchanged).** `mesh_prologue` (`crates/victory-shader/src/emit/lower.rs`) refuses a mesh program whose outputs exceed DXIL's 32 KiB mesh output limit. It computes the size the way the validator does: 4 × columns per element × the declared maximum rounded up to 32, summed over the vertex and primitive signatures. The refusal goes through the same path as the existing mesh limits. The formula is backed by the PR's DXC boundary measurements, and two independent corpus runs show the same ~71 programs moving from validator errors to this refusal, with nothing else changing. I rechecked the test's numbers: 44 vertex scalars × 128 × 4 plus 40 primitive scalars × 64 × 4 is exactly 32768, and the extra scalar puts the second case over the limit. **What changed since the last verdict:** the only new commit, `8d9b91b`, fixes the unused-variable warning raised earlier. In `a_mesh_program_over_the_output_budget_is_refused`, the program at the limit is now marked used under `cfg(not(windows))`. Nothing else changed. The question from before remains for the maintainer: these programs are now refused rather than passed to the driver. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

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

Closing because refusing these programs would make things worse. The formula is right, but on main the 71 mesh programs over the output budget are emitted, fail only the offline validator, and get their pipelines from the AMD driver, so their draws (character skin, fire, decals) run. With this change they would be refused and those draws dropped; a report on #2398 describes characters' faces and skin missing in exactly that state. A clearer reason string is not worth losing the draws.

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

**@⁠Marvisak** on GitHub · 2026-11-25 22:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/1961#issuecomment-7176059208) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because refusing these programs would make things worse. The formula is right, but on `main` the 71 mesh programs over the output budget are emitted, fail only the offline validator, and get their pipelines from the AMD driver, so their draws (character skin, fire, decals) run. With this change they would be refused and those draws dropped; a report on #2398 describes characters' faces and skin missing in exactly that state. A clearer reason string is not worth losing the draws. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

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!1961
No description provided.