Memory: free idle textures under PC memory pressure; stop placed-view shapes from filling up #206
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!206
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-206"
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?
@kripotker on GitHub · 2026-11-26 11:37 UTC · original
kripotker:memory-cuts→main· +1719 −220 · 27 files · 16 commits · openTwo memory fixes, measured on an RX 7900 XTX with 32 GB RAM (
play.ps1withVICTORY_PORT_CONSTANTS=1).1. Idle texture copies go after 5 s under PC memory pressure
resource::let_go_idlekept idle host textures for 10 minutes while the card was under 88 % of its budget. But what the card spills to system memory counts against the PC's commit too: at 18 minutes the process had 41 GB private and only 1.4 GB of commit left.Now, while
crate::residency::pressured()is set, idle copies go after 5 s.play.ps1turns onVICTORY_RESIDENCY=1, which was already in the code but off.2. Placed-view shapes: padding zeroed, index keyed by hash
The padding words of placed views' descriptions hold the title's stack junk: resource words 1 and 13, a shader resource view's word 3, and a buffer view's word 9. Values like
bf800000and3f7ff8acshowed up there. Direct3D reads none of them, but each new value made a new shape.The 4,194,304 shapes were full after about 30 minutes. After that, every placed view became a table entry that is never freed (over 1 million in one run, and growing).
I found the words with a temporary census: over 200,000 new shapes, I counted how many stayed distinct with each word zeroed. Zeroing word 3 alone merged 42 %.
placed()now zeroes those words when the view is recorded. The shape index is also keyed by the shape's hash, checked against the list, instead of holding a second full copy of every shape.Results
The before and after frame times come from different scenes (on foot against in a boat), so treat that row as "no worse", not a measured gain.
The cost of fix 1 is re-uploads: about 45,000 textures (5.4 GB) were made again over about 38 minutes. I saw no pop-in while driving.
Testing
cargo test -p victory-gpu --lib -- descriptor residency pool vram_: 64 passed. The descriptor test now also checks that junk in the padding words gives the same view and shape.--profile diag --features diagnostics.🤖 Generated with Claude Code
@kripotker on GitHub · 2026-11-26 13:29 UTC · original
Update: two more commits, Series X memory and fps
Measured on an RX 7900 XTX with 31 GB of RAM, in Series X mode. Each figure is at the same spot, standing still at the boat start, with
play.ps1.*Before this PR, about half of the 41 GB was paged out.
081a286: preludes share their list's allocatorOn this card, a command list made on a fresh allocator costs 1.16 MB of commit: the allocator's first block. On an allocator that already has a block, a list costs 0.15 MB, and recording 600,000 commands then resetting adds nothing. The ignored test
inplace::tests::lists_costmeasures this.A lazily made prelude now records into its host list's own allocator. That allocator is idle then, and it is reset only after the list's submissions have run. That saves about 1 MB per prelude, about 1.1 GB for the ~1,100 preludes in a run. No prelude errors in testing.
VICTORY_SHARED_PRELUDE=0restores an allocator of its own.Also in this commit:
VICTORY_CARD_BUDGET_MB, off by default. A 9 GB cap holds the card at about 9.5 GB, but frames go from about 58 to 85 ms. Card copies of title buffers no longer fit and get snapshotted on the CPU instead (29 ms against 2).heaps_opened_per_part_cost: 256 heaps opened from address cost about 1 MB of commit in all.605569d:VICTORY_PORT_ALL, 1 MiB windows, fewer spare blocksVICTORY_PORT_ALL=1lets renderer port 1 go past the title's 32-bit graphics memory. Every buffer or window that is one stretch of a section is used in place.play.ps1turns it on together withVICTORY_WINDOW_KB=1024;-Safeleaves both off. The earlier 256 KiB slowdown doesn't show at 1 MiB: snapshots take 1.3 ms a frame.play.ps1 -Console series-spasses the console model.Negative results, for the record
VICTORY_PORT_ALL=1+VICTORY_INPLACE=2+VICTORY_CARD_BUFFERS=0together: private memory climbed from 29 to 87 GB in about 40 s, until commit ran out. Each switch alone stays at 26–27 GB. I haven't found the cause; avoid that combination.Series S, for comparison (
-Console series-s, same spot)21 fps (48 ms). 18.6 GB in RAM against 23.5 GB in Series X with the first two commits. The title asks for 9.8 GB of memory against 15.0 GB, and host render targets take 1.4 GB against 2.9 GB.
Private memory came out almost the same (28.7 against 29.3 GB). In Series S the title asks for a 16 GB reservation hundreds of times; in Series X it asks once for 24 GB. Not investigated yet.
@kripotker on GitHub · 2026-11-26 13:48 UTC · original
6505796: 16 MiB texture blocksSame spot and method as above, about 8 minutes after launch, against
605569d:Bug found on the way: the first upload of a texture recorded an aliasing barrier whenever the pool was on. A texture bigger than a block is committed, and the host refuses that barrier: the list fails to close. Before this, a texture had to be over 64 MiB to hit it; with 16 MiB blocks it happens at startup.
pool::poolednow tells pooled textures apart by their private data, and only those get the barrier.VICTORY_BIG_TRACE=1logs a backtrace for every block of our own of 256 MiB or more. The 401 MB block in the memory line since run 65 is the title's own audio heap (ApuAlloc).Since the PR was opened: 41.3 → 25.2 GB private and 20.5 → 10.9 GB card in Series X, with frame time down from about 64 ms to about 50.
@kripotker on GitHub · 2026-11-26 15:33 UTC · original
Update: texture blocks back to 64 MiB, and what the remaining memory is
Pushed:
ef2ce61sets the texture blocks back to 64 MiB by default. With 16 MiB blocks, one run showed garbage 4x4 blocks on a character's shirt in the boat cutscene; with 64 MiB the same scene renders clean.VICTORY_TEXTURE_BLOCK_MB=16still picks the smaller blocks, which save about 1 GB of card memory at the same frame time.Series X at the boat start (7900 XTX):
Run-to-run noise in card usage is about ±0.5 GB.
True RAM footprint: closing the game freed 20.46 GB of RAM, so Series X uses about 20.5 GB of RAM plus about 10.9 GB of card memory, roughly 31.4 GB in all.
Tried and dropped (nothing pushed):
VICTORY_PORT_ALL): of 131,072 mapping calls, 126,600 map a single page, and with the neighbour's slice taken into account 120,050 of them were already in order, so not one page needed moving. The scattered title memory is recycled pages (not fresh) and GPU page-mapping aliases (69,557 pages) of views that are already mapped. Renaming slices cannot fix either.Leads:
🤖 Generated with Claude Code
@kripotker on GitHub · 2026-11-26 17:18 UTC · original
Update: where the unexplained memory went, and 1 GB less RAM
Traced (WPR VirtualAllocation trace with call stacks, live regions at the boat matched to the allocation that made them):
Pushed:
c53599eplay.ps1 now cuts windows on 64 KiB (VICTORY_WINDOW_KB=64, was 1024) and setsVICTORY_INPLACE=1. On the 1 MiB grid, 1.1 GB of window copies lay over the title's unmapped pages; for most of them the unmapped pages were inside the asked range, between separate asks in one cell. On 64 KiB the windows fall between those pages and the port uses them in place (39,882 placed against 907).fb489d5the port unmaps its view of a region the title remapped once nothing is placed in its heap. Before, those views stayed mapped for good, which the finer grid would have turned into thousands of leaked views (12,993 forgotten regions in one run).At the boat, Series X (RAM measured as memory freed when the game closes):
Card usage moved between 11.2 and 12.5 GB across runs with either setting. The difference is empty spare blocks the texture pool keeps while the card has room (5,120 against 6,464 MB in blocks, with the same live textures), not the windows.
Rendering: with the old settings, one run showed the grey shirt dark with black blotches and the floral shirt neon green in the boat cutscene. The new defaults rendered the same shots correctly in four runs. That points the earlier garbage reports at stale copies of title memory, not at texture block size.
Tried and reverted: a fresh command allocator per list reset (no RAM saved, 150 ms a frame);
VICTORY_WINDOW_TAILS=1with a 256 KiB grid (RAM −0.7 GB, no gain overall).Tests: victory-gpu passed 370/370 in 5 of 6 full runs.
descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytesfailed once in a full run and passes alone, so it looks like a shared-state flake.🤖 Generated with Claude Code
@Fedalv on GitHub · 2026-11-26 18:11 UTC · original
Linux/Proton (RADV, RX 7900 XTX): the
play.ps1part of this PR makes the frame 2.5x slower here; the code part is fineSetup: Linux (kernel 7.2), Ryzen 7 7800X3D (SMT off), 30 GB RAM, RX 7900 XTX, Mesa RADV 26.2.5, Proton Experimental 11.0-20261112 with the view-tree wineserver (#111) and vkd3d-proton master
71cae09. Tree: main2de9980plus this PR and others, diagnostics build, Series X profile, the launcher's settings. Same opening sequence each run, 300 s.play.ps1linesVICTORY_INPLACE=1,VICTORY_PORT_ALL=1,VICTORY_WINDOW_KB=64,VICTORY_RESIDENCY=1)(±4 ms is the spread between identical runs here.) The counters point at the wait: with the four settings, 0.4 submissions a frame settle for "title memory read … by a fill of upload memory", 19.7 ms of waiting for the card a frame, against 0.1 settles and 0.8 ms without them; card steps refused 0.38 a frame against 0.05.
I did not separate the four settings from each other.
VICTORY_INPLACEis the likely one: reading title buffers where they are means the card reads PC memory over PCIe, and the 60 fps plan in #43 lists the single-copy path as measured 2-4x slower (R1). The Windows numbers in the PR text (49 ms) suggest it behaves differently there, so maybe theplay.ps1change could be kept out of this PR, or made a separate opt-in, rather than turned on for every launcher user.AI-assisted (Claude Code); runs on my machine.
@kripotker on GitHub · 2026-11-26 18:49 UTC · original
@Fedalv thanks for measuring this, and for separating the code from the settings.
You're right. Those four settings are aimed at PCs whose graphics share their memory (an iGPU with LPDDR5X is the target), where reading the game's memory in place costs nothing and saves a copy. On Windows with a 7900 XTX they measured neutral here (50–51 ms against 49–50 at the boat), but a 2.5× hit on RADV is too much for a default.
Done in
996eafaand4508cae:VICTORY_PORT_ALL,VICTORY_WINDOW_KB=64,VICTORY_INPLACE=1andVICTORY_RESIDENCY=1are now opt-in behindplay.ps1 -LowMemory, documented in the README. Without the switch,play.ps1sets what main sets (plus the new-Consoleoption, which defaults to Series X as before).Your counters fit the PCIe explanation: settles for "title memory read … by a fill of upload memory" and the submitting thread waiting on the card both go up when the card reads PC memory in place. If you get a chance to try the settings one at a time,
VICTORY_INPLACE=1(private memory in place) andVICTORY_PORT_ALL=1(view memory in place) would be the two to separate.VICTORY_WINDOW_KB=64on its own only changes how copies are cut.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.