Skip to content

Sweep: the once-a-second sweep in bounded steps (texture sweep by window and time budget, slot eviction with a rest, parts in turn): frames over 100 ms from about 25 a run to 0-2 - #3858

Open
duckey-dev wants to merge 3 commits into
trustno1-coder:mainfrom
duckey-dev:bounded-sweep

Conversation

@duckey-dev

Copy link
Copy Markdown
Contributor

What was wrong

The once-a-second sweep() in host.rs runs on the submitting thread, so its cost lands in a frame. A scripted walk put the worst frames on it. Every frame over 200 ms in the first 75 s (22 of 22) fell in a sweep or right after one, and so did 18 of the 22 frames over 100 ms after that.

  • resource::let_go_idle over the card's line. Each sweep walked and sorted every texture in the table (46,000-77,000 in that run) under the table's lock, then locked each idle one. It let little go (about 76 MB a sweep) and took 55-81 ms a sweep, 7-10 ms once settled. The title's own texture creation waits on that lock meanwhile.
  • The slot eviction (VICTORY_SLOT_EVICT=1, which the launcher sets) walked the whole table again at every sweep. It let go of nothing in the whole run, at 93 % of the budget.
  • The dead render targets' pass (every 5 s) also walked the whole table in one call.
  • All of these, plus the window copies and staging buffers, ran in the same sweep, so the costs added up in one frame.

What it changes

New module crates/victory-gpu/src/sweeping.rs holds the pure parts, which need no device and have unit tests:

  • walk: walks a table from where the last walk stopped, under a count (8,192 entries) and a clock (read every 64 entries).
  • in_turn: runs the sweep's extra parts one after the other while time is left.
  • BackOff: the slot eviction's rest.
  • The time each part took, for a line in the frame-rate report.

In resource.rs and host.rs:

  1. Texture sweep (VICTORY_SWEEP_BOUNDED, on).
    • Over the card's line, each sweep looks at a window of at most 8,192 textures, starting where the last sweep stopped. The look gets half of VICTORY_SWEEP_BUDGET_MS.
    • The window's idle copies are let go longest idle first in the rest of the budget. The next sweep begins at the first copy not reached.
    • A copy found held (a slot, a list) or written by the host is passed by for 5 s (a new held_until stamp on Hosted). Only the look is put off: the copy is not let go any sooner or later than the rules say.
    • The limit is worked out again from the card's rule at each sweep, so what one sweep could not let go, the next one asks for.
    • The streamed-out part and the part of the table without a limit also stop at the budget and go on from there.
    • "Longest idle first" now holds within a window, not across the whole table. A whole turn of a 70,000-texture table is about nine sweeps.
  2. Dead render targets. The 5 s pass is its own function (let_go_dead_targets). Bounded, it walks the table over several calls under the same count and budget. Its rules are unchanged.
  3. Slot eviction (VICTORY_SLOT_EVICT_BOUNDED, on).
    • The same window and budget: half the budget for the look, the rest for letting go.
    • After a whole pass over the table that let nothing go, it rests for VICTORY_SLOT_EVICT_BACKOFF_MS (30,000).
    • The rest ends early if the card's use rises by 2 % of its budget, or if room for textures (resource::room) is refused after there was some.
  4. Parts in turn (VICTORY_SWEEP_SPREAD, on).
    • The texture sweep runs at every sweep.
    • Then three parts run in turn while the budget lasts, counted from the sweep's start: windows and staging buffers, dead render targets, and slot eviction. At least one runs each sweep, and a part with nothing to do passes its turn on.
  5. A flush (F7/F8) still runs everything at once, as before. The player asked for that hitch.
  6. The settle made for a sweep behind flights (VICTORY_SWEEP_AHEAD off) is unchanged. It is only timed.
  7. The frame-rate report gets one line when a sweep ran since the last line: each part's calls, its longest and summed milliseconds, and how many sweeps had a walk stopped at the budget.

A texture is still let go only under the table's lock and its own lock, and only when nothing but its title texture holds it, as before.

