perf(gpu): cache watch::ahead snapshot by generation across flushes and flush_one #4532
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4532"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by YounesAH15 on 2026-11-30T22:01:21Z.
Summary
Part of #2415 (CPU wall): eliminates redundant
JOURNALRwLock acquisitions andJournal::aheadvector copies across submission flushes and one-at-a-timeBatch::flush_onechecks.Problem
Batch::refresh_front_spans,Batch::refresh_written_before, andBatch::flush_allcalledwatch::ahead_snapshot_into(&mut self.ahead_snap)on every flush (~40-47 flushes/frame), acquiring the globalJOURNALread lock and cloningJournal::aheadeven whenKEPTwas active andJournal::aheadhad not changed all submission.Batch::flush_one(~330-350 calls/frame before shader writes) calledshadow.nothing_new(...)->watch::nothing_new_single(...), acquiringJOURNALon each non-published range instead of reusingBatch::ahead_snap, and did not incrementFLUSHES[2]when skipping unchanged spans.Changes
crates/victory-gpu/src/watch.rs:AHEAD_GENbumped underjournal_mut()at all 5Journal::aheadmutation sites (ask_ahead,ask_ahead_done,ask_once,ask_more,ask_once_end).ahead_snapshot_cached(out, cached_gen)which returns in a singleAcquireload (zero locks, zero copies) whenJournal::aheadis unchanged.ahead_snapshot_cached_reuses_until_gen_bumps.crates/victory-gpu/src/host.rs:ahead_gen: u64andBatch::ensure_ahead_snap().ensure_ahead_snap()intoBatch::flush_one,Batch::refresh_front_spans,Batch::refresh_written_before, andBatch::flush_all(simplifying away the localsnappedbool).Batch::flush_oneto useshadow.nothing_new_with(&self.ahead_snap, ...)and count skipped no-ops inFLUSHES[2].crates/victory-gpu/src/shadow.rs:Shadow::nothing_newwith#[cfg_attr(not(test), allow(dead_code))]so release builds stay warning-free.Verification
watch::blocks_all_tests::ahead_snapshot_cached_reuses_until_gen_bumps— okhost::refresh_tests::chunked_nothing_new_with_matches_individual— okBatch::flush_one(one at a time in ~335 before shader writes): 0.3-0.8 ms/frame (down from 1.8-2.4 ms/frame on prior ~346-352 call runs).VRAM 4.5/7.1 GB,binds dropped: 0.00/frame,raw view clamp: [0, 0, 0, 0],buffer views left null: 0.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-11-30T22:39:13Z.
Relevant for CPU-bound PCs: on a Ryzen 5 5600X + RTX 3060 (Series S, DLSS Performance) the submitting thread is busy 44-54 ms of a 55-58 ms frame, refreshes are 11-15 ms of that, and the title waits on that thread at its presents. A lock and a copy saved per flush counts there.
Two small things:
flush_one(crates/victory-gpu/src/host.rs:14036) used to callShadow::nothing_new, which honoursVICTORY_PART_EXACT(watch::part_exact()→nothing_new_single(.., exact)).nothing_new_withalways takes the non-exact path. That is still correct (only more conservative), but withPART_EXACT=1fewerflush_onecalls are skipped than before. Worth a line in the description, or a fallback to the old call whenpart_exact()is on.ahead_snapshot_cached_reuses_until_gen_bumpsasserts thatAHEAD_GENdoes not move between two calls, butAHEAD_GENis process-global, and any other test in the same binary that callsask_ahead/ask_once/ask_once_end(therefresh_testsdo) can bump it in between. The test could flake under the default parallel runner. Testingahead_snapshot_cachedagainst a local generation counter, or serialising with the watch tests' lock, would avoid that.It overlaps textually with #4422 and #4488 in
Batch::flush_all(thesnappedlogic). #4422's bitsetsift_byalso readsself.ahead_snap, so whichever lands second needsensure_ahead_snap()in front of it.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by YounesAH15 on 2026-12-01T03:10:36Z.
Thanks for the review @IRennie74!
AHEAD_GENbeing process-global under parallelcargo test. Pushed a commit introducingahead_snapshot_with_gen(gen_counter, out, cached_gen)and updatingahead_snapshot_cached_reuses_until_gen_bumpsto run against a localAtomicU64(re-verified withcargo test -p victory-gpu ahead_snapshot_cached: 1 passed, 0 failed).VICTORY_PART_EXACT: On currentmain(e1251c31),Shadow::nothing_newandwatch::nothing_new_singledo not useVICTORY_PART_EXACT— both callWRITTEN_EPOCHS.all_within(...), differing only in borrowing&journal().aheadvs reusing&self.ahead_snap.#4422/#4488— happy to rebase and placeself.ensure_ahead_snap()in front ofsift_byif those land first.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:38:14Z.
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed