Repository navigation
GPU: opt-in batched argument clamp for runs of indirect draws - #9
Merged
Merged
Conversation
Every indirect execution records a clamp of its own: a UAV barrier, a compute dispatch, a second barrier, two transitions of the argument buffer and a forced pipeline and compute root rebind, between every two of the world's thousands of indirect draws. VICTORY_INDIRECT_CLAMP=batch lets consecutive indirect draws share one clamp dispatch. It is recorded before the first of them and walks a table of jobs (offset, kind, stride, records) in the list's upload memory; the draws after it only add a job while the list is recorded, and keep the bound pipeline and the buffer's state. A record joins the open batch only while nothing recorded since its dispatch can have written it: compute work ends the batch, a draw whose shaders write wherever they compute (heap-direct or title-memory writes) closes it to later records, and a record inside a range the list's draws declared they write gets a new clamp. A draw joining after a draw that declared writes gets a barrier alone. Indirect dispatches keep a clamp of their own. The default stays one clamp per execution (always): batches cut the world's GPU time by about a third on an RTX 5090, but one run showed a skinned character with stretched triangles that the per-execution clamp never showed, and the cause is not found. never records no clamp (diagnostics). The frame-rate line now ends with the clamps recorded and the indirect executions they bound per frame, and a second line gives why batches were opened and the barriers recorded alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Every indirect execution records its own argument clamp: a UAV barrier, a compute dispatch, a second UAV barrier, two transitions of the argument buffer, and a forced pipeline + compute-root rebind afterwards. The world records ~5,100 indirect executions per frame, so each pair of draws has a graphics → compute → graphics round trip between them.
This adds an opt-in batched clamp (
VICTORY_INDIRECT_CLAMP=batch,crates/victory-gpu/src/indirect.rs). The default is unchanged (one clamp per execution).With
batch, consecutive indirect draws share one clamp dispatch:bindwith a compute pipeline) ends the batch;defer_gpu_write) gets a new clamp;VICTORY_INDIRECT_CLAMP=always|batch|never:always(default) = previous behaviour,batch= the above,never= no clamp (diagnostics only: garbage arguments can then hang the device).Diagnostics: the frame-rate line now ends with
N argument clamps for M indirect executions/frame, and a second line gives why batches were opened (none open / other buffer / shader writes anywhere / written range / job memory full) plus the lone barriers.Measured (RTX 5090, diag build, world, 240 s, same binary,
VICTORY_GPU_UPLOAD=1 VICTORY_GPU_UPLOAD_WRITES=1 VICTORY_LAZY_COPY_BACK=1, steady state ~+180..+239 s, medians)always(default)batchBatching cuts GPU time by ~23 ms/frame (~27%), but the frame is CPU-bound (preparing + copy-back), so frame time moves only within run-to-run noise. No frame-rate win is claimed. Remaining batches per frame: ~33 first draw of a list / after compute, ~36 another argument buffer, ~35 after shader writes anywhere, 0 written range, 0 job memory full; 0 lone barriers.
Why opt-in
In one
batchworld run, a cutscene frame showed a skinned character with stretched/exploded triangles. A per-execution-clamp run of the same shot showed a clean silhouette. The two later runs (batchandalwayswith identical keys) reached a dark section of the cutscene where both show the same pre-existing triangle fragments, so they neither confirm nor clear the batching. I did not find the missed hazard by reading the code (all in-list writers I could find either end the batch or are declared). The suspect is clamping a record before the draws that come before it in the run. Sobatchstays opt-in until a like-for-like shot is clean.Tests
consecutive_draws_share_one_clamp: draws join one clamp, a declared write over a record and compute work each start a new one, every named record is clamped, an unnamed one stays as written.the_clamp_switch_reads_its_three_values.Gate:
cargo clippy -p victory-gpu --all-targets -- -D warnings,cargo clippy -p victory --features diagnostics --all-targets -- -D warnings,cargo test -p victory-gpu -- --test-threads=1(181 passed),cargo xtask policy.Known gaps / follow-ups
batch(capture the same cutscene shot withalwaysandbatch), then consider making it the default. Even then it only pays off once the CPU side of the frame is smaller.🤖 Generated with Claude Code