Skip to content

Host lists: pool the copy sources; memory pressure trims spares down to 128 MiB instead of to nothing - #57

Merged
trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
Yorivel:fix/reuse-list-upload-buffers
Nov 28, 2026
Merged

trustno1-coder merged 1 commit into
trustno1-coder:mainfrom
Yorivel:fix/reuse-list-upload-buffers

Conversation

@Yorivel

@Yorivel Yorivel commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Two changes in host.rs that remove most of the "new memory waited for" time in gameplay on a 24 GB card with 64 GB of RAM.

1. HostList::upload takes its buffers from a pool.
Every copy a list recorded made a new upload or shared buffer and waited for it to be resident (MakeResident), then freed it at the list's reset (the shortcut: note on the function asked for this). The buffers now come from a pool by size class (a power of two, at least 64 KiB) and go back at the reset. VICTORY_UPLOAD_POOL_MB caps what is kept per kind: 1024 by default, 0 restores the old behaviour. The callers write or zero the bytes they use and copy by offset, so a reused buffer with old contents is fine.

2. Memory pressure trims spares down to SPARE_MOST instead of dropping them all.
trim_spare_chunks emptied the spare scratch chunks every second while residency::pressured() held. On this PC (64 GB of RAM, system-managed page file, commit limit 67.8 GB) the commit headroom stays under 4 GiB for the whole session while the title runs: victory.exe commits about 40 GB with about 22 GB of physical memory still free. So the pressure never ended, and lists made the chunks again right away: 12,925 chunks (13.5 GB) in 5 minutes. The trim now keeps the 128 MiB given last, and it covers the new copy-source pool as well.

Measured

RTX 4090, i9-14900K, 64 GB, driver 621.40, release build. About 5 minutes of play each, same save. Counts come from a local per-caller counter around upload_buffer / shared_buffer / uav_buffer and resident(); that counter is not part of this PR.

before after
waits for new memory to be resident 68,000, 17.3 s 37,000, 9.3 s
longest single wait 1,006 ms 152 ms
copy-source buffers made (HostList::upload) 19,324 93
scratch chunks made (take_chunk) 12,925 2,462

No visual differences were noticed in play.

What is left (not in this PR), for whoever picks it up

  • Buffers made with each new host list: the indirect budget (budget, make_card_budget) and the batch buffers (batch_place), about 13,500 buffers and 7.5 s of waits per 5 minutes. The idle pool (IDLE_MOST, 512) still lets about 3,000 lists be made per session.
  • Shadow copies: shadow.rs 5255/466/5579/5669, about 10,000 buffers and 4 s.
  • The frame itself is bound by preparing, not by the card: about 28 ms a frame on the submitting thread against 0-2 ms of GPU time. Of that: refreshes 6.7 ms, card-step planning 6.0, copies to card copies 4.4 (31 MB in about 58,000 ranges a frame), write watch 3.1, flights 2.3.
  • residency::pressured() on 64 GB machines: commit headroom is a poor signal when the page file is system-managed (it can grow), and the pressure stays on for the whole session.

Testing

  • cargo check on this branch (based on d12eb1b).
  • Played on 959dcaf plus these changes, as measured above. The three commits since then (thread groups, shaders) were not played with this change yet.

🤖 Generated with Claude Code

@Yorivel

Yorivel commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

A follow-up from the same machine (RTX 4090, i9-14900K, 64 GB, release build with this PR), in case it helps with where the frame time goes after the waits are gone.

The frame is bound by preparing, not by the card. In the prison area, the frame line reads 34-55 ms a frame, with the card busy 0-2 ms of it. The submitting thread spends about 28 ms a frame preparing:

part ms / frame
refreshes (refresh_front, ~970 real updates) 6.7
card-step planning 6.0
copies to card copies (31 MB in ~58,000 ranges) 4.4
write watch 3.1
bytes under flights' writes 2.3