Variable Default Meaning
VICTORY_SWEEP_BOUNDED on (=0: off) The texture sweep's walks (and the dead render targets' pass) under the count and the clock. =0 is the code path as before.
VICTORY_SLOT_EVICT_BOUNDED on (=0: off) The slot eviction's walk under the count and the clock, with its rest. =0 walks everything at every sweep, as before.
VICTORY_SWEEP_SPREAD on (=0: off) The extra parts in turn. =0 runs all of them at every sweep, as before.
VICTORY_SWEEP_BUDGET_MS 3 (1-1,000) The time budget of a sweep's bounded walks.
VICTORY_SLOT_EVICT_BACKOFF_MS 30,000 (0: no rest) The slot eviction's rest after a whole pass that let nothing go.

The three on/off switches are toggled! switches, so VICTORY_AB can flip them while the title runs in diagnostics and ab builds.

How it was tested

  • GPU and profile: AMD Radeon RX 7900 XTX, AMD Ryzen 7 7800X3D, Windows 11, Series X, native 1440p, no DLSS/FSR, no frame generation, ray tracing off.
  • A scripted 4-minute walk in the open world from a save. Frames after the first 75 s were counted.
  • Before: about 25 frames over 100 ms a run.
  • After: 0-2 a run.
  • cargo test passed for the crates it touches: no failure that main does not have on this machine (the 13 sweep tests pass; victory-gpu's suite was run five times on main and on this branch). Both of CI's clippy runs add no warning over main.

Limits:

Not tested

  • This branch in the game as it stands on main (built and unit-tested only).
  • NVIDIA and Intel cards, 8 GB cards, PCs with 16 GB of RAM, Series S.
  • Whether the card stays over its line longer because the texture sweep lets go per window rather than across the whole table. Nothing in the walk showed it, but it was not measured.
  • Each switch on its own. The numbers above are for all three on.

Checked for overlap

🤖 Generated with Claude Code

…n turn, the slot eviction's rest, each part timed

The pure half of bounding the once-a-second sweep (crate::sweeping): `walk`
looks at most 8,192 entries from where the last stopped and reads the clock
every 64; `in_turn` runs the sweep's extra parts one after the other while
time is left; `BackOff` is the slot eviction's rest after a pass that let
nothing go, ended by its time, a 2 % rise of the card's use or room refused
after there was some. The switches and numbers (VICTORY_SWEEP_BOUNDED,
VICTORY_SLOT_EVICT_BOUNDED, VICTORY_SWEEP_SPREAD, VICTORY_SWEEP_BUDGET_MS,
VICTORY_SLOT_EVICT_BACKOFF_MS) are read here; nothing uses them yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nd a time budget, the slot eviction with a rest, the parts in turn, each part timed

The once-a-second sweep runs on the submitting thread, and the frames of a
scripted walk over 200 ms (22 of 22 in the first 75 s) fell in or right after
one: over the card's line `resource::let_go_idle` walked and sorted every
texture (46,000-77,000) under the table's lock and locked each idle one,
letting little go (55-81 ms a sweep); the slot eviction walked them all again
and let go of nothing in the whole run.

- Texture sweep (VICTORY_SWEEP_BOUNDED, on; =0 as before): over the line, a
  window of at most 8,192 textures from where the last sweep stopped, looked
  at in half of VICTORY_SWEEP_BUDGET_MS (3), its idle copies let go the
  longest idle first in the rest of it; the next sweep begins at the first not
  reached. A copy found held is passed by for 5 s. The limit is the card's
  rule anew at each sweep, so what one could not let go the next asks for.
  The streamed-out part and the part of the table without a limit stop at the
  budget too and go on there; the dead render targets' pass every 5 s walks
  the table over several calls.
- Slot eviction (VICTORY_SLOT_EVICT_BOUNDED, on; =0 as before): the same
  window and budget; after a whole pass that let nothing go it rests
  VICTORY_SLOT_EVICT_BACKOFF_MS (30,000; 0: no rest), less if the card's use
  rises 2 % of the budget or room is refused after there was some.
- The sweep (VICTORY_SWEEP_SPREAD, on; =0 as before): the texture sweep at
  every sweep, then windows and staging buffers, dead render targets and
  slot eviction in turn while the budget from the sweep's start lasts, at
  least one; a part with nothing to do gives its turn on. A flush (F7/F8)
  runs all at once as before. The settle made for a sweep behind flights is
  left as it was (VICTORY_SWEEP_AHEAD), only timed.
- The frame-rate report says, when a sweep ran since its last line, each
  part's calls, longest and summed milliseconds, and how many sweeps had a
  walk stopped at the budget.

A texture is still let go only under the table's lock and its own, held
by nothing but its title texture, as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-performance] Sweep: the once-a-second sweep in bounded steps (texture sweep by window and time budget, slot eviction with a rest, parts in turn): frames over 100 ms from about 25 a run to 0-2 Sweep: the once-a-second sweep in bounded steps (texture sweep by window and time budget, slot eviction with a rest, parts in turn): frames over 100 ms from about 25 a run to 0-2 Nov 30, 2026
Reaching the end of the texture table does not mean the candidate
loop reached every copy. Remember a deadline cut across windows and
only enter backoff after a complete pass that released nothing.

