24% Less Shared GPU Memory (Window Growing + Card Memory Ledger) #2910
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2910"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-11-29T18:46:32Z.
This turns window growing (
VICTORY_WINDOW_GROW) on by default, together with a fix that makes it pay off. On an RTX 4070 Ti with 32 GB of RAM, the PC's memory shared with the card in steady play went from about 7.6 GB to 5.8 GB (-24 %) in the same scene, at the same frame rate. It also adds a card memory line to the log, every 5 seconds in every build, which says what holds the card's memory and the shared memory. That's how the gain was found, and it might help with memory reports from other PCs.Summary
card memory by owner:line, every 5 s in every build. It covers the card's own memory and the PC's memory shared with the card. For each it gives the system's figure, what the layer's own heaps and committed resources hold by owner, and what isn't counted.VICTORY_CARD_MEMORY=0turns it off. Later commits added descriptor heaps, lists' scratch and textures made for Streamline as owners, and the texture and shared buffer blocks' free space and fill (#4462).pool.rs's 64 MiB shared blocks, which they left fragmented. Each window is now an allocation of its own.VICTORY_WINDOWS_POOLED=1brings back the old behaviour.VICTORY_WINDOW_GROW=0turns it off.VICTORY_VIEW_REACH=1makes translated programs note how far each root view is read. It's slow (2-3 fps) and only meant for measuring.VICTORY_WINDOW_ROOT_KBuses those numbers to bound a root view's window, also off by default (it saved nothing at a safe margin, see below).The card memory ledger can be split out into its own PR (with window growing stacked on top) if that's easier to review.
Measurements
One PC: RTX 4070 Ti 12 GB, 32 GB RAM, Windows 11. Series X, 1440p, DLSS Performance, 2x frame generation. Same save and spot, an unattended 12-minute run each, the last few minutes compared.
main)pool.rs)A run with the new defaults and no switches at all came out at about 6.0 GB of shared memory, in a slightly lighter stretch (about 4,900 draws). So -20 % to -24 % is a fair range. Moving to a busier area later raised it to about 6.9 GB, with nothing piling up.
Details
What the ledger showed
The shared memory was mostly the layer's own, on purpose, not the driver moving things off a full card:
The ledger and the game's RAM
On NVIDIA the driver maps the card's own memory into the process as write-combined private pages, so it counts in the game's private bytes one for one. #4288 found and measured this, and #4204 fixes the process line's accounting that hid it. 16 min into a run on this PR: 18.8 GB of host private bytes were unnamed, and the card's use (9.1 GB) plus the shared memory (6.8 GB) covered 15.9 GB of it. So the ledger's two groups together say where most of the game's RAM goes, and a cut in either is a cut in RAM.
Why growing alone wasn't enough
Growing makes windows fit their asks: the windows asked for with a length went from 24 % to 91 % used. But the smaller windows were then cut from the shared buffer blocks. A block goes back only when it's empty, and each block kept a few long-lived windows. In one run that was 49 blocks holding 3,136 MB, with about 945 MB live and 33 of the blocks under a quarter full. Shared memory went up rather than down.
With windows as allocations of their own, the gain shows. Turning the blocks off on their own changes nothing, because the default windows are 6 MiB and never pooled.
The loading spike
While the world first loads, the windows a longer one replaces are held for about ten seconds beside it. In one run that was 1,754 windows, 3,738 MB, and shared memory peaked at about 9.4 GB. It was back at the steady figure about ten seconds later, and peak commit was still lower than before.
Root views
A root view has no size, so its window runs to the end of its 4 MiB cell plus 2 MiB.
VICTORY_VIEW_REACHmeasured 8,758 of them: 93 % were read no more than 64 KiB past their address, and the furthest 1.4 MB. Bounding them at 2 MiB past their address (VICTORY_WINDOW_ROOT_KB=2048) saved nothing, because the margin needed for the few long ones cancels the gain. So it stays off. A bound per kind of view might do better, and the switch is there to measure that.Not covered
mainwithout it. Nothing new or worse.Tests
VICTORY_VIEW_REACH: a root view read notes its reach only when asked, and a format load through a root view too. Both validate withdxil.dll.cargo test -p victory-gpu --lib: 922 pass. Two fail, and they fail without this change too:every_switch_of_the_translator_is_in_the_key:VICTORY_SCALAR_SPLITSis in the cache key, but the translator no longer reads it.a_change_is_saved_at_once_however_the_game_was_started: flaky here, and it passes on its own.cargo test -p victory-shader --lib: 465 pass.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by neongatzu on 2026-11-29T22:02:48Z.
Tested on an 8 GB card with 16 GB of RAM, where the PC's memory shared with the card is the wall. Caveat first: this was not upstream main. I applied this PR's commit onto another fork's tree (4 conflicts, resolved by hand:
buffer_sidestakes both the image flag andown;resize_fetchis not in that tree and was left out;shared_bufferthere returns aResult). The rest of the run's switches are that fork's launcher defaults.PC: RTX 3060 Ti 8 GB, 16 GB RAM, Windows 11 26200, NVIDIA 621.24, 64 GB fixed pagefile on NVMe. Series S profile, 1080 upscaled to 1440, DLSS Performance, no frame generation.
Without this PR (same scene): the run ended after about 7 minutes with
0x8007000Ewhen a host command list closed; shared memory peaked at 7,189 MB against a cap of about 7.5 GB, the card at 8,020 MB of a ~7,000 MB budget.With this PR (defaults): the run lasted 11.5 minutes and was closed by hand, no crash. Shared memory peaked at 7,058 MB, the card at 7,392 MB. Frame rate unchanged (median ~15-17 fps, bound by host-copy refreshes paging on this RAM size). The ledger line was the most useful part, e.g. after 8 minutes:
So on this PC the shared blocks are gone as intended, windows asked with a length are tight, and nearly all window memory is root views without a length.
With
VICTORY_WINDOW_ROOT_KB=2048added: memory dropped a lot (shared 5,041 MB, windows without a length 609 holding 2,625 MB after 4 minutes), but after 4 minutes a host command list failed to close with0x80070057(E_INVALIDARG, "a command recorded into it was invalid"). That error did not appear in any of the earlier runs on this PC today, with or without this PR, so the root reach looks like the cause: perhaps some step still sizes a copy or a view by the cell's extent rather than the shorter window. I had no diagnostics build to name the command withVICTORY_D3D12_DEBUG=1. The ledger showed 8 windows taken over by a longer one at the moment of the crash, 0 in the minutes before.Happy to run a diagnostics build if that would help.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-29T23:01:35Z.
We ran a test of this PR on a 12 GB RTX 50 card, A/B against its own base (
f889bb07, the v2026.11.29.02 hotfix this branch sits on). The gain holds there, and is larger than on the 4070 Ti.Setup:
So it's about -2.3 GB shared and -3 GB private, with no measurable change in frame rate or CPU time on this machine.
Pictures: a burst check (10 captures a second, counted by eye) shows one-frame stretched polygons and flashing trees on both sides at about the same rate. On the base alone it was 12 of 100 frames. That is the folding default of the hotfix, which
05d1c564fixes on main; current main showed none here. A rebase onto main would let a picture check of this PR come out clean.AI Assisted
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Jesper-Andersson on 2026-11-30T21:03:08Z.
We built a similar per-class counter for the card's memory on our fork, before we saw this PR. Rather than open a second ledger PR, we'd like to offer the few parts of ours that aren't in your
card memory by owner:line or on main yet. This is step 0 of #4462, which has our measurements.What your line already covers, as we read the diff: both memory groups, bytes by owner (texture blocks, render targets, aliased target heaps, depth twins, card copies, buffers made ahead and more), the uncounted rest against
QueryVideoMemoryInfo, rounding against what the title asked for, the window spans, and a fill census of the shared buffer blocks. Main also prints the texture blocks' free and resting MB, empty blocks and a four-bucket fullness count on request (VICTORY_POOL_STATS=1). Ours counts only the card's own memory, so most of it overlaps with those.What ours adds:
CurrentUsage:From one 28-minute session on our build:
The over-time table is in #4462.
A companion number that is already on main: with
VICTORY_SMALL_WHEN_FULL, the "textures made from their small levels for want of room ... waiting to grow now N" line. Next to the texture-block figures it shows when the card is full enough that textures start small.Setup: our fork's build (upstream v2026.11.30.02, plus opt-in ports that are off unless set, plus our counter commit). RTX 2070 SUPER 8 GB, driver 621.40, Windows 11, Series S profile, DLSS Performance, FSR 3 frame generation. GPU clock state not recorded.
Not tested: we haven't run this PR. Our counter has run in a few sessions on one PC. It counts the card's own memory only.
Two ways this could go:
Which do you prefer?
Drafted with AI assistance (Claude Code).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-11-30T21:13:54Z.
@Jesper-Andersson added the texture block detail to the
card memory by owner:line (2f58529d). New part, between the windows and the shared buffer blocks:texture blocksowner earlier in the line.freeis free space inside the blocks. DXGI counts it as in use; only an empty block can be given back.restingwas given back but can't be reused yet.by fillis blocks that are empty / under ¼ full / ¼–½ / ½–¾ / ¾ and up. Each block is in one, so they add up to the block count. Empty is split out so idle blocks show on their own.busyif a pool is locked at that moment.The per-class split was already in the line (render targets, title buffer copies, card copies of title memory, windows, uploads), so your steps can read from it instead of a second counter.
On a 4070 Ti 12 GB, 10 min in-world: about 30 blocks, 60–200 MB free inside, empty blocks in 12 of 95 samples (never more than 2). Same picture as yours.
NOTE: I started adding this before seeing your comment above since I didn't refresh the page, sorry. Was going off your issue tag. Reviewing the extra notes you added.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-11-30T21:36:20Z.
@Jesper-Andersson went with folding them in, since you offered (
ff647c58):uav_pool::take_uav: between-copies, indirect budgets/args/batches): own owner, with idle spares shown once they pass 1 MB. You were right that it sat under card copies of title memory before.2 min in-world on a 4070 Ti 12 GB:
Owners added
descriptor heaps 30andlists' scratch 25. The uncounted card part dropped from ~570–610 to 526 MB at the same point.GPU detile targets are only made with
VICTORY_GPU_DETILE=1(off by default), so they're not tagged.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-12-01T02:32:31Z.
@neongatzu thanks, the 8 GB / 16 GB case is the one this is for, and the
0x8007000Egoing away matters more than the peak numbers.Your window line matches ours: on a 4070 Ti over 89 min, the windows asked for without a length grew from 695 to 824 (3.9 to 4.6 GB), with about half their bytes past the highest address read. That's the next thing I'm looking at.
Two PRs that bear on your ledger numbers at 16 GB: #4204 fixes the process line's accounting (console section views were counted as named private bytes, which hid most of the unnamed part; found on a 16 GB / 2060 PC), and #4288 shows that on NVIDIA the card's memory is mapped into the process, so it counts in private bytes, and adds
VICTORY_TEXTURE_COMMIT_FLOOR_MB, which lowers the texture limit when the PC's commit left falls under 4 GB. That floor never acted on my 32 GB PC; on yours it likely would.Yes to the diagnostics run, for the
VICTORY_WINDOW_ROOT_KB=2048case only: a diagnostics build withVICTORY_D3D12_DEBUG=1names the command when a list fails to close. If it names a copy or view that reads past a root window's end, the cap is cutting off something the card still reads, and the fix has to bound windows by measured reach rather than a fixed size. If it names something else, it's likely the late-session0x80070057that main hits without this PR too.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-12-01T02:32:33Z.
@DoubleD17 thanks for the A/B. -2.3 GB shared and -3 GB private with no change in frame time is an awesome result to see.
The branch is on current main now (
ff647c58), so the folding fix (05d1c564) is in. If you have time for the picture check again, that would tell us whether anything on screen comes from this PR.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by shurhundo on 2026-12-01T02:37:39Z.
Heads up: this overlaps #3723 (open, currently mergeable), which adds a
crate::tiersrefault/Holds system and a fix (fc7d3930) forgrown()not reporting regrown windows to it, exactly theVICTORY_WINDOW_GROW=1path this PR makes the default. Neither PR currently references the other, and both editgrown()/grow_reach()/made_window()/buffer_sides(), so whichever lands second will need to rethread its changes through the other's reshaped functions. Once this PR's default flip ships, #3723's refault fix stops being opt-in coverage and becomes load-bearing for everyone's default window behavior, so it's worth syncing merge order with that PR rather than landing independently.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-12-01T03:09:24Z.
Tested
VICTORY_WINDOW_GROW=1on an 8 GB VRAM / 32 GB RAM NVIDIA system — strong improvement on both Shared GPU RAM and frame-time stability.System & profile:
--fg-type fsr --framegen 3), ray tracing off, warm pipeline cache (2,742–2,748pipelines loaded),VICTORY_SAMPLED_EVICT=1,VICTORY_AMBIENT=0.8,VICTORY_AMBIENT_SPECULAR=1Matched 60 s in-world A/B (
+10 s..+58 ssteady window):VICTORY_WINDOW_GROW=0)VICTORY_WINDOW_GROW=1T+U+C)34.2+1.1+0.4)33.4+1.1+0.4)>100 mshitches (steady / all)<2 s)<2 sremakesBoth runs logged
HERO LEAD = 0,UPLOAD OVER HOST WRITE = 0, and0Victory errors.Extended 12-minute soak stability (
VICTORY_WINDOW_GROW=1+VICTORY_SAMPLED_EVICT=1):7d93ee0759alongside our rebased local optimization stack (VICTORY_POOL_SMALL=0,VICTORY_RIPE_BLOCKS=12).0crashes,0device losses,0Victory errors,0>100 mshitches in the final 8.7 minutes, and steady-state Shared GPU RAM down to5,837 MB(-2.1 GBvs the baseline above) with no visual artifacts across inspected start/mid/end frames.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Remorce on 2026-12-01T07:11:44Z.
Heads-up: with ray tracing on, this PR currently loses the device.
VICTORY_HW_RT=1at 4K, DLSS Performance: #2910 alone loses the device (0x887A0005) about 20 s in, where main at the same commit (e1251c31) runs the full 5 min. The emulated path does the same.Runs and numbers: https://github.com/trustno1-coder/VIctory-NVIDIA/discussions/4773
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.