CPU profile (samply, 60 s, symbolicated against the PDB). Of the submitting thread's wall time:

  • ~15 % in condvar waits, about a third of them for the wide_each refresh workers;
  • ~10 % blocked on mutexes:
    • 6.5 %: watch::guards, through watch::writes → guard() from Shadow::update_free. Every refresh worker takes the one GUARDS lock, and protect() (VirtualProtect) runs while it is held, so the parallel refreshes mostly run one at a time.
    • 2.9 %: retire_resource, through HostHeap::keep ← constant_at: the push rate on the global RETIRED queue. The drops are already outside the lock.
  • ~7 %: watch::kernel_written, through ask_ahead, mostly kernel time.

What we tried, and why it is not in this PR. A local prototype ran VirtualProtect with the guards' lock released:

  • note the run's blocks protected and clean under the lock;
  • mark them in-flight, so that protect_alias doesn't trust them yet;
  • release the lock, protect;
  • take the lock again, and on a refusal undo the notes and fall back to protect().

It was slower: preparing 30 ms against 28, refreshes 8.5-8.8 ms against 6.7. Taking the lock twice per run costs more than the wait it removes, and about 15 % of the blocks fell back anyway. In that run one NPC's arms also showed RGB squares, normal at the same spot after a restart without it. That is a single sighting, but it is the kind of lost write such a change can cause, so we dropped it.

So the contention is real, but releasing the lock around the syscall alone doesn't pay. Fewer, larger protection calls per refresh, or guard state split per region, look like the directions that could. That is your call on the design, of course. Happy to test anything on a 4090.

Also seen, not looked into: 330-400 draws a frame dropped "without a host pipeline (0 being made)" in the same area, with the cache warm.

One thing about memory pressure on this PC: with a system-managed page file, the commit limit here is 67.8 GB, and victory.exe commits about 40 GB with ~22 GB of RAM still free. So residency::pressured() is on for the whole session.

jacksparrows4704-source pushed a commit to jacksparrows4704-source/VIctory-NVIDIA that referenced this pull request Nov 27, 2026
GPU: emit null buffer SRV/UAV when descriptor names a buffer with null resource
@bob7up

bob7up commented Nov 27, 2026

Copy link
Copy Markdown

Here’s a baseline data point for this PR from a 10 GB RTX 3080. I ran a release build with my checkout at d12eb1b. My system has a Ryzen 7 9800X3D, 64 GB RAM, Windows 11 Pro build 26300, and NVIDIA driver 621.24. Settings were Series X, 2560×1440 output, DLSS Balanced, and frame generation off.

I loaded a save and left the game mostly idle for about 2 hours 30 minutes. I saved again and closed it manually. The log showed no crash or GPU device-loss messages.

Shortly before shutdown, VIctory logged host memory pressure limiting texture prefetch and idle upload storage, with 3,066 MiB of available commit and 13,735 MiB of free physical memory. The attached F3 snapshot from the waterfront porch shows 106.0 ms/frame (9.4 FPS), 96.4 ms submit busy, 41.7 ms GPU busy, and 8.7 of 8.8 GB of the reported VRAM budget in use. That’s a single snapshot from the run.

Would a same-save comparison with this PR on the 3080 be useful?

I ran the test locally and used OpenAI Codex to help draft this report.

victory-nvidia-stability-redacted.log

f3-waterfront-porch

@Yorivel

Yorivel commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Another finding from the same 4090, this time with the structure builder on (VICTORY_BVH_BUILDER=1, frame generation off). It's about the stutter in the first minute or two of ray tracing, when the builder makes the scene's structures.

What the stutter frames wait for. The submitting thread waits 50-250 ms for flights, settled for "title memory read … by a fill of upload memory". A release-build counter at that wait (in blocked_by) shows every one of those fills is FillTo::Slot, i.e. constants for a descriptor slot. So they are fills card_steps can do on the card, and it already does 3,000-4,000 of them a frame. None were scratch fills or buffer starts.