In the bounded path, count bytes actually released so a renewed
candidate can give the next oldest its turn within the same budget.
@tyr0nsur

Copy link
Copy Markdown
Contributor

A deadline cut can look like a complete empty pass and trigger the 30-second rest. The table cursor can wrap before the candidate loop runs. If the first candidate became active again and the deadline cuts the loop before the next one, PASS_WHOLE and went == 0 can still arm backoff. The same mistake occurs if an earlier window was cut and the final window had no candidates.

Follow-up 063d3d9 records a cut across windows and only arms the rest when the attempts finished. The bounded path also counts bytes actually released. It can move past a renewed candidate to the next oldest while there is time, with the existing deadline and cap. The unbounded path still uses the preselected candidate set.

A deterministic regression failed on the old pass accounting. It now covers both an earlier window cut and a final window cut, plus the complete empty-pass control. A second test exercises a failed first candidate, an expired deadline, and progress when the next attempt has time. The targeted sweeping and resource diagnostics suite passed on Windows (58 passed, 1 ignored), as did staged asset policy. Gameplay frame pacing remains to be measured.

@duckey-dev

Copy link
Copy Markdown
Contributor Author

@tyr0nsur You're right, thank you. The rest was armed on "the walk wrapped, the pass began at the table's start, nothing went", and the letting-go loop stops at the deadline after its first candidate. So a window whose first candidate was in use again, cut before the second, read as a whole pass that let nothing go, and slot eviction rested for 30 s with candidates never tried. The same holds when an earlier window was cut, as you say.

I read 063d3d9 and ran it on Windows on top of this branch: the sweeping tests (15, with your two), the resource tests, and both of CI's clippy runs, which add no warning over main. I've added it to this PR's branch as your commit, unchanged. Its move from the preselected oldest-covering set to "oldest first until the bytes actually released meet the need" on the bounded path is a behaviour change I agree with: a renewed candidate no longer uses up the allowance.

Not measured in the game on my side yet either; I'll say here when it is.

PranThow added a commit to PranThow/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
@ColorC

ColorC commented Nov 30, 2026

Copy link
Copy Markdown

Disclosure: This cross-validation benchmark and comment were executed and posted by an AI agent on real hardware (RTX 5070 Ti 16 GB Blackwell + Ryzen 7 9800X3D, Win11 26200, ReBAR ON). No game screenshots are included; telemetry only.

Open-World Walking Cross-Validation on RTX 5070 Ti (VICTORY_HW_RT=1, 1440p DLSS Quality + 3x MFG)

Merged PR #3858 (default VICTORY_SWEEP_BUDGET_MS=3) into our HWRT build and ran a 4-minute open-world streaming walk + 6-scene multi-time-of-day teleport stress test (Noon / Sunset / Night / Misty Dawn; 0 crashes):

Metric (victory_gpu::sweeping & frame_times) Before #3858 (4-min HWRT Walk) With #3858 (VICTORY_SWEEP_BUDGET_MS=3) Delta
Max single sweep duration 48.2 ms 1.9 ms (steady walk) -46.3 ms (-96%)
Frames > 100 ms (4-min walk) 38 7 (4 of 7 were first-time cold shader compiles) -82%
P95 frame time (4-min walk) 70.0 ms 49.4 ms -20.6 ms
1% Low (P99) frame time (4-min walk) - 53.3 ms (18.8 fps) Clean
6-Scene Multi-Time Stress (Sunset / Noon / Vice City Noon / Misty Dawn) - >100 ms = 0 on all 4 steady scenes Zero sweep stalls

Note on edge cases: Under very heavy VICTORY_CARD_METER_PIPELINES=1 + VICTORY_SUBMIT_FRAMES=2 telemetry runs, first / slot eviction parts still occasionally showed 5–19 ms sweeps while textures stayed strictly bounded at 1.7–2.1 ms (stopped at the budget), confirming the texture-sweep time budget works as designed and eliminates the dominant streaming hitch source. Strong LGTM!

PranThow added a commit to PranThow/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…ed steps (texture sweep by window and time budget, slot eviction with a rest, parts in turn): frames over 100 ms from about 25 a run to 0-2
FormulaChenZen added a commit to FormulaChenZen/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
Preserve EXEC masks across loop joins, including the light atlas used in 24/7 interiors. Include the shader regression cases from trustno1-coder#2853 and trustno1-coder#3871.

Enable split submission in the two Foxhound launchers (trustno1-coder#3809). Snapshot the hash buffers before the sender records work (trustno1-coder#3881), including allocation failures affecting declared and probed ranges.

Port the incremental resource sweep and empty-pass backoff from trustno1-coder#3858. Preserve manual flush behavior and include coverage for sweep progression and eviction.
@botto854

Copy link
Copy Markdown

Same-binary A/B on a 32 GB machine, where the sweep's cost turns out to sit mostly outside the bounded parts.

Setup: i9-14900K (8P+16E), RTX 4090 24 GB, 32 GB RAM (the layer treats it as limited host RAM), Windows 11 Insider 26300, driver 617.14. Series X profile, DLAA, FG off, RT as play sets it, diagnostics build of v2026.11.29.05 + #2305 + this PR's three commits (incl. 063d3d9), warm shader/pipeline cache. Unattended scripts/bench.ps1 runs from one copied save (standing on a balcony: camera pans and a few steps back and forth, about 8,000–9,500 draws/frame), 30 s warm-up then 240 s measured. Both variants from the same binary, interleaved run by run (on, off, on, off …): "off" = VICTORY_SWEEP_BOUNDED=0, VICTORY_SLOT_EVICT_BOUNDED=0, VICTORY_SWEEP_SPREAD=0. Frame times from the frame log (every frame), not the 5-s lines.

runs median frame p95 p99 frames > 50 ms / min frames > 100 ms / min
this PR on (defaults) 5 44.8 ms 108.0 ms 143.0 ms (140–155) 433 80.0 (79.5–91.9)
off 4 46.0 ms 114.3 ms 155.7 ms (151–161) 446 95.6 (94.6–96.4)

(Medians of the per-run figures, range in brackets. A fifth "off" run was lost to the #2393 SSE4a fault while loading, unrelated.) Every "on" run had fewer >100 ms frames than every "off" run, so the gain is real here, but it is about −16 % of the >100 ms frames and −8 % p99, not the near-zero reported above.

Why so much is left — the sweep's own timing lines (victory_gpu::sweeping) over all runs:

sweeps mean per sweep p95 longest max
on 1,414 30.8 ms 62.6 ms 90.4 ms
off 1,158 44.5 ms 89.9 ms 119.5 ms

The texture walk is held to its budget as designed (textures … longest 3.0, stopped at the budget), but on this machine the long sweeps are almost entirely the first part (residency refresh and, under pressure, the spare/idle trims, pool::room, memory_now) — e.g. first 1x longest 71.7 next to textures 1x longest 3.1. With 32 GB of RAM the layer enters host memory pressure about 30 s into the world and never leaves it (one WARN victory_gpu::residency per run, no way back; free physical memory median ~1 GB, minimum ~0.4 GB per the compile memory lines), so the pressure trims in first run at every sweep and are not under VICTORY_SWEEP_BUDGET_MS. Machines with 64 GB probably never take that branch, which may explain the difference to the 7900 XTX / 5070 Ti results.

I haven't profiled which call inside first it is yet; I'll add that here when I have it. Happy to run a build with finer timing of that part if useful.

@duckey-dev

Copy link
Copy Markdown
Contributor Author

@botto854 Thank you, this is the measurement the description was missing. Agreed on all of it: what this PR puts under VICTORY_SWEEP_BUDGET_MS is the texture walk, the dead render targets' pass and the slot eviction. The first part is only taken in turn with the others and timed; nothing inside it is bounded. My numbers come from a 64 GB machine that never enters host memory pressure, so the trims in first cost next to nothing there, and the "about 25 to 0-2" figure should be read as "on a machine without host memory pressure". On 32 GB your -16 % of frames over 100 ms is the honest size of it. I'll put that limit in the description.

Your finer timing of first would be very welcome (which of the residency refresh, the spare/idle trims, pool::room and memory_now holds the 70 ms). If it is the trims, the natural follow-up is to give them the same treatment as the other parts: a walk that goes on from where it stopped under the sweep's budget, in turn with the rest, with a flush still doing everything at once. I can write that as a separate PR, but I cannot reproduce the pressure here (64 GB), so it would rest on your A/B. If you would rather write it, the helpers are sweeping::walk and in_turn.

This branch also needs a rebase onto current main (conflicts in host.rs and resource.rs); I'll do that.

@botto854

Copy link
Copy Markdown

Timed each step of sweep() on v2026.11.30.01 (+ #2585, without this PR, so the whole sweep is one piece), same
14900K / 4090 / 32 GB, same route, two 4-minute runs. Sweeps over 5 ms are logged: 202 of 229 and 223 of 252,
all but one with pressured() true.

Total per sweep: median 25 / 24 ms, p95 55 / 53 ms, max 147 / 77 ms (run 1 / run 2).

step share of sweep time median p95 max
send::trim 31 / 40 % 6.0 / 6.8 27.6 / 32.9 42.9 / 48.1
resource::let_go_idle (end of sweep) 29 / 30 % 7.0 / 7.0 18.0 / 12.2 39.6 / 41.7
trim_spare_chunks 25 / 22 % 5.0 / 4.8 18.0 / 16.4 55.9 / 22.7
list::trim_idle 7 / 5 % 0 / 0 9.7 / 8.9 51.9 / 17.5
shadow::let_go_idle 6 / 1 % 0 / 0 6.2 / 0.9 111.7 / 5.0
texback::sweep_read_backs 2 / 2 % 0.2 / 0.3 2.1 / 2.1 3.9 / 6.0
residency::refresh, pool::room, memory_now, video_memory, trim_library, texture::let_go_idle ~0 % 0 ≤0.1 ≤3

(ms, run 1 / run 2; trim_spare_uploads, trim_spare_linear, trim_snapshot_pool, uav_spare never reached
0.1 ms. shadow::let_go_idle went over 20 ms in only 2 sweeps of run 1, none of run 2.)

So it's the trims, not refresh / room / memory_now. Within first, send::trim + trim_spare_chunks are ~80 % in both runs.

Two things I noticed reading them (not measured separately, so treat as hypotheses):

  • send::trim drops the Memory buffers (release of mapped upload resources) while holding SPARE, and
    send::memory() takes the same lock. trim_spare_chunks already drops outside its lock.
  • On 32 GB keeps_under_pressure() (8 GiB physical free) is never true, so every sweep cuts both pools to the
    16 MiB floor, and the next frames presumably allocate fresh send buffers / chunks again. That would be churn
    at 1 Hz rather than reclaiming idle memory. Using a low-water mark over the last few sweeps (only free what
    wasn't touched since) might fix the cost and the churn in one go.

Happy to A/B a follow-up on this box. If you'd rather I write it, say so, but you know the sweeping
module better, so I'd go with your version and test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants