Sweep: the whole once-a-second sweep on a below-normal thread of its own, in slices (VICTORY_SWEEP_OFF_THREAD=1, off by default) #4559
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!4559
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4558"
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?
@IRennie74 on GitHub · 2026-11-30 22:24 UTC · original
IRennie74:pr/sweep-off-thread→main· +1699 −863 · 36 files · 15 commits · closed without mergingWhat it changes
The once-a-second sweep (
host::sweep) runs inline inHost::submit, at a moment nothing is in the air, so the card stands idle for as long as it takes. On our machine, walking, it took 56-67 ms (median) and up to 242 ms, and a present pause followed within three frames after 40-78 % of sweeps.With
VICTORY_SWEEP_OFF_THREAD=1the whole pass goes to one thread,victory-sweep:pool::room, thememory now:line,pipeline::trim_library, the threelet_go_idles (windows, staging buffers, host copies of textures) and, behind the last one, the slot eviction. In diagnostics builds the memory census ofcopystat::logmoves too (45-60 ms every ~5 s, much of it under the textures table's lock).inplace::tickstays there, and so doesslot_evict_ready, as on main.THREAD_PRIORITY_BELOW_NORMALand is kept off the frame's cores (cores::keep_off_the_frames_cores). It yields 1 ms after each 5 ms of work. A yield (sweeper::slice) comes only between steps, never with a lock held.VICTORY_SLOT_EVICT_ASIDEstays the default path when the switch is off. With the switch on, the slot eviction runs inline onvictory-sweep(sweeper::here()) instead of handing its look tovictory-slot-look. It takes the textures tableSLOT_LOOK_PARTentries at a time with a slice between parts, as the aside look does, and its choice is carried out at once. Off the sweep's thread the inline look is unchanged: the whole table under one hold.VICTORY_UPCOPY_CHECK=1the sweep stays inline. Its look needs the card at rest, and only the submitting thread can bring it there. If the thread cannot be made, the sweep also stays inline, with a warning.sweep aside:line comes once a second, from the sweep's thread. It gives the passes, the work, the longest pass and step, the yields, the requests replaced, the submitting thread's time on sweep duties, the pools skipped because they were busy, and the longest holds of the textures table, the heaps and the windows' table.The module doc of
crates/victory-gpu/src/host/sweeper.rssets out why it is safe on another thread, at another moment than "before a submission starts". In short:retire, which waits for every submission begun or queued.This is the same argument as
VICTORY_SWEEP_AHEADandVICTORY_SLOT_EVICT_ASIDE.Off by default in code. No launcher default is changed here. We run it on by default locally.
What this PR does not bring: our split looks (the windows' and textures' looks done in two short holds). On main the windows' look takes its table's write lock once, as it does inline. The textures' own look is bounded by main's 4 ms budget (#2549). The
sweep aside:line reports both holds, so this can be judged from logs. #4227's rule for when a sweep is due (not on main yet) is left out too. If it lands first, the off-thread branch should ask under the sameduerule.How it was tested
Rig: RTX 3060 12 GB, Ryzen 5 5600X, 32 GB; Series S profile at 960x540, DLSS performance, frame generation off, diagnostics build. Walking route through the cell after the opening.
Where it was measured: our pre-merge branch based on
41adb551, which did not yet have main'sVICTORY_SLOT_EVICT_ASIDE. In that build the switch also turned on our split looks for the windows and the textures (short holds). This PR does not bring them (see above).Before (inline sweep): 56-67 ms a sweep while walking (up to 242 ms), with nothing in flight. A pause followed within 3 frames after 40-78 % of sweeps (14-26 of ~63 pauses a minute).
After, two A/B pairs (
VICTORY_SWEEP_OFF_THREAD=1vs off):Not A/B measured on current main. Main already moves the slot eviction's look aside, and standing that look was ~85 % of the sweep's samples, so the gain on main is expected to be smaller than the numbers above.
In a combined build: the switch is on in our combined build, which measured walking pauses at ~1 a minute. That run combined many changes, so it does not isolate this one.
Not run against the game for this PR. This branch was built and unit-tested only.
Checks:
cargo build --locked --profile diag -p victory --features diagnostics: built.cargo test -p victory-gpu --lib: the five new tests inhost::sweeper::testspass (the request queue, newest wins, no lost wake-up, slicing). Any failures are listed below and are pre-existing on main.cargo clippy -p victory-gpu --all-targets -- -D warnings: no findings in the files this touches.cargo xtask policy --staged: clean.cargo testpassed for the crates it touches: yes, apart from the pre-existing failures belowPre-existing, in code this does not touch (known before this change; not re-run on a clean main here):
cargo test -p victory-gpu --lib: 1135 passed, 3 failed, 66 ignored. The failures:shader_cache::tests::every_switch_of_the_translator_is_in_the_key(VICTORY_ORACLE_RUNS is not read by the translator any more).list::thin::tests::bindings_record_no_work.watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock(flaky, a timing assertion).cargo clippy -p victory-gpu --all-targets -- -D warningsstops on two errors in lines this does not change:host.rstest code (seed % 3 == 0, manualis_multiple_of);shadow.rs:7204(rangednever used).--all-featuresadds a third,copystat.rs:1471(mbnever used).Checked for overlap
I searched the open pull requests for the same issue and for the files this touches. Related: #4138, #3951, #3858, #4227, #3750, #4306
#4138 (background threads for the D3D12 retirement and the periodic sweeps): our review there asked for it to be split. This PR is the narrower half:
It does not touch retirement (
retire/bury) or how D3D12 objects are released.#3951 moves only the release of trimmed spares off the submitting thread. This moves the whole pass, so the two overlap on the pressure trims; whichever lands second should be rebased onto the other.
#3858 bounds the inline sweep in steps. That is complementary: it shortens the pass, and this moves the pass. Both touch
sweep()andresource.rs, so whichever lands second needs a rebase.#4226 decides when a sweep is due. It is not on main and not included here (see above).
#3750 / main's
VICTORY_SLOT_EVICT_ASIDE: it stays the default path. With this switch on, the eviction runs inline onvictory-sweepinstead, in the same parts.#4305 moves the texture sweep off the frame for small PCs. That overlaps in purpose but uses a different mechanism.
@davemathews12 on GitHub · 2026-12-01 00:49 UTC · original
I read the change against
mainfor anything the sweep could now free or move while the submitting thread or a flight still uses it. I found nothing.residency::refresh()only samplesGlobalMemoryStatusExand flipsPRESSURED. It doesn't evict or make anything resident, so it's safe on any thread. (I checked it because it isn't in the "why it holds" list.)let_go_idles and the trims hand objects toretire(). That keeps them until every submission begun or queued has finished, whichever thread calls it, the same ruleVICTORY_SWEEP_AHEADalready relies on with flights in the air. A list holds what it names until it's settled and reset, so the submission being prepared can't lose anything.SLOT_EVICT_ASIDE, so it isn't new.sweep aside:line, so a starved sweeper under memory pressure shows up in logs.I need to run in again on my windows PC. This is a code read only, combined with the walking numbers in #4555.
@IRennie74 on GitHub · 2026-12-01 02:36 UTC · original
Thanks for the careful read, and agreed on
residency::refresh(): it only samples and flipsPRESSURED, so moving it is safe for the reason you give.Added the starvation check in
b072d5f1. Thesweep aside:line now also saysthe pass before the last finished X ms ago, longest wait from asking to a pass Y ms. It is the pass before the last because the line is written by the sweep thread right after a pass, so the last pass's own age is always about 0; X is therefore the gap between passes, and Y the longest wait since the previous line between the submitting thread's word and a pass beginning. A sweeper starved under memory pressure shows as X and Y growing well past the 1 s cadence (or 1.5 s when pressed). There's a test for it (a_late_pass_shows_its_gap_and_its_wait_on_the_line).A run on your PC would be very welcome; on a 16-thread CPU I'd expect Y to stay near zero, which is a useful contrast with the 6-core numbers.
@trustno1-coder on GitHub · 2026-12-01 18:37 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