Memory: free idle textures under PC memory pressure; stop placed-view shapes from filling up #206

Open
github-bot wants to merge 16 commits from github-bot/gh-206 into main AGit
Owner

@⁠kripotker on GitHub · 2026-11-26 11:37 UTC · original
kripotker:memory-cuts → main · +1719 −220 · 27 files · 16 commits · open

Two memory fixes, measured on an RX 7900 XTX with 32 GB RAM (play.ps1 with VICTORY_PORT_CONSTANTS=1).

1. Idle texture copies go after 5 s under PC memory pressure

resource::let_go_idle kept 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.ps1 turns on VICTORY_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 bf800000 and 3f7ff8ac showed 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

Before After
Process private memory 41.3 GB 28.5 GB
Commit left 1.4 GB 3.2 GB
Card memory in use 20.5 GB 11.9 GB
Spilled to system memory 10.0 GB 7.5 GB
Frame time (avg of 30 lines) 63.6 ms 57.6 ms
New placed-view shapes ~85,000/min ~4,500/min

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.
  • The buffer-view word 9 case is not covered by a unit test.
  • Played in-game with --profile diag --features diagnostics.

🤖 Generated with Claude Code

**@⁠kripotker** on GitHub · 2026-11-26 11:37 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206) `kripotker:memory-cuts` → `main` · +1719 −220 · 27 files · 16 commits · open Two memory fixes, measured on an RX 7900 XTX with 32 GB RAM (`play.ps1` with `VICTORY_PORT_CONSTANTS=1`). ## 1. Idle texture copies go after 5 s under PC memory pressure `resource::let_go_idle` kept 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.ps1` turns on `VICTORY_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 `bf800000` and `3f7ff8ac` showed 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 | | Before | After | |---|---|---| | Process private memory | 41.3 GB | 28.5 GB | | Commit left | 1.4 GB | 3.2 GB | | Card memory in use | 20.5 GB | 11.9 GB | | Spilled to system memory | 10.0 GB | 7.5 GB | | Frame time (avg of 30 lines) | 63.6 ms | 57.6 ms | | New placed-view shapes | ~85,000/min | ~4,500/min | 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. - The buffer-view word 9 case is not covered by a unit test. - Played in-game with `--profile diag --features diagnostics`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The sweep kept idle host textures for 10 minutes while the card was under
88 % of its budget, but what the card spills to system memory is commit
too: at 18 minutes the process held 41 GB private with 1.4 GB of commit
left. With the pressure signal on, the same point was 28.5 GB private and
11.9 GB on the card (was 20.5), at 57.6 ms a frame (was 63.6).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The padding words of placed views' descriptions (resource words 1 and 13,
a shader resource view's word 3, a buffer view's word 9) hold the title's
stack junk. Direct3D reads none of them, but each new value made a new
shape: the 4M shapes were full after 30 minutes, and every placed view
after that became a table entry kept for good. Zeroed, new shapes fell
from about 85,000 to 4,500 a minute.

The shape index was a second full copy of every shape; it is now keyed
by the shape's hash, checked against the list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:42:47 +00:00
A list made on a fresh allocator costs it its first block: 1.16 MB of
commit on an RX 7900 XTX, against 0.15 MB for a list on an allocator
that has one (inplace::tests::lists_cost). A lazily made prelude now
records into its host list's allocator, which is idle then (the list is
closed before it is submitted) and is reset only after every submission
of the list ran; the prelude never resets it. 1,107 preludes held about
1.3 GB in run xtx-padfix. VICTORY_SHARED_PRELUDE=0: an allocator of its
own, as before.

VICTORY_CARD_BUDGET_MB caps the card budget every rule plans with (off
by default). At 9216 it held the card at about 9.5 GB but frames went
from about 58 to 85 ms: card copies of title buffers no longer fit and
were snapshotted on the CPU instead (29 ms against 2).

Ignored tests that measure on the real card: lists_cost, and
heaps_opened_per_part_cost (256 heaps opened on parts of private
memory cost about 1 MB in all).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
VICTORY_PORT_ALL=1 takes renderer port 1 past the title's 32-bit
graphics memory: every title buffer and window that is one stretch of
a section is placed in a heap opened through a view of ours, with no
host copy. play.ps1 turns it on with VICTORY_WINDOW_KB=1024 (not with
-Safe). At the boat start, against the same build without them: 26.3 GB
private (was 29.3), 20.9 GB of it in memory (was 23.5), host copies of
title memory 3.3 GB (was 4.0), 49 ms a frame (was 53-58).

