Skip to content

D3D12.X: an optional page budget evicts CPU-filled title textures LRU - #640

Open
LeonardoS11 wants to merge 1 commit into
ivall:mainfrom
LeonardoS11:vram-page-budget
Open

LeonardoS11 wants to merge 1 commit into
ivall:mainfrom
LeonardoS11:vram-page-budget

Conversation

@LeonardoS11

@LeonardoS11 LeonardoS11 commented Nov 24, 2026 •

Copy link
Copy Markdown

The title-texture pages in vram.rs (shared 64 KiB pages per title address, #248/#288) only ever grow: a page is kept while any live texture covers its address, and the pool heaps behind them are never released. A title that recycles texture memory inside its own allocator gives XCL no signal that the old textures are dead, so the pages cover every address the title ever used for textures, not what it uses now. On a retail title streaming its world after the menus, with XCL_ACTIVITY=1 and a temporary counter on a local build: the pages went from 3.6 GB in the menus to 9.7 GB (8.6 GB shared + 1.1 GB extra tiles, 62 k live targets) while the title's own crash context reported 3.6 of its 6.2 GB texture heap in use; local video memory reached 13.7 GB on a 12 GB card, frames dropped to 2–3 fps and the title's stall watchdog (+0x2215c35, #232) ended it. Related: #320, #345, #292 (a different approach: retiring overwritten placements).

This adds an opt-in budget, XCL_PAGE_BUDGET_MB. Unset or 0 keeps today's behaviour.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: pool_cap() turns the budget into a number of 64 MB pool heaps. At the cap, take_tile calls evict_lru, which unmaps the least recently touched textures the CPU fills (placed through place_pages) until 512 tiles came back, and reuses their tiles instead of making another pool. Never evicted: GPU-owned targets (place), textures the GPU wrote (pin, from note_gpu_write), textures under 4 tiles, and anything placed, remapped or transitioned in the last 5 s. Pages another mapped texture still shares stay. take_evicted / any_evicted / touch / eviction_counts for the callers.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: an evicted texture is mapped again (remap_if_unmapped) and uploaded whole when its memory is written again (refresh_once) or a submitted transition names it (submitted, which also refreshes its LRU time). forget_content drops its D3D12.X: a title texture whose memory is as at its last upload is not uploaded again #486 content hash so the unchanged-upload skip does not leave the fresh tiles empty.
  • crates/xcl/src/host.rs: one page budget: N textures evicted, M mapped again line next to the XCL_ACTIVITY memory line, only once something was evicted.

Known limit: XCL does not see the title read a texture, only write or transition it. An evicted texture the title still samples without rewriting or transitioning it reads as zero (tier-2 unmapped tiles) until one of those happens. That is why the budget is opt-in.

Tested

Regression run

Same title, 60 s, no input, budget unset (the default this PR keeps).

main:

xcl-smoke v1
commit: 3db536ebe231418d76e8d6e52ccee0b47330a522
gpu: NVIDIA GeForce RTX 3080 Ti
title: Jogo
seconds: 60
exit: 0x0
frames shown: 1448 (PresentX 1448)
presents per 2 s (last 3): 60 60 30
device removals: 0
crashes: 0
peak commit: 17058 MB

this PR:

xcl-smoke v1
commit: 38bf6a324ac3d11387b81592f3dd5fd6fe38ddac
gpu: NVIDIA GeForce RTX 3080 Ti
title: Jogo
seconds: 60
exit: 0x0
frames shown: 1475 (PresentX 1476)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16506 MB

Not tested

  • AMD and Intel GPUs; cards with less video memory.
  • This branch alone with the budget set on the retail title (only on the local build above). A 60 s run without input stays in the menus, where the pages (about 3.6 GB) never reach a budget, so the regression run does not exercise eviction.
  • Whether textures evicted and never rewritten or transitioned show up empty in a visible place: the runs above did not look for it.

AI use

  • Claude Code with Claude Opus 5.5: measured the growth, wrote the code, the two tests and this description, and ran the tests and the regression runs on the hardware above. Opened as a draft until I have reviewed the diff myself.

🤖 Generated with Claude Code

The title-texture pages (vram.rs) grow with every 64 KiB page of title
memory a texture has ever covered: pool heaps are never released, and a
title that recycles texture memory inside its own allocator gives no
signal that the old textures are dead. On a retail title that streams
its world this reached 9.7 GB of pages (13.7 GB of local video memory on
a 12 GB card) and the driver paging stalls set off the title's watchdog.

XCL_PAGE_BUDGET_MB caps the pool heaps. At the cap, take_tile evicts the
least recently touched textures the CPU fills (placed through
place_pages; never GPU-owned targets, never textures the GPU wrote, none
under 4 tiles or touched in the last 5 s) and reuses their tiles. An
evicted texture is mapped again and uploaded whole when its memory is
written again or a submitted transition names it; its content hash is
forgotten so the unchanged-upload skip does not leave it out. Unset or 0
keeps the current behaviour.

Tests: page_budget_evicts_the_least_recently_touched_cpu_filled_texture
(vram.rs, GPU) and
a_texture_mapped_again_after_eviction_is_uploaded_even_if_unchanged
(title_textures.rs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeonardoS11
LeonardoS11 marked this pull request as draft November 24, 2026 02:48
@LeonardoS11
LeonardoS11 marked this pull request as ready for review November 24, 2026 02:50
@LocranKing

Copy link
Copy Markdown

Tested on NVIDIA GeForce RTX 3060 Ti (8 GB, wave32).

Tested

  • Commit: 38bf6a324ac3d11387b81592f3dd5fd6fe38ddac (pr-640, clean tree)
  • Hardware / software: Windows 11 Home Build 26200, Ryzen 5 5500, 31.8 GB RAM, RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 688 passed, 0 failed, 41 ignored, exit 0; 2 (no wave64) skipped (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware)

Regression run (scripts/smoke.ps1, 60 s, XCL_NETWORK=0, title folder name redacted)

main (dd2ae9a):

xcl-smoke v1
commit: dd2ae9a70af5eb5aad60f02d86e386b72abe1e95
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1525 (PresentX 1525)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14720 MB

PR #640 (38bf6a3, XCL_PAGE_BUDGET_MB unset):

xcl-smoke v1
commit: 38bf6a324ac3d11387b81592f3dd5fd6fe38ddac
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1574)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14718 MB

PR #640 (38bf6a3, XCL_PAGE_BUDGET_MB=2048):

xcl-smoke v1
commit: 38bf6a324ac3d11387b81592f3dd5fd6fe38ddac
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1540 (PresentX 1540)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14583 MB
  • With XCL_PAGE_BUDGET_MB=2048, xcl.log reported page budget: 92 textures evicted, 0 mapped again, target pages 3403 MB (pools 3456 MB) and 6016 MB local VRAM at 58 s (down from 3577 MB / pools 3584 MB and 6144 MB local on main).

Not tested: Walking past the start/menu screens into world streaming, debug build, XCL_SAMPLE_* tests on this branch, AMD / wave64.

AI use: Antigravity (Gemini 4 Hydrogen) ran the builds, tests, and smoke runs and drafted this report from the actual command outputs and logs.

@thatirishguyyy

Copy link
Copy Markdown

Independent Windows Radeon comparison on 38bf6a3, RX 9070 XT (driver 32.0.32029.2010), release. Both focused regressions passed, including GPU eviction and re-upload after eviction.

I ran the same binary and saved profile with XCL_PAGE_BUDGET_MB=0 and 4608. Starting available system commit differed by about 78 MiB. At the final logged streaming sample, the texture pool was 5,184 MiB off / 4,672 MiB on, local video memory 8,653 / 8,212 MiB, and process commit 19,159 / 19,051 MiB. The budget run evicted 554 textures and remapped 11. Both runs ended at an external 5 GiB system-commit guard during world streaming. One pair does not establish a performance difference.

AI-assisted (Codex ran and summarized the measurements).

@albertoglvn

Copy link
Copy Markdown

8 GB data point with the budget set. Native Windows 11, RTX 4060 Laptop 8 GB (7956 MiB), driver 621.24, 15 GB RAM + 40 GB page file, release MSVC build. The newer retail title (TitleID 7952987A), Series X profile, XCL_NETWORK=0, XCL_ACTIVITY=1, XCL_PAGE_BUDGET_MB=4096. Build: #484 head (9783066) with #495 (3ae0841), #496 (409f40f) and this PR (38bf6a3) cherry-picked on top. They applied cleanly. cargo test --lib -p xcl -- title_textures:: vram:: passes (18 passed).

Compared with the same base without this PR (#333 comment, one run each):

without budget budget 4096 MB
ended at 277.5 s, #333 assert (+0x193e00f, E_OUTOFMEMORY) 320.9 s, +0x23cf683 write at 0 (watchdog, #232)
"no video memory for more pages" 9 0
target pages, peak 6623 MB 5306 MB
page pools, peak 6656 MB 5312 MB
sparse pools, peak 1792 MB 1984 MB
local video memory, peak 10207 MB 9207 MB

Evictions: 561 by 160 s, 8714 by 280 s (824 mapped again). None after 280 s.

Observations:

  • The cap is soft on this title. The pools went to 83 heaps against a cap of 64, because when evict_lru frees nothing, take_tile makes another pool. So most of what was added past 4 GB was not evictable (GPU-written, pinned, under 4 tiles, or touched within 5 s). Sparse pools grow outside the budget (+1 GB here).
  • Frame rate: from 160 s, when local video memory went past the card's size, it ran mostly at 0–5 presents per second until the end. I can't tell from one run how much of that is eviction, paging and streaming, and how much is compile stalls. From 294 s to the end there were no presents at all, while large compute PSOs were still being built (up to 390 KB of DXIL), then the watchdog fired. That matches the Retail title: null write at +0x2215c35 (#159) still hits on NVIDIA RTX 4070 Ti, with and without XCL_NETWORK=0 #232 stop described above.
  • Missing textures: some textures were visibly missing during play. That fits the known limit in the description: an evicted texture the title only samples reads as zero. I didn't check which textures they were.

So on 8 GB this takes the run past the out-of-memory stop to the same watchdog stop that larger cards reach. A budget taken from the adapter's QueryVideoMemoryInfo local budget, minus what XCL uses outside the pages, might keep the total under the card's size better than a fixed number. I haven't tried that.

AI use: the logs were analysed and this comment drafted with Claude Opus 5.5; I ran the game and checked the results.

@albertoglvn

Copy link
Copy Markdown

Follow-up to my run above: the same build without XCL_PAGE_BUDGET_MB (#484 + #495 + #496 + this PR, so this PR's code is in but the budget is off). Same machine, same profile.

budget 4096 MB no budget
play starts (~60 presents / 2 s) ~140 s ~122 s
frames collapse (≤ 10 presents / 2 s) ~160 s, local 7.9 GB ~140 s, local 8.3 GB
ended at 320.9 s, watchdog (+0x23cf683) 160.1 s, #333 assert (+0x193e00f, 12× "no video memory")
target pages / sparse / local at the end 5306 / 1984 / 9207 MB 6638 / 1792 / 10204 MB

So the frame collapse is not caused by the eviction. Both runs drop to almost no frames about 20 s into play, once local video memory goes past the card's 7956 MiB. With the budget, the run then keeps going for another 160 s instead of failing CreateHeap within 20 s.

At the menus, local video memory outside the target pages and sparse pools is about 1.7 GB (6139 − 3577 − 896 MB). To stay under 8 GB, pages + sparse would have to stay below roughly 6 GB, but the run above had 5.3 + 2.0 GB, and about 3.6 GB of the pages are already in use at the menus. So on the Series X profile, an 8 GB card would need the cap enforced more strictly, which means more missing textures.

(One other run of this build crashed at 13 s inside the NVIDIA driver, nvwgf2umx.dll+0x85b227, read at 0x3c, the same place as in #345, while shaders were loading and before any eviction. The rerun was fine, so I'm treating it as intermittent.)

AI use: the logs were compared and this comment drafted with Claude Opus 5.5; I ran the game.

@crosettiremi

crosettiremi commented Nov 24, 2026 •

Copy link
Copy Markdown

Paired native Windows 11 runs on an RX 7900 XT (20 GB), retail 1.0.2.1, DXC 1.9.2602.17. I applied the budget change to a local integration build that also includes #690, bounded PSO waits and sparse-buffer release changes. Both runs used the same release executable, saved profile, A at 37 s, DRED, and separate copies of the same starting application caches (1,062 prior-use shader sets). The driver cache was shared. The 6 GiB run went first. CPU compilation overlapped parts of both runs, so I am reporting memory and outcomes only.

Activity sample near 148 s 6,144 MiB budget Budget off
Texture pools 6,336 MiB 10,112 MiB
Active target pages 5,453 MiB 9,737 MiB
Local video memory 10,225 MiB 14,069 MiB
Process commit 25,149 MiB 28,877 MiB

With the budget on, the last sample reported 8,175 textures evicted and 1,045 mapped again. The budget run ended at 159.855 s with an access violation in the title. The control ended at 157.917 s with an access violation in vcruntime140 on a thread processing audio. Both passed the account picker and streamed world assets. Neither reached verified playable frames. Zero device removals in both. These runs show a smaller memory footprint, but do not establish a cause for either crash or whether evicted textures rendered correctly.

Combined workspace suite: 724 passed, 0 failed, 41 ignored. Upstream change tested: 38bf6a3. Workspace command: cargo test --workspace --locked --offline -- --test-threads=4. Codex (GPT-6) ran the checks and summarized the local logs.

@ethandepstein-del

Copy link
Copy Markdown

Code audit + NVIDIA RTX 5080 test run on 38bf6a324ac3d11387b81592f3dd5fd6fe38ddac:

Three bugs found in the revive path

  1. Use-after-free in title_textures::submitted (title_textures.rs:585-591):
    • revive collects raw usize resource addresses from notes (recorded when the command list was built) and calls ID3D12Resource::from_raw_borrowed(&p) -> vram::remap_if_unmapped(r) without holding TEXTURES.lock() or cloning a COM reference.
    • If another thread calls Release / forget(res) between recording/taking res and remap_if_unmapped(r), r.GetDevice(...) dereferences a freed COM object.
    • Fix: Clone live COM references under TEXTURES.lock() via clone_resources(&revive) (matching forget()) before calling remap_if_unmapped.
  2. Current submission still samples NULL tiles (real.rs:5028-5034 + title_textures.rs:573-599):
    • title_textures::submitted(&mapped) is called after ExecuteCommandLists has already submitted the command lists to the GPU, and only marks e.pending = true for the next submit. So the submission that actually transitions and draws with the revived texture still samples unmapped NULL tiles on that frame.
    • Reviving + uploading evicted textures referenced by lists before ExecuteCommandLists (inside refresh) would avoid the blank frame.
  3. take_evicted drops the entry even when remap_if_unmapped returns false (title_textures.rs:581, 799):
    • If remap_if_unmapped fails (returns false), res was already removed from EVICTED and REMAPS was already incremented, leaving the texture permanently unmapped and never retried.
    • (Minor perf note: any_evicted() acquires the EVICTED mutex and touch(res) acquires the global PAGES mutex per barrier note when XCL_PAGE_BUDGET_MB > 0; an AtomicUsize count for any_evicted() and batching touch calls under one PAGES lock would avoid lock churn.)

Tested

  • Hardware / OS / toolchain: NVIDIA GeForce RTX 5080 (driver 617.42), AMD Ryzen 7 9800X3D, Windows 11 25H2 (build 26200.9711), rustc 1.100.0 (MSVC), debug build.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 688 passed, 0 failed, 41 ignored.
  • New tests a_texture_mapped_again_after_eviction_is_uploaded_even_if_unchanged and page_budget_evicts_the_least_recently_touched_cpu_filled_texture: both passed.
  • SKIPPED GPU/D3D12 tests: gpu_geometry_wave32_prefix_count_over_a_mask / gpu_wave32_program_in_wave64_hardware (no wave64), plus 2 D3D12 debug-layer tests (no d3d12SDKLayers.dll).

Not tested

  • Retail title / scripts/smoke.ps1 run (test suite only).
  • AMD / Intel GPUs.

AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above.

@albertoglvn

Copy link
Copy Markdown

One more data point, about what the LRU order sees on this title. Same machine (RTX 4060 Laptop 8 GB). Build: main f4ce27c + #495 + #496 + this PR, budget off, plus a local measurement patch: touch() also runs without a budget and counts transitions per target; every 10 s it logs the mapped targets by evictable, EVICT_MIN_TILES, age of touched, and touches == 0. Tiles are summed per texture, so shared pages count twice.

At 62 s, just before #333's out-of-memory stop at 63.5 s:

textures on pages MB textures
GPU-written or GPU-owned (never evicted) 3339 917
under 4 tiles (never evicted) 942 14490
CPU-filled, touched < 5 s 2069 1419
CPU-filled, 5–30 s 1546 701
CPU-filled, 30–120 s 584 188
CPU-filled with no transition since placement 4200 2308

So on this title, every CPU-filled texture on the pages (the age rows add up to the same 2308 textures) has never appeared in a submitted transition. Their touched is only the placement time, so evict_lru evicts the textures placed longest ago, whether or not they are still sampled. Nothing maps them back either, since take_evicted is only reached from a transition or a CPU write. That fits the missing textures I saw with the budget. Some signal of use other than transitions seems to be needed here, such as descriptor creation for the resource, or its being referenced by a list that was submitted.

The same counts at 32 s (menus, before streaming) show that most of the floor is GPU-written: 3367 MB of 3598 MB of target pages. With 1.1 GB of committed resources (buffers 571 MB, UAV textures 419 MB, two 3840×2160 display targets), 465 MB of arenas and 1–1.8 GB of sparse pools, that leaves about 1 GB of an 8 GB card for CPU-filled textures on the Series X profile. The driver's share of the local count, outside heaps and committed resources, was only about 136 MB.

AI use: the measurement patch and this comment were written with Claude Opus 5.5; I ran the game.

burber added a commit to burber/xcl that referenced this pull request Nov 24, 2026
… card, no out-of-order waits; first builds of world compute pipelines remain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants