Skip to content

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

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

LeonardoS11 wants to merge 1 commit into
xcl-dev: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 (kept per Pages as cap, so tests can set it). At the cap, take_tile takes the tiles the last eviction round gave back first; only when there are none does it call evict_lru, which unmaps the least recently touched evictable textures until 512 tiles came back. A round that finds nothing to evict is not repeated for a second (EVICT_IDLE), and the pools grow past the budget meanwhile. Evictable: only textures title_textures keeps in step with the title's memory (set_evictable from register), of 4 tiles or more, not placed, remapped, transitioned or uploaded in the last 5 s, and not written by the GPU (pin). Pages another mapped texture still shares stay. revive maps an evicted texture again and takes it out of the evicted set only when that worked. The budget needs late release (XCL_LATE_RELEASE=0 turns it off with a warning): evicting unmaps a texture from another thread, which is safe only while a texture's last Release reaches vram::forget before the object goes.
  • crates/xcl/src/hle/d3d12x/title_textures.rs: evicted textures are mapped again before the work that uses them. revive_listed runs before a submit, ahead of refresh, for the textures its lists transition (references taken under the TEXTURES lock), and marks them pending so this submit's refresh uploads them whole. A texture written again by the CPU is mapped again in refresh_once before its upload (if that fails it stays evicted and is not uploaded). A copy into an evicted texture maps it again when it is recorded (note_gpu_write), with no upload over what the GPU writes. Uploads and submitted transitions refresh the LRU time. forget_content drops the D3D12.X: a title texture whose memory is as at its last upload is not uploaded again #486 content hash of a texture mapped again so the unchanged-upload skip does not leave its fresh tiles empty.
  • crates/xcl/src/hle/d3d12x/real.rs, list_x.rs: call revive_listed before refresh in ExecuteCommandLists and KickoffX (in KickoffX the refresh moved after reclaim_for_kickoff, which only does bookkeeping, so the segments split before it are covered).
  • 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.

Changes since the review (thanks @mastrr9, @iggyvilla and the review above): eviction no longer repeats for every tile of a placement at the cap; textures are mapped again before the submit that uses them instead of after it; a failed remap keeps the texture evicted; no vram code dereferences a key of a texture that may be gone (late release required, references cloned under the lock in the revive path); uploads refresh the LRU time; textures title_textures refused are never evicted; a copy into an evicted texture maps it first; pin/touch return at once with the budget off.

Known limit: XCL does not see the title read a texture, only write, copy into or transition it. An evicted texture the title still samples without any of those reads as zero (tier-2 unmapped tiles) until one happens, and a draw already queued may read zero or, at the cap, the newer texels of a reused tile for a frame. That is why the budget is opt-in.

