Skip to content

Shaders: keep mesh outputs within D3D12's 32 KiB - #459

Closed
AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:mesh-output-budget
Closed

AnoHunted wants to merge 1 commit into
Marvisak:mainfrom
AnoHunted:mesh-output-budget

Conversation

@AnoHunted

Copy link
Copy Markdown
Contributor

What

  • container::mesh_output_bytes measures a mesh shader's outputs the way the DXIL validator does: 4 bytes per
    component 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/PSG1 and PSV0 are
    written from. MESH_OUTPUT_LIMIT is 32 KiB.
  • mesh_prologue checks the size before it calls setMeshOutputCounts:
    • Within 32 KiB, nothing changes.
    • Past it, the maxima come down to the group's lane count. setMeshOutputCounts, the entry's mesh state and
      PSV0 all get the lowered values.
    • If the outputs still pass 32 KiB at the lane count, the module is emitted as before, with the lower maxima
      (marked shortcut:): drivers have been seen to take such modules, and refusing them would drop draws that may
      work today. Whether to refuse them instead is the owner's call; it is a one-line change.
  • Tests:
    • emit::container::tests::mesh_output_size_counts_components_and_aligned_maxima: the size on synthetic
      signature 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 through emit. It
      has 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. PSV0 must now say 64/64. With 1 + 1
      rows it fits at 256 and must keep 256/256. Where dxil.dll is 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, position
      plus 15 vertex rows and 2 primitive rows. That is 72 components, 36 KiB even at 128. It still translates, and
      PSV0 must say 128/128.

Why

#201 lists 53 translated mesh shaders that dxil.dll refuses with "vertex plus primitive output size is greater
than 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:

  • Microsoft's DirectX-Specs, 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 the
    number of scalar attributes times 4.
  • DXC implements it as rule Sm.MeshShaderOutputSize ("For shader '%0', vertex plus primitive output size is
    greater than %1.", utils/hct/hctdb.py). ValidateEntrySignatures in lib/DxilValidation/DxilValidation.cpp
    (v1.8.2502, the version Corpus census: 185 emitted DXIL modules fail dxil.dll validation #201 used) sums GetRows() * GetCols() over every element of the output signature
    times ALIGN32(maxVertexCount). It adds the same sum over the primitive signature times
    ALIGN32(maxPrimitiveCount). The total times 4 is compared with kMaxMSOutputTotalBytes = 1024 * 32
    (include/dxc/DXIL/DxilConstants.h). Our elements are one row each, so the count is cols.

Why lowering is safe. The same spec makes SetMeshOutputCounts counts past the declared maxima undefined, and
writes 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, storePrimitiveOutput and emitIndices all
take 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 the
shader writes.

  • The one case that changes is a primitive whose indices name a vertex at or past the lane count. No lane wrote
    that vertex before either, so it was already undefined.
  • A side effect: primitives past the lane count used to be counted by setMeshOutputCounts but never written, not
    even 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_sendmsg GS_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.dll from Microsoft's DXC release v1.9.2609
(VICTORY_DXIL pointing at its bin\x64\dxil.dll), so the validator steps of the tests ran (no "validation
skipped" 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 new
    mesh_maxima_past_the_lanes_come_down_to_fit modules pass dxil.dll's validator.
  • cargo test -p victory-shader --lib: main 69 passed; branch 72 passed, 0 failed (constant_color_validates
    and 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.
  • The new emit tests on main with the tests alone and no fix (an earlier version of the second test, which then
    expected a refusal): mesh_maxima_past_the_lanes_come_down_to_fit fails (PSV0 declares (256, 256) where
    (64, 64) is expected). The current ..._keep_the_lane_maxima test 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 <noreply@anthropic.com>
@DaviTostes

Copy link
Copy Markdown

Verified dc838d6 on 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

Copy link
Copy Markdown
Contributor

Native DispatchMesh check for dc838d6 on Windows 11 build 26200, Rust 1.98.1 MSVC and Windows SDK dxil.dll 1.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.

  • With lower.rs from d2a4bae, the same input emits 256/256 and the validator rejects it for exceeding 32,768 bytes. This control was validator-only.
  • At 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 RTX 5090 (10de:2b85) and Radeon iGPU (1002:13c0) both created the mesh pipeline and returned all 64 expected pixels from actual DispatchMesh for both inputs. The D3D12 debug queues contained no error or corruption messages.

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

Copy link
Copy Markdown

Tested on Windows 11 + retail shaders.rpf (1.0.2.1) using victory translate --validate.

Tested

  • Commit: dc838d6 (pr-459, clean tree)
  • Environment: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, Rust 1.98.1 (x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0 dxil.dll
  • cargo xtask policy: asset policy: 151 files ok
  • cargo test --workspace: 267 passed, 0 failed, 4 ignored
  • victory translate <shaders.rpf> --validate (diag build): 26084 / 26084 translated; mesh DXIL stayed at 8191 emitted of 8506; 8129 validated (unchanged vs main d2a4bae; VS/PS 12272 / 12172 and CS 1693 / 1670 also unchanged).

Not tested: Live GPU / WARP runtime execution.

AI use: Antigravity (Gemini 4 Hydrogen) ran the checks and victory translate --validate and drafted this report from the command outputs.

@Proudnoob4

Copy link
Copy Markdown

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 declares NumThreads=(128,1,1), 79 vertex outputs, and setMeshOutputCounts(…, 128, 128), so by mesh_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

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Data point, offline against main d2a4bae: victory translate --list --validate over the title's shaders.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).

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
… lane count past 32 KiB)

AnoHunted's Marvisak#459: a mesh shader whose declared vertex and primitive
maxima take more than D3D12's 32 KiB of outputs declares the lane count
instead, where that is lower.

No textual conflict. Mechanical, crates/victory-shader/src/emit/mod.rs:
git placed Marvisak#459's three test items at the end of the file, inside
`atomic_tests` (Marvisak#48's module, which is last in this tree); they are
moved to the end of `tests`, where Marvisak#459 has them, and its `emit` call
passes `Target::ANY` (Marvisak#223's argument).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
Seven more upstream PRs are in (Marvisak#493, Marvisak#483, Marvisak#206, Marvisak#469, Marvisak#459, Marvisak#454,
Marvisak#579) and the wave64 stack is at Marvisak#439's head 965ce30. Records how each
was combined with what the tree had, that a capped view heap keeps
2^18 dynamic slots and why, Marvisak#189 and Marvisak#578 as left out, and a new
section with testers' reports from the title: the set without the
world-entry hang on three NVIDIA cards and how this tree differs from
it, VICTORY_SKIP_WAVE64 as the switch to try, and Marvisak#136 bisected as
making every frame black.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@slint6614-dev

Copy link
Copy Markdown

Measured on the full retail shader pack (26,503 containers) with victory translate --validate, against main d2a4bae (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-shader passes (72).

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…rol flow; waterfall loops proven)

Marvisak#566 is stacked on Marvisak#307, which this tree holds as its first two commits
(the tree's resource.rs was identical to ffa6635's). The merge so also
brings Marvisak#307's last two commits, 077ec8b and 6285e19. Git found upstream
main as the base, which sets Marvisak#307's own lines against themselves; each
file was merged with ffa6635 as the base instead.

- crates/victory-shader/src/resource.rs: Marvisak#566's, unchanged (the tree had
  no edits of its own there).
- crates/victory-shader/src/emit/lower.rs: no conflict on that base. The
  tree's lowering is kept (Marvisak#307's waterfall arm of v_readfirstlane before
  the console-flow form, fetched_index through Marvisak#483's heap guard), with
  Marvisak#566's Source::LanePhi arms and tests. lane_heap_index joins the
  indices heap_index and fetched_index return, so each is already
  guarded. Marvisak#226's annotation test passes the per-lane form to track.
- crates/victory-shader/src/structure.rs: both sides' additions kept:
  MAX_MEMO (Marvisak#288) with MAX_MEET, and in Structured the wave64 stack's
  execs, others and pairs with Marvisak#566's reach and paired_masks.
  paired_masks is filled last, since it takes the masks pairs reads.
- crates/victory-shader/src/emit/mod.rs: translate keeps Marvisak#309's spill
  forwarding and Marvisak#223's target, structures first and passes the per-lane
  form to track as Marvisak#566 does. The threading retry of emit passes its
  own. The tests' helpers (Marvisak#223's, Marvisak#306's, Marvisak#459's, Marvisak#48's) pass it too.
- apps/victory/src/translate.rs: Marvisak#566's arm (Source::LanePhi is no
  leaf); the tree's fix already counted Fetched as loaded, as 077ec8b
  does.
- docs/architecture.md: no conflict on that base; Marvisak#566's text.
- emit/image_tests.rs (Marvisak#160), emit/lane_read_loop_tests.rs (Marvisak#439),
  sgpr_spill.rs (Marvisak#309, Marvisak#320): track takes the per-lane form. Helpers
  that return the error keep the order of failures (resources, I/O,
  then structure).
- emit/waterfall_tests.rs (new, Marvisak#566): lower::Parts gets the tree's
  target, console_cf and per_lane_only; the dispatch fills Marvisak#483's guard
  dwords.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@AnoHunted

Copy link
Copy Markdown
Contributor Author

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_REQ value 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.

@AnoHunted AnoHunted closed this Nov 24, 2026
claude-GTA6 added a commit to claude-GTA6/VIctory that referenced this pull request Nov 24, 2026
Some mesh programs export more per-vertex components than fit D3D12's
32 KiB even at one vertex per lane (65-68 components from 128 lanes).
dxil.dll refuses them ("vertex plus primitive output size is greater
than 32768"), and drivers that build the pipeline anyway run undefined
behaviour.

The prologue measures the outputs as the validator does (4 bytes per
component of every vertex and primitive element, times the maxima
rounded up to 32) and, past the cap, brings the maxima down to the lane
count: lane n writes only vertex n and primitive n. This part is
AnoHunted's, from the closed Marvisak#459; on its own it clears none of these
programs, but a linked program needs it to fit.

emit::translate_linked re-emits such a mesh program and its pixel
program for each other: arbitrary values the pixel program never reads
leave both signatures, read ones end after their last read component.
D3D12 links equal masks only, so both sides change together. Elements
stay in the program while it is lowered (16-bit halves are placed from
every element of a row); exports past the linked columns are dropped
and the signature is cut when the module is finished
(lower::Parts::linked_cols). The pipeline uses the linked pair when its
bindings equal the originals; otherwise nothing changes.

Co-authored-by: AnoHunted <360473103+AnoHunted@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…instead of hiding them

FSPX modules (bare or in a DXBC ACCC part) are parsed for their thread group,
wave size and GFX10 code size; translate() reports them as unsupported rather
than a missing DXIL part. Device slot 67 (DeserializeComputePipelineStateX)
logs its pieces and returns E_FAIL (VICTORY_SLOT67_HR, diagnostics build, picks
another result); VICTORY_FSPX_REJECT_SLOT62 fails slot 62 for FSPX modules.

Refs Marvisak#459

Co-authored-by: JMAN730 <JMAN730@users.noreply.github.com>
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…nostics-459-111a

Shaders: parse FSPX compute modules; fail device slot 67 (Marvisak#459)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants