Cut write-watch guard CPU ~3x and lock contention up to 6x in buffer refreshes #4248
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!4248
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4247"
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?
@vilaris on GitHub · 2026-11-30 17:45 UTC · original
vilaris:perf/guard-first-refresh→main· +811 −820 · 33 files · 12 commits · closed without mergingWhy
During gameplay, buffer refreshes keep the submitting thread busy for ~18 ms a frame of wall time. Splitting
watch::writesby the way it answers showed where the time goes. The kernel's own write-watch askings (GetWriteWatch) were cheap: about 45 calls and 0.2-0.5 ms a frame. Nearly all of the cost was inwatch::guard. Each refresh span over view memory that only the guards can answer calledguarditself from itswide_each_scopedworker, and every one of those calls queued on the guards' single global lock.Change
watch::guard_first(VICTORY_GUARD_FIRST, on by default,0turns it off). Before the flush spreads its updates over threads, the spans that only guarding can answer are guarded once, on the flushing thread, with one call per run of touching spans. Each span's ownwritesthen finds its blocks published and answers from the bits, with noguardcall and no lock queue.Before and after
Same release build and launcher on an RTX 4070 (12 GB, driver 621.1), same gameplay route, with the same local per-branch counter in both runs (not part of this PR) and
VICTORY_REFRESH_WHYoff. Numbers are per frame, from the one-second report lines of the steady gameplay window. Gameplay input was manual.VICTORY_GUARD_FIRST(session 5972)guardCPU, summed over threadsVirtualProtectWhat this shows:
Selected report lines, transcribed from the local logs:
In the "after" run, the
guardcall count includes the pre-pass's own calls. Its time is what dropped.Validation
cargo test -p victory-gpu --lib --locked: same failures as currentmain(list::thin::tests::bindings_record_no_work,shader_cache::tests::every_switch_of_the_translator_is_in_the_key);watch::tests are flaky onmaintoo (3/10 runs).cargo clippy -p victory-gpu --all-targets -- -D warningsstops on three existing errors invictory-shader(emit/lower/analysis.rs), also present onmain.cargo xtask policy --stagedgit diff --check🤖 Generated with Claude Code
@IRennie74 on GitHub · 2026-11-30 18:23 UTC · original · edited 2026-11-30 18:44 UTC
Two things to settle before this goes in on by default:
The pre-pass is serial on the flushing thread.
guard_firstruns in theBatchfront (host.rs, just beforeFRONT[1]is added), beforewide_each_scopedspreads the spans. So everyguardit does now runs one after another on the submitting thread, not beside each other on the workers. Your table shows the summedguardCPU dropping (34-81 -> 9-31 ms). It does not show how much of the remaining 9-31 ms is now the pre-pass's own wall time on the submitting thread.FRONT[1]already brackets it (the lap afterask_aheadnow includesguard_first), so its before/after would answer that directly.This matters most on small CPUs. On a Ryzen 5 5600X + RTX 3060 12 GB (Series S, DLSS Performance, diagnostics build), the submitting thread is the frame's wall:
So moving work from the workers onto the submitting thread is the direction that can hurt there. The same rig also spends 10-13 ms a frame waiting for the guards' lock, so less contention is welcome. The open question is only where the remaining guard time lands.
Default. The PR says frame time is unchanged (50-62 -> 52-65 ms median). With no frame gain measured yet,
asked_for!(off unless1) seems the safer default until a run on a 6-core showsFRONT[1]not growing. Turning it on later is a one-line change.Minor:
guard_firstwidens each span to whole 64 KiB blocks beforemerged, so a run can include view memory no span asked about. That does not affect coherence (writesonly notes and publishes), but it canmaterializea lazy view a little earlier than before.Related: #4027 takes the guards' lock off the title's copy path (
opened_for_writing). The two attack the same lock from different callers and should compose.@vilaris on GitHub · 2026-11-30 19:15 UTC · original
Done
@KruIN689 on GitHub · 2026-11-30 19:26 UTC · original
Independent test on different hardware: RTX 5080 (driver 621.40), Ryzen 9 9950X3D, 47 GB, Windows 11. Series X, native 1440p, DLSS and FG off,
VICTORY_HW_RT=1.Method: one release build of this branch merged with main
e1251c31, A/B by the switch (VICTORY_GUARD_FIRST=0for off), 2+2 alternating runs of auto-driven roaming (walk and drive), 6 min each, stats over the last 4 min:No errors in any run. On this 16-thread X3D the difference sits within run-to-run noise, both for refresh time and for fps. That fits your note that about half of the guard time was lock waiting: with fewer spans per flush here there may be little contention to remove. It costs nothing measurable either. A 6- or 8-core CPU would show it better than this one.
(Measured and written with Claude Code, for KruIN689.)
@gabrielecabrini on GitHub · 2026-11-30 20:04 UTC · original
Tested in game on Linux (Proton). With
VICTORY_GUARD_FIRSTon, the frame was faster both standing and moving.Setup: RTX 4070 SUPER 12 GB, i5-14600KF, NVIDIA 620.73.04, Proton Experimental 11.0-20261123b, Series S, DLSS off. Release build of this PR on main
e1251c31. Same save and route in both runs: about 60 s standing still, then about 60 s walking and turning the camera. One run each: A is the default, B isVICTORY_GUARD_FIRST=0.@trustno1-coder on GitHub · 2026-12-01 18:45 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