Shaders: pack a mesh shader's 16-bit outputs with its pixel shader's inputs when they pass 32 KiB (#283) #397
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!397
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-397"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@RenzoWit35 on GitHub · 2026-11-25 00:22 UTC · original
RenzoWit35:fix/283-mesh-output-size→main· +877 −14 · 10 files · 1 commits · openFixes #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 withvertex plus primitive output size is greater than 32768.mesh_prologuealready 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 atfinish()as an unsigned, constant element of half the columns.mesh_output_bytescounts it that way.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.lower.rs,eval_packed): every read of a packed channel takes each vertex's dword (attributeAtVertex), picks its half and weighs the three vertices withSV_Barycentrics, asP0 + i·P10 + j·P20, the formula of the console's f16 interpolation. A flat read is the provoking vertex's half.victory-gpu):BarycentricsSupported(newHost::barycentrics,OPTIONS3), and both stages translate linked with the same bindings as their own translation (the root signature is made from that one).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.dllrefuses 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, readsSV_Barycentrics, and validates.a_linked_pair_draws_what_the_pair_apart_draws: the linked pair is created and drawn on an RTX card (and withVICTORY_WARP=1on 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-gpupass (218 and 112).cargo clippy -D warningsis clean with and withoutdiagnostics, andcargo xtask policypasses.load_probeinvictory-loaderfails on this machine: it cannot link its mingw probe DLL, which this change does not touch.Not verified
mesh_link/translate_linked. Atranslate --pipelinesrun, or an in-game run with the startup log linemesh shader outputs pass 32 KiB: its 16-bit outputs are packed..., would show how many get linked and whether any falls back.For review
attributeAtVertexreads and their own weighting per packed value read, instead of one interpolated load. Only those pairs pay it.🤖 Generated with 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]>@avt0m4t48 on GitHub · 2026-11-25 01:09 UTC · original
I tested
4f4900bbwith 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 sourceTwo cases are worth adding before enabling this by default.
ATTRPAIRin PS row 3 .xy and an untouched FP32BASE00in row 3 .zw, the plain PS validates. Linked translation succeeds but DXV reports different interpolation modes in the same row after packing. Moving onlyBASE00to 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.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.
4f4900bb2eto1b788235e4View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.