On a PC of 32 GB or less the texture pool keeps 12 empty blocks while
the card has room, not 64. (Most of the 3.5 GB free in texture blocks
were holes in blocks in use; filling the fullest block first showed
garbage in textures cut from holes, so that is not done.)

play.ps1 -Console series-x|series-s passes the console model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠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 First two commits All four commits
Process private (commit) 41.3 GB 28.5–29.3 GB 26.3 GB
Of it in RAM 20.3 GB* 22.3–23.5 GB 20.9 GB
Card memory in use 20.5 GB 11.9–12.4 GB 11.8 GB
PC memory shared with the card 10.0 GB 7.5–8.5 GB 6.8 GB
Host copies of title memory 4.3 GB 3.3–4.0 GB 3.3 GB
Frame time 63.6 ms 53–58 ms 48.8–49.3 ms (~20 fps)

*Before this PR, about half of the 41 GB was paged out.

081a286: preludes share their list's allocator

On 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_cost measures 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=0 restores 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 blocks

  • VICTORY_PORT_ALL=1 lets 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.ps1 turns it on together with VICTORY_WINDOW_KB=1024; -Safe leaves both off. The earlier 256 KiB slowdown doesn't show at 1 MiB: snapshots take 1.3 ms a frame.
  • On PCs with 32 GB of RAM or less, the texture pool keeps 12 spare blocks, not 64.
  • play.ps1 -Console series-s passes the console model.

Negative results, for the record

  • VICTORY_PORT_ALL=1 + VICTORY_INPLACE=2 + VICTORY_CARD_BUFFERS=0 together: 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.
  • Filling the fullest texture block first (to let sparse blocks drain) showed black blotches on a character's shirt in a cutscene that rendered clean without it. Likely textures not fully uploaded, showing leftover data from reused holes. Reverted. In this run 3.5 of 5.5 GB of texture blocks were free, almost all of it holes in blocks still in use.

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:29 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7193434676) ## 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 | First two commits | All four commits | |---|---|---|---| | Process private (commit) | 41.3 GB | 28.5–29.3 GB | **26.3 GB** | | Of it in RAM | 20.3 GB* | 22.3–23.5 GB | **20.9 GB** | | Card memory in use | 20.5 GB | 11.9–12.4 GB | **11.8 GB** | | PC memory shared with the card | 10.0 GB | 7.5–8.5 GB | **6.8 GB** | | Host copies of title memory | 4.3 GB | 3.3–4.0 GB | 3.3 GB | | Frame time | 63.6 ms | 53–58 ms | **48.8–49.3 ms** (~20 fps) | \*Before this PR, about half of the 41 GB was paged out. ### `081a286`: preludes share their list's allocator On 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_cost` measures 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=0` restores 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 blocks - `VICTORY_PORT_ALL=1` lets 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.ps1` turns it on together with `VICTORY_WINDOW_KB=1024`; `-Safe` leaves both off. The earlier 256 KiB slowdown doesn't show at 1 MiB: snapshots take 1.3 ms a frame. - On PCs with 32 GB of RAM or less, the texture pool keeps 12 spare blocks, not 64. - `play.ps1 -Console series-s` passes the console model. ### Negative results, for the record - **`VICTORY_PORT_ALL=1` + `VICTORY_INPLACE=2` + `VICTORY_CARD_BUFFERS=0` together:** 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. - **Filling the fullest texture block first** (to let sparse blocks drain) showed black blotches on a character's shirt in a cutscene that rendered clean without it. Likely textures not fully uploaded, showing leftover data from reused holes. Reverted. In this run 3.5 of 5.5 GB of texture blocks were free, almost all of it holes in blocks still in use. ### 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.
A texture block goes only once every texture in it went, and the sweep
lets textures go here and there: on 64 MiB blocks 3.5 GB of 5.5 GB were
free in holes (run xtx-xcuts). The texture pool's blocks are now 16 MiB
(staging stays on 64). At the boat start: texture blocks 4.5 GB (2.4 GB
free), card 10.85 GB (was 11.77), private 25.2 GB (was 26.4); frames
53.4 ms against 51.3 (within the run-to-run spread there).

A texture bigger than a block is committed on its own. The first upload
gave every texture an aliasing barrier while the pool was on, which the
host refuses for a committed resource (debug layer: "cannot use aliasing
barrier since committed resource memory cannot be aliased"; a 5808x5808
BC1 texture, 17 MB). pool::pooled tells a texture cut from a block by
its private data, and only those take the barrier.

VICTORY_BIG_TRACE=1 logs a backtrace where each block of our own of
256 MiB or more is made. The 401 MB block seen since run 65 is the
title's audio heap (ApuAlloc), the title's to ask for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠kripotker on GitHub · 2026-11-26 13:48 UTC · original

6505796: 16 MiB texture blocks

Same spot and method as above, about 8 minutes after launch, against 605569d:

64 MiB blocks 16 MiB blocks
Process private 26.4 GB 25.2 GB
Card memory in use 11.8 GB 10.9 GB
Texture blocks 5.5 GB, 3.5 GB of it free 4.5 GB, 2.4 GB free
Frame time 51.3 ms 53.4 ms (within the run-to-run spread at this spot)

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::pooled now tells pooled textures apart by their private data, and only those get the barrier.

VICTORY_BIG_TRACE=1 logs 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 13:48 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7193860231) ## `6505796`: 16 MiB texture blocks Same spot and method as above, about 8 minutes after launch, against `605569d`: | | 64 MiB blocks | 16 MiB blocks | |---|---|---| | Process private | 26.4 GB | **25.2 GB** | | Card memory in use | 11.8 GB | **10.9 GB** | | Texture blocks | 5.5 GB, 3.5 GB of it free | **4.5 GB, 2.4 GB free** | | Frame time | 51.3 ms | 53.4 ms (within the run-to-run spread at this spot) | **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::pooled` now tells pooled textures apart by their private data, and only those get the barrier. `VICTORY_BIG_TRACE=1` logs 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.
A power of two from 4 to 64. At the boat start 8 MiB blocks made 4.1 GB
of texture blocks against 4.5 on 16, with 2.4 GB of them free on both,
and frames 52.2 ms against 49.4: the free part is spread over nearly
every block (a few small textures alive in each), which smaller blocks
do not change. 16 stays the default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
16 MiB blocks saved 0.9 GB of the card but showed garbage 4x4 blocks on
a shirt in the boat cutscene (run xtx-census). With 64 MiB the same
scene renders clean (run xtx-block64check). VICTORY_TEXTURE_BLOCK_MB=16
still picks the smaller blocks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠kripotker on GitHub · 2026-11-26 15:33 UTC · original

Update: texture blocks back to 64 MiB, and what the remaining memory is

Pushed: ef2ce61 sets 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=16 still 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):

Setting Card (local) Private Frame
64 MiB blocks (default) 10.9–11.9 GB 26.2 GB 49.1 ms
16 MiB blocks 10.55 GB 24.7 GB 49.1 ms

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):

  • Consecutive slices for the title's physical pages (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.
  • Zeros for textures placed in reused pool memory and fullest-block-first placement: neither reproduced the garbage blocks in four runs, fewer than 64 textures landed in reused holes, and fullest-first's gain is within noise.

Leads:

  • The garbage-block runs both logged a block's heap pointer being reused (a block let go and a new one made at once), about 40 s before the garbage showed. Smaller blocks and fullest-first both churn blocks more. A slot that still names a dead texture would then read the new block's textures. This needs a reliable repro first.
  • The 6.09 GiB view outside title memory is the title pool's section window (xmem). Its 5.3 GB of resident pages are the title's own pages, shared, so it costs no extra RAM.

🤖 Generated with Claude Code

