perf(gpu): lock-free warm fast path, off-lock sweep, and batched land in memory::ready #3943
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3943
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3943"
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?
@steven-seagull27 on GitHub · 2026-11-30 12:33 UTC · original
steven-seagull27:perf/memory-ready-lock-convoy→main· +1352 −82 · 2 files · 1 commits · closed without mergingSummary
Eliminates the multi-threaded
MEMORYmutex convoy inmemory::ready()across concurrent command-list recording threads and submission-timememory::landcallbacks, with zero behavioral changes:Off-lock per-list deduplication and steady-state fast path (
memory.rs):prefilter_dispatchto run per-list deduplication (named_key,land_key,written_key,small_key) andshadow::in_bufferresolution before acquiringMEMORY, preserving exactNamed2::CheckIfNotPackedshort-circuit semantics when multiple root views share a 64 KiB page.ReadyFastState(FAST) mirroring fixed GPU virtual addresses (directory_gpu,faults_gpu),current_frame,copies_len, spare-page counts, and per-heap(base, made)UAV slot runs so warm dispatches whose prefiltered work is empty returnSome(Ready)without lockingMEMORY(while still checkingREAD,bring_up_key(copies_len),SPAREreserve, anddiagnostics_active()).usescounting to atomic counters onReadyFastState(note_use/take_uses) and measuredWAIT/WAITEDonly on contendedMEMORY.try_lock()misses (TryLockError::WouldBlock).Off-lock rolling frame sweep with generation / ABA validation (
memory.rs):look_againintoplan_look_again(snapshots this frame'sSWEEPslice underMEMORY),probe_look_again(runswatch::writes_since, dirty-pagecopy_mappedreads, andVirtualQuerypacked-header checks off-lock), andapply_look_again(re-locksMEMORYand merges dirty dwords / retires vanished packed structures only ifsweep_page_validconfirmslooked, monotonicgeneration,(copy, at),born, andtakendid not change while unlocked).Batched deferred
memory::landper title-write epoch (host.rs,memory.rs):Deferred::memory_landsandHostList::defer_memory_landto coalesce allMemory::land(at)addresses recorded within the same epoch into a singleStep::Hostclosure in recorded order under oneMEMORYlock acquisition at submission time, splitting automatically onDeferred::title_writtenand clearing onDeferred::clear.Synthetic
--releaseMulti-Threaded Contention Benchmark (Before41adb551vs After, 3-run median)Measured with
cargo test --locked -j 3 -p victory-gpu --lib --release -- memory::tests::bench_memory_ready_multithreaded_contention --ignored --nocapture --test-threads=1on a synthetic workload of 4 recording threads × 150 dispatches/frame (600calls/frame) over 120 frames (after 10 warmup frames) with 512 syntheticMEM_WRITE_WATCHmapped 64 KiB pages (4 swept pages/frame, 2 dirtied/frame):41adb551)ready()CPU time per frameMEMORYmutex waits per frameMEMORYmutex wait time per frameMEMORYmutex held time per frameVerification
memory::tests::prefilter_dispatch_deduplicates_constants_and_addressesmemory::tests::prefilter_dispatch_defers_same_page_named2_until_packed_checkmemory::tests::prefilter_dispatch_tracks_written_and_small_buffersmemory::tests::fast_state_hits_when_warm_and_invalidates_on_every_guardmemory::tests::sweep_page_valid_rejects_concurrent_updates_and_aba_remapsmemory::tests::defer_memory_land_batches_addresses_and_splits_across_title_writtenmemory::tests::bench_memory_ready_multithreaded_contention(#[ignore])cargo test --locked -j 3 -p victory-gpu --lib -- memory:: --test-threads=1— 12 passed, 0 failed (1 ignored)cargo test --locked -j 3 -p victory-gpu --lib -- released_view_heap_evicts_memory_heap_entry --test-threads=1— 1 passed, 0 failedcargo check --locked -j 3 -p victory-gpu --lib --features diagnostics— cleancargo clippy --locked -j 3 -p victory-gpu --lib --tests— 0 new warnings inmemory.rsorhost.rsgit diff --check origin/main..HEAD— cleanAI-assisted. Synthetic verification only.
4ab1ace261to33377ca879@steven-seagull27 on GitHub · 2026-11-30 18:29 UTC · original
Rebased cleanly onto latest
main:#3706(Deferred::held) alongsideDeferred::memory_landsinHostList,ReadyFastStatelock-free warm fast path, and off-lockplan_look_again/probe_look_again/apply_look_again.memory::unit tests,--features diagnosticscheck,clippy --lib --tests, andxtask policy.@nicolasabosch on GitHub · 2026-11-30 21:52 UTC · original
Tested on an RTX 4070 Laptop 8 GB: no measurable fps difference in this scene (2 runs).
Tested on main
e1251c31with this PR (33377ca8) merged on top and nothing else changed. Release build, same profile as main.Setup
victory play --series-s --dlss performance --framegen 2, with no fps cap and the window minimized.host:reports, about 200 s. These are real frames, not generated ones.On this laptop, identical main runs differ by up to about 2–2.5 fps, so only an effect of roughly 2–3 fps or more would be visible in this scene.
Not tested: driving, camera turns, interiors, an image comparison, other GPUs.
33377ca879to492f24084d@upipibi on GitHub · 2026-12-01 04:13 UTC · original
Race review of #3943 (head
492f2408), on by default with no switch: it holds. I found no lost update or stale fast-path answer, and no crash in the tests below. One small difference frommain, noted at the end. CPU and synthetic tests only, no game files.The fast path (
FAST.try_ready). Each mirror is written underMEMORYwherever its source changes:copies_lenwherecopies.push;heaps.insert/remove;hold,releaseandanother. Everyfree.pop()goes throughhold.current_framebefore the sweep.Every check the slow path would act on is either repeated or makes the fast path decline:
another_failed_frame;READkeep (list.used(READ));made == copies_len;bring_up_key(copies_len).A torn read of two mirrors can only make it decline. So when it answers, it gives what the locked path would have given at the moment it loaded
copies_len.prefilter_dispatchoff the lock. The keys are per list, and a list is recorded by one thread, so taking them beforeMEMORYchanges no outcome.first_useis still taken in the same order as onmainrelative toin_bufferandpossible, andnamed(2, at)waits for the packed check (CheckIfNotPacked).The sweep off the lock (
plan/probe/apply_look_again). The probe asks the write watch, then reads, in that order, asbringdoes onmain. So a write between the two is seen at the next sweep.applydrops a page's result if another thread took it meanwhile:bringsetslooked, andtake/holdbumpgeneration, andsweep_page_validchecks both, as well astaken,at,copyandborn. A packed structure is retired only afterthere()is asked again under the lock. A plan that is still running when the next frame begins is checked the same way.defer_memory_land. The batch is split at every step that writes title memory (Deferred::title_written) and cleared on reset. Within a batch, a laterlandnow runs at the first one's place, earlier than onmainrelative to steps that only read title memory. Abring_upstill follows each, so what it brings is still sent.Tests. RTX 3070, Ryzen 9 5950X, Windows 11. This PR merged onto
main5fabb46e(clean):bench_memory_ready_multithreaded_contention(release,--ignored)memory::victory-gpulibcard_steps::…::shared_scratch_eliminates_flight_settle_end_to_endvictory-gpulib,mainuav_pool::…::host_list_uav_pool_lifecycle_retire_trim_and_info_queueBoth single failures are flakes I have also seen on
main(#3902 covers the second).One difference from
main. Onmain, everyready()of a frame waits for that frame's sweep. Here, other threads go on while the sweep is unlocked, including through the fast path. So a page the sweep refreshes can reach a list recorded in that window a little later than onmain. The sweep already refreshes only a slice of the pages each frame, so this looks harmless, but it isn't quite "zero behavioral changes". I didn't measure it in a game.Tested with the help of Claude Code (Claude Opus 5.5).
@albertik322-sudo on GitHub · 2026-12-01 17:00 UTC · original
Small positive on a laptop, in a batch with #4394 and #4395. PC: RTX 3070 Laptop 8 GB, i7-11800H, 32 GB RAM, Windows 11. Series S, 1080p output, DLSS Performance, FG x4.
prep medians across sessions: ~46 ms before this batch, ~44-45 ms after; fps median 17.4 to 17.8 in light scenes. Within scene noise individually, but the direction held across three separate sessions. No instability, no crashes attributable to it (unlike #4944, which I reported separately).
@trustno1-coder on GitHub · 2026-12-01 18:47 UTC · original
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