GPU: an indirect execution's argument buffer stays readable until the next clamp (one barrier fewer, ~0.4 µs per indirect call) #3307
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!3307
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3307"
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?
@KainanP on GitHub · 2026-11-26 16:53 UTC · original
KainanP:perf/indirect-dispatch→main· +274 −61 · 3 files · 1 commits · openFollow-up to #2586.
ExecuteIndirectwith dispatch arguments costs about 3.0 µs a call on main, against 0.86 µs for a plainDispatch(list bench, comment 7197644545). #2472 and #3197 batch the clamp for indirect draws only, and I found no open PR for dispatches. This PR makes the per-call clamp cheaper on the CPU, for indirect dispatches and for every indirect draw that is still clamped alone. The arguments the GPU reads and the clamping rules don't change.Where the time goes
I timed each step of one indirect dispatch with
rdtsc(temporary counters, not in this PR), on 1 thread, on main. Shares of the call:indirect::bound: twoResourceBarriercallsDispatchlist.budget()+list.arguments()(lock,GetDesc,GetGPUVirtualAddress)indirect::done: a thirdResourceBarriercall, right after the executionSetPipelineState+ root signatureused_pipeline(string set) + twokeep(QueryInterface + AddRef + push)ExecuteIndirectitselfhost_signature(global mutex + COM clone),shadow::find, refresh, signature layoutDispatchpays this too)Most of the gap to a plain
Dispatchis driver calls the clamp needs: two barrier calls, a compute dispatch, and a pipeline switch away from the title's pipeline and back.Change
Only
crates/victory-gpu:indirect.rs,host.rs). The list's argument buffer used to go common → unordered access → indirect argument → common on every call. Now it stays in the indirect-argument state after the execution. The next clamp's existing barrier moves it from there to unordered access.HostList::closeputs it back to common, and so does a bigger buffer replacing it mid-list (the old one is transitioned before it is kept). Between lists the buffer is common as before, so the "its states are known whatever order lists run in" rule still holds.indirect::doneis gone. The GPU sees the same ordering: the transition from indirect argument to unordered access waits for the previous execution's reads, as the transition to common did.draw.rsbind,HostList::holds_pipeline). The clamp forcesSetPipelineStateand the root signature again (kept), but the list already holds that pipeline.used_pipelineand the twokeepcalls now run only when the pipeline differs from the last one the list kept since its reset.draw.rshost_signature). They are made once and kept for good (as before, but leaked as&'static), and each thread remembers the last one it asked for. Five title threads no longer share a mutex and one object's reference count per call.host.rs). The argument buffer's width and the budget word's GPU address are remembered, not asked of the driver on every call.I didn't do a window or a hoist (#3197's or #2472's approach) for dispatches. An indirect dispatch's arguments are usually written by the dispatch just before it in the same list, and compute pipelines store through views. Both PRs end their windows at every dispatch for this reason, so batching would cover no dispatch without proving which buffers each dispatch writes.
Measured
List bench (
pipeline::list_bench, fork branchperf/list-call-bench,VICTORY_LIST_BENCH_INDIRECT=1): each thread records one indirect call at a time into its own list, and the list's close is timed with the calls. Release build, ns per call, median of 15 interleaved runs [min–max]:¹ main + #1978 + #2821 + #3258 + #3274 + #3275.
That is about −0.4 µs per indirect call (−10 to −14%). The exception is indexed draws on 5 threads on main, which are dominated by lock convoys elsewhere (#2586) and stay within their spread. The rest of the gap to a plain
Dispatchis the clamp's barriers, its dispatch and the pipeline switch.Hardware: RTX 4060 Laptop, i7-14650HX, Windows 11. Foreign CPU load: several unrelated Python jobs were running throughout, the same for all builds. Builds were interleaved run by run so they share it.
Not measured: the title. I have no in-game numbers. The bench records only indirect calls, which is the best case for the per-call saving. GPU time should not change (same commands, one barrier fewer), but I didn't time it.
Tests
New:
indirect::tests::each_execution_reads_its_own_clamped_records: five indirect dispatches in one list through the clamp and the list's one argument buffer, including one past 65,535 groups in x, one past 2^20 groups (runs empty), and one with 6,000 records that makes the list replace its 64 KiB buffer while it is readable. A counting compute shader records how many groups each execution ran: 6, 65,535, 0, 5, 7. Each barrier is also replayed from the buffers' states (the debug layer's rule), and all end common. With the clamp's barrier changed back to "from common", the test fails.host::tests::a_list_holds_the_pipeline_it_last_kept_until_its_resetdraw::tests::host_signatures_are_made_once(same object across threads and kinds)Existing
indirect::tests are updated fordone's removal and still check the same values and states.cargo test -p victory-gpu, same failures as main on each adapter:63bcca4memory_tests::heap_direct_texture_reads_mark_their_heap_index, which access-violates on main too)VICTORY_D3D12_WARP=1,--features diagnostics, one thread)The failures on main are
descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views, plusdraw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_viewon Intel.cargo clippy --workspace --all-targets -- -D warningspasses with and without--all-features, andcargo xtask policypasses. rustfmt was applied to the changed lines only.Overlap
This conflicts textually with #2472, #3197, #2168 and #2201. All four call
indirect::doneor takelist.arguments()expecting a common buffer. If one of them lands first, I'll rebase this onto it. The combination is straightforward: their batched passes remove the clamp for the draws they cover, and this PR makes the clamps that are left cheaper. It also toucheshost_signature, which #1356 turns into anRwLock(I'm offering #1356 a rebased branch in its thread).AI use: Claude Code (Claude Opus 5.5) profiled, wrote the change and its tests, ran the measurements and drafted this description.
🤖 Generated with Claude Code
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.