**@⁠kripotker** on GitHub · 2026-11-26 15:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7196444375) ### Update: texture blocks back to 64 MiB, and what the remaining memory is **Pushed:** `ef2ce61` sets 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=16` still 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):** | Setting | Card (local) | Private | Frame | |---|---|---|---| | 64 MiB blocks (default) | 10.9–11.9 GB | 26.2 GB | 49.1 ms | | 16 MiB blocks | 10.55 GB | 24.7 GB | 49.1 ms | 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):** - *Consecutive slices for the title's physical pages* (`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. - *Zeros for textures placed in reused pool memory* and *fullest-block-first placement*: neither reproduced the garbage blocks in four runs, fewer than 64 textures landed in reused holes, and fullest-first's gain is within noise. **Leads:** - The garbage-block runs both logged a block's heap pointer being reused (a block let go and a new one made at once), about 40 s before the garbage showed. Smaller blocks and fullest-first both churn blocks more. A slot that still names a dead texture would then read the new block's textures. This needs a reliable repro first. - The 6.09 GiB view outside title memory is the title pool's section window (xmem). Its 5.3 GB of resident pages are the title's own pages, shared, so it costs no extra RAM. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A region the title remaps is forgotten, but our view of its stretch
stayed mapped for good. With windows on a 64 KiB grid the title's
remapping forgets thousands of regions (12,993 in run xtx-fine64), so
the views piled up. A forgotten region now waits until nothing is
placed in its heap; then the heap goes and the view is unmapped (8,610
unmapped, 180 waiting, in run xtx-newdefaults). The port's test checks
that the view stays while buffers are placed and goes after.

The in-place census also says, for windows over unmapped pages, whether
what was asked of each is one run, scattered or holed itself
(VICTORY_INPLACE_CENSUS_S sets when the second census runs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows cut on 1 MiB lay over the title's unmapped pages (1.1 GB of
copies) and were copied. Cut on 64 KiB they fall between them, and the
port uses them in place; VICTORY_INPLACE=1 does the same for windows in
private memory. At the boat (Series X): copies of title memory 2.0 GB,
were 3.3; RAM 19.4 GB, was 20.4; 50-51 ms a frame, was 49-50.

The old settings showed the grey shirt dark with black blotches and the
floral shirt neon green in the boat cutscene (run xtx-burst-old2); the
new ones rendered it right in four runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠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):

Owner Resident
Host copies of title memory (cached system memory the driver allocates on our list threads) 3.4 GB
Upload and staging buffers (write-combined) 3.1 GB
AMD driver's own heaps 2.1 GB
Our own heap 2.2 GB

Pushed:

  • c53599e play.ps1 now cuts windows on 64 KiB (VICTORY_WINDOW_KB=64, was 1024) and sets VICTORY_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).
  • fb489d5 the 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):

Old defaults New defaults
Host copies of title memory 3,311 MB 1,998 MB
RAM 20.41 GB 19.41 GB
Frame 49–50 ms 50–51 ms

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=1 with 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_bytes failed once in a full run and passes alone, so it looks like a shared-state flake.

🤖 Generated with Claude Code

**@⁠kripotker** on GitHub · 2026-11-26 17:18 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7198814495) ### 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): | Owner | Resident | |---|---| | Host copies of title memory (cached system memory the driver allocates on our list threads) | 3.4 GB | | Upload and staging buffers (write-combined) | 3.1 GB | | AMD driver's own heaps | 2.1 GB | | Our own heap | 2.2 GB | **Pushed:** - `c53599e` play.ps1 now cuts windows on 64 KiB (`VICTORY_WINDOW_KB=64`, was 1024) and sets `VICTORY_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). - `fb489d5` the 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):** | | Old defaults | New defaults | |---|---|---| | Host copies of title memory | 3,311 MB | 1,998 MB | | RAM | 20.41 GB | 19.41 GB | | Frame | 49–50 ms | 50–51 ms | 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=1` with 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_bytes` failed once in a full run and passes alone, so it looks like a shared-state flake. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠Fedalv on GitHub · 2026-11-26 18:11 UTC · original

Linux/Proton (RADV, RX 7900 XTX): the play.ps1 part of this PR makes the frame 2.5x slower here; the code part is fine

Setup: 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: main 2de9980 plus this PR and others, diagnostics build, Series X profile, the launcher's settings. Same opening sequence each run, 300 s.

median ms/frame "on the GPU" (submitting thread waiting for the card) copying back
without this PR's play.ps1 lines 52.0 1.4 ms ~24 ms
with them (VICTORY_INPLACE=1, VICTORY_PORT_ALL=1, VICTORY_WINDOW_KB=64, VICTORY_RESIDENCY=1) 132.7 28.9 ms ~43 ms
this PR's code, those four settings removed again 55.5 — —