Tested

  • NVIDIA GeForce RTX 3080 Ti (12 GB, 32-lane waves), AMD Ryzen 9 5900X, 64 GB; Windows 11 Pro 26200; Rust stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100).
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 (debug) on 5d6fac8: 744 passed, 0 failed, 41 ignored. The three tests, all GPU:
    • page_budget_evicts_the_least_recently_touched_cpu_filled_texture (vram.rs): the oldest evictable texture goes first, its pages go back, a GPU-written one stays, a round with nothing evictable returns 0, an evicted one maps again once.
    • page_budget_one_placement_at_the_cap_evicts_one_batch (vram.rs): 40 textures of 16 tiles, pools at the cap with no spare tile, one more texture placed: the 32 oldest (one batch of 512 tiles) are evicted and the rest stay. It fails without the take-the-batch-first change (40 evicted).
    • page_budget_an_evicted_texture_is_mapped_again_before_the_work_that_uses_it (title_textures.rs): an evicted texture a list transitions is mapped again by revive_listed, pending, its content hash forgotten; a copy recorded into an evicted texture maps it again with no upload pending.
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Retail title with XCL_PAGE_BUDGET_MB=6144, XCL_NETWORK=0, XCL_ACTIVITY=1, walked through the menus into its first world load. These runs were on a local build that also carried other open PRs (D3D12.X: a slow graphics pipeline waits at most 4 s once per build (#232) #267, D3D12.X: bound compute pipeline waits so slow compiles do not trip wa… #533, Memory: decommitted sparse tiles stay mapped until the next submit #532, Memory: a freed sparse block is decommitted before its address is reused #348) and local diagnostics, not on this branch alone, so they show what the budget does, not this branch's numbers: pages held at 4.6–6.0 GB and local video memory at 10.1 GB (13.7 GB without the budget), 9,791 textures evicted and 1,094 mapped again over 456 s, 30 fps in the menus, the world's geometry drawn. The title still stops at the Retail title: null write at +0x2215c35 (#159) still hits on NVIDIA RTX 4070 Ti, with and without XCL_NETWORK=0 #232 watchdog later on this machine, for compile stalls this PR does not address.

Regression run

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

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3080 Ti
title: Jogo
seconds: 60
exit: 0x0
frames shown: 1290 (PresentX 1290)
presents per 2 s (last 3): 60 41 4
device removals: 0
crashes: 0
peak commit: 16156 MB

this PR:

xcl-smoke v1
commit: 5d6fac8cb6c1ccddf95adc273862e5cb4be5ae2a
gpu: NVIDIA GeForce RTX 3080 Ti
title: Jogo
seconds: 60
exit: 0x0
frames shown: 1429 (PresentX 1429)
presents per 2 s (last 3): 60 60 36
device removals: 0
crashes: 0
peak commit: 18100 MB

Both runs drop presents in their last seconds, the main run more than this PR's, so the drop is not from this PR (on this main the recompiler output changed, and the title's shaders were compiling again).

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, copied into or transitioned show up empty in a visible place: the runs above did not look for it.
  • The review fixes on the retail title with the budget set: only the unit tests and the regression run (budget unset) above ran on 5d6fac8.

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

@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.

@mastrr9

mastrr9 commented Nov 24, 2026

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
… the card, no out-of-order waits; first builds of world compute pipelines remain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pvfreis pvfreis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Read at 38bf6a3 against merge base 3db536e. Code read only; nothing built or run.

With XCL_PAGE_BUDGET_MB unset, the eviction path is unreachable (pool_cap() == 0), and I found no
lock-order problem (PAGES → EVICTED only; TEXTURES is dropped before every vram call). The
points below are about the budget-on path, apart from 5. They do not repeat the three revive-path
points already posted on the PR (borrowed pointer in submitted, remap after ExecuteCommandLists,
take_evicted consumed when the remap fails).

Findings

1. CONFIRMED: at the cap, every tile taken starts another 512-tile eviction round

crates/xcl/src/hle/d3d12x/vram.rs:289-306 (take_tile), :410-434 (evict_lru).

evict_lru gives tiles back through release_tiles(.., true), which pushes them to cooling with
the time now, never to free. So the self.free.pop() at :299 after the eviction is always
None, and take_tile returns one tile from cooling.pop_front() (:304).

bind calls take_tile once per tile. On the next call free is still empty, the front of
cooling is not yet 2 s old (:293), the pools are still at the cap, so evict_lru(EVICT_BATCH)
runs again (:298) although cooling still holds about 511 tiles from the round before. before
(:412) is taken inside evict_lru, so each round wants 512 more tiles.

Scenario: pools at the cap, a new 4 MiB texture (64 tiles, none shared) is placed. Result: 64 rounds
asking for 64 x 512 = 32,768 tiles (2 GiB), bounded only by what is eligible. In practice one
placement at the cap evicts every CPU-filled texture of 4+ tiles not touched for 5 s, not one batch.
Each round also scans and sorts all of targets under the PAGES lock. This fits the eviction
counts reported in the comments (8,000 to 9,800 textures) and the missing textures.

Suggested fix: at the cap, take from cooling first and evict only when both free and cooling
are empty, for example:

if cap > 0 && self.pools.len() >= cap {
    if self.cooling.is_empty() {
        self.evict_lru(EVICT_BATCH);
    }
    if let Some((t, _)) = self.cooling.pop_front() {
        return Some(t);
    }
}

2. CONFIRMED: an upload does not refresh the LRU time, so a texture just written is evictable

crates/xcl/src/hle/d3d12x/title_textures.rs:771-805 (refresh_once), vram.rs:654-664 (touch).

touched is set on placement (vram.rs:582), on remap (:632) and from submitted for
transitions (title_textures.rs:580). The CPU-write path (refresh_once → upload_all) never
calls touch for a texture that is still mapped.

Scenario: a texture is placed at t = 0 and stays in a shader-resource state. The title streams mips
into its memory at t = 6 s; the submit uploads them. A placement at the cap in the same frame sees
touched = t = 0, so this texture is among the first evicted, right after its upload. It then reads
as zero until the title writes or transitions it again. For a title that does not transition its
sampled textures, the order is creation order, not use order.

Suggested fix: in refresh_once, call vram::touch for each entry of todo (one PAGES lock for
the batch would be better than one per texture).

3. LIKELY: a GPU copy into an already-evicted texture is lost, and some evictable textures can never come back

vram.rs:582 (evictable: !require_aligned), vram.rs:669-677 (pin),
title_textures.rs:459-469 (note_gpu_write), :592-599 (revive in submitted).

a) pin only clears evictable. If the texture is already evicted when the title records
CopyTextureRegion / CopyResource into it, it stays unmapped: the copy goes to NULL tiles. After
the submit, submitted revives it and sets e.pending = true without looking at e.gpu_written
(:594-597), and refresh_once uploads pending entries before its gpu_written check (:776-781).
So the stale CPU view is uploaded over a texture whose contents the title's memory does not hold (the
case note_gpu_write's comment describes: an atlas that is zeros in memory). Table::remove
already guards this at :263 (if !e.gpu_written).

