Shaders: keep mesh outputs within D3D12's 32 KiB #459
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!459
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/459/head"
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?
@AnoHunted on GitHub · 2026-11-24 03:41 UTC · original
AnoHunted:mesh-output-budget→main· +201 −1 · 3 files · 1 commits · closed without mergingWhat
container::mesh_output_bytesmeasures a mesh shader's outputs the way the DXIL validator does: 4 bytes percomponent of every vertex and every primitive signature element, times the vertex and primitive maxima, each
rounded up to a multiple of 32. It reads the same
SigElements the signature metadata,OSG1/PSG1andPSV0arewritten from.
MESH_OUTPUT_LIMITis 32 KiB.mesh_prologuechecks the size before it callssetMeshOutputCounts:setMeshOutputCounts, the entry's mesh state andPSV0all get the lowered values.(marked
shortcut:): drivers have been seen to take such modules, and refusing them would drop draws that maywork today. Whether to refuse them instead is the owner's call; it is a one-line change.
emit::container::tests::mesh_output_size_counts_components_and_aligned_maxima: the size on syntheticsignature elements. Components count, not rows (two elements sharing a row add up separately), the maxima
round up to 32, and the boundary is exactly 32,768 bytes.
emit::tests::mesh_maxima_past_the_lanes_come_down_to_fit: a synthetic mesh program goes throughemit. Ithas 64 lanes, declares 256 vertices and 256 primitives, and exports the position plus 6 vertex rows and 2
primitive rows. That is 28 + 8 components: 36 KiB at 256, 9 KiB at 64.
PSV0must now say 64/64. With 1 + 1rows it fits at 256 and must keep 256/256. Where
dxil.dllis found, each module must also pass the validator.emit::tests::mesh_outputs_past_32_kib_at_the_lane_count_keep_the_lane_maxima: 128 lanes, 256/256, positionplus 15 vertex rows and 2 primitive rows. That is 72 components, 36 KiB even at 128. It still translates, and
PSV0must say 128/128.Why
#201 lists 53 translated mesh shaders that
dxil.dllrefuses with "vertex plus primitive output size is greaterthan 32768". The prologue declared the console's maxima (up to 256 and 256) whatever the outputs took. It refused
only maxima above 256.
The rule:
d3d/MeshShader.md, section "Mesh shader output size limits":vert_attr_bytes * ALIGN32(n_verts) + prim_attr_bytes * ALIGN32(n_prims) <= 32,768. The attribute bytes are thenumber of scalar attributes times 4.
Sm.MeshShaderOutputSize("For shader '%0', vertex plus primitive output size isgreater than %1.",
utils/hct/hctdb.py).ValidateEntrySignaturesinlib/DxilValidation/DxilValidation.cpp(v1.8.2502, the version #201 used) sums
GetRows() * GetCols()over every element of the output signaturetimes
ALIGN32(maxVertexCount). It adds the same sum over the primitive signature timesALIGN32(maxPrimitiveCount). The total times 4 is compared withkMaxMSOutputTotalBytes = 1024 * 32(
include/dxc/DXIL/DxilConstants.h). Our elements are one row each, so the count iscols.Why lowering is safe. The same spec makes
SetMeshOutputCountscounts past the declared maxima undefined, andwrites past them too: "The hardware implementation is not required to clamp or mask out of bounds writes." So the
maxima may only come down where the module provably writes no more than the new values. In the translated module,
lane n writes only vertex n and primitive n:
storeVertexOutput,storePrimitiveOutputandemitIndicesalltake the flat thread id, as the console's NGG exports do. No vertex or primitive index reaches the lane count
(
[numthreads]), so maxima above it name slots that no lane ever writes. Lowering them takes away nothing theshader writes.
that vertex before either, so it was already undefined.
setMeshOutputCountsbut never written, noteven culled by the prologue, so their indices were undefined. With the lowered count they are not declared.
What cannot be derived. The console's real counts come from one lane's
s_sendmsgGS_ALLOC_REQ(m0 = vertices | primitives << 12), a run-time value. The translator finds that message only to place barriers,
and it lowers to nothing. It does not track the counts. So nothing below the lane count is provable, and a
shader whose outputs pass 32 KiB even there keeps an out-of-spec module (with smaller maxima than before).
No draw is lost. #201 says the D3D12 runtime created pipelines for all 8,191 emitted mesh modules, so these
shaders may draw today on drivers that accept them; this change keeps emitting the ones it cannot bring under the
cap. I could not check how the 53 split between "fits at the lane count" and "still over" (no access to that
corpus). #71 reports NVIDIA hangs in mesh passes; outputs past the limit are one possible factor,
not shown to be the cause.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1.
dxil.dllfrom Microsoft's DXC release v1.9.2609(
VICTORY_DXILpointing at itsbin\x64\dxil.dll), so the validator steps of the tests ran (no "validationskipped" line on either side).
Main and branch side by side in one job (
--test-threads=1):cargo test -p victory-shader --lib mesh_ -- --nocapture: main 4 passed; branch 7 passed, 0 failed. The newmesh_maxima_past_the_lanes_come_down_to_fitmodules passdxil.dll's validator.cargo test -p victory-shader --lib: main 69 passed; branch 72 passed, 0 failed (constant_color_validatesand the existing translated-mesh draw test pass on both).
cargo test --workspace: main 264 passed, 0 failed, 4 ignored; branch 267 passed, 0 failed, 4 ignored.cargo clippy -p victory-shader --tests: no warnings on main or on the branch.emittests on main with the tests alone and no fix (an earlier version of the second test, which thenexpected a refusal):
mesh_maxima_past_the_lanes_come_down_to_fitfails (PSV0declares(256, 256)where(64, 64)is expected). The current..._keep_the_lane_maximatest was not run on main; main declares(256, 256)there, so it would fail its(128, 128)check the same way.Not tested
AI-assisted (Claude Code, Claude Opus 5.5). No game files were used.
A translated mesh shader declared the console's vertex and primitive maxima (up to 256 each) whatever its outputs took, so wide outputs at those maxima passed the 32 KiB that D3D12 allows a mesh shader and the validator refused the module ("vertex plus primitive output size is greater than 32768"). The prologue now measures the outputs as the validator does (4 bytes per component of every vertex and primitive signature element, times the maxima rounded up to 32). Past the cap, the maxima come down to the lane count: lane n writes only vertex n and primitive n, so no group writes more. Outputs that pass the cap even at the lane count are still emitted as before, with the lower maxima, so no draw that works today is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>@DaviTostes on GitHub · 2026-11-24 03:42 UTC · original
Verified
dc838d6on Arch Linux x86_64 (rustc 1.98.1,cargo test -p victory-shader): 59 passed, 0 failed, 0 ignored.Not covered: DispatchMesh on a real host device (no game data or Windows GPU run here) and the interaction with the game's mesh pipelines.
@fuzeofficlal on GitHub · 2026-11-24 04:10 UTC · original
Native DispatchMesh check for
dc838d6on Windows 11 build 26200, Rust 1.98.1 MSVC and Windows SDKdxil.dll1.8.2502. The original synthetic fixture uses 64 threads, declared maxima 256/256, 28 vertex scalars and 8 primitive scalars (36 KiB). Only primitive 63 draws a nondegenerate triangle, using vertices 61, 62 and 63.lower.rsfromd2a4bae, the same input emits 256/256 and the validator rejects it for exceeding 32,768 bytes. This control was validator-only.dc838d6, the 256/256 input emits 64/64 and validates. Its entire DXIL container matches the otherwise identical input declaring 64/64 from the start.The local test ran with
cargo test --locked --offline -p victory-shader mesh_clamp_hardware_probe -- --nocapture --test-threads=1. The readback covers the last valid primitive and vertex indices for this synthetic mesh; the pixel shader uses a constant color.@LocranKing on GitHub · 2026-11-24 04:18 UTC · original
Tested on Windows 11 + retail
shaders.rpf(1.0.2.1) usingvictory translate --validate.Tested
dc838d6(pr-459, clean tree)1.98.1(x86_64-pc-windows-msvc), Windows SDK10.0.26100.0dxil.dllcargo xtask policy:asset policy: 151 files okcargo test --workspace: 267 passed, 0 failed, 4 ignoredvictory translate <shaders.rpf> --validate(diagbuild):26084 / 26084translated; meshDXILstayed at 8191 emitted of 8506; 8129 validated (unchanged vsmaind2a4bae; VS/PS12272 / 12172and CS1693 / 1670also unchanged).Not tested: Live GPU / WARP runtime execution.
AI use: Antigravity (
Gemini 4 Hydrogen) ran the checks andvictory translate --validateand drafted this report from the command outputs.@Proudnoob4 on GitHub · 2026-11-24 05:00 UTC · original
I measured #459 on the full 26,503-container corpus (A/B:
main d2a4bae+ Agility, with and without #180 + #459; release,translate --validate --list, 10 chunks, all exit 0). Result posted on #201: the mesh output-size group is 53 → 53, none cleared. (The compute group 23 → 0 is from #180.)Reason, from one failing module (
(MS_VS_PedTransformFire_52f61330_Wrapped~3.dxbc): it declaresNumThreads=(128,1,1), 79 vertex outputs, andsetMeshOutputCounts(…, 128, 128), so bymesh_output_bytes' own formula the size is 4 × (79 × 128) = 40,448 B > 32 KiB. The clamp lowers the maxima to the lane count — but the lane count is already 128, so nothing changes. The emitted DXIL is byte-identical between base and fix (27,368 B, same hash).So the programs in this group are the ones where the lanes already reach the maximum; lowering the maxima to the lane count cannot reduce them. To clear them the maxima would have to go below the lane count, with the prologue culling lanes whose vertex/primitive index exceeds the new maximum (and their exports), or the output rows reduced. I haven't checked whether either is safe for these programs — just reporting that the current rule does not touch them.
AI-assisted (Claude Code). I ran the census on Windows 10, RTX 4080; no game data beyond shader hashes.
@iurysf on GitHub · 2026-11-24 06:02 UTC · original
Data point, offline against main
d2a4bae:victory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17.With this PR, the 53 mesh modules rejected with
vertex plus primitive output size is greater than 32768(#201) are still 53. Mesh emitted is unchanged at 8,191, the other validator failures are unchanged too (185 total), and nothing regresses. So on this corpus none of the 53 seem to qualify for lowering the maximums (the "lane n only writes n" case). It may help to log which check refuses them.After #306, these 53 are the only validator rejections left on this corpus (see my comment on #306).
@slint6614-dev on GitHub · 2026-11-24 07:47 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate, against maind2a4bae(emitted / validated). Windows 11, dxil.dll from SDK 10.0.26100.With this PR the 53 mesh programs refused with "vertex plus primitive output size is greater than 32768" are still all refused (VS/PS 12172, CS 1670, MS 8129 validated, same as main). So on the real pack the lowered maxima do not bring them under 32 KiB, or the path is not taken for them: they may all be in the "still past 32 KiB at the lane count"
shortcut:case.cargo test -p victory-shaderpasses (72).@AnoHunted on GitHub · 2026-11-24 10:21 UTC · original
Thank you @Proudnoob4, @iurysf, @slint6614-dev and @LocranKing for the corpus runs, and @fuzeofficlal for the native DispatchMesh check. Together they settle it. The lowering is correct: the 64/64 module validates, is identical to one declaring 64/64 from the start, and draws the same on NVIDIA and AMD. But it clears none of the real 53, so they must all exceed 32 KiB even at their lane count.
Getting them under the limit needs the program's real vertex and primitive counts: the
GS_ALLOC_REQvalue in m0, which the translator doesn't track today. Lowering to the lane count can't get there. With the review queue as long as it is, I'm closing this rather than ask for a review of a change with no effect on the title. The size measurement (mesh_output_bytes) is on the branch if a count-based fix wants it.Pull request closed