Skip to content

GPU: indirect dispatches and executions that may store share clamp windows - #3676

Draft
neonbyte1 wants to merge 5 commits into
Marvisak:mainfrom
neonbyte1:pr/clamp-window-dispatches
Draft

neonbyte1 wants to merge 5 commits into
Marvisak:mainfrom
neonbyte1:pr/clamp-window-dispatches

Conversation

@neonbyte1

Copy link
Copy Markdown

Stacked on #3197 (pr/clamp-window, 0c997d40) — draft until it lands. The diff against 0c997d40 is 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 != DISPATCH in draw::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:

  • after an execution that may store, the window takes the next execution only while no barrier (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.
  • barriers between executions that do not store leave the window as it is: nothing in it wrote.
  • anything else ends the window exactly as before: any draw, dispatch or UAV clear that is not a joining indirect execution, a host library's work, the list's end (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: windowed takes stores and records it in a per-window Run (stored, fresh); Run::takes refuses 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_groups and sync call stale_window. sync did nothing and records nothing; it is one cached-flag check now.
  • draw.rs: execute_indirect asks only for the switch and a host pipeline; the kind and may_store are no longer part of the decision (a dispatch, and an execution that may store, join). may_store is asked only with the switch on, so an off build does the work GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #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 frame now 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); ClampStoring is 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's D3DCompile ignores) and read the budget through RWByteAddressBuffer::Load (E5005 there), so clamp() is None and argument_clamp_builds — #3197's own test — fails, as do all 14 clamp tests on ef4224db1 and on 0c997d40 alike (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's crate::compute and shader idiom (root signatures serialized in Rust, the budget a RWStructuredBuffer<uint>; no logic changed), and ran the same device tests there: all 15 indirect::tests:: pass, including the three below (scratch/PrGaps/wine-gpu.log, exit 101 only from seven draw::tests::a_* texture tests, which fail at draw.rs:2552 on 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 — the Run rule: 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 on ef4224db1. 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 on tmp/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 on tmp/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.
  • The existing window tests (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 new windowed signature and the Run rule.
  • Skips without a host device as before (host() is None).

Measured

Our test stack (perf/gpu-gaps @ c3886d64d: upstream main plus 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 is VICTORY_GPU_GAPS=1 — the same code this branch ships behind VICTORY_CLAMP_WINDOW alone.

Env, both: VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info VICTORY_EARLY_RELEASE=1 VICTORY_EARLY_BARRIERS=1; A adds VICTORY_GPU_GAPS=1.

A: this change B: control Δ
frame, pair 1 (ms) 175.8 188.2 −12.4
frame, pair 2 (ms) 195.8 200.6 −4.8
frame, mean of the pairs −8.6
on the GPU (ms) 59.2 / 67.4 63.2 / 69.4 −3.0
preparing (ms) 71.3 / 76.1 76.3 / 76.4 −2.6
clamp passes a frame 1,011 / 1,007 1,130 / 1,137 −125
— single clamps 911 / 908 1,025 / 1,030 −118
— windows (executions) 100 (3,104) / 100 (3,191) 105 (3,032) / 106 (3,157)
draws that may store, in windows 107 / 114 0
indirect dispatches, in windows 0 / 0 0
window executions left for a barrier or sync 0 / 0 —

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 (upstream main, 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

  • No in-game run of this branch: it is stacked on GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3197 and does not carry the Wine compiler fix (1aa472de7/916655cc) the stack has, so it does not run under Wine here yet; the GPU tests were run on tmp/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 GPU, Shaders: spread compute dispatches past 65,535 groups in x across z (fixes #2256) #2312 hides the dispatch half there.
  • No run on a tree without GPU, Shaders: spread compute dispatches past 65,535 groups in x across z (fixes #2256) #2312, i.e. no measurement of the dispatch half.
  • The Windows side is untested (all four runs are Wine + vkd3d-proton). The rule rests on the console's own ordering, not on a driver's, so I do not expect a difference; I have not checked.
  • No GPU-based validation of the removed waits, and no capture replay. With the switch on, the barriers between joined executions are gone (they were ours, not the title's); I saw no missing work in two pairs of runs.
  • The draw.rs routing (which execution opens, joins or ends a window) has no CPU test: execute_indirect needs 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.
  • Win32/driver: only one GPU (RTX 5090), one driver, one vkd3d-proton build.

Overlap

AI-assisted (Claude); measured on my machine, no game data shared.

Slay326 and others added 5 commits November 26, 2026 13:04
…OW=1)

Each indirect execution had a clamp of its own: a wait for all earlier
work, a compute dispatch, another wait, then the draw, about 5,100 times a
world frame. With the switch, an indirect draw opens a window: one clamp
pass recorded where the single clamp would be, reading a table the CPU
fills while recording. The indirect draws after it that store to no
buffer add their records to that table and read them clamped from the
window's part of the argument buffer, with no pass and no barrier of
their own. The pass clamps in draw order and charges the list's budget in
that order, as the single clamps did.

A window ends at any draw, dispatch or unordered-access clear other than
a joining indirect draw, at an indirect dispatch, at an indirect draw
whose shaders may store, at work a host library records and at the list's
end; a draw opens a new one when the table, the bytes or the records are
full or its arguments lie in a host copy the pass has no view of.

Off by default; the clamp shader is the host's own, so the translator's
source hash and the shader cache stay as they are. Counters per frame in
the copy statistics line (diagnostics).
Regression test for the case reported on Marvisak#3197 together
with Marvisak#2996 (5385cc6).
The window's pass carried its own copy of the mesh bounds; a change to
the single clamp's rule (Marvisak#2996, 5385cc6) left the window
on the old one and dropped mesh groups (reported on Marvisak#3197). Both shaders
now take the rule from one HLSL function.
The window's mesh rule divergence fixed in bdc4167 was found and integrated
first by Andrew (d16ae7d) on Marvisak#3197.

Co-authored-by: Andrew <296776509+andrewpozdnakov7-jpg@users.noreply.github.com>
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.

2 participants