fix: copies by address give their card room back when they go (+ VRAM census and churn tests) #549

Merged
KainanP merged 1 commit from upstream-pr/549 into main 2026-11-27 22:23:29 +00:00
KainanP commented 2026-11-27 21:00:46 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T21:00:46Z.


Change

shadow::by_address puts the copies that ray-tracing shaders read by address (the arenas of memory.rs, 64 MiB each, its directory, and the pages around small title buffers) on the card, at most VICTORY_MEMORY_CARD_MB of them (4,096 MB by default). The count it checked was a static USED inside the function that only ever grew:

  • nothing took it down when such a copy went;
  • it grew even when the copy was then refused (over the limit) or its buffer could not be made.

So the limit was on the bytes ever made, not on the bytes alive. Once 4,096 MB had been made in a process, every later arena went to the PC's memory, even with the card nearly empty, and every step of every ray then reads it over the bus. The counter the HUD shows (BY_ADDRESS_CARD_BYTES) only grew too.

Now BY_ADDRESS_CARD_BYTES is the count:

  • it is taken only when the arena goes on the card;
  • it is given back when the card buffer is not made;
  • it is given back when the copy goes (Shadow::by_address_card, read in Drop).

The limit, the 97 % line and everything else stay as they were.

How much this matters in game today: little, and I say so plainly. memory.rs keeps every arena for the whole run (pages are recycled inside them), so in one game session the bytes made and the bytes alive are the same, unless arenas are let go some day. This PR fixes the count so that what the limit says is true. I found it with the VRAM census below, which is the larger part of this PR.

The census (shadow::vram_census, two ignored device tests, plus the regression test). It makes each of the base's card-memory consumers through the base's own paths and reads QueryVideoMemoryInfo (local) around each one. The run below is on an RTX 4060 Laptop 8 GB (budget 7,188 MB) with the LowVram overrides (CARD_WINDOWS_MB=512, CARD_BUFFERS_MB=512, CARD_BUFFERS_MIN_KB=64, CARD_RESERVE_BUDGETS=1, TEXTURE_ROOM_PERCENT=85, TEXTURE_MAX_SIZE=1024):

Consumer (made through) Card memory
device + host at start 11 MB
card work: compare pass, its lists (card_ready; results are PC memory) +1 MB
card copies of title buffers, 4 MiB each, until refused (register + find) +512 MB (128 of 512 copies get a card side: CARD_BUFFERS_MB)
window card sides, 4 MiB windows, until refused (find outside buffers) +512 MB (128 of 512: CARD_WINDOWS_MB)
16 ray-tracing arenas of 64 MiB (by_address) +1,024 MB, all on the card; they also count as windows (window bytes counted: 1,536 MB)
texture pool: 64 textures of 1 MiB (pool::texture) +832 MB, of which 768 MB are empty blocks made ahead
one title view heap, 1,000,000 slots (HostHeap::new) +30 MB
one title sampler heap, 2,048 slots +0 MB
256 host lists, 256 KiB of clamped arguments and 2 batch places each +80 MB (about 0.3 MB a list)
everything let go back to 844 MB = 11 MB + 832 MB of empty texture blocks the pool keeps below 85 %

The churn (shadow::vram_census::churn): 24 cycles. Each cycle makes and lets go of 32 card copies, 32 windows, 4 arenas, 64 pool textures and 16 host lists of growing sizes.

  • What is in use, less the pool's empty blocks, is 12 MB in the first half and 12 MB in the second, the same as at the start. The card memory itself does not creep. The counts of card copies and windows come back to 0.
  • The only thing that did not come back was the arena count. Before this fix, arenas on the card per cycle went 4 × 16, then 0 × 8; after, 4 × 24.

