Repository navigation
GPU: an indirect execution's argument buffer stays readable until the next clamp (one barrier fewer, ~0.4 µs per indirect call) - #3307
Conversation
… next clamp Each indirect execution recorded three barrier calls for the list's argument buffer (common -> unordered access, -> indirect argument, then back to common right after the execution). The buffer now stays readable as arguments after the execution: the next clamp's barrier moves it from there (one call fewer per execution), and the list's close, or a bigger buffer replacing it, puts it back to common, so between lists it is common as before. The arguments and the barriers' ordering the GPU sees are the same. Also on the per-call path of every indirect execution: - a pipeline bound again only because the clamp replaced it is not kept and named again (two QueryInterface + AddRef and a set lookup a call); - command signatures are made once for good and each thread remembers the last one, so no shared lock or reference count per call; - the argument buffer's width and the budget's address are remembered instead of asked of the driver each call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dukestar69
left a comment
There was a problem hiding this comment.
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
- Tracking the indirect argument buffer's state so consecutive clamps transition directly from
INDIRECT_ARGUMENTtoUNORDERED_ACCESS(and back toCOMMONonce onHostList::close) plus caching host command signatures is clean and sound. cargo test -p victory-gpu --lib indirect:: -- --test-threads=1(RTX 5090): 7 passed, 0 failed (includingargument_buffers_move_from_their_current_statesandeach_execution_reads_its_own_clamped_records).cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 21 passed, 0 failed (includinghost_signatures_are_made_once).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Independent local verification of PR #3307 on exact head Environment: Windows 11 x64, Rust 1.98.1 MSVC. WARP only ( Head, The one failure is Control on I did not mutation-test the PR's claim that the test fails with the clamp barrier reverted to "from common". Timing claims were not checked (WARP is not a performance measure). AI use: Claude Code (Claude Sonnet 5.5). |
|
I resolved the conflicts with #3197 at On verified app-local Agility 1.620.2/WARP 1.0.22, all 15 indirect tests passed. The mixed test alternates mesh windows and single dispatch clamps in one list, includes a 6,000-record clamp that grows the argument buffer, checks every readback, and replays the recorded barriers to COMMON. The translated 24-group mesh test passed with the window switch both off and on. Full GPU diagnostics passed 259 tests with 1 ignored in both settings on rerun. One parallel window-on run hit @KainanP and @Slay326 this branch preserves both incoming heads if the merge order makes it useful. The tests cover correctness; I did not rerun the laptop timing comparison. If reusing the resolution, please retain its Git author or add |
Follow-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:memory_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