(±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_INPLACE is 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 the play.ps1 change 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.

**@⁠Fedalv** on GitHub · 2026-11-26 18:11 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7200153276) **Linux/Proton (RADV, RX 7900 XTX): the `play.ps1` part of this PR makes the frame 2.5x slower here; the code part is fine** Setup: 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: main `2de9980` plus this PR and others, diagnostics build, Series X profile, the launcher's settings. Same opening sequence each run, 300 s. | | median ms/frame | "on the GPU" (submitting thread waiting for the card) | copying back | |---|---|---|---| | without this PR's `play.ps1` lines | 52.0 | 1.4 ms | ~24 ms | | with them (`VICTORY_INPLACE=1`, `VICTORY_PORT_ALL=1`, `VICTORY_WINDOW_KB=64`, `VICTORY_RESIDENCY=1`) | 132.7 | 28.9 ms | ~43 ms | | this PR's code, those four settings removed again | 55.5 | — | — | (±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_INPLACE` is 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 the `play.ps1` change 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.
VICTORY_PORT_ALL, VICTORY_WINDOW_KB=64, VICTORY_INPLACE=1 and
VICTORY_RESIDENCY=1 were on for every launcher user. On a card of its
own the card then reads the game's memory over PCIe: neutral on Windows
with a 7900 XTX (50-51 ms), but 132.7 ms a frame instead of 52.0 on
Linux/Proton with RADV (reported on PR #206). They are now opt-in with
-LowMemory, meant for integrated graphics; without it the settings are
main's again. The README names -LowMemory and -Console.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠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 996eafa and 4508cae: VICTORY_PORT_ALL, VICTORY_WINDOW_KB=64, VICTORY_INPLACE=1 and VICTORY_RESIDENCY=1 are now opt-in behind play.ps1 -LowMemory, documented in the README. Without the switch, play.ps1 sets what main sets (plus the new -Console option, 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) and VICTORY_PORT_ALL=1 (view memory in place) would be the two to separate. VICTORY_WINDOW_KB=64 on its own only changes how copies are cut.

**@⁠kripotker** on GitHub · 2026-11-26 18:49 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/206#issuecomment-7200898495) @⁠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 `996eafa` and `4508cae`: `VICTORY_PORT_ALL`, `VICTORY_WINDOW_KB=64`, `VICTORY_INPLACE=1` and `VICTORY_RESIDENCY=1` are now opt-in behind `play.ps1 -LowMemory`, documented in the README. Without the switch, `play.ps1` sets what main sets (plus the new `-Console` option, 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) and `VICTORY_PORT_ALL=1` (view memory in place) would be the two to separate. `VICTORY_WINDOW_KB=64` on its own only changes how copies are cut.
The sampler looked only at the title's submitting threads. Our threads now
register at their start (before the recording is on) when the switch is set,
16 places instead of 4, and each sample names the site of its stack.

Found with it on a Ryzen 7 7700: the list threads wait 86% of the time, so
list translation is not what limits the frame; the submitting thread is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
a5ded79 called crate::timeline::our_thread() from the list, heap-sync and
submit threads unconditionally, but it exists only with the diagnostics
feature: builds without it (cargo test, the release profile) failed. Each
call is now behind the same cfg as the title's own (queue.rs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After the world loads, tens of thousands of textures go idle and the few
still used lie scattered over nearly every texture block, so the blocks
never empty (run ram4-held: 6.9 GB of blocks for 1.5 GB of textures).
With the residency switch (play.ps1 -LowMemory):

- pool.rs: once a second, with more than 256 MB free in the texture
  blocks, the blocks under three quarters used are marked draining. New
  pieces go to other blocks first. The sweep lets idle copies in them go
  after a few frames (and, there, placed copies whose title memory is gone).
- resource.rs: copies that descriptor slots hold in a draining block are
  moved: the next copy is made like the old one in another block and
  filled from it with a CopyResource on the texture pass's list, and its
  slots are made again once that list has run. Filling it from title
  memory instead showed a shirt in other textures' colours: the title
  writes that memory without telling us. What the new copy holds is
  noted only when the list is submitted, and it is not uploaded ahead.
- descriptor/host.rs: slots remade after a texture's copy changed are
  only those whose texture has a host copy. Another texture at the same
  start whose copy was let go got an empty one, shown for good.
- pool.rs: staging blocks are 16 MiB and two spare ones are kept, not as
  many as texture blocks (12 empty blocks of 64 MiB were 768 MB of RAM
  holding 67 MB of staging).
- Spans::next_start: no BTreeMap range whose start is past its end (a
  texture shorter than 4 KiB panicked the submit thread).
- play.ps1 -LowMemory: 16 MiB texture blocks, 4 made ahead, window tails.

Series S at the boat, 7900 XTX test PC (RAM freed when closed + the card's
own memory): 15.9 + 7.8 = 23.7 GB at 39.9 ms a frame (run shirt-j), was
16.2 + 11.7 = 27.9 GB at 41.3 ms (run shirt-a). The shirt was right in
the last three runs. VICTORY_POOL_DRAIN=0 turns draining off,
VICTORY_POOL_MOVE=0 the moves only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shirt at the boat came back in other textures' colours again (run
shirt-k), part of it right: a copy was moved before it was ever filled
(made for a slot with its upload still to come, or itself the new copy of
a moved one whose card copy had not run). The move passed on whatever its
memory held before, and the pending fill landed on the copy let go. A copy
is now moved only if what it holds is noted (its fill was submitted), no
upload ahead is on its way, and no earlier move of it waits to be filled.