The census's other findings (the texture pool's made-ahead blocks, host lists that keep their largest indirect buffers, arenas that count against the window budget) are listed in the PR comment below. The pool one has its own PR (#550).

Linked issue: Refs VIctory #3505 (8 GB laptop VRAM creep on AnyXboxX main, 6,559 → 7,145 MiB in 6 min).

Verification

RTX 4060 Laptop 8 GB, Intel UHD (a78b); third_party/victory, CARGO_TARGET_DIR outside the tree.

cargo test -p victory-gpu --lib --release -- --exact shadow::vram_census::arenas_give_their_card_room_back
  before → FAILED: where each arena lay: [1 × 64, 0 × 8]
  after  → ok
cargo test -p victory-gpu --lib --release -- --ignored --exact shadow::vram_census::churn --nocapture (LowVram env, VICTORY_BURY_LAG=0)
  before → FAILED: arenas on the card per cycle [4 × 16, 0 × 8]; in use less empty blocks 12 → 12 MB
  after  → ok: [4 × 24]; 12 → 12 MB
cargo test -p victory-gpu --lib --release -- --test-threads=1             → 484 passed; 0 failed; 46 ignored (RTX)
VICTORY_D3D12_ADAPTER=Intel cargo test -p victory-gpu --lib --release -- shadow:: pool:: → 57 passed; 0 failed; 5 ignored
cargo clippy -p victory-gpu --all-targets --release                       → the 2 warnings main has (overlay.rs, draw.rs); none in the files touched
cargo xtask policy                                                        → asset policy: 307 files ok
ANYXBOXX_REQUIRE_RUNTIME=1 python -m pytest -n auto                    → 1979 passed
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed!

Oracle and test data

  • shadow::vram_census::arenas_give_their_card_room_back makes and lets go of 72 arenas of 64 MiB, one after another (4,608 MB in all, past the 4,096 MB limit), and checks that each one lies where the first did. It fails without the fix (shown above).
  • The census and the churn are ignored device tests, because they fill part of the card. Their output above is the measurement.
  • No test data from a title.

Checklist

  • The PR covers a single reviewable behaviour (the count; the census is the test harness that found it).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (n/a)
  • README: no README change.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: only the VRAM figures of VIctory #3505, as posted by their author.
  • Code taken from another project: none.

AI use: made with Claude Code (Claude Opus 5.5): code reading, the census and churn harness, the fix, the tests and this description. The device runs were made on my RTX 4060 Laptop.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5533038604 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/549). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T21:00:46Z. --- ## Change `shadow::by_address` puts the copies that ray-tracing shaders read by address (the arenas of `memory.rs`, 64 MiB each, its directory, and the pages around small title buffers) on the card, at most `VICTORY_MEMORY_CARD_MB` of them (4,096 MB by default). The count it checked was a `static USED` inside the function that only ever grew: - nothing took it down when such a copy went; - it grew even when the copy was then refused (over the limit) or its buffer could not be made. So the limit was on the bytes ever made, not on the bytes alive. Once 4,096 MB had been made in a process, every later arena went to the PC's memory, even with the card nearly empty, and every step of every ray then reads it over the bus. The counter the HUD shows (`BY_ADDRESS_CARD_BYTES`) only grew too. Now `BY_ADDRESS_CARD_BYTES` is the count: - it is taken only when the arena goes on the card; - it is given back when the card buffer is not made; - it is given back when the copy goes (`Shadow::by_address_card`, read in `Drop`). The limit, the 97 % line and everything else stay as they were. **How much this matters in game today: little, and I say so plainly.** `memory.rs` keeps every arena for the whole run (pages are recycled inside them), so in one game session the bytes made and the bytes alive are the same, unless arenas are let go some day. This PR fixes the count so that what the limit says is true. I found it with the VRAM census below, which is the larger part of this PR. **The census** (`shadow::vram_census`, two ignored device tests, plus the regression test). It makes each of the base's card-memory consumers through the base's own paths and reads `QueryVideoMemoryInfo` (local) around each one. The run below is on an RTX 4060 Laptop 8 GB (budget 7,188 MB) with the `LowVram` overrides (`CARD_WINDOWS_MB=512`, `CARD_BUFFERS_MB=512`, `CARD_BUFFERS_MIN_KB=64`, `CARD_RESERVE_BUDGETS=1`, `TEXTURE_ROOM_PERCENT=85`, `TEXTURE_MAX_SIZE=1024`): | Consumer (made through) | Card memory | |---|---:| | device + host at start | 11 MB | | card work: compare pass, its lists (`card_ready`; results are PC memory) | +1 MB | | card copies of title buffers, 4 MiB each, until refused (`register` + `find`) | +512 MB (128 of 512 copies get a card side: `CARD_BUFFERS_MB`) | | window card sides, 4 MiB windows, until refused (`find` outside buffers) | +512 MB (128 of 512: `CARD_WINDOWS_MB`) | | 16 ray-tracing arenas of 64 MiB (`by_address`) | +1,024 MB, all on the card; they also count as windows (window bytes counted: 1,536 MB) | | texture pool: 64 textures of 1 MiB (`pool::texture`) | +832 MB, of which **768 MB are empty blocks made ahead** | | one title view heap, 1,000,000 slots (`HostHeap::new`) | +30 MB | | one title sampler heap, 2,048 slots | +0 MB | | 256 host lists, 256 KiB of clamped arguments and 2 batch places each | +80 MB (about 0.3 MB a list) | | everything let go | back to 844 MB = 11 MB + 832 MB of empty texture blocks the pool keeps below 85 % | **The churn** (`shadow::vram_census::churn`): 24 cycles. Each cycle makes and lets go of 32 card copies, 32 windows, 4 arenas, 64 pool textures and 16 host lists of growing sizes. - What is in use, less the pool's empty blocks, is 12 MB in the first half and 12 MB in the second, the same as at the start. **The card memory itself does not creep.** The counts of card copies and windows come back to 0. - The only thing that did not come back was the arena count. Before this fix, arenas on the card per cycle went `4 × 16, then 0 × 8`; after, `4 × 24`. The census's other findings (the texture pool's made-ahead blocks, host lists that keep their largest indirect buffers, arenas that count against the window budget) are listed in the PR comment below. The pool one has its own PR (#550). Linked issue: Refs [VIctory #3505](https://github.com/Marvisak/VIctory/issues/3505) (8 GB laptop VRAM creep on AnyXboxX main, 6,559 → 7,145 MiB in 6 min). ## Verification RTX 4060 Laptop 8 GB, Intel UHD (a78b); `third_party/victory`, `CARGO_TARGET_DIR` outside the tree. ``` cargo test -p victory-gpu --lib --release -- --exact shadow::vram_census::arenas_give_their_card_room_back before → FAILED: where each arena lay: [1 × 64, 0 × 8] after → ok cargo test -p victory-gpu --lib --release -- --ignored --exact shadow::vram_census::churn --nocapture (LowVram env, VICTORY_BURY_LAG=0) before → FAILED: arenas on the card per cycle [4 × 16, 0 × 8]; in use less empty blocks 12 → 12 MB after → ok: [4 × 24]; 12 → 12 MB cargo test -p victory-gpu --lib --release -- --test-threads=1 → 484 passed; 0 failed; 46 ignored (RTX) VICTORY_D3D12_ADAPTER=Intel cargo test -p victory-gpu --lib --release -- shadow:: pool:: → 57 passed; 0 failed; 5 ignored cargo clippy -p victory-gpu --all-targets --release → the 2 warnings main has (overlay.rs, draw.rs); none in the files touched cargo xtask policy → asset policy: 307 files ok ANYXBOXX_REQUIRE_RUNTIME=1 python -m pytest -n auto → 1979 passed python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools → All checks passed! ``` ## Oracle and test data - `shadow::vram_census::arenas_give_their_card_room_back` makes and lets go of 72 arenas of 64 MiB, one after another (4,608 MB in all, past the 4,096 MB limit), and checks that each one lies where the first did. It fails without the fix (shown above). - The census and the churn are ignored device tests, because they fill part of the card. Their output above is the measurement. - No test data from a title. ## Checklist - [x] The PR covers a single reviewable behaviour (the count; the census is the test harness that found it). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (n/a) - [x] README: no README change. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: only the VRAM figures of VIctory #3505, as posted by their author. - [x] Code taken from another project: none. _AI use: made with Claude Code (Claude Opus 5.5): code reading, the census and churn harness, the fix, the tests and this description. The device runs were made on my RTX 4060 Laptop._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KainanP commented 2026-11-27 21:01:26 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-27T21:01:26Z.


