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
@Dukestar69 on GitHub · 2026-11-26 17:09 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
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).
@oni-swr on GitHub · 2026-11-26 17:32 UTC · original
Independent local verification of PR #3307 on exact head
f23c88f90d322f2dcb7b13b143711e0d4dc34f39. Control:origin/main63bcca43c6a00a758510398fa43096ce7e4f7df0.Environment: Windows 11 x64, Rust 1.98.1 MSVC. WARP only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1), Windows SDK 10.0.26100.0 x64dxil.dll1.8.2502.11 onPATH, no physical GPU, no game files. All runs used--locked -j 4 --no-fail-fast -- --test-threads=1.Head,
cargo test -p victory-gpu --lib --features diagnostics: 248 passed, 1 failed, 1 ignored. The PR's new and changed tests all passed:indirect::tests::each_execution_reads_its_own_clamped_records,host::tests::a_list_holds_the_pipeline_it_last_kept_until_its_reset,draw::tests::host_signatures_are_made_once, and the updatedindirect::tests::tests (argument_buffers_move_from_their_current_states,argument_clamp_builds,a_record_that_does_not_fit_ends_the_budget,a_spent_budget_stays_spent,rejected_records_do_not_wrap_the_budget,the_budget_goes_to_the_first_records).Head, without
diagnostics: 233 passed, 1 failed, 1 ignored.The one failure is
frame::tests::waits_end_on_ticks_and_count_frames(frame.rs:231). It failed in every run on this machine under WARP, on head and on main (5/5 each, run alone). The PR doesn't touchframe.rs.Control on
origin/main(--features diagnostics): 244 passed, 2 failed, 1 ignored. The failures were the sameframetest pluspipeline::placed_uav_tests::placed_uav_dispatch_writes_its_texture, which passed on head. I saw that one only once, so I'm treating it as a flake and not as a result of this PR. Head has 250 tests against main's 247, the three new tests.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).
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 17:43 UTC · original
I resolved the conflicts with #3197 at
0c997d4and #2996 at5385cc6in the exact integrationaf504f3. The window and single-clamp paths share one argument buffer. Both now take its incoming state fromHostList::arguments(). Closing a logical window leaves the buffer readable. Growth or command-list close returns the retired buffer to COMMON. Allocating window scratch first means a refused scratch allocation cannot advance the tracked argument state.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
a_slot_rewritten_while_its_view_is_prepared_views_the_new_record; the exact descriptor test passed four isolated runs on each of main and the integration, and the subsequent serial and parallel integration suites passed. Strict GPU Clippy passed with default and all features, and policy passed.@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
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit. AI-assisted with Codex.@borosf on GitHub · 2026-11-26 19:03 UTC · original
Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head
f23c88f:Result: victory-gpu lib: 232 passed / 2 failed (both known baseline); all 3 new PR tests passed.
Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.
Synthetic tests only; no game data used. Full log kept locally. — borosf
@evan-kolberg on GitHub · 2026-11-26 19:16 UTC · original
I tested KainanP’s argument-buffer lifetime change in isolation on Mac main
bf99e728, using an Apple M4 Pro and D3DMetal 4.0 beta 3. Both builds used the same precompiled clamp. For 330 valid indirect dispatches, transitions fell from 990 to 661 in one list and from 990 to 693 in 33 lists. Every run returned all 1,320 expected words. Growth and reset also passed, and the traced argument buffers ended inCOMMON. KainanP’s #3307 head · Stefa008’s clamp buildAcross ABBA and BAAB runs, one-list recording and close had a pooled median of 175.45 → 171.60 µs. Host submit-to-return moved from 2.990 to 3.323 ms, with a higher candidate median in each order. The 33-list check went from 2.475 to 2.753 ms. Each pooled median uses 48 generated samples per build and list count. These are host wall-clock intervals.
Prepared and tested with Codex.
@fuzeofficlal on GitHub · 2026-11-26 20:58 UTC · original · approved these changes
Clean, well-scoped optimization. Verified the state transitions and lifecycle invariants across all callers:
crates/victory-gpu/src/host.rs:1790-1835, 2295-2342,crates/victory-gpu/src/indirect.rs:209-242):indirect::boundvalidatesclamp(),list.budget(), and 4-byte alignment before callinglist.arguments(...), soarguments.readableis never flipped on early returns.INDIRECT_ARGUMENT -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT(including after a dropped!ranindirect execution), mid-list buffer growth transitions the replaced bufferINDIRECT_ARGUMENT -> COMMONbeforeself.keep(&old)(and leaves state untouched ifshared_bufferfails),capture::read_indirectpreservesINDIRECT_ARGUMENT(INDIRECT_ARGUMENT -> COPY_SOURCE -> INDIRECT_ARGUMENT),HostList::closerestoresCOMMONidempotently viastd::mem::take(&mut arguments.readable), andHostList::resetclearsreadableandkept_pipeline.crates/victory-gpu/src/draw.rs:654-659, 1848-1889,crates/victory-gpu/src/host.rs:2347-2349):holds_pipelinesafely deduplicatesused_pipeline/keepacross indirect clamp re-binds untilHostList::reset, andhost_signature'sthread_local!cache over leaked&'static ID3D12CommandSignaturematches the process-lifetime retention of the existingMADEtable without per-call mutex or COM refcount traffic.main, passedcargo xtask policy,cargo clippy --locked -p victory-gpu --tests -- -D warnings(both default and--features diagnostics), and all 9 targetedindirect,draw::tests::host_signatures_are_made_once, andhost::tests::a_list_holds_the_pipeline_it_last_kept_until_its_resettests on both NVIDIA GeForce RTX 5090 and WARP withVICTORY_D3D12_DEBUG=1.indirect::boundcalls (including a dropped!rangap),capture::read_indirect, mid-list >64 KiB buffer growth,close,reset, and a second submission reusing the grown buffer — zero D3D12 Debug Layer errors on both RTX 5090 and WARP.LGTM!
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.