b) Every place_pages texture is evictable, including those title_textures::register then
refuses (device_x.rs:911: console formats 116 / 117, textures without texels or with more than one
plane). They are not in TEXTURES, so note_transitions drops their transitions (:548) and
refresh_once never lists them: once evicted, nothing maps them again, and a later GPU copy into
them is lost for good.

Whether a title hits either depends on it creating such a texture more than 5 s before the first
GPU copy into it while the pools are at the cap; I could not check that.

Suggested fix: default evictable to false and set it only when register succeeds; in pin, map
an evicted target again at record time (the title queue waits for the mapping in before_execute)
and remove it from EVICTED; in the revive loop, do not set pending when e.gpu_written.

4. CONFIRMED: the two tests do not cover the paths the description names

vram.rs:1019-1071, title_textures.rs:1196-1204.

  • a_texture_mapped_again_after_eviction_is_uploaded_even_if_unchanged only checks that removing a
    key from LAST_CONTENT makes same_as_last_upload return false. No eviction, remap or upload
    happens in it, so it would still pass if submitted / refresh_once stopped calling
    forget_content.
  • page_budget_evicts_... calls evict_lru(1) directly. Nothing drives take_tile at the cap
    (pool_cap() is a OnceLock read from the environment), which is where finding 1 is.

Suggested fix: give Pages a cap that tests can set, place textures past it and assert how many are
evicted for one placement; extend gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes
(it already has read_r8) to evict a texture, revive it with unchanged memory and read the texels
back.

5. CONFIRMED (minor, default path): pin takes the PAGES lock with the budget off

title_textures.rs:469, vram.rs:669-677.

touch returns early when pool_cap() == 0; pin does not. With the option unset, every
CopyTextureRegion and CopyResource the title records now takes the global PAGES mutex (held
by bind across CreateHeap and UpdateTileMappings) and looks the resource up. Results are
unchanged, but it is new work and contention on the default path.

Suggested fix: the same if pool_cap() == 0 { return; } as in touch.

Verdict

Not ready with the budget on: finding 1 makes one placement at the cap evict nearly everything
eligible, and 2 and 3 make the wrong textures go or not come back; the default-off path is unchanged
apart from the extra lock in 5.

Review by Claude Code (Claude Fable 5.2); each point checked by a person before posting.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…-watch merge

