Shaders: pack a mesh shader's 16-bit outputs with its pixel shader's inputs when they pass 32 KiB (#283) #397

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

@⁠RenzoWit35 on GitHub · 2026-11-25 00:22 UTC · original
RenzoWit35:fix/283-mesh-output-size → main · +877 −14 · 10 files · 1 commits · open

Fixes #283.

Problem

D3D12 caps a mesh shader's outputs at 32 KiB and charges 4 bytes per signature scalar, 16-bit ones included (as the comment on #283 found with dxv). The console gives each 16-bit output value a 32-bit scalar of its own, so a mesh shader of 128 vertices with more than 64 output scalars, 71 of them in the title, fails validation with vertex plus primitive output size is greater than 32768. mesh_prologue already brings the maxima down to the lane count, but these do not fit even at 128. NVIDIA draws them anyway; other drivers may not.

Declaring the values 16-bit does not help (same 4 bytes), and lowering the vertex maximum drops triangles. What fits is two halves per 32-bit column. The pixel shader then has to agree on that layout, and each stage is translated on its own today.

Change

  • emit::Link (victory-shader/src/emit/mod.rs): the 16-bit per-vertex elements, by semantic, that a mesh shader and the pixel shader it feeds declare packed. emit::mesh_link(container) returns one for a mesh shader that passes 32 KiB at its lane count and fits once packed; emit::translate_linked(container, &link) translates either stage with it. With no link everything is as before.
  • SigElement::packed (container.rs): while lowering, a packed element keeps the console's 16-bit channels; SigElement::host() declares it at finish() as an unsigned, constant element of half the columns. mesh_output_bytes counts it that way.
  • Mesh stores (lower.rs, export): the halves of each packed column are gathered into one dword and stored as .i32. A column that two exports would each write half of is refused, and that pair falls back to the plain translation.
  • Pixel reads (lower.rs, eval_packed): every read of a packed channel takes each vertex's dword (attributeAtVertex), picks its half and weighs the three vertices with SV_Barycentrics, as P0 + i·P10 + j·P20, the formula of the console's f16 interpolation. A flat read is the provoking vertex's half.
  • Host (victory-gpu):
    • A mesh pipeline uses the linked pair only when the mesh shader has a link, the host reports BarycentricsSupported (new Host::barycentrics, OPTIONS3), and both stages translate linked with the same bindings as their own translation (the root signature is made from that one).
    • A linked pipeline the host refuses is made again from the stages as translated alone, so no draws are lost.
    • Linked translations have shader-cache entries of their own, keyed by the link.

Testing

New emit::link_tests, on a synthetic mesh program of 16 rows of packed halves (34,816 bytes) and a pixel program that interpolates one high half:

  • packed_mesh_outputs_fit_the_limit_and_validate: translated alone, dxil.dll refuses it with the #283 message; linked, it takes 18,432 bytes, keeps 128 vertices and validates.
  • a_packed_pixel_input_is_weighed_per_vertex: the linked pixel program declares the element unsigned with 2 columns, reads SV_Barycentrics, and validates.
  • a_linked_pair_draws_what_the_pair_apart_draws: the linked pair is created and drawn on an RTX card (and with VICTORY_WARP=1 on WARP). Every texel matches the pair translated apart within one f16 step; 48 of 256 differ by that one step, where the host's interpolator and our weighting round differently.
  • a_mesh_program_past_the_limit_gets_its_halves_packed: mesh_link's decision, including no link for a program that fits.

cargo test -p victory-shader -p victory-gpu pass (218 and 112). cargo clippy -D warnings is clean with and without diagnostics, and cargo xtask policy passes. load_probe in victory-loader fails on this machine: it cannot link its mingw probe DLL, which this change does not touch.

Not verified

  • The title's 71 shaders. I have no game files here, so the real containers have not been through mesh_link/translate_linked. A translate --pipelines run, or an in-game run with the startup log line mesh shader outputs pass 32 KiB: its 16-bit outputs are packed..., would show how many get linked and whether any falls back.
  • A driver that refuses the unpacked shaders. Both the RTX card and WARP took the pair translated apart too, so this shows the packed form is valid and draws the same. It does not show a driver where the fix changes what you see. Reports from AMD or Intel would.

For review

  • Cost: pixel shaders fed by these mesh shaders do three attributeAtVertex reads and their own weighting per packed value read, instead of one interpolated load. Only those pairs pay it.
  • A pixel shader that declares a linked semantic as 32-bit is not packed. Its pipeline is then refused as linked and made from the separate translations.
  • Independent of #61. #61 only makes validators before 1.8 get past PSV0 to this check.

🤖 Generated with Claude Code

**@⁠RenzoWit35** on GitHub · 2026-11-25 00:22 UTC · [original](https://github.com/fxceless/victory-fork/pull/397) `RenzoWit35:fix/283-mesh-output-size` → `main` · +877 −14 · 10 files · 1 commits · open Fixes #283. ## Problem D3D12 caps a mesh shader's outputs at 32 KiB and charges 4 bytes per signature scalar, 16-bit ones included (as the comment on #283 found with `dxv`). The console gives each 16-bit output value a 32-bit scalar of its own, so a mesh shader of 128 vertices with more than 64 output scalars, 71 of them in the title, fails validation with `vertex plus primitive output size is greater than 32768`. `mesh_prologue` already brings the maxima down to the lane count, but these do not fit even at 128. NVIDIA draws them anyway; other drivers may not. Declaring the values 16-bit does not help (same 4 bytes), and lowering the vertex maximum drops triangles. What fits is two halves per 32-bit column. The pixel shader then has to agree on that layout, and each stage is translated on its own today. ## Change - **`emit::Link`** (`victory-shader/src/emit/mod.rs`): the 16-bit per-vertex elements, by semantic, that a mesh shader and the pixel shader it feeds declare packed. `emit::mesh_link(container)` returns one for a mesh shader that passes 32 KiB at its lane count and fits once packed; `emit::translate_linked(container, &link)` translates either stage with it. With no link everything is as before. - **`SigElement::packed`** (`container.rs`): while lowering, a packed element keeps the console's 16-bit channels; `SigElement::host()` declares it at `finish()` as an unsigned, constant element of half the columns. `mesh_output_bytes` counts it that way. - **Mesh stores** (`lower.rs`, `export`): the halves of each packed column are gathered into one dword and stored as `.i32`. A column that two exports would each write half of is refused, and that pair falls back to the plain translation. - **Pixel reads** (`lower.rs`, `eval_packed`): every read of a packed channel takes each vertex's dword (`attributeAtVertex`), picks its half and weighs the three vertices with `SV_Barycentrics`, as `P0 + i·P10 + j·P20`, the formula of the console's f16 interpolation. A flat read is the provoking vertex's half. - **Host** (`victory-gpu`): - A mesh pipeline uses the linked pair only when the mesh shader has a link, the host reports `BarycentricsSupported` (new `Host::barycentrics`, `OPTIONS3`), and both stages translate linked with the same bindings as their own translation (the root signature is made from that one). - A linked pipeline the host refuses is made again from the stages as translated alone, so no draws are lost. - Linked translations have shader-cache entries of their own, keyed by the link. ## Testing New `emit::link_tests`, on a synthetic mesh program of 16 rows of packed halves (34,816 bytes) and a pixel program that interpolates one high half: - `packed_mesh_outputs_fit_the_limit_and_validate`: translated alone, `dxil.dll` refuses it with the #283 message; linked, it takes 18,432 bytes, keeps 128 vertices and validates. - `a_packed_pixel_input_is_weighed_per_vertex`: the linked pixel program declares the element unsigned with 2 columns, reads `SV_Barycentrics`, and validates. - `a_linked_pair_draws_what_the_pair_apart_draws`: the linked pair is created and drawn on an RTX card (and with `VICTORY_WARP=1` on WARP). Every texel matches the pair translated apart within one f16 step; 48 of 256 differ by that one step, where the host's interpolator and our weighting round differently. - `a_mesh_program_past_the_limit_gets_its_halves_packed`: `mesh_link`'s decision, including no link for a program that fits. `cargo test -p victory-shader -p victory-gpu` pass (218 and 112). `cargo clippy -D warnings` is clean with and without `diagnostics`, and `cargo xtask policy` passes. `load_probe` in `victory-loader` fails on this machine: it cannot link its mingw probe DLL, which this change does not touch. ## Not verified - **The title's 71 shaders.** I have no game files here, so the real containers have not been through `mesh_link`/`translate_linked`. A `translate --pipelines` run, or an in-game run with the startup log line `mesh shader outputs pass 32 KiB: its 16-bit outputs are packed...`, would show how many get linked and whether any falls back. - **A driver that refuses the unpacked shaders.** Both the RTX card and WARP took the pair translated apart too, so this shows the packed form is valid and draws the same. It does not show a driver where the fix changes what you see. Reports from AMD or Intel would. ## For review - **Cost:** pixel shaders fed by these mesh shaders do three `attributeAtVertex` reads and their own weighting per packed value read, instead of one interpolated load. Only those pairs pay it. - **A pixel shader that declares a linked semantic as 32-bit** is not packed. Its pipeline is then refused as linked and made from the separate translations. - **Independent of #61.** #61 only makes validators before 1.8 get past PSV0 to this check. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
D3D12 caps a mesh shader's outputs at 32 KiB and charges 4 bytes per
signature scalar, 16-bit ones included. The console gives each 16-bit
value a 32-bit scalar of its own, so a mesh shader of 128 vertices with
more than 64 of them (71 in the title) fails validation; NVIDIA draws
them anyway, other drivers may not.

Such a mesh shader and the pixel shader it feeds are now translated
together (emit::Link, from emit::mesh_link): their 16-bit per-vertex
elements are declared packed, two channels per unsigned 32-bit column,
constant. The mesh shader stores each column as the dword of its two
halves; the pixel shader reads each vertex's dword (attributeAtVertex),
takes its half and weighs the three vertices with SV_Barycentrics, as
the console's f16 interpolation does. Every vertex is kept.

The host does this only for mesh shaders that do not fit even with
their maxima at their lane count, when packing makes them fit, the host
reads barycentrics (OPTIONS3) and both stages translate linked with the
same bindings; a linked pipeline the host refuses falls back to the
stages as translated alone. Linked translations have cache entries of
their own.

Tested with a synthetic mesh program of 16 16-bit rows (34,816 bytes):
the validator refuses it as before ("vertex plus primitive output size
is greater than 32768") and takes it packed (18,432 bytes); the linked
pair is created on an RTX card and on WARP and draws what the pair
translated apart draws, within one f16 step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:31 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 01:09 UTC · original

I tested 4f4900bb with an independent, source-built GFX10 mesh and pixel pair. The 128-vertex mesh has 65 output scalars and emits a triangle using vertices 125–127. The plain mesh fails the 32 KiB DXV check. The linked mesh and both linked pixel variants (flat and perspective-center) pass. An otherwise fitting 64-scalar control produces no link. Synthetic fixture source

Two cases are worth adding before enabling this by default.

  • Shared signature rows. With ATTRPAIR in PS row 3 .xy and an untouched FP32 BASE00 in row 3 .zw, the plain PS validates. Linked translation succeeds but DXV reports different interpolation modes in the same row after packing. Moving only BASE00 to row 4 lets the linked PS validate. The same failure occurs in a linked MS output row that holds both the packed pair and an untouched float. The emitted signature needs to separate those rows or reject the linked layout before handing it to D3D12.
  • Plain-first translation. A PS reading the same half pair with both perspective-center P1/P2 and a P0 move emits valid linked DXIL. Plain translation fails at offset 40 with one input interpolated two ways. The plain-translation requirement in HostPipeline::new prevents that valid linked path from being attempted.

The split-export guard behaved as written. Two separate native exports with disjoint masks for the same packed column are refused. A single joint export validates, while the oversized split pair's plain fallback still fails DXV. This limits coverage if any of the title's shaders use that form.

These marks are translation and Microsoft DXV results at the PR head. The affected title shaders and PR-specific Windows PSO creation remain unverified.

**@⁠avt0m4t48** on GitHub · 2026-11-25 01:09 UTC · [original](https://github.com/fxceless/victory-fork/pull/397#issuecomment-7149255479) I tested `4f4900bb` with an independent, source-built GFX10 mesh and pixel pair. The 128-vertex mesh has 65 output scalars and emits a triangle using vertices 125–127. The plain mesh fails the 32 KiB DXV check. The linked mesh and both linked pixel variants (flat and perspective-center) pass. An otherwise fitting 64-scalar control produces no link. [Synthetic fixture source](https://github.com/avt0m4t48/victory-fork/tree/3e84d4d12011ee8864710b61ec6dda60f1763f97/crates/victory-shader/tests/mesh_link) Two cases are worth adding before enabling this by default. - **Shared signature rows.** With `ATTRPAIR` in PS row 3 .xy and an untouched FP32 `BASE00` in row 3 .zw, the plain PS validates. Linked translation succeeds but DXV reports different interpolation modes in the same row after packing. Moving only `BASE00` to row 4 lets the linked PS validate. The same failure occurs in a linked MS output row that holds both the packed pair and an untouched float. The emitted signature needs to separate those rows or reject the linked layout before handing it to D3D12. - **Plain-first translation.** A PS reading the same half pair with both perspective-center P1/P2 and a P0 move emits valid linked DXIL. Plain translation fails at offset 40 with `one input interpolated two ways`. The plain-translation requirement in [HostPipeline::new](https://github.com/fxceless/victory-fork/blob/4f4900bb2e46149997685060d97f52abdc6cea0b/crates/victory-gpu/src/pipeline/host.rs#L362) prevents that valid linked path from being attempted. The split-export guard behaved as written. Two separate native exports with disjoint masks for the same packed column are refused. A single joint export validates, while the oversized split pair's plain fallback still fails DXV. This limits coverage if any of the title's shaders use that form. These marks are translation and Microsoft DXV results at the PR head. The affected title shaders and PR-specific Windows PSO creation remain unverified.
github-bot force-pushed github-bot/gh-397 from 4f4900bb2e to 1b788235e4 2026-11-26 16:29:29 +00:00 Compare
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/397/head:github-bot/gh-397'
git switch 'github-bot/gh-397'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-397'
git switch 'github-bot/gh-397'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-397'
git switch 'github-bot/gh-397'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-397'
git switch 'main'
git merge --squash 'github-bot/gh-397'
git switch 'main'
git merge --ff-only 'github-bot/gh-397'
git switch 'main'
git merge 'github-bot/gh-397'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.