On Series X, draining every block under three quarters moved 4.8 GB of
textures in seven minutes (the same ones again and again) and frames of
the opening's cutscenes took 100 to 600 ms (run x-final2). Now only the
emptiest blocks under three quarters drain, as many as hold the free bytes
past the 256 MB line: the fewest bytes moved for each byte freed. And in a
draining block an idle copy goes after 3 s and 90 frames, not 4 frames,
which let go and made again copies used every few frames.

Series S at the boat: 15.5 + 7.7 = 23.1 GB at 39.2 ms (run shirt-l), 15.8
+ 7.7 = 23.5 GB at 40.0 ms (shirt-m); the shirt right in shirt-l, -m and
-n. Series X: 27.0 to 27.6 GB, which leaves a 32 GB PC short of memory:
seconds-long frames after the residency switch's pressure warning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Measured on Series X at the opening (play.ps1 -LowMemory, 7900 XTX, 32 GB): RAM
19.0 -> 17.6-18.1 GB at the boat; frames over 1.5 s in a 450 s run 5-11 -> 1-3;
P99 at the boat 327 -> 150-270 ms; the picture at the shirt close-up unchanged.

Stalls:
- xmem map_alias (CopyPageMappings): runs of consecutive pages are one view after
  their placeholders are joined; page by page it held the mapping lock for
  seconds while the lists' threads waited (the frames of 1-5 s).
- shadow: windows and title-buffer copies are made outside the LOOSE and
  BUFFERS locks, re-checked on insert (an in-place one made while a let-go ran
  is made again).
- port: regions opened outside their lock, kept ordered (BTreeMap): no walk
  over thousands at every placement and every remapped page; a remap that
  touches a stretch being opened retires it.
- host::mapped: one copy-queue wait covers every caller that came before it.
- Under host memory pressure idle textures go oldest first, 512 MB a sweep.

RAM:
- A submission takes the title list's host list; the title's Reset gets one
  from the pool (~600 closed title lists each held an allocator); the idle pool
  is trimmed to its low-water mark once a second.
- Idle send memory 192 MB (was 768); lists' budgets are 256-byte slots of
  shared 1 MiB buffers; root constant buffers ask for 64 KiB windows.
- -LowMemory: VICTORY_D3D12_DRED=faults.

Diagnostics: VICTORY_FRAME_TIMES=<file> (every present, release builds too),
"a long frame" lines, VICTORY_STALL_STACKS=<ms> (all stacks when no frame came
for that long), a census of private memory every 30 s (alive.rs: our buffers
by the line that made them, the rest by allocation size, resident sampled),
time spent making buffers and opening title memory on the heap pass's line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/pool.rs
  • crates/victory-gpu/src/resource.rs
  • crates/victory-gpu/src/texture.rs
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.
git fetch -u origin '+refs/pull/206/head:github-bot/gh-206'
git switch 'github-bot/gh-206'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-206'
git switch 'github-bot/gh-206'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-206'
git switch 'github-bot/gh-206'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-206'
git switch 'main'
git merge --squash 'github-bot/gh-206'
git switch 'main'
git merge --ff-only 'github-bot/gh-206'
git switch 'main'
git merge 'github-bot/gh-206'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.