Integrates upstream PRs xcl-dev#594, xcl-dev#640, and xcl-dev#551:
- Order reserved-texture tile unmaps behind known title queues with GPU
  fences before releasing tiles back to pools (xcl-dev#594).
- Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures
  when texture page pools hit the cap, remapping and re-uploading on use
  (xcl-dev#640), preventing unbounded VRAM growth during world streaming.
- Merge write-watch scan gaps up to 64 MiB and clip regions with binary
  search to cut GetWriteWatch overhead during streaming (xcl-dev#551).
@burber

burber commented Nov 24, 2026

Copy link
Copy Markdown

Second 12 GB NVIDIA card with the retail title: the budget keeps local video memory under the card

Setup: RTX 4070 Ti 12 GB (driver 32.0.16.1062), i5-13600K, 32 GB RAM + 32 GB page file, Windows 11 26300, DXC 1.8.2502. Release build of main 9182f27 + #533 + #267 + #708 + this PR; it merged cleanly. Title 1.0.2.1, XCL_NETWORK=0, same scripted input each run, world loading from ~80 s.

Tests: cargo test --release --workspace gives 669 passed, 0 failed. That includes page_budget_evicts_the_least_recently_touched_cpu_filled_texture and a_texture_mapped_again_after_eviction_is_uploaded_even_if_unchanged.

Retail runs:

without the budget (runs 13–14) XCL_PAGE_BUDGET_MB=6144 (runs 15–16)
local video memory at the end 14.2–14.6 GB 10.3–10.4 GB
target pages 9.7 GB 5.5–5.8 GB (pools 6.1–6.3 GB)
commit 28–30 GB 25.7–26.1 GB
evictions — 7316 textures evicted, 42 mapped again
  • I saw no visible corruption in the frame dumps before the stall. These are coarse quarter-size dumps of the loading screens only; no gameplay was reached.
  • Both budget runs still end at the title's watchdog (+0x23cf683, ~128 s). It follows 10–13 compute pipelines that are still building after 4 s on the NVIDIA driver, so the budget removes the video memory overrun but not that stall.

Investigated with AI assistance; all numbers are from runs on my machine.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…-watch merge

Integrates upstream PRs xcl-dev#594, xcl-dev#640, and xcl-dev#551:
- Order reserved-texture tile unmaps behind known title queues with GPU
  fences before releasing tiles back to pools (xcl-dev#594).
- Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures
  when texture page pools hit the cap, remapping and re-uploading on use
  (xcl-dev#640), preventing unbounded VRAM growth during world streaming.
- Merge write-watch scan gaps up to 64 MiB and clip regions with binary
  search to cut GetWriteWatch overhead during streaming (xcl-dev#551).
@albertoglvn

Copy link
Copy Markdown

Following up on the census above. I tried a signal of use other than transitions, and measured what a page budget could free on this title at all. Same machine (RTX 4060 Laptop, 7956 MiB). Build: main f4ce27c + #495 + #496 + this PR, plus two local patches:

  1. Use by T#. dev_create_srv_x notes which shared-heap SRV index belongs to which placed texture. Once a second, xcl reads word 0 of every image T# in the console view heaps and maps it back to the texture. A texture whose T# is in a shader-visible heap gets touched = now, and an evicted one found there is mapped again and uploaded. A scan takes 2–9 ms.
  2. Eviction order. evict_lru takes textures whose T# is in no view heap first (any size, once 2 s old). It passes over a texture whose pages are all shared with other mapped textures, since unmapping it frees nothing.

With the first patch alone and XCL_PAGE_BUDGET_MB=4096, every round logged "0 MB back" and the title stopped at 62.8 s. Every candidate sat on pages another texture still used.

With both patches and the same budget:

  • Rounds freed 20, 32, 32 and 0 MB, all before 62 s. After that every candidate was passed over: 4162 MB of them in the last round.
  • 5547 textures were evicted and 1977 mapped again. Between 36 s and 58 s, while frames were still coming, I saw no missing or flickering textures. That's unlike my earlier budget runs, so the T# looks like a usable signal.
  • The out-of-memory stop moved from 63 s to 94 s, but presents fell to 0 at 62 s, so that's no more playable time.
  • Target pages still grew to 6400 MB. The GPU-written textures (3370 MB) and the small ones (about 800 MB) are already above the budget.
  • evict_lru walks the same shared textures again on every submit: the pass-over count reached 33 million. A real version would need to remember them.

Then, with the budget off, I counted each page once (no double counting of shared pages), by the strongest of its holders. At 62 s, just before the device was removed at 63 s:

pages held by MB
a GPU-written or GPU-owned texture 3200
else a CPU-filled texture whose T# is in a shader-visible heap 1737
only CPU-filled textures with their T# in no shader-visible heap 1091 (827 of it under 2 s old)
no user 0
all pages 6028

Everything else counted local at that point came to about 3950 MB: sparse pools 1856, committed 1158, arenas 465, system heaps 337, driver 136. That leaves about 4000 MB of the card for pages. The first two rows alone are 4937 MB. So even a page-level budget that gave back every page held only by textures with no T# would leave the Series X profile about 930 MB over on an 8 GB card, before the in-use textures it would have to drop. On this title, 8 GB looks out of reach for any eviction scheme. The T# signal may still help on cards with somewhat more memory.

If it's useful, I can open the T# signal as its own small PR on top of this one.

AI use: the patches, measurements and this comment were written with Claude Opus 5.5; I ran the game.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…-watch merge

Integrates upstream PRs xcl-dev#594, xcl-dev#640, and xcl-dev#551:
- Order reserved-texture tile unmaps behind known title queues with GPU
  fences before releasing tiles back to pools (xcl-dev#594).
- Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures
  when texture page pools hit the cap, remapping and re-uploading on use
  (xcl-dev#640), preventing unbounded VRAM growth during world streaming.
- Merge write-watch scan gaps up to 64 MiB and clip regions with binary
  search to cut GetWriteWatch overhead during streaming (xcl-dev#551).
@woreksami

Copy link
Copy Markdown

Test report on an 8 GB card, which Not tested lists.

Tested

budget unset (same tree without this PR) XCL_PAGE_BUDGET_MB=3072
target pages, menus 3578 MB at 14 s → 4554 MB at 38 s 3488–3497 MB from 12 s to 226 s
local video memory 6204 MB at 14 s → 7297 MB at 38 s 6078 MB from 16 s to 226 s
process commit 14543 MB at 14 s → 16310 MB at 38 s 14491 MB from 22 s to 226 s
fps 30 in the menus 30.0 in every sample from 185 s to 255 s
run ended 60–80 s (my commit watcher, < 3 GB free system commit) 271 s (same watcher)
  • With the budget, after the first button press at 229 s the title starts loading and the pages grow past the budget: 4212 MB at 250 s, 4268 MB at 264 s (pools 4288 MB). page budget: 250 textures evicted, 24 mapped again by 264 s. So on this title most of what is placed after the menus is not evictable here (GPU-written or recent), and the budget slows the growth rather than capping it.
  • No crash or device removal in the run; it was ended by my watcher, not by XCL (this machine's commit limit is 43 GB, see Newer retail game on a 32 GB machine: 31 default DXC threads and ~18 GB commit run Windows out of memory #542).

Not tested

  • Whether evicted textures show up empty on screen: nobody looked for it in this run.
  • This PR alone on main; other budgets than 3072; scripts/smoke.ps1; AMD.

AI use

  • Claude Code with Claude Opus 5.5: merged the branches, ran the tests and the title, read the logs and wrote this report from those runs.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…-watch merge

Integrates upstream PRs ivall#594, ivall#640, and ivall#551:
- Order reserved-texture tile unmaps behind known title queues with GPU
  fences before releasing tiles back to pools (ivall#594).
- Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures
  when texture page pools hit the cap, remapping and re-uploading on use
  (ivall#640), preventing unbounded VRAM growth during world streaming.
- Merge write-watch scan gaps up to 64 MiB and clip regions with binary
  search to cut GetWriteWatch overhead during streaming (ivall#551).
@thatirishguyyy

Copy link
Copy Markdown

Follow-up on the RX 9070 XT. I cherry-picked 808a8a4 onto beaa245 (7c4f641 locally), built once in release, and ran two pairs with the same profile and a 5 GiB Windows commit-headroom guard. I reversed the order for the repeat. Starting system commit headroom was within 100 MiB inside each pair.

Measurement Budget off XCL_PAGE_BUDGET_MB=4096
First BCPack refusal to process exit, original pair 20.0 s 30.6 s
First BCPack refusal to process exit, repeat pair 19.9 s 30.1 s
Last logged frame checkpoint, both pairs 900 1,200
Last sampled texture-page heap pool, both pairs 4,672 MiB 4,224 MiB
Last sampled local video memory, original pair 7,429 MiB 7,107 MiB
Last sampled local video memory, repeat pair 7,429 MiB 6,979 MiB

The budget runs logged 329 evictions each, with 3 and 2 remaps. Both settings still reached the commit guard. The first BCPack refusal is a repeatable log marker for comparing the streaming interval after manual menu navigation. At 128 refusals, all four runs reported the same breakdown: 100 BC5, 20 BC7, and 8 BC1. The focused page_budget_evicts_the_least_recently_touched_cpu_filled_texture GPU test also passed.

AI-assisted with Codex for the runs, log analysis, and report.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…-watch merge

Integrates upstream PRs ivall#594, ivall#640, and ivall#551:
- Order reserved-texture tile unmaps behind known title queues with GPU
  fences before releasing tiles back to pools (ivall#594).
- Add opt-in XCL_PAGE_BUDGET_MB to evict LRU CPU-filled title textures
  when texture page pools hit the cap, remapping and re-uploading on use
  (ivall#640), preventing unbounded VRAM growth during world streaming.
- Merge write-watch scan gaps up to 64 MiB and clip regions with binary
  search to cut GetWriteWatch overhead during streaming (ivall#551).
@UdontJustEatEm

UdontJustEatEm commented Nov 25, 2026 •

Copy link
Copy Markdown

@LeonardoS11 Thanks for working on this. I tested the texture-page budget offline on a desktop RTX 5050 (7,910 MiB), NVIDIA driver 621.24, Ryzen 5 5500, 16 GiB RAM, and Windows 11 build 26300.9974. The title build was 1.0.2.1.

Tested

  • Baseline XCL cbc296ab65a2661a61e3e2da109134bcd5319f60 reached world loading. A 64 MiB D3D12 heap for title textures returned 0x8007000E, followed by the title breakpoint at +0x193e00f. The run recorded 4,740 presents and about 9,652 MiB of live texture pages just before the failure.
  • Exact PR revision 5d6fac8cb6c1ccddf95adc273862e5cb4be5ae2a with XCL_PAGE_BUDGET_MB=3072 and the default pipeline wait got past that heap failure. It recorded 2,012 presents, 5,340 evictions, and 36 remaps. The texture pools reached 6,592 MiB, consistent with the budget acting as a soft threshold. This run reused a completed setup profile and later hit the +0x23cf683 watchdog.
  • I adapted D3D12.X: an optional page budget evicts CPU-filled title textures LRU #640 onto cbc296ab and tested a learned 4,095 MiB coherent window with XCL_PSO_WAIT_MS=50. It got past the 40-bit BVH address error seen with the 512 MiB window. It ended with 0x887a0005 after 2,978 presents. The last counters showed 1,331 skipped draws and 3,469 skipped dispatches.
  • A separate run combined that adaptation with DirectStorage: read a physical-page list again when its request runs #1405, DirectStorage: a queue made with AutoSubmitDisabled waits for Submit #1599, a 3,584 MiB coherent window, and a warmed direct-DXIL cache. It logged 179 driver-blob hits and zero failed DirectStorage requests. It reached 2,817 presents before device removal. One compute pipeline still took 52.2 seconds to build. The captures showed the loading panel.

Tile-count example from the local adaptation

The newer allocator reserves tiles in a batch. Suppose a new texture needs A and C. It can initially share A, so it needs one fresh tile. If eviction releases the last mapping of A, it needs two. The adaptation recalculates the missing count and preferred heap after eviction and before reserving the batch.

# Simplified allocator flow
missing, preferred_heap = count_missing_tiles(placement)
while budget_pressure_requires_eviction(missing):
    if evict_eligible_textures() == 0:
        break
    missing, preferred_heap = count_missing_tiles(placement)
reserve_tile_batch(missing, preferred_heap)

Not tested

A same-revision budget-on/budget-off comparison, either storage patch in isolation, or longer sessions. A 3D world frame remains unverified.

I adapted the patch to the newer base, ran the offline tests on my PC, and drafted this report from the measured results.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (5d6fac8)

Hardware / environment

  • Commit 5d6fac8cb6c1ccddf95adc273862e5cb4be5ae2a. Windows 11 build 26200, AMD Ryzen 7 3800X, Intel Arc A770 (DXGI adapter 0, driver 32.0.101.9175).
  • Rust 1.100.0 (0ef1bc386 2026-11-09) for x86_64-pc-windows-msvc, DXC 1.9.2609.5 (01b62ad47).

Commands and results

  • cargo test --workspace --no-run outside the Arc lock exited 0. The diff adds three D3D12 tests and no CPU-only tests.
  • Inside Invoke-ArcTest.ps1, with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1, ran the prebuilt library test binary once per test. All three commands and the wrapper exited 0.
    • xcl-77aca8ccb20e299f.exe --exact hle::d3d12x::title_textures::tests::page_budget_an_evicted_texture_is_mapped_again_before_the_work_that_uses_it --format terse
    • xcl-77aca8ccb20e299f.exe --exact hle::d3d12x::vram::tests::page_budget_evicts_the_least_recently_touched_cpu_filled_texture --format terse
    • xcl-77aca8ccb20e299f.exe --exact hle::d3d12x::vram::tests::page_budget_one_placement_at_the_cap_evicts_one_batch --format terse
  • Log totals: 3 passed, 0 failed, 0 ignored, 1 case-sensitive ^SKIPPED line. Two additional tests returned silently before their assertions. Effective coverage: 0 exercised, 3 skipped.

Observed behavior

The title-texture test logged no reserved textures. An independent DXGI/D3D12 probe reported resource heap tier 1 on the A770 at feature levels 11.0 and 12.0. Both VRAM tests require tier 2, and title-texture page placement also requires tier 2.

Not tested

Eviction and remapping assertions, the full GPU workspace suite, and game smoke runs.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr640-focused.log and published.

@thehollowedone

thehollowedone commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent synthetic GPU check of 5d6fac8 on Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug. A test-only fixture queues a real readback of a 512×512 RGBA8 title texture behind a CPU-controlled fence, then places another texture while the read completion fence is still pending. It compares the 16 original pool tile IDs with the replacement's IDs. The gate is released before the bounded GPU drain.

Tested

  • cargo test --offline --locked -j 4 -p xcl --lib --no-run built. The exact test hle::d3d12x::vram::tests::page_budget_does_not_reuse_tiles_before_a_queued_read_retires ran in four fresh processes with --exact --nocapture --test-threads=1, two per setting.
  • With XCL_TEST_QUEUED_READ_UNCAPPED=1, both controls passed. The read was pending, the original stayed mapped, and the replacement reused 0/16 tile IDs.
  • With the cap forced to the existing pool count, both runs failed the intended assertion. The read was pending, the original was evicted, and the replacement reused 16/16 of its tile IDs. The control and cap runs were alternated. No runs skipped, timed out, or reported device removal.

Pixel readback follow-up. I extended the same fixture to upload a patterned 512×512 RGBA8 texture, verify all 262,144 texels with a normal read, reset the readback to a sentinel, and repeat the read behind the gate. The footprint offset and row pitch were accounted for in the comparison. In two fresh uncapped processes, the queued read returned 262,144/262,144 expected texels with 0/16 tile IDs reused. In two capped processes, the original was evicted while the read remained pending, 16/16 IDs were reused, and the completed read returned zero for all 262,144 texels. No sentinel texels remained. Both capped runs failed the intended pixel assertion, both controls passed, and all four drained after gate release without skips, ignored tests, timeouts, or device removal. This is a synthetic readback failure on this adapter. The updated test-only patch is saved locally.

Not tested
Full workspace suite, AMD, retail title, or a corrected eviction policy.

AI use
Codex (GPT-6, exact variant unavailable) wrote and ran the fixture and drafted this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@Narcosasso

Copy link
Copy Markdown

Heads-up: this no longer merges into current main (0829441). #1747 (3bc7143, "keep vram::Pages tile mappings contiguous per heap") replaced the free / cooling vectors in Pages with a per-heap TilePool (take_batch, drain_cooling) and added reclaiming of empty pool heaps (PoolHeaps, XCL_VRAM_KEEP_SPARE_POOLS), so take_tile's cap check and evict_lru's free.len() + cooling.len() accounting have to be ported onto that allocator, not just conflict-resolved.

Also: #782 is stacked on the earlier revision of this PR (38bf6a3), and its own commit (4928ce5) conflicts with the current head (5d6fac8) in submitted, Pages and evict_lru (evict_idle_until vs evict_after). Testing the two together needs #782 rebased first.

AI use: found with Claude Code (Claude Opus 5.5) while merging main + #640 + #782; checked by me on the PR pages.


Generated by Claude Code

@anon31-006459

Copy link
Copy Markdown

Test report for #640 on Linux / NVIDIA 8 GB: a rebase of 5d6fac8 onto the per-heap tile pool (#1747), not your exact commit. With XCL_PAGE_BUDGET_MB=3072 the retail title reached the in-world intro cutscene with the page pools held at the budget and no memory pressure; it then ended on the +0x23cf683 null write that it also hits without the budget (#662 / #675).

What was tested

Setup

Result (one run with the budget)

  • page budget 3072 MB (48 pools of 64 MB) at start. Evictions began early in the run and reached 3,171 textures by the end of story loading (rounds of 34, 15, 4, 124, 879 and 175 textures; the 879-texture round gave back only 4 MB, as most of those pages were still shared with mapped textures).
  • 28–30 fps through the menus and loading (27.9 fps over 300 frames at 2,700 frames). The world phase started: the intro cutscene drew world geometry (untextured silhouettes of signage, trees and lamps) at ~20 fps.
  • Memory during the world phase: 5–9 GB of RAM available, ~1 GB of swap in use. No device removal, no vkCreate* failure.
  • End: 0xc0000005 in game_scarlett_master.exe+0x23cf683 (write at 0, rcx=0x70024c348) at ~284 s; the title's crash log reports Game Running, 4 min 12 s, frame 2,343, 34 peds.

For comparison, not a clean A/B

  • The run just before it, the same tree without the budget, used 20 GB of swap (no swap file yet) and its own cgroup memory limit, which was lowered during the run. It filled RAM and swap during loading (~19 GB swapped, memory stall time 30–40 %) and ended on the same +0x23cf683 write. So the budget is not what changes the end here; it is what kept memory in bounds on an 8 GB card.

Not tested

AI use: Claude Code (Claude Opus 5.5) rebased the PR, ran the title and wrote this report from the logs; I reviewed it before posting.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2385 solves the same problem (for #1773) in a different way: #1607, group D111. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@voiceovarian1-max

Copy link
Copy Markdown

A fix for the holes @requiemsnkrp reported above (sampled-only textures evicted and never mapped again): the budget does not evict a texture that a view slot still names. The art stays. But on this title the budget then frees almost nothing.

Setup: Linux, Proton Experimental's Wine + vkd3d-proton 3.1, RTX 4070 Ti 12 GB, retail title, Series S profile, XCL_PAGE_BUDGET_MB=4096. This PR's 5d6fac8 merged locally with others on #2057's head, not this PR alone.

  • Before: the loading art went black from the first eviction round (1,573 textures evicted, 0 mapped again).
  • The change (~80 lines with a test): console_heap::note_resource already keeps slot → resource for XCL_TRACE_FRAME. With a budget on, it also counts the view slots that name each texture (vram::viewed), and evict_lru skips a texture any slot names. The census in the log counts those textures apart.
  • After: the art stays in colour. But in the world 1,326 textures (2,966 MB) are named by a view and 0 are evictable, so the pools grew to 6.4 GB anyway (6.9 GB without a budget).

So for a title that keeps a view on most of what it loads, an LRU page budget either leaves holes or frees little. #2385's approach (dropping top mips) may fit those titles better.

Not tested: Windows, AMD, this PR's exact head (it no longer merges into main).

AI use: found, fixed and written with Claude Code (Claude Opus 5.5) from runs it made on this machine.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: take_tile reuses a cooling tile immediately at budget (vram.rs:332-354), bypassing the two-second delay that protects in-flight GPU readers. EVICT_MIN_AGE is CPU LRU time, not a GPU fence; an in-flight draw can sample newly written texels, risking corruption/device loss. Also, revival occurs only for CPU upload, a named transition, or GPU write. A texture continually sampled without transition can be evicted to null tiles and never revived; this is reported as disappearing loading-screen artwork. Please add sampled-resource use tracking plus fence-safe tile retirement, or do not evict possibly sampled textures. Tests cover explicit transition/copy but not active sampling/in-flight reuse. #640 also needs an explicit coexistence/selection decision with #2385.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.