GPU: indirect dispatches and executions that may store share clamp windows #3676
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3676"
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?
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-28T05:30:05Z.
Stacked on #3197 (
pr/clamp-window,0c997d40) — draft until it lands. The diff against0c997d40is the one commit here and nothing else (crates/victory-gpu/src/{indirect,draw,list,copystat}.rs). #2472 is not needed; #3531 (our read-mark rule) is not needed but composes (see Overlap).What's wrong
#3197's windows refuse every indirect dispatch (
kind != DISPATCHindraw::execute_indirect) and every execution whose shaders may store (draw::may_store). Each of those keeps a clamp of its own: a wait for all earlier work, a one-group compute pass, another wait, the execution, then the transition back that waits for its compute work. Two traced world frames: 1,618 of 1,822 indirect dispatches were recorded right after another indirect dispatch with nothing between it and them (no barrier, no barrier group, no pipeline sync, no other command); each had a clamp of its own and ran alone.The rule, and why it is safe
A window's pass clamps every record before the window's first execution runs. An execution that stores can write the records of a later one; on the console, a later execution reads its records when the command processor reaches it, which may be while an earlier one still runs — unless the title put a barrier or a pipeline sync between them. Records written by one execution and read by the next with neither between race on the console too, so the title does not do that. So, with a window open:
List::Barrier), barrier group (BarrierGroups) or pipeline sync (Sync) came between (indirect::Run,indirect::stale_window). A barrier after an execution that may store ends what the window takes: the next execution opens a window of its own, whose pass runs (and waits) after the earlier execution.end_window).Nothing about which executions run, in what order, or what they read changes; only where their records are clamped moves. The executions also run without our waits between them, as the title recorded them: in base each indirect dispatch was ordered against its neighbours only by our clamps' barriers, which the title never asked for (direct dispatches have none either).
What changes
indirect.rs:windowedtakesstoresand records it in a per-windowRun(stored,fresh);Run::takesrefuses the next execution after a barrier or pipeline sync following one that may store.stale_window(list)is the barrier/sync hook. The window's pass needed no change: it already clamps a dispatch record with the single clamp's bounds (x groups past 65,535, more than 2^20 groups in all, 64 threads a group, the list's budget in window order), and mesh/draw/indexed records as before.list.rs:barrier,barrier_groupsandsynccallstale_window.syncdid nothing and records nothing; it is one cached-flag check now.draw.rs:execute_indirectasks only for the switch and a host pipeline; the kind andmay_storeare no longer part of the decision (a dispatch, and an execution that may store, join).may_storeis asked only with the switch on, so an off build does the work #3197 promises (one flag check). An execution the window cannot take is clamped on its own as before, which ends the window.copystat.rs(diagnostics):clamps per framenow splits the windowed executions into indirect dispatches and draws that may store, and counts the executions that opened a window because a barrier or pipeline sync came after one that may store (ClampWindowDispatches,ClampWindowStores,ClampStale);ClampStoringis now only the draws that may store that a window refused (alignment, size, a full table or records, a fifth source buffer).The switch is unchanged:
VICTORY_CLAMP_WINDOW=1, off by default, and with it unset the added work is one cached-flag check per draw plus one per barrier, barrier group and sync.Tests
GPU test status: observed on a Wine-fixed scaffold, not on the branch itself. #3197's head cannot run any clamp test under Wine here: its clamp shaders put their root signature in a
[RootSignature]attribute (which Wine'sD3DCompileignores) and read the budget throughRWByteAddressBuffer::Load(E5005 there), soclamp()isNoneandargument_clamp_builds— #3197's own test — fails, as do all 14 clamp tests onef4224db1and on0c997d40alike (scratch/PrGaps/gpu.log,gpu-window.log). That fix is the one Slay326 is taking into #3197 (1aa472de7/916655cc), not in its head. I therefore built a throwaway scaffold,tmp/gaps-wine-test= this commit + that fix'scrate::computeand shader idiom (root signatures serialized in Rust, the budget aRWStructuredBuffer<uint>; no logic changed), and ran the same device tests there: all 15indirect::tests::pass, including the three below (scratch/PrGaps/wine-gpu.log, exit 101 only from sevendraw::tests::a_*texture tests, which fail atdraw.rs:2552on that tree's own test helper building a root signature from a blob — the same Wine gap, untouched by this change).CPU (no device; observed):
indirect::tests::a_window_takes_after_stores_only_until_a_barrier— theRunrule: an empty window takes; a barrier after executions that do not store leaves it taking; right after one that may store it takes; a barrier after that one stops it. Passes onef4224db1. Fails without the change (the window takes anything that fits).GPU (device; the tests write their own records, no game data):
indirect::tests::dispatch_windows_clamp_as_single_clamps_do— passes ontmp/gaps-wine-test. 60 indirect dispatch records from one buffer with draws interleaved in the same windows, and a 6-record dispatch at the end: every record is the single clamp's word for word (same()runs the same steps twice, once clamped one at a time and once windowed). Covers x groups past 65,535, more than 2^20 groups in all, plain records, all-ones garbage, the limit case(1024,1024,1), zero groups, and a budget that runs out in the middle of the window (the records after it run empty).indirect::tests::a_barrier_after_a_store_ends_what_the_window_takes— passes ontmp/gaps-wine-test. A store between two executions, with and without a barrier: with the barrier the second record is clamped from the value the store wrote ([9,1,1], the single clamp's answer); without it one window clamps both up front ([5,1,1]). The barrier half fails without the change.windows_clamp_as_single_clamps_do,a_store_ends_the_window,a_window_clamps_max_records_whatever_the_count,windows_leave_the_argument_buffer_common,a_spent_budget_stays_spent,rejected_records_do_not_wrap_the_budget,the_budget_goes_to_the_first_records,a_record_that_does_not_fit_ends_the_budget,windowed_mesh_grids_are_the_single_clamps,argument_buffers_move_from_their_current_states,argument_clamp_builds) still pass with the newwindowedsignature and theRunrule.host()isNone).Measured
Our test stack (
perf/gpu-gaps@c3886d64d: upstreammainplus the open NVIDIA/Wine stack — among them #3197, #2472, #2312, #3531 and the Wine compiler fix), RTX 5090, Linux/Wine 11.22 + vkd3d-proton (GE-Proton11-14), headless gamescope, the title's window fitted to 1920×1080 (console Xbox Series X), prison yard after the intro, warm shader cache, 420 s runs, A(on)-B(off) then A-B again. Medians of the last 30 frame reports; the only difference between A and B isVICTORY_GPU_GAPS=1— the same code this branch ships behindVICTORY_CLAMP_WINDOWalone.Env, both:
VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info VICTORY_EARLY_RELEASE=1 VICTORY_EARLY_BARRIERS=1; A addsVICTORY_GPU_GAPS=1.Runs:
09034a7-gaps-on-u1,09034a8-gaps-off-u1(pair 1),09034a8d-gaps-on-u2,09034a8e-gaps-off-u2(pair 2). No device removal, no crash in any of the four.Read that table carefully: on that stack every indirect dispatch takes #2312's spread layout (930 and 924 a frame,
clamps per frame by reason), and only the single clamp writes a spread record — so on that stack the joins came from the ~110 indirect draws whose shaders may store, and the dispatch half of this change contributed nothing measurable there. The dispatch saving is expected on a tree without #2312 (upstreammain, where those records clamp to 65,535 groups in x), and on a tree with it only once the window's pass can spread a record too. I have not measured the dispatch half in game; the 1,618-of-1,822 figure above is a count from two traced world frames, not a frame-time result.Picture check against the control at frames 1700 and 2048 (luma, from the saved frames of the four runs): mean luma 45.5 vs 45.8 and 45.0 vs 45.2 (pair 1), 45.6 vs 45.5 and 44.9 vs 45.0 (pair 2); share of pixels differing by more than 32 of 255: 7.5 % and 7.7 % (pair 1 — the character's animation phase and input hint differ, the same order as two runs of one binary), 0.3 % and 0.5 % (pair 2). No missing geometry, shadows or lighting.
Not tested
1aa472de7/916655cc) the stack has, so it does not run under Wine here yet; the GPU tests were run ontmp/gaps-wine-test(this commit plus that fix's compiler/root-signature mechanics only), not on the branch itself. The in-game numbers come from the same change on the stack (above), which is why #2312 hides the dispatch half there.draw.rsrouting (which execution opens, joins or ends a window) has no CPU test:execute_indirectneeds a host pipeline and a list. The window pass's records are covered by the GPU tests above; the routing is covered by the runs.Overlap
windowed, so theRunrule only applies to windows. On a tree with both, a storing execution that a prelude hoisted keeps its ordering as #2472 gives it; not measured.may_storeto "may write arguments". Composes: fewer executions count as storing, so fewer barriers end a window; this branch does not touch that predicate.AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-29T08:00:38Z.
Where the measurement lives: fork issue https://github.com/neonbyte1/VIctory/issues/177 (
RESULT: https://github.com/neonbyte1/VIctory/issues/177#issuecomment-7252763596).We now hold our own PRs to a rule on the fork: a hardware test with an adjacent control of the PR's own tree before it leaves draft. This one does not meet it yet and stays a draft.
AI-assisted (Claude); measured on my machine, no game data shared.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.