Shaders: honor the mesh allocation request counts #586
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!586
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-586"
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?
@Kam471 on GitHub · 2026-11-24 05:13 UTC · original
Kam471:mesh-alloc-counts→main· +6198 −340 · 22 files · 21 commits · openProblem
Console mesh shaders declare their output maxima in the container, then request the group's real vertex and primitive counts with
s_sendmsg(GS_ALLOC_REQ)in M0 (vertices = m0 & 0xFFF,primitives = m0 >> 12). The translator ignored the request and declared the maxima. A culled group, whose request path is skipped, still exported its declared 128 vertices and 128 primitives; stale or undefined positions become full-screen garbage with a deferred pixel shader. In the world, the transform family took 0.8-5 s per dispatch and hit the 2 s watchdog.Change
SetMeshOutputCountsat the join: the decoded counts, clamped to the declared maxima.(0,0), emits a defined zero-area vertex 0 and zero indices; real exports overwrite both.Validator
dxil.dllrejects the natural two-call shape:so the only accepted shape is one call at a uniform join. That is the form emitted, and the test asserts it.
Tests
mesh_alloc_counts_translate_and_validate: a 128-thread mesh with a uniform two-way branch, requests(3,3)and the console dummy(1,1); both forms validate.gpu_mesh_alloc_counts_culled_group_draws_nothing: a culled(1,1)group leaves the target clear; the(3,3)control rasterizes.gpu_mesh_alloc_counts_culled_dispatch_cost.cargo test -p victory-shader: 113 passed, 0 failed.dxil.dll: nineMS_VS_Transform*/MSNC_VS_Transform*variants,!MS_VS_DepthSkin, andMS_VS_BreakableGlassNoCrack.In-game
With this and the rendezvous bound in the first commit, seven previously hanging transform hashes (
37f363f0a5dcd806,14c00e888b4df658,0d9d1c59733d6340,89036e16fa081505,3fd417e7d6f55114,857b2e13c9cc107f,c9dee8dc4ad07dd4) translated and ran with no mesh dispatch over 50 ms and no device removal. One hash (c962201cddbdd7dd) still took 5.1 s; that turned out to be a root-SRV read past the host copy and is fixed by #493, not by this change. No title data is included here.Stack
The first two commits are #464 and #459; the last two are this PR (the rendezvous bound and the allocation counts). Review the last two.
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]>@iurysf on GitHub · 2026-11-24 06:17 UTC · original
Tested offline against main
d2a4baewithvictory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17. This branch carries the #464 and #459 commits, so the numbers measure the stack:v_readfirstlanerefusal meant to be this broad? The GPU side is being measured on an RTX 4070 and I'll post it here.AI-assisted.
@iurysf on GitHub · 2026-11-24 07:06 UTC · original
In-game data point, following my offline numbers above. RTX 4070 (driver 32.0.16.2101), diag build, default loop limit,
VICTORY_D3D12_DRED=1, 300 s runs. One run each, and the host CPU was busy with other jobs, so treat the timings loosely.d2a4baeslow host list ms=6732 commands=42)v_readfirstlanerefusal drops offline. The window title was empty, so I have no fps for it.draw.rsandlower.rs). On our RTX 4070, #493 + #483 is the pair that stops the removal (see #493), so I couldn't test the combination.AI-assisted.
@fuzeofficlal on GitHub · 2026-11-24 07:13 UTC · original
For the #201 output-size case, I tested an incremental change on
9b5e239that uses the two output limits encoded by proven literal M0 definitions. It takes the maxima across all planned requests and changes the declaration only when the result fits the output budget. It also gates dummy vertex initialization on a nonzero vertex count.My synthetic 128-thread mesh exports 19 signature elements (67 components). With a literal allocation of 96 vertices and 1 primitive, this head declares
128/128and the Windows SDK validator rejects the output size. The follow-up declares96/1, validates, and native D3D12 reads back 16/16 expected pixels using the last vertex output. The zero-count case validates and leaves all 16 pixels clear. The literal-97 and runtime-count controls retain the old declarations and validator result. The serial shader suite passed 114 tests, including a portable test for two different literal request sites and a runtime operand.Incremental source change on this head
@iurysf on GitHub · 2026-11-24 08:12 UTC · original
Root-cause note from the RTX 4070 runs, supporting this PR's allocation-count fix and suggesting a split.
What the hangs look like here: on main + #493 + #483, the slowest lists are dominated by one mesh+pixel pair,
[mesh 51ff151f75cd5759, pixel 7fe75645c406cac6]. The same draw costs 38 ms, 678 ms, 1.1 s or 1.7 s depending on the frame, and it is the stalled list in DRED (5.5 s) in the #595 run. I checked offline:VICTORY_SHADER_LOOP_LIMIT, #452 and spin-wait handling don't apply. The pixel program is cheap (693 instructions, loop-free), which points at coverage, not shader cost.s_sendmsg GS_ALLOC_REQ(M0 = prims << 12 | verts) and has the null-primitive path for a culled group. The emitted DXIL has a constantSetMeshOutputCounts(128, 128)and default (0,0,0) indices. That holds for all mesh programs: every one of the 9,282 mesh containers hasGS_ALLOC_REQ+ a null-primitive path + a barrier, and 40 of 40 sampled DXIL mesh modules have a single(128,128).That's exactly the diagnosis in this PR's description (undefined positions becoming full-screen garbage under a deferred pixel shader). So the allocation-count part looks like the fix for the remaining multi-second lists on NVIDIA too.
The problem with the PR as it stands: the same branch's wave64 mesh emulation refuses 610 mesh programs with
v_readfirstlane in divergent control flow(emulated_readfirstlane), measured offline earlier. That includes51ff151f75cd5759(offset0x63c). So with this PR the slow draw disappears because it is no longer emitted, and the draws it makes disappear with it. In game we saw 1–6 draws/frame.Suggestion:
GS_ALLOC_REQcounts, i.e. oneSetMeshOutputCountsat the uniform join, clamped to the declared maxima, with (0,0) on the culled path. Commit9b5e239(~325 lines) seems to be where (b) lives. It doesn't cherry-pick onto main as-is (3 conflict regions) because it uses the emulation'sscratch_ptr/lds_barrier/emu_barrier/uniformity analysis.waveReadLaneFirst) instead ofErr. Main already emits and validates those 610. It only differs when the value varies between the two halves of a console wave, which could be logged.We'd be glad to measure a split (b) on the RTX 4070. The next step on our side is a run of main + #493 + #483 with and without
VICTORY_SKIP_PIPELINES=51ff151f75cd5759,649aa1b64998a5f2andVICTORY_GPU_TIMING=1, to confirm how much of the GPU frame time those draws account for. I'll post the result here.AI-assisted.
@iurysf on GitHub · 2026-11-24 08:26 UTC · original
Follow-up to my previous comment: the in-game test does not confirm that this pair causes the multi-second submissions.
RTX 4070 (driver 32.0.16.2101), main + #493 + #483, default loop limit, 300 s,
VICTORY_GPU_TIMING=1, one run per condition, host CPU busy:VICTORY_SKIP_PIPELINES=51ff151f75cd5759,649aa1b64998a5f2The skip was applied: the program was bound but not translated, so its draws were dropped. Skipping it didn't lower GPU time or peaks. And in this base run none of the slow submissions involved the pair at all, while other sessions had it in 1 of 27 or 18 of 60. So the peaks depend on more than this pair, e.g. session conditions or the order pipelines get compiled.
What still stands from the offline analysis: every emitted mesh program declares a constant
SetMeshOutputCounts(128, 128)while the console requests its real counts withGS_ALLOC_REQ, and the wave64 emulation in this branch refuses 610 mesh programs, including that one. Whether honoring the counts reduces GPU time on NVIDIA is still open. We're preparing a minimal counts-only build (without the wave64 emulation) to measure that directly, with repeated runs on an idle CPU.AI-assisted.
@GlorpGirl on GitHub · 2026-11-24 09:03 UTC · original
RTX 5090 (desktop), driver 621.01, Windows 11, 64 GB: tested this PR merged onto main at
c7a5f49(conflicts in draw.rs, list.rs, watch.rs and lower.rs resolved by hand) plus #588, diag build withVICTORY_D3D12_DEBUG=1andVICTORY_D3D12_DRED=1. Like iurysf's RTX 4070 run, the device is still removed (DXGI_ERROR_DEVICE_HUNG), and no 3D shows before it.What may be new: list splitting doesn't avoid it.
VICTORY_LIST_SPLIT=64: hung, with a list stopped at command 120 of 122 (op 42, an indirect draw).VICTORY_LIST_SPLIT=16: hung after a submission of 1 list that stopped at command 86 of 87 (op 42). That list holds texture uploads and one indirect mesh dispatch with mesh04b9be3756e8f41c/ pixel1af4a50c7fb40c97.So on this GPU a single emulated indirect mesh dispatch of
04b9be3756e8f41cseems to run past the 2 s watchdog by itself, or never finishes. For comparison, main plus #588, #587, #578 and #189 (wave64 mesh refused on 32-lane hosts) runs through the intro credits without a removal, but draws no 3D. Happy to run a counts-only build or other variants on the 5090.@iurysf on GitHub · 2026-11-24 09:39 UTC · original
In-game result for the counts-only idea, as promised above. On NVIDIA it doesn't measurably change GPU time.
I built a minimal counts-only prototype on main
c2e7254, without the wave64 emulation: https://github.com/iurysf/VIctory/commits/mesh-alloc-counts-proto (977ece0).GS_ALLOC_REQhas a decodable M0 and the requests share a join that post-dominates the entry and dominates the exports, thread 0 zeroes an LDS dword and the request stores M0 there. A barrier and oneSetMeshOutputCountsat the join then declare the requested counts, clamped to the declared maxima, and the skipped path declares (0,0).In game: RTX 4070, driver 32.0.16.2101, main
c2e7254+ #493 + #483 as the base, 3 runs each alternating, 300 s,VICTORY_GPU_TIMING=1+DRED=1, idle host CPU.So on this GPU, in the first mission's intro, the constant 128/128 declaration doesn't seem to be what makes frames slow. The counts are still the correct translation of
GS_ALLOC_REQ, and the branch is there if it helps the split.AI-assisted.
@slint6614-dev on GitHub · 2026-11-24 10:42 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. This PR conflicts with mainc7a5f49, so it was measured on its own base (main before #612: MS 8191 / 8129 / 8191).With this PR, MS: 7582 / 7538 / 7582, so 591 fewer validated mesh programs:
v_readfirstlanethat the emitter refuses in divergent flow.Given that mesh programs draw most of the world, it may be worth making the request path not depend on a divergent
v_readfirstlane, or falling back to the declared maxima when it cannot be proven uniform, before this lands.@EduBertozzi on GitHub · 2026-11-24 12:50 UTC · original
Windows 10 + Pascal run of this PR's own tests, and a design question on the mesh rendezvous.
Setup: Windows 10 Education 22H2 (19045), GTX 1060 6 GB (582.66, 32-lane waves, no mesh shaders), Rust 1.98.1, debug. I tested this PR's head
9b5e239on its own base, with #486 merged locally so the test binaries get SM 6.6 from the Agility SDK runtime. The redistributable WARP 1.0.22 (Microsoft.Direct3D.WARP: SM 6.6, waves of 4 to 128 lanes, mesh shaders) was beside the test binary.cargo test -p victory-shader wave64 -- --test-threads=1:gpu_128_threads_ds_swizzle_and_dpp_row_mask, inWave32mode on WARP, fails at the dispatch with the device removed, 3 of 3 times when run alone. The same test passes on the GTX 1060.recommended_wave64_mode_matches_device_capabilitiesasserts that WARP recommendsEmulate. That holds for in-box WARP (4-lane waves), but WARP 1.0.22 recommendsNative. GitHub's runners list the in-box WARP, so CI won't see this.no dxc for a pixel shader; PSO skippedhere (Windows SDK 10.0.28000 installed,dxil.dllfound). So where the tests find no DXC, they pass without building a mesh pipeline or drawing anything.On the mesh wave rendezvous (
wave_barrier, the spin-wait bounded byspin_limit). A wave that waits on an LDS counter for another wave of its group to arrive depends on that wave being scheduled meanwhile, and D3D12 doesn't promise that. #439's design notes (docs/wave64-on-wave32.md, "Groups of several console waves") dropped this approach for that reason. Their measurement on an RTX 5070: the upper half of a group didn't write LDS before the lower half read it unless a barrier ordered them, 20 of 20 runs. Where the partner wave isn't running, the bounded wait ends after 4096 rounds with the program going on as if it had arrived. That gives a wrong result, at the cost of the spin. That fits the RTX 4070 and 5090 runs above, which still remove the device. For mesh groups of one console wave (64 threads), #439's console flow needs no wait at all: group barriers, with both halves taking every branch together.Splitting: +1 to the split suggested above. The DualSense/HUD input, list splitting, guarded views and spin-wait limits could each be measured and merged on their own. That would also show which part changes the NVIDIA runs.
For the group-size question this leaves open, I've asked for a census of the title's mesh programs on #778 (
victory mesh-census: group sizes, LDS, barriers, lane reads). Every one of them is wave64, so whether they fit in one console wave decides a lot.AI-assisted (Claude Code); runs on my machine, no game data.
@ricarmandoagent on GitHub · 2026-11-24 13:08 UTC · original
This branch carries four other unmerged PRs, and the body has no
Depends online:The description covers only the mesh allocation request. As it stands the diff cannot be reviewed as one topic, and merging it lands four unrelated changes at once — #150 is not even in the same subsystem.
Please rebase on
main, and either split this into the stack it is (withDepends on:naming each parent) or wait for them to land first.AI-assisted review.
@BaggyALPHA on GitHub · 2026-11-24 16:25 UTC · original
I checked whether the literal-M0 approach discussed here could tighten the vertex declaration for the 53 output-size failures in #201. I used an offline diagnostic on #459 head
dc838d6, paired its request analysis with the SDK validator results, and left the emitted DXIL unchanged.All 53 failing modules had one allocation request each. None of the 53 request operands was a literal. I also traced the low 12 vertex-count bits separately, propagating known bits through scalar moves, bitwise operations, shifts, and SSA joins. This let the probe consider the vertex bound even if the primitive field was unknown. It proved a bound of 96 or fewer for 0 of 53 and left all 53 unresolved.
That does not establish that any request exceeds 96 at runtime. It does show that the literal-M0 change demonstrated on synthetic shaders would not match this group as written. This check did not run the #586 runtime code or exercise rendering.
AI-assisted analysis and write-up (OpenAI Codex). Aggregate counts only.
@Marvisak on GitHub · 2026-11-25 00:28 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:README.md,crates/victory-gpu/src/descriptor/host.rs,crates/victory-gpu/src/draw.rs,crates/victory-gpu/src/host.rs,crates/victory-gpu/src/list.rs,crates/victory-gpu/src/shader_cache.rs,crates/victory-gpu/src/watch.rs,crates/victory-hle/src/modules/mod.rsand 5 more.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.