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) #4558

Closed
IRennie74 wants to merge 15 commits from upstream-pr/4558 into main
IRennie74 commented 2026-11-30 22:24:44 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-11-30T22:24:44Z.


What it changes

The once-a-second sweep (host::sweep) runs inline in Host::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=1 the whole pass goes to one thread, victory-sweep:

  • What moves: the residency refresh, the pressure trims, the UAV spares, pool::room, the memory now: line, pipeline::trim_library, the three let_go_idles (windows, staging buffers, host copies of textures) and, behind the last one, the slot eviction. In diagnostics builds the memory census of copystat::log moves too (45-60 ms every ~5 s, much of it under the textures table's lock).
  • What stays on the submitting thread: the once-a-second gate (an atomic compare) and a signal (an atomic swap and an unpark). It never waits. inplace::tick stays there, and so does slot_evict_ready, as on main.
  • One pass at a time, the newest request wins. A sweep asked for while a pass runs replaces any request not yet begun, so passes never pile up.
  • Below normal priority, in slices. The thread runs at THREAD_PRIORITY_BELOW_NORMAL and 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.
  • Slot eviction: main's VICTORY_SLOT_EVICT_ASIDE stays the default path when the switch is off. With the switch on, the slot eviction runs inline on victory-sweep (sweeper::here()) instead of handing its look to victory-slot-look. It takes the textures table SLOT_LOOK_PART entries 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.
  • Stays inline: with VICTORY_UPCOPY_CHECK=1 the 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.
  • A 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.rs sets out why it is safe on another thread, at another moment than "before a submission starts". In short:

  • Each part lets go only of what nothing names: no list, no slot, no pass, and nothing used for seconds. It decides under the lock the other threads hand objects out under.
  • What goes still goes through retire, which waits for every submission begun or queued.
  • The spare pools hold only what has finished on the card.

This is the same argument as VICTORY_SWEEP_AHEAD and VICTORY_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. #4226'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 same due rule.

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's VICTORY_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=1 vs off):

    on off
    hitches a minute 57 / 55 99 / 84
    frame-to-frame variability 30.7 / 29.6 ms 40.1 / 40.4 ms
    flicker events 56 / 54 72 / 77
    pauses 43 / 49 70 / 39
    fps 15.3 / 14.6 14.6
  • 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 in host::sweeper::tests pass (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 test passed for the crates it touches: yes, apart from the pre-existing failures below

Pre-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 warnings stops on two errors in lines this does not change:

    • host.rs test code (seed % 3 == 0, manual is_multiple_of);
    • shadow.rs:7204 (ranged never used).

    --all-features adds a third, copystat.rs:1471 (mb never used).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #4138, #3951, #3858, #4226, #3750, #4305

  • #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:

    • one thread for one pass, bounded (newest wins, one at a time);
    • below normal priority, kept off the frame's cores, and sliced (1 ms yield per 5 ms of work);
    • no lock held across a yield;
    • the submitting thread only signals.

    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() and resource.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 on victory-sweep instead, in the same parts.

  • #4305 moves the texture sweep off the frame for small PCs. That overlaps in purpose but uses a different mechanism.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5574878941 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4558). Originally posted by [IRennie74](https://github.com/IRennie74) on 2026-11-30T22:24:44Z. --- ## What it changes The once-a-second sweep (`host::sweep`) runs inline in `Host::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=1` the whole pass goes to one thread, `victory-sweep`: - **What moves:** the residency refresh, the pressure trims, the UAV spares, `pool::room`, the `memory now:` line, `pipeline::trim_library`, the three `let_go_idle`s (windows, staging buffers, host copies of textures) and, behind the last one, the slot eviction. In diagnostics builds the memory census of `copystat::log` moves too (45-60 ms every ~5 s, much of it under the textures table's lock). - **What stays on the submitting thread:** the once-a-second gate (an atomic compare) and a signal (an atomic swap and an unpark). It never waits. `inplace::tick` stays there, and so does `slot_evict_ready`, as on main. - **One pass at a time, the newest request wins.** A sweep asked for while a pass runs replaces any request not yet begun, so passes never pile up. - **Below normal priority, in slices.** The thread runs at `THREAD_PRIORITY_BELOW_NORMAL` and 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. - **Slot eviction:** main's `VICTORY_SLOT_EVICT_ASIDE` stays the default path when the switch is off. With the switch on, the slot eviction runs inline on `victory-sweep` (`sweeper::here()`) instead of handing its look to `victory-slot-look`. It takes the textures table `SLOT_LOOK_PART` entries 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. - **Stays inline:** with `VICTORY_UPCOPY_CHECK=1` the 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. - **A `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.rs` sets out why it is safe on another thread, at another moment than "before a submission starts". In short: - Each part lets go only of what nothing names: no list, no slot, no pass, and nothing used for seconds. It decides under the lock the other threads hand objects out under. - What goes still goes through `retire`, which waits for every submission begun or queued. - The spare pools hold only what has finished on the card. This is the same argument as `VICTORY_SWEEP_AHEAD` and `VICTORY_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. #4226'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 same `due` rule. ## 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's `VICTORY_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=1` vs off): | | on | off | |---|---|---| | hitches a minute | 57 / 55 | 99 / 84 | | frame-to-frame variability | 30.7 / 29.6 ms | 40.1 / 40.4 ms | | flicker events | 56 / 54 | 72 / 77 | | pauses | 43 / 49 | 70 / 39 | | fps | 15.3 / 14.6 | 14.6 | - **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 in `host::sweeper::tests` pass (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 test` passed for the crates it touches: yes, apart from the pre-existing failures below Pre-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 warnings` stops on two errors in lines this does not change: - `host.rs` test code (`seed % 3 == 0`, manual `is_multiple_of`); - `shadow.rs:7204` (`ranged` never used). `--all-features` adds a third, `copystat.rs:1471` (`mb` never used). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #4138, #3951, #3858, #4226, #3750, #4305 - **#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: - one thread for one pass, bounded (newest wins, one at a time); - below normal priority, kept off the frame's cores, and sliced (1 ms yield per 5 ms of work); - no lock held across a yield; - the submitting thread only signals. 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()` and `resource.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 on `victory-sweep` instead, 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 commented 2026-12-01 00:49:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by davemathews12 on 2026-12-01T00:49:22Z.


I read the change against main for anything the sweep could now free or move while the submitting thread or a flight still uses it. I found nothing.

  • residency::refresh() only samples GlobalMemoryStatusEx and flips PRESSURED. 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.)
  • What is let go: all three let_go_idles and the trims hand objects to retire(). That keeps them until every submission begun or queued has finished, whichever thread calls it, the same rule VICTORY_SWEEP_AHEAD already 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.
  • The one gap is the one the module already names: a host texture taken but not yet recorded is protected only by its idle time. That's the same exposure as SLOT_EVICT_ASIDE, so it isn't new.
  • Starvation: at below-normal priority on a busy 6-core machine, a pass could start late. Since the newest word wins, that only delays trims rather than piling them up. One small suggestion: put the age of the last finished pass on the 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 #4554.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7296779041 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4558#issuecomment-7296779041). Originally posted by [davemathews12](https://github.com/davemathews12) on 2026-12-01T00:49:22Z. --- I read the change against `main` for anything the sweep could now free or move while the submitting thread or a flight still uses it. I found nothing. - **`residency::refresh()`** only samples `GlobalMemoryStatusEx` and flips `PRESSURED`. 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.) - **What is let go:** all three `let_go_idle`s and the trims hand objects to `retire()`. That keeps them until every submission begun or queued has finished, whichever thread calls it, the same rule `VICTORY_SWEEP_AHEAD` already 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. - **The one gap is the one the module already names:** a host texture taken but not yet recorded is protected only by its idle time. That's the same exposure as `SLOT_EVICT_ASIDE`, so it isn't new. - **Starvation:** at below-normal priority on a busy 6-core machine, a pass could start late. Since the newest word wins, that only delays trims rather than piling them up. One small suggestion: put the age of the last finished pass on the `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 #4554.
IRennie74 commented 2026-12-01 02:36:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by IRennie74 on 2026-12-01T02:36:20Z.


Thanks for the careful read, and agreed on residency::refresh(): it only samples and flips PRESSURED, so moving it is safe for the reason you give.

Added the starvation check in b072d5f1. The sweep aside: line now also says the 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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7298796394 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4558#issuecomment-7298796394). Originally posted by [IRennie74](https://github.com/IRennie74) on 2026-12-01T02:36:20Z. --- Thanks for the careful read, and agreed on `residency::refresh()`: it only samples and flips `PRESSURED`, so moving it is safe for the reason you give. Added the starvation check in b072d5f1. The `sweep aside:` line now also says `the 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 commented 2026-12-01 18:37:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:37:47Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321244163 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4558#issuecomment-7321244163). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:37:47Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!4558
No description provided.