VRAM census of the base under LowVram: the full table. Code reading plus the harness in this PR. RTX 4060 Laptop 8 GB, budget 7,188 MB; "measured" means QueryVideoMemoryInfo local around the allocation.

# Consumer Size under LowVram Kind Gate / cap Given back?
1 Device + host at start 11 MB measured fixed — —
2 Card copies of title buffers (shadow::card_for) ≤ 512 MB (CARD_BUFFERS_MB), measured +512 per buffer ≥ 64 KiB 97 % of budget (reserved) yes, with the copy (churn: 0 MB left)
3 Their "before" twins (hashes) 16 B per 64 KiB piece, at least 64 KiB committed each per copy that shaders write — yes
4 Window card sides (window_card_for) ≤ 512 MB (CARD_WINDOWS_MB), measured +512 per 4 MiB window 97 % (reserved) yes, when the window goes; the sweep's idle time is the RAM rule (5 min with ≥ 12 GiB free RAM), not a VRAM one
5 Ray-tracing arenas by address (memory.rs + by_address) 64 MiB each, up to 3 GiB of pages + 1,024 spare pages, directory 16 MB; measured +1,024 for 16 grows with the pages rays touch; never let go during a run MEMORY_CARD_MB 4,096 and 97 %; also counted in the window bytes (16 arenas → 1,536 MB counted against the 512 MB window cap) count fixed here
6 Texture pool blocks (pool.rs) 64 MB blocks; 12 made ahead and up to 64 kept empty below 85 %: measured +768 MB of empty blocks for 64 MB of textures pool below 85 %: 64 (now: what fits under the line, #550); from 85 %: 2 empty blocks past the count, once a second
7 Host copies of textures the title's, the levels over 1,024 texels cut (#506) per texture resource::room 85 % of use less empty blocks, plus the reserves; floor min(2 GB, budget/4) idle ones from 85 % down to 82 % (vram_keep), 10 min below
8 Room kept for render targets (#536) 1,666 MB on this budget accounting only — as targets are made
9 Title view heap (HostHeap::new) 30 MB each (1,000,000 slots on NVIDIA), measured per title heap — with the heap
10 Title sampler heap ~0 (2,048 slots) per title heap — with the heap
11 Host lists: clamped indirect arguments + batch places + card budget ~0.3 MB a list with 256 KiB of arguments and 2 batches (measured 80 MB / 256 lists) per list; indirect_scratch doubles, batch_args only grows, both kept across reset(); idle pool up to 512 lists none with the list (churn: 0 left)
12 Card-steps lists (CARD_STEPS=2) 4 MB each + a host list pool, grows to the most in flight, never trimmed — no (bounded by the flights)
13 Depth twins the size of each depth texture again (+ stencil copy-through, plane twin) per depth texture — with it
14 Upload/readback rings, scratch chunks (≤ 1 GiB kept), staging blocks, shared CPU sides of copies PC memory (non-local), not VRAM pools — —
15 Query heaps ≤ 32 KB, timing builds only — — —
16 GPU-upload windows (WINDOWS_BAR_MB), tile heaps (LEVELS_ON_DEMAND) 0 (off; no ReBAR here) — — —

Churn, 24 cycles of card copies, windows, arenas, pool textures and host lists. What is in use, less empty texture blocks, was 12 → 12 MB: no creep in any of our own pools. The only thing that did not come back was the arena count (this PR).

So the creep YUYING234 saw on #3505 (6,559 → 7,145 MiB in 6 min) does not come from a leak in these paths. The consumers that grow with play are the title's own textures and targets (7, 13), and the arenas (5), if ray tracing is on. Two of the findings could be follow-ups if a timed 8 GB run points at them:

  • (5) arenas count against the 512 MB window cap, so with ray tracing no window gets a card side;
  • (11) host lists keep their largest indirect buffer forever.
<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7228060407 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/549#issuecomment-7228060407). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T21:01:26Z. --- **VRAM census of the base under `LowVram`: the full table.** Code reading plus the harness in this PR. RTX 4060 Laptop 8 GB, budget 7,188 MB; "measured" means `QueryVideoMemoryInfo` local around the allocation. | # | Consumer | Size under LowVram | Kind | Gate / cap | Given back? | |---|---|---|---|---|---| | 1 | Device + host at start | 11 MB measured | fixed | — | — | | 2 | Card copies of title buffers (`shadow::card_for`) | ≤ 512 MB (`CARD_BUFFERS_MB`), measured +512 | per buffer ≥ 64 KiB | 97 % of budget (reserved) | yes, with the copy (churn: 0 MB left) | | 3 | Their "before" twins (hashes) | 16 B per 64 KiB piece, at least 64 KiB committed each | per copy that shaders write | — | yes | | 4 | Window card sides (`window_card_for`) | ≤ 512 MB (`CARD_WINDOWS_MB`), measured +512 | per 4 MiB window | 97 % (reserved) | yes, when the window goes; the sweep's idle time is the RAM rule (5 min with ≥ 12 GiB free RAM), not a VRAM one | | 5 | Ray-tracing arenas by address (`memory.rs` + `by_address`) | 64 MiB each, up to 3 GiB of pages + 1,024 spare pages, directory 16 MB; measured +1,024 for 16 | grows with the pages rays touch; **never let go during a run** | `MEMORY_CARD_MB` 4,096 and 97 %; also counted in the window bytes (16 arenas → 1,536 MB counted against the 512 MB window cap) | count fixed here | | 6 | Texture pool blocks (`pool.rs`) | 64 MB blocks; **12 made ahead and up to 64 kept empty below 85 %**: measured +768 MB of empty blocks for 64 MB of textures | pool | below 85 %: 64 (now: what fits under the line, #550); from 85 %: 2 | empty blocks past the count, once a second | | 7 | Host copies of textures | the title's, the levels over 1,024 texels cut (#506) | per texture | `resource::room` 85 % of use less empty blocks, plus the reserves; floor min(2 GB, budget/4) | idle ones from 85 % down to 82 % (`vram_keep`), 10 min below | | 8 | Room kept for render targets (#536) | 1,666 MB on this budget | accounting only | — | as targets are made | | 9 | Title view heap (`HostHeap::new`) | 30 MB each (1,000,000 slots on NVIDIA), measured | per title heap | — | with the heap | | 10 | Title sampler heap | ~0 (2,048 slots) | per title heap | — | with the heap | | 11 | Host lists: clamped indirect arguments + batch places + card budget | ~0.3 MB a list with 256 KiB of arguments and 2 batches (measured 80 MB / 256 lists) | per list; `indirect_scratch` doubles, `batch_args` only grows, both kept across `reset()`; idle pool up to 512 lists | none | with the list (churn: 0 left) | | 12 | Card-steps lists (`CARD_STEPS=2`) | 4 MB each + a host list | pool, grows to the most in flight, never trimmed | — | no (bounded by the flights) | | 13 | Depth twins | the size of each depth texture again (+ stencil copy-through, plane twin) | per depth texture | — | with it | | 14 | Upload/readback rings, scratch chunks (≤ 1 GiB kept), staging blocks, shared CPU sides of copies | PC memory (non-local), not VRAM | pools | — | — | | 15 | Query heaps | ≤ 32 KB, timing builds only | — | — | — | | 16 | GPU-upload windows (`WINDOWS_BAR_MB`), tile heaps (`LEVELS_ON_DEMAND`) | 0 (off; no ReBAR here) | — | — | — | **Churn**, 24 cycles of card copies, windows, arenas, pool textures and host lists. What is in use, less empty texture blocks, was 12 → 12 MB: no creep in any of our own pools. The only thing that did not come back was the arena count (this PR). So the creep YUYING234 saw on #3505 (6,559 → 7,145 MiB in 6 min) does not come from a leak in these paths. The consumers that grow with play are the title's own textures and targets (7, 13), and the arenas (5), if ray tracing is on. Two of the findings could be follow-ups if a timed 8 GB run points at them: - (5) arenas count against the 512 MB window cap, so with ray tracing no window gets a card side; - (11) host lists keep their largest indirect buffer forever.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!549
No description provided.