Shaders, GPU: link over-budget mesh and pixel shaders under D3D12's 32 KiB output limit #2398
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!2398
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2398"
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?
@Texbirds on GitHub · 2026-11-25 12:46 UTC · original
Texbirds:feat/shader-mesh-linked-output-budget→main· +819 −16 · 5 files · 2 commits · openProblem
On
main(940d32f), the remaining 71 mesh shader DXIL validation failures all fail withvertex plus primitive output size is greater than 32768. These shaders declare 65–68 output components across 128 lanes (up to 34,816 B > 32,768 B), so loweringmax_vertices/max_primitivesto the thread count alone cannot fit them under D3D12's 32 KiB budget, while refusing them drops their draws.Fix
victory-shader/src/emit/container.rs,emit/mod.rs):MESH_OUTPUT_LIMIT(32 * 1024) andmesh_output_bytesmatching DXIL's 32-vertex / 32-primitive chunked output-size validation formula (also readable from emitted DXIL viaPSV0/OSG1/PSG1with noHostShader/ shader-cache schema change).victory-shader/src/emit/lower.rs):max_vertices/max_primitivespush its output footprint past 32 KiB, tighten them toms.threads(every lowered mesh output writesmesh_thread()).victory-shader/src/emit/lower.rs,emit/mod.rs,victory-gpu/src/pipeline.rs,pipeline/host.rs):emit::translate_linked(mesh, pixel, options)which inspects the paired pixel shader'sISG1read masks (or empty reads for depth-onlypixel = None), removes arbitrary (kind == 0) outputs the pixel shader never reads, and trims unread leading/trailing channels identically on both stages so D3D12 cross-stage signature linking stays exact.packed_halfandunnamed_rowanchored to the unpruned console signatures (x.inputs/x.outputs) so 16-bit packed-half placement is preserved when dead elements are pruned.HostPipeline::new, invoke cachedpipeline::translate_linkedonly when a mesh shader still exceedsMESH_OUTPUT_LIMITstandalone (zero overhead for the ~99% of mesh shaders already under 32 KiB).Tests
container::tests::mesh_output_bytes_matches_dxil_budgetemit::tests::mesh_exceeding_32k_tightens_counts_to_group_threads(64-lane mesh tightened from 34,816 B to 17,408 B +dxil.dllvalidation)emit::tests::linked_mesh_and_pixel_prune_unused_outputs_under_32k_and_draw(128-lane, 68-component = 34,816 B mesh linked depth-only to 2,048 B and linked with a paired pixel shader readingTEXCOORD0.xy+TEXCOORD15.zwto 4,096 B, validated withdxil.dlland rendered on hardware + WARP verifying all 256 pixels match[1.0, 0.5, 0.25, 1.0])Verification
Awaiting Windows CI (
cargo clippydefault +--all-features,cargo test --workspace --locked) and hardware/corpus testing.@steven-seagull27 on GitHub · 2026-11-25 13:02 UTC · original
Tested
35ae33bon an RTX 5080 (driver 621.40) and built-in Microsoft WARP (10.0.26100.10068). All three new tests passed on the unmodified PR head. I also ran the linked draw once per adapter with readback logging and checked each adapter’s DXGI identity.[1.0, 0.5, 0.25, 1.0][1.0, 0.5, 0.25, 1.0]The 128-thread synthetic mesh declared 34,816 bytes standalone. Linking reduced that to 4,096 bytes with the paired pixel shader and 2,048 bytes for positions alone. The Windows SDK DXIL validator accepted both linked mesh shaders and the paired pixel shader. The separate 64-thread case validated at 17,408 bytes.
The PR test validates the positions-only mesh. As an additional local check, I drew it on the RTX with no pixel shader into a D32 target cleared to 1.0. With a full viewport, 256/256 depths read exactly 0.5. With a half-width scissor, all 128 covered pixels read 0.5 and all 128 outside it retained 1.0. On built-in WARP, that additional draw returned a device error before any depth readback, so its depth result is inconclusive. The color readback above completed on both adapters.
These are synthetic shader fixtures. The 71 title shaders and their in-game draws remain unverified here.
@Marvisak on GitHub · 2026-11-25 15:55 UTC · original · edited 2026-11-26 00:20 UTC
Automated triage for the maintainers.
Merge candidate. Mesh shaders over D3D12's 32 KiB output budget have their counts tightened to the thread count (
Lower::new,crates/victory-shader/src/emit/lower.rs). One that still doesn't fit is translated again with its pixel shader (translate_linked,emit/mod.rs), dropping outputs the pixel shader never reads.13ac07baddresses both findings from the last triage:emit_linked_meshreturns an error if the linked mesh is still overMESH_OUTPUT_LIMIT(on both the paired and depth-only paths), andHostPipeline::new(crates/victory-gpu/src/pipeline/host.rs) now refuses the pipeline instead of falling back to the over-budget standalone mesh. Count tightening now looks at the unprunedx.outputs/x.prims, so pruning can't bring back 256 primitives on a 128-thread mesh. The test covers the exact limit, one component over it, and the kept primitive count.On your reply: confirmed in the diff. eIBart0's in-game run on AMD in this thread (all 71 previously refused mesh shaders translate; faces and skin render) and the RTX/WARP/Intel runs are on the earlier head. A hardware re-run of
13ac07bwould be welcome. CI: passing.Generated by Claude Code
@eIBart0 on GitHub · 2026-11-25 16:13 UTC · original
Tested on AMD: RX 9070 XT (driver 32.0.31041.3013), Windows 11, ported onto Belobug's AMD fork (
01aadd1). All 71 previously refused mesh shaders translate, and characters' faces and skin now render in game (they were missing before). The PR's three tests pass on Windows with dxil.dll validation.Two notes from the port, in case they help here too:
v_mbcnt_lo_u32_b32 v1, -1, 0declaredWaveOpswithout emitting a wave op (the fork treats mesh masks as host masks), so the new tests failed validation with "Flags must match usage". Setting the flag only wherewaveGetLaneIndexis emitted fixed it. Upstream may not hit this, since mesh masks are not host masks there.translate_linkedreturnsNonefor a mesh still over 32 KiB, the standalone over-budget mesh went on to PSO creation. Refusing the pipeline in that case keeps the previous clean refusal.@Texbirds on GitHub · 2026-11-25 16:17 UTC · original
Thanks @steven-seagull27 for testing
35ae33bon RTX 5080 and WARP (including the extra depth-only readback)!Two quick notes on the minor points from triage:
"first bind"log size:bound()incrates/victory-gpu/src/pipeline.rslogsp.shaders(the original unlinkedPipeline::shaders), whereas linkedShaders only live inHostPipeline::stageswithtranslatedalready initialized, so"first bind"still reports the original container size and nothing reads.containeron linked stages.depth_mspasses DXIL validation and produced 256/256 exact depths (and exact scissor bounds) on RTX 5080, if @steven-seagull27 still has the WARPHRESULT/ debug-layer message handy I'd be happy to check whether it's a WARP quirk or anything in the emitted positions-only DXIL.Leaving
35ae33buntouched for now so the verified head stays intact unless a maintainer wants changes.@KainanP on GitHub · 2026-11-25 19:03 UTC · original
Tested
35ae33bmerged onto currentmain(13f91ca, merges cleanly) on a laptop with an RTX 4060 Laptop (driver 610.47), an Intel UHD Graphics iGPU (8086:a78b, driver 31.0.101.5445, 16 lanes, no FP64) and WARP (10.0.26100.9818), Windows 11 26200.9974, rustc 1.98.1. Validation used the Windows SDKdxil.dll(10.0.26100.0).mainhas no way to pick an adapter by name, so a local patch (not pushed) selects NVIDIA or Intel for bothemit::host::Hostandvictory-gpu's host device and logs which adapter each test process used. Intel is new coverage for this PR.cargo test -p victory-shader --lib --locked --no-fail-fastandcargo test -p victory-gpu --lib --locked --no-fail-fast, run onmainand on the merge, per adapter. WARP:VICTORY_WARP=1, and for victory-gpuVICTORY_D3D12_WARP=1with--features diagnostics, since that switch only exists there. On the RTX I skippedemit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexon both sides, because it crashes the test process with an access violation onmaintoo.main→ mergemain→ mergeThe +4 in victory-shader are this PR's 3 tests plus the ported test below. Every failure also fails on
mainon the same adapter, and none is in mesh or linking code (stride/gather/permute/BVH/fspx/64-bit image atomics, already known per adapter). *descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_recordfailed once onmainand passed 3 of 3 reruns, so it is flaky, not a difference.All 3 tests from this PR pass on every adapter. With
--nocapture, both linked draws read back 256/256 on the RTX and on WARP. The Intel UHD reports no mesh shader support (D3D12_OPTIONS7), so there the draw parts skip themselves ("no mesh shaders on the hardware device"). Translation, the byte counts anddxil.dllvalidation still pass, and the WARP leg of the same process still draws 256/256. In practice an iGPU of this generation never reaches the linked path in the game. The PR's 16-lane coverage is that nothing regresses there.Test that could be cherry-picked. I ported the test I had written for the closed #1563 to this PR's
emit_pruned/pixel_input_reads(commit194e921, on top of35ae33b, test only). It covers whatlinked_mesh_and_pixel_prune_unused_outputs_under_32k_and_drawdoes not:dxil.dllmust refuse the unlinked 128-lane / 68-component mesh with "greater than 32768". The existing test checks only the byte count.TEXCOORD1.xand.w, with two unread channels between them, andTEXCOORD15.yalone. It declaresTEXCOORD16and never reads it.OSG1=SV_Position,TEXCOORD1(col 0, 4 cols),TEXCOORD15(col 1, 1 col). PixelISG1= the same two, withTEXCOORD16gone. The footprint is 4,608 bytes, and both modules validate.It passes on all three adapters, both on the PR head and merged onto
main.cargo clippy -p victory-shader --all-targetswith--features hostand with--all-features,-D warnings: clean. rustfmt: clean.A small note:
cargo clippy -p victory-shader --all-targetswithout thehostfeature now warns thatemit::lower::loweris never used, since onlyemit::hostand the tests call it after this change. CI builds the workspace withhoston, so CI doesn't see the warning.This supersedes #1563 (claude-GTA6's earlier mesh+pixel linking, closed without a reason). We had asked there whether it would come back before reviving it from a fork. With this PR covering it, we won't revive it, and I've left a note there.
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.
@brainbudt on GitHub · 2026-11-25 21:10 UTC · original
Independently tested
35ae33bmerged onto13f91ca. Windows MSVC workspacecargo check --testspassed, and the sparse linked draw produced the expected RGBA output on all 256/256 pixels on Windows WARP (10.0.26100.9818). Two issues found before merge:translate_linkedreturnsOkfor still-over-budget output (crates/victory-shader/src/emit/mod.rs:530,crates/victory-gpu/src/pipeline/host.rs:353): With 128 lanes, 60 live components + position produces 32,768 bytes and validates, but 61 or 64 live components returnsOkat 33,280 B / 34,816 B. Microsoft DXIL Validator1.9.2609.5(anddxv) rejects both (vertex plus primitive output size is greater than 32768), yet the GPU path caches the pair as a success—and on link error it can still pass the known-over-budget standalone mesh to pipeline creation. Please enforce<= 32,768bytes on both return paths and refuse pipeline creation when an over-budget mesh fails to link.crates/victory-shader/src/emit/lower.rs:594): In a 128-thread fixture declaring 256 primitives, standalone DXIL emitssetMeshOutputCounts(128, 128), whereas sparse linked DXIL restores(128, 256)while bothemitIndicescalls still index by thread ID, leaving primitives 128–255 without indices. Preserving the pre-pruning count decision avoids this mismatch.@Texbirds on GitHub · 2026-11-25 21:54 UTC · original
Thanks for the boundary cases. I addressed both findings in
40290dc:translate_linkedchecks the final mesh output size in both the paired and depth-only paths. It accepts exactly 32 KiB and rejects anything larger. If a known-over-budget standalone mesh fails to link, pipeline creation stops instead of falling back to it.I extended the existing regression test to cover the exact limit, one retained component over it, and preservation of the 128-primitive count in both linked modes.
git diff --checkpassed. Windows blocked Cargo’s build scripts locally, so the revised test still needs a Windows run.@Texbirds on GitHub · 2026-11-25 22:40 UTC · original
Pushed the fixes rebased onto
main(f3578e3) at13ac07b(the earlier40290dchadn't been pushed yet):emit_linked_meshincrates/victory-shader/src/emit/mod.rsnow enforces<= MESH_OUTPUT_LIMIT(32 KiB) on both the paired and depth-only paths, andHostPipeline::new(crates/victory-gpu/src/pipeline/host.rs) refuses the pipeline if an over-budget mesh fails to link instead of falling back to the standalone over-budget mesh (also addressing @eIBart0's note).Lower::new(crates/victory-shader/src/emit/lower.rs) checks the original unprunedx.outputs/x.primssignatures so sparse linking cannot restoremax_primitives = 256on a 128-thread mesh.emit_pruneddispatches tolower::lowerwhenkeepisNone, clearing thedead_codewarning onvictory-shaderbuilds without--features hostnoted by @KainanP.linked_mesh_and_pixel_prune_unused_outputs_under_32k_and_drawto cover the exact 32 KiB boundary, one component over the limit, and preservation ofmax_primitives = 128across standalone, depth-only, and linked modes.@fuzeofficlal on GitHub · 2026-11-26 00:38 UTC · original
Code review and native RTX 5090 Mesh Shader + WARP + DXIL verification at head
13ac07b570b8merged cleanly ontomain(63bcca43c6a0):pipeline/host.rs:436-450triggerspipeline::translate_linkedonly when standalonemesh_output_bytes > MESH_OUTPUT_LIMIT(32 KiB), passes emptyKeptOutputsfor depth-only passes, and rejects the pipeline cleanly if pruned outputs still exceed 32 KiB.emit/mod.rs:459-490, 520-571reads PSISG1+25(ReadWriteMask),prune_signature(lower.rs:595-601, 657-677) drops unreadkind == 0outputs/inputs and tightensmax_vertices/max_primitivesto.min(ms.threads), while lowering (lower.rs:8199, 10010, 10200) continues indexing register slots against the unprunedself.xsignature so slot alignment stays intact.main(63bcca43),crates/victory-shader/src/emit/lower.rsis522,975B (1,313B under the 512 KiBxtask policycap). Worth noting if merged alongside otherlower.rs-growing PRs (e.g.#2776/#2920).VICTORY_D3D12_DEBUG=1,dxil.dll10.0.26100.0, Rust 1.98.1):victory-shader(emit::tests emit::lower::tests) 52/52 passed (includinglinked_mesh_and_pixel_prune_unused_outputs_under_32k_and_drawandmesh_exceeding_32k_tightens_counts_to_group_threadsexecuting on native Blackwell mesh pipelines);victory-gpu(pipeline) 28/28 passedvictory-shader52/52 passed;victory-gpu --features diagnostics(pipeline) 28/28 passedcargo xtask policy:191 files ok;cargo clippy --locked -p victory-shader -p victory-gpu --tests -- -D warnings(default +--all-features): 0 warnings.LGTM.
@steven-seagull27 on GitHub · 2026-11-26 01:22 UTC · original · edited 2026-11-26 01:42 UTC
@Texbirds I reran the depth-only case on
13ac07b. On built-in WARP 10.0.26100.10068 the positions-only mesh PSO was created. The first D32 draw then returned0x887A0005(DXGI_ERROR_DEVICE_REMOVED), andGetDeviceRemovedReasonreturned the same HRESULT. The D3D12 info queue reported message 234,ID3D12Device::RemoveDevice, with “Plug-and-play stop has been exercised on this adapter.” I saw no preceding validation error in the queue. The draw also failed with the debug layer off.I compiled a separate native
ms_6_6mesh in DXC with 128 threads, 128 vertices, 128 copies of triangle (0, 1, 2), and positions generated fromSV_GroupIndex. I used the same depth buffer, root signature, viewport, command recording and readback. Each cell below ran in a separate process with the debug layer.0x887A00050x887A0005SV_Position.ztoSV_Depth“Exact” means all 256 pixels read 0.5 in the full draw. With a half-width scissor, 128 read 0.5 and 128 kept the clear depth of 1.0, at the expected positions. The ordinary linked color draw matched 256/256 on the RTX and built-in WARP. The updated assertions for exactly 32 KiB, one component over budget, and the 128-primitive limit also passed. The native control narrows the built-in WARP failure to something reproducible without VIctory’s mesh translation. It has not identified the cause in the D3D12 stack.
App-local Microsoft WARP 1.0.22 behaved differently on this PC. Its native control produced exact depth with and without a PS. The translated draw left all 256 depths at the clear value in both cases, and the ordinary linked color check matched 0/256. I would track that software runtime separately from the built-in WARP HRESULT above.
Follow-up on portable WARP 1.0.22. The translated mesh writes degenerate primitive indices before the guest
exp primwrites its actual indices. A native DXC mesh reproduced the discrepancy with just two assignments to one primitive. Each thread used its ownSV_GroupIndex, in bounds, and a depth pixel shader was present throughout. Here's how many of the 256 pixels received depth 0.5:(0,1,2)(0,0,0)(0,0,0)then(0,1,2)(0,1,2)then(0,0,0)Both DXC
-Odand-O3retained the twoemitIndicescalls and produced the same table. The D3D12 mesh specification says the last write to the same primitive supplies its indices. The portable runtime behaved as if the first write won on this fixture. DirectX mesh shader specification, Vertex IndicesAs a diagnostic on this one shader, every lane exports a primitive, so I omitted the initial degenerate write. The actual translated linked draw then produced 256/256 correct color pixels on portable WARP. Full-frame depth was correct at 256/256 and the scissored depth was correct at 128 written + 128 clear, three runs on all three adapters. General guest shaders can leave primitives unwritten and still need initialization. This explains the portable result separately from the built-in WARP no-pixel-shader device removal.
AI-assisted with Codex. Synthetic draws only.
@r4tedx on GitHub · 2026-11-26 07:07 UTC · original
Tested
13ac07b5merged onto currentmain(842b0cb). It merges cleanly.The new commit (
13ac07b5) looks right to me. The count tightening now measures the original signatures, so pruning cannot bring the declared counts back. A linked mesh that still exceeds 32 KiB is refused by name, and the pipeline is refused rather than silently falling back to the standalone mesh. The unpruned path callslower::loweragain, which also clears the clippy finding I reported earlier (function `lower` is never used).cargo clippy -p victory-shader --all-targets -- -D warningsis now clean with and without--features diagnostics. So arevictory-gpu(both) andvictory.Offline census over the title's shader pack:
vertex plus primitive output size is greater than 32768when translated alone. That is expected, because the fix is in the linked path.translate_linked(mesh, None, ..), through a small local census aid that is not part of this PR): 71 of 71 validate, 68 at 2,048 B and 3 at 2,560 B.Tests (WARP),
main+ this PR:victory-shaderlib 300 passed, 4 failed, the same 4 that fail onmainon this machine's WARP. The PR's tests pass, including the 32 KiB boundary case inlinked_mesh_and_pixel_prune_unused_outputs_under_32k_and_draw.victory-gpupipelinetests: 28 passed, 0 failed.The unit tests are synthetic. Local title data was used offline for the census: a translation of the title's shader pack, with only counts and refusal reasons reported.
AI-assisted
@catminou4 on GitHub · 2026-11-25 13:19 UTC · original · reviewed
Link over-budget mesh+pixel shader pairs (LinkedPair/LinkedKey, +761). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Large; needs hardware validation.
@fuzeofficlal on GitHub · 2026-11-26 14:28 UTC · original · approved these changes
Reviewed
13ac07b570b806fbe77434a6240b6f6d190b063emerged cleanly ontomain(63bcca43c6a0) and verified on Windows 11 x64 with native NVIDIA GeForce RTX 5090 mesh shaders, Microsoft WARP, the D3D12 Debug Layer, and Windows SDKdxil.dll(10.0.26100.0).Code Review
crates/victory-shader/src/emit/container.rs:8,13,emit/mod.rs:383,emit/lower.rs:675):mesh_output_bytesmatchesPSV0v2 header offsets (+12max_vertices,+14max_primitives,+24stage13) and the 32-vertex/32-primitive alignment rule. Checking the original unprunedx.outputs/x.primsensures sparse linking cannot inflatemax_primitivesback pastms.threads, andmesh_prologuedrives bothsetMeshOutputCountsand theemitIndicesguard directly from the tightened counts.crates/victory-shader/src/emit/lower.rs:105,131,8202,10013,10193,emit/mod.rs:459,520,555):pixel_input_readsreads PSISG1+25read masks cleanly,prune_signaturetrims leading/trailing unread channels consistently across MSoutputs/primsand PSinputs, andpacked_half/unnamed_rowstay anchored to the unprunedself.xsignatures so packed 16-bit slot indices stay intact.crates/victory-gpu/src/pipeline.rs:220,236,255,pipeline/host.rs:412-435): Under-budget mesh pipelines bypasstranslate_linkedwith zero overhead and unchanged pipeline library cache keys;translate_linkeduses the sameOptions { view_marks: true }asshader_cache, and an over-budget mesh that still exceeds 32 KiB after linking is cleanly refused rather than falling back to the invalid standalone DXIL.main(63bcca43),crates/victory-shader/src/emit/lower.rsis522,975bytes (1,313bytes below the 512 KiBxtask policycap)—worth keeping in mind if otherlower.rs-growing PRs land alongside it.Verification (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1+ SDKdxil.dll10.0.26100.0, Rust1.98.1)cargo run --locked -p xtask -- policy:191 files ok.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(withouthost), plus-p victory-shader -p victory-gpu --all-targets(default and--all-features): 0 warnings.victory-shader(emit::container::tests emit::tests emit::lower::tests,--features host): 54/54 passed on RTX 5090 and 54/54 passed on WARP (--nocaptureconfirmed both adapters executed the linked draw and validated withdxil.dllwithout skipping).victory-gpu(pipeline::,VICTORY_D3D12_DEBUG=1): 23/23 passed on RTX 5090; 26/26 passed on WARP (--features diagnostics).dxil.dllrejects the unlinked 34,816 B mesh withvertex plus primitive output size is greater than 32768, and accepts a linked mesh retaining a non-contiguous read (TEXCOORD1.x/.wkept ascols=4plusTEXCOORD15.ytrimmed tocol=1, cols=1,4,608B).LGTM.
View 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.