Skip to content

host, send, uav_pool: trim only unborrowed low-water spare pools at 1 Hz sweep - #3381

Open
Maverick0351a wants to merge 1 commit into
trustno1-coder:mainfrom
Maverick0351a:fix/sweep-spare-low-watermark
Open

Maverick0351a wants to merge 1 commit into
trustno1-coder:mainfrom
Maverick0351a:fix/sweep-spare-low-watermark

Conversation

@Maverick0351a

Copy link
Copy Markdown
Contributor

Summary

  • sweep() runs once per second (1 Hz) inside Host::submit when !behind (all in-flight submissions have landed, so 100% of the active per-frame D3D12 upload, scratch, submission-send, and UAV buffers have just been returned to the spare pools).
  • On 32 GB hosts where physical_free < 5 GiB (pressured() == true and keeps_under_pressure() == false, even with > 60 GiB of commit headroom available), the 1 Hz sweep() previously called immediate trim_to(16 MiB) / trim_to(0) on UPLOAD_SPARE, SPARE, SPARE_SHARED, UAV_SPARE, and send::SPARE:
    • send::trim() did not track a low-water mark (low), removed the largest buffers first (spare.remove(0)), and dropped ID3D12Resource inside SPARE.lock().
    • trim_spare_uploads(), trim_spare_chunks(), and uav_pool::sweep_uav_spare() used trim_to instead of Spare::trim_above(most), destroying 80-150 MiB of the active per-frame working set every second at !behind only for the very next frame to stall for 20-253 ms calling CreateCommittedResource + Map in D3D12 (frame_times: 27 frames, median 35.6 ms, p99 52-115 ms; 1 over 50 ms at 1 Hz; VICTORY_SEND_OWN: 27-253 ms taking them out of the CPU sides).
  • This PR:
    1. Tracks (kept, bytes, low) in send::SPARE, evicts only the unborrowed low-water surplus (spare.low.saturating_sub(floor)) in send::trim() unless critical_commit() is true, and drops evicted ID3D12Resource allocations outside SPARE.lock().
    2. Uses Spare::trim_above in the 1 Hz sweep() hooks (trim_spare_uploads(), sweep_spare_chunks(), and uav_pool::sweep_uav_spare()) when !critical_commit(), while preserving immediate trim_spare_chunks() for F7 hard flush (drop_spare_chunks()), xmem fallback, and tests.

moritz-eckhard-nickel added a commit to moritz-eckhard-nickel/VIctory-NVIDIA that referenced this pull request Nov 30, 2026
…y unborrowed low-water spare pools at 1 Hz sweep

trustno1-coder#3381 by Maverick0351a, head 5cd08d8.
JustOptimize added a commit to JustOptimize/VIctory-Enhanced that referenced this pull request Nov 30, 2026
…he 1 Hz sweep (PR trustno1-coder#3381)

Port of trustno1-coder#3381, applied clean. On a PC under RAM pressure the 1 Hz sweep emptied the spare upload, scratch, send and UAV buffer pools every second (80 to 150 MiB of the active per-frame set), and the next frame stalled 20 to 253 ms in CreateCommittedResource and Map. Now send::SPARE tracks a low-water mark and only the unborrowed surplus is trimmed (all of it only under critical commit), and evicted resources are dropped outside the lock. Upstream: a 32 GB host, median 35.6 ms with a 1 Hz hitch before; not run on a 3080 here.
JustOptimize added a commit to JustOptimize/VIctory-Enhanced that referenced this pull request Nov 30, 2026
@tyr0nsur

Copy link
Copy Markdown
Contributor

I reproduced a send-cache regression at 5cd08d8. In give_back, the cap loop removes the first entry after appending the newly returned buffer. If that buffer is larger than the entire cap, the loop evicts every existing spare before dropping the oversized buffer too. In a deterministic test with a 128 MiB cap, a 2 GiB one-shot return unnecessarily evicted the existing 16 and 64 MiB spares. This can happen with a large exact-size send from #3729 as well.

Cherry-pickable commit 8fb4ea9 restores the original largest-first cap eviction and preserves the remaining buffers' return order for the low-water trim. It reuses the host Spare accounting and drops the released buffers outside the lock. Both new tests failed with the original cap behavior and passed with the fix. On Windows, the spare filter passed 11 tests. I also applied this PR plus the follow-up and #3729 together on 41adb551; all six send unit tests passed there (two hardware probes were ignored). Staged asset policy passed.

Tested cache behavior only. In two existing RTX 4060/32 GB .05 logs, host pressure was logged but the 4 GiB upload refusal did not appear. No in-game timing measurement for this patch. Reviewed and tested with Codex assistance.

@dyshay

dyshay commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics, and the CPU tests of the touched code pass. A run on an RTX 4090 is queued. Frame times will follow here.

@Lyrnc

Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Measured this side by side with the other fixes for the same send-spare churn on an RTX 5080 + 9800X3D, 32 GB (where pressured() always holds), on vnv 829188e + #3347. Walking, Series X native 1440p, DLSS off, 300 s windows; first round, one run each:

arm fps >100 ms per 1,000 send trim per sweep card copies
base 19.5 55.4 68.0 ms 10.6 ms
this PR 21.7 35.0 9.3 ms 6.3 ms
#3411 20.2 52.5 4.9 ms 6.3 ms
#3994 (per-size window, release off the submitting thread) 20.3 52.1 0.0 ms 6.1 ms

This PR had the best fps and the fewest long frames in this round. The second round is running and I'll post it here. The 9.3 ms left in this PR's trim step is spent on the submitting thread; #3994 moves the release to its own thread, so the two could combine.

AI use: Claude Code (Claude Opus 5.5).

@Lyrnc

Lyrnc commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Shootout, final (2 runs per arm): RTX 5080 + 9800X3D, 32 GB, vnv 829188e + #3347, walking, Series X native 1440p, DLSS off, world +30..330 s. Every arm has the same local per-step sweep timing.

arm fps (2 runs) >100 ms per 1,000 send trim per sweep (submitting thread) card copies send buffers made / let go in 300 s largest kept spare
base 19.5 / 19.7 55.4 / 51.6 68.0 / 73.5 ms 10.6 / 10.0 ms (every second) n/a
#3994 (8b80173) 20.3 / 21.4 52.1 / 39.0 0.0 / 0.0 ms 6.1 / 6.2 ms 6/4, 7/4 416–480 MiB
#3381 21.7 / 20.1 35.0 / 46.3 9.3 / 9.2 ms 6.3 / 6.5 ms n/a n/a
#3411 (bundle) 20.2 / 20.8 52.5 / 45.4 4.9 / 4.9 ms 6.3 / 6.1 ms n/a n/a

AI use: Claude Code (Claude Opus 5.5).

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.

4 participants