Why card steps don't take them. A release-build counter of take_steps' refusals gives about 100 a minute, all BEHIND_PLACED ("a copy at its place in a list writes what it reads, or reads or writes what it writes"). That is the case the doc comment on placed_order() describes: a copy of a few hundred bytes into the title's constant ring, placed in a list, ahead of fills that read the ring. With the builder's work in flight, each refusal costs the whole wait.

VICTORY_PLACED_ORDER=1 doesn't clear it here. The refusals stay at about 100 a minute, so the placed copy really does stand ahead of a fill that reads its bytes, and the submission is not cut (cut_for) at that point. The doc says the case did not come up in runs submit-1 to submit-3. In this game's ray tracing start-up it comes up constantly, so the cut path may deserve a look with a real capture.

We are trying a local prototype of the cut, and will report back with numbers either way.

Also on the ray tracing side, with fixes on a local branch, PR to follow if you want it:

  • The RT "crash" after 1-3 minutes is the title's own 30 s watchdog (+0x23cf683). Once upload::reserve found no 64 MiB gap in [4 GiB, 2^37), memory::ready asked for another arena at every builder dispatch, under the MEMORY lock. Frames took 7-32 s.
  • Fix: retry at most once a frame, and reserve the arenas' address space (50 × 64 MiB) when the host is made. After it: no crash, 28 arenas instead of 19, ~18 pages a frame without a copy instead of 280-650, 22-28 fps steady.
  • RT pipelines are skipped by victory warm unless it runs with VICTORY_BVH_BUILDER=1, yet they are still marked done in warm-done.txt. Warming with the switch (--again --used) removed the RT pipeline builds at start-up.

@heklokate

Copy link
Copy Markdown

Test results on an RTX 3070 Laptop GPU

I saw fewer calls that waited for residency in both runs. Total wait time and frame-time tails improved in one run and worsened in the other. The mean of the two median FPS readings was 9.60 on main and 9.73 with the PR, a 0.13 FPS difference with 1.01 FPS of run-to-run spread on main.

Hardware and setup. Intel Core i9-12900H, RTX 3070 Laptop GPU (8 GB, driver 32.0.16.1742), 32 GB DDR5-4800, Windows 11 build 26100. Release build, Series S, DLSS Quality, frame generation off. The same deck save and independently warmed caches were used throughout.

Samples. Two valid runs per build, one 30-second PresentMon window per run starting at 180–181 seconds after launch. The table lists each run separately. Warm-ups and an earlier main capture affected by background compilation were excluded.

Revisions. Main d12eb1b and PR 99096e6. The upload pool used the PR defaults.

Metric Main 1 Main 2 PR 1 PR 2
Frames sampled 291 267 305 260
Median FPS 10.10 9.09 10.56 8.89
1% low FPS 6.40 6.65 7.59 3.82
P95 frame time (ms) 136.29 138.13 118.38 146.10
P99 frame time (ms) 156.17 150.41 131.81 262.05
Median draws per frame 6018 5880 5989 6029
CPU busy median (ms) 98.45 109.30 94.11 111.79
GPU busy median (ms) 88.75 91.89 85.80 96.52

Both builds logged host memory pressure. In the first run, the warnings reported 2,581/2,589 MiB physical memory free and 7,042/7,033 MiB available commit on main/PR. The residency counter is cumulative and is logged in steps of 1,000 waits.

Run Main count / total / elapsed PR count / total / elapsed
1 19,000 / 38.31 s / 175.5 s 14,000 / 32.38 s / 175.8 s
2 19,000 / 41.01 s / 176.1 s 14,000 / 56.24 s / 170.3 s

In run 2 the PR had already accumulated more wait time at the earlier log line. Its longest reported wait in these snapshots was 4.79 s, versus 1.49 s on main. The same deck view was visible in each run, with draw counts within 3%. The GPU was still busy for most of the frame interval on this laptop.

A first warm-up attempt for each build hit the same guest access violation. Both completed warm-up after a retry.

Tested and documented by Codex.

@Yorivel

Yorivel commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the BEHIND_PLACED finding above, with numbers from a local prototype.

Prototype (VICTORY_FILL_FROM_PLACED=1, local only):

  • A fill counts as not blocked, and reads from the copy's source instead, when the nearest earlier copy at its place in the same list wrote all of its bytes, out of memory no flight writes.
  • Applied in blocked_by, in place::read_by, and in run_deferred (the CPU fill).

Result (RTX 4090, ray tracing start-up, ~3 minutes):

  • 4,096+ fills redirected; BEHIND_PLACED refusals went from ~100 a minute to 0.
  • Slot fills that still wait for flights: about 50 in 3 minutes.
  • The start-up stutter did not change. Single waits of 40-220 ms remain, still settled as "a fill of upload memory", and nothing looked wrong on screen.

So the copy at its place in the same list is one cause of those waits, but not the one that dominates the stutter. We're now logging the remaining waiting fills: what last wrote their bytes, and whether a flight writes them. We'll post what that shows.

@Yorivel

Yorivel commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Last follow-up on the ray tracing start-up waits. Three local prototypes, all behind switches, all now off again. Each one removed the refusal it targeted, and each time the next rule took its place; the stutter did not change.

run refusals in ~3 min fills waiting for flights
baseline ~100 × BEHIND_PLACED ~120
+ VICTORY_FILL_FROM_PLACED (a fill behind a copy at its place reads the copy's source) ~100 × BEHIND_PLACED ~120
+ VICTORY_PLACED_ORDER=1 98 × BEHIND_PLACED 121: 34 behind a copy whose source flights write, 87 of flights' own bytes
+ VICTORY_PLACED_IN_FRONT (such a copy is also done on the card in front, if nothing ahead in its list reads its destination) 0 × BEHIND_PLACED, 51 × "a copy done on the card is read through another host copy" 41, all of flights' own bytes

What this says:

  • The waits come from refusals of whole submissions. One fill the plan cannot order drags every fill it could have done into the CPU wait.
  • The constant ring is held by more than one host copy. With the placed copies done in front, the refusal moves to copied_read.
  • Counters used, release build: what last wrote a waiting fill's bytes in its list (scanned back from the fill); how card_steps ends (nothing in the air / not blocked / nothing chosen / taken); take_steps' refusals by reason.

Two directions look worth trying: refusing step by step instead of the whole submission, and one host copy for the ring (or copied_read for it). Both are your design calls. The prototypes are a local patch; I can share it if it helps.

sethwololo pushed a commit to sethwololo/tempo-launcher that referenced this pull request Nov 27, 2026
Host lists: pool the copy sources; memory pressure trims spares down to 128 MiB instead of to nothing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MrSquirrel489 pushed a commit to MrSquirrel489/VIctory-NVIDIA that referenced this pull request Nov 27, 2026
… pressure trims spares down to 128 MiB instead of to nothing
MrSquirrel489 pushed a commit to MrSquirrel489/VIctory-NVIDIA that referenced this pull request Nov 27, 2026
…k when its submission lands

Conflict with PR trustno1-coder#57 (upload pool) in host.rs: both additions kept. The
memory bench counts RETIRED over its shards (PR trustno1-coder#139).
eleboucher pushed a commit to eleboucher/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
GPU: emit null buffer SRV/UAV when descriptor names a buffer with null resource
eleboucher pushed a commit to eleboucher/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
GPU: emit null buffer SRV/UAV when descriptor names a buffer with null resource
@claudeFrancoisAI

Copy link
Copy Markdown

A data point from a 16 GB machine, where the pressure never clears: here this goes the wrong way, and so does the trim half on its own.

Tree: main from just before 64d4931 with #321, #342, #382, #293, #394, #340, #294, #72, #39 and #326 on top; this PR's host.rs change applied cleanly. Launcher settings with VICTORY_RELAY=2, VICTORY_CARD_STEPS=2, VICTORY_ASYNC_SUBMIT=1, Series S, DLSS Quality, FSR 3 frame generation 2x. 4 cores / 8 threads, 16 GB RAM, RTX 2000 Ada 16 GB (about RTX 4060 class), opening cell, ~4,350 draws. Medians of the 5-second lines over 100 s, runs in this order in one session:

Run fps frame submitting thread: waiting for flights card busy ("card's clock")
without the PR 14.1 71.0 ms 6.9 ms 82-89 %
with the PR 9.9 100.5 ms 48.6 ms 54-68 %
with the PR, again 10.5 94.9 ms 47.9 ms 59-69 %
PR reverted, only "spare scratch chunks trimmed down to 128 MiB under pressure, not to nothing" 10.6 94.0 ms 45.1 ms 55 %
PR reverted, trim to nothing as before 13.7 72.8 ms 6.5 ms 86 %

(The first run with the PR had a browser drawing on the same card; the second did not.)

So with the spare chunks kept, the submitting thread stands waiting for flights about 40 ms more a frame and the card idles behind it, and it is the keeping itself that does it here, not the pooled copy sources. On this PC the pressure rule (under 3 GB free) is true for the whole run, so before the change every spare chunk went each second and the lists made about 63 upload buffers a second again; that churn turns out to be cheaper than whatever reusing a chunk costs with the relay on. I have not traced where the wait comes from; my guess is a chunk given back and taken again while a flight that names it is still in the air.

The thread does not say whether the 4090 / 64 GB runs had VICTORY_RELAY=2; if they did not, it may be worth one run with it before this becomes the default for machines under pressure. Glad to run a variant on this machine if that helps.

… to spare, keep 128 MiB of spares

Every copy a list recorded (HostList::upload) made a new upload or shared
buffer and waited for it to be resident, then freed it at the list's reset.
They are now taken from a pool by size class (power of two, 64 KiB at
least) and given back at the reset; VICTORY_UPLOAD_POOL_MB (1024 per kind,
0 = as before) caps what is kept.

Under memory pressure, the spare scratch chunks (and the pooled copy
sources) are trimmed down to SPARE_MOST (128 MiB) instead of all of them,
but only while 8 GiB or more of the PC's memory is free
(keeps_under_pressure). Then the pressure is the commit limit's, not the
memory's: with 64 GB and a system-managed page file the commit headroom
stays under 4 GiB for the whole session with ~20 GB free, and the spares
freed every second were made again at once. With memory really short they
all go, as before: on a 16 GB PC keeping them cost ~40 ms a frame of waits
for flights (review on trustno1-coder#57).

RTX 4090, i9-14900K, 64 GB, about 5 minutes of play each:
- waits for new memory to be resident: 68,000 / 17.3 s -> 37,000 / 9.3 s
- longest single wait: 1,006 ms -> 152 ms
- copy-source buffers made: 19,324 -> 93
- scratch chunks made: 12,925 -> 2,462

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yorivel
Yorivel force-pushed the fix/reuse-list-upload-buffers branch from 99096e6 to 924911f Compare November 28, 2026 14:18
@Yorivel

Yorivel commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

@claudeFrancoisAI thanks, that's a clear result, and it fits what we see: on this PC the pressure is the commit limit's, not the memory's (64 GB, system-managed page file, ~20 GB free while pressured() stays true), so keeping the spares helped here, and it hurts where memory is actually short.

Updated the branch (now on top of 63b902f, including the memory stack's low window):

  • The upload pool is unchanged.
  • The trim under pressure now depends on free memory. With 8 GiB or more of the PC's memory free (residency::physical_free()), the spare scratch chunks and the pooled copy sources go down to SPARE_MOST (128 MiB). Below that they all go, as on main, which is your 16 GB case.

If you have a moment for a rerun on your 16 GB machine: it should now match "PR reverted, trim to nothing as before" whenever less than 8 GB is free. If 8 GiB turns out to be the wrong line for you, the free-memory figure in your pressure warnings would tell us where it should sit.

@claudeFrancoisAI

Copy link
Copy Markdown

Thanks for the quick turn. The figures you asked for, from the same 16 GB machine (page file now fixed at 40 GB):

The one pressure warning of a session comes at world load: physical_free_mib=3032, available_commit_mib=38320, spare_scratch_mib=126.

Free physical memory sampled every 3 s during play: 1.1 to 2.5 GB in the prison dormitory, 0.3 to 1.6 GB in heavier scenes, and dips to 30 to 350 MB for a few seconds while a new scene loads.

So with a line at 8 GiB of free memory this PC always takes the "all go" branch, and I expect 924911f to behave like main here. I will rerun it and post the numbers. A line that this machine could ever cross would have to sit near 2 GiB, and I would not trust that: the regression I measured (submitting thread waiting for flights 6.9 ms to 48 ms) appeared with 2 to 3 GB free.

One more data point that may explain why kept spares hurt here: on this machine the scarce resource is not RAM or commit but the memory shared with the card (budget 7,517 MB, half the RAM, no Resizable BAR so every upload and shared buffer lives there). A scene load takes it from 5.3 to 7.8 GB in ten seconds. 128 MiB of spare upload chunks is counted in that budget too. If the trim could look at the shared budget (video_memory()'s third and fourth numbers) instead of free RAM, it would follow the thing that actually runs out on 16 GB PCs.

@claudeFrancoisAI

Copy link
Copy Markdown

The rerun, with two caveats first.

It is a port, not 924911f itself. My tree is on an older base with a different shader translator, and moving it to 63b902f would mean rebuilding the whole shader cache, so I applied 924911f onto my base instead. What carried over: the pool of copy sources, keeps_under_pressure() with the 8 GiB line and residency::physical_free(), and both trims following it. What did not: the memory stack's low window (my base has no Spare::low), so those three lines are out.

The scene is not the one from my first report. The save moved on, and the run now starts on the boat at the beginning of the next mission, so I measured there, on the same view for both builds (about 3,560 draws a frame). One run each, 90 to 100 seconds, medians of the 5-second lines.

without the PR: 14.6 fps, 68.4 ms a frame, submitting thread 53.9 ms in its submissions, 5.2 ms of them waiting for flights
with the port: 14.5 fps, 69.4 ms a frame, submitting thread 55.8 ms, 6.0 ms waiting for flights

So the regression is gone: the wait for flights that went from 6.9 to 48 ms with the first version stays at 5 to 6 ms, and the frame is within my run-to-run noise (about 0.3 fps). The run with the port also had 254 host pipelines being made in the background during the measurement, because the executable changed, so if anything it is the pessimistic side. Free memory was 1.2 to 2.3 GB in both, far under the 8 GiB line, so this PC took the "all go" branch the whole time, as intended.

One thing to watch on 16 GB machines: the memory shared with the card (GPU Process Memory, Shared Usage, sampled every 3 s). In the measured scene 2,545 MB without the PR and 2,717 MB with the port. At the peak of the load, 3,381 MB without and 4,132 MB with. That is the pool of copy sources filling before the first trim. On this PC the budget is 7,517 MB and a heavier load already reaches 5.4 GB, so 750 MB more is affordable here, but on a card without spare room it is the kind of margin that decides whether the load survives. A smaller VICTORY_UPLOAD_POOL_MB default when the shared budget is small would cover it.

@trustno1-coder
trustno1-coder merged commit 2ecb3d9 into trustno1-coder:main Nov 28, 2026
1 check failed
@Yorivel
Yorivel deleted the fix/reuse-list-upload-buffers branch November 28, 2026 19:13
onvleedani-sudo pushed a commit to onvleedani-sudo/VIctory-NVIDIA that referenced this pull request Nov 28, 2026
Adapt upstream PR trustno1-coder#57 while releasing idle sources under host pressure and tracking allocations by the existing submission lifetime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants