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

Open
RenzoWit35 wants to merge 1 commit from upstream-pr/397 into main
RenzoWit35 commented 2026-11-25 00:22:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by RenzoWit35 on 2026-11-25T00:22:43Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594225783 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/397). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-25T00:22:43Z. --- 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)
avt0m4t48 commented 2026-11-25 01:12:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T01:09:00Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7149255479 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/397#issuecomment-7149255479). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T01:09:00Z. --- 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.
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/397:upstream-pr/397'
git switch 'upstream-pr/397'

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