Repository navigation
D3D12.X: an optional page budget evicts CPU-filled title textures LRU - #640
LeonardoS11 wants to merge 1 commit into
Conversation
|
Tested on NVIDIA GeForce RTX 3060 Ti (8 GB, wave32). Tested
Regression run ( main ( PR #640 ( PR #640 (
Not tested: Walking past the start/menu screens into world streaming, debug build, AI use: Antigravity ( |
|
Independent Windows Radeon comparison on I ran the same binary and saved profile with AI-assisted (Codex ran and summarized the measurements). |
|
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, Compared with the same base without this PR (#333 comment, one run each):
Evictions: 561 by 160 s, 8714 by 280 s (824 mapped again). None after 280 s. Observations:
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 AI use: the logs were analysed and this comment drafted with Claude Opus 5.5; I ran the game and checked the results. |
|
Follow-up to my run above: the same build without
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 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, AI use: the logs were compared and this comment drafted with Claude Opus 5.5; I ran the game. |
|
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.
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: |
|
Code audit + NVIDIA RTX 5080 test run on Three bugs found in the revive path
Tested
Not tested
AI use: code review and test run orchestrated with Antigravity (Gemini 4 Neon) on the hardware listed above. |
|
One more data point, about what the LRU order sees on this title. Same machine (RTX 4060 Laptop 8 GB). Build: main At 62 s, just before #333's out-of-memory stop at 63.5 s:
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 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. |
… the card, no out-of-order waits; first builds of world compute pipelines remain Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
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_unchangedonly checks that removing a
key fromLAST_CONTENTmakessame_as_last_uploadreturn false. No eviction, remap or upload
happens in it, so it would still pass ifsubmitted/refresh_oncestopped calling
forget_content.page_budget_evicts_...callsevict_lru(1)directly. Nothing drivestake_tileat the cap
(pool_cap()is aOnceLockread 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.
…-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).
|
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 Tests: Retail runs:
Investigated with AI assistance; all numbers are from runs on my machine. |
…-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).
|
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
With the first patch alone and With both patches and the same budget:
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:
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. |
…-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).
|
Test report on an 8 GB card, which Not tested lists. Tested
Not tested
AI use
|
38bf6a3 to
808a8a4
Compare
…-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).
|
Follow-up on the RX 9070 XT. I cherry-picked
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 AI-assisted with Codex for the runs, log analysis, and report. |
…-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).
|
Test report on an AMD RX 6750 XT (12 GB, driver 32.0.21045.29003), Ryzen 7 5700X, 32 GB RAM, Windows build 26200, release build. What was tested: 5d6fac8 no longer applies to current Run: the retail title, 300 s, A pressed at 15-35 s to reach the world,
Not tested: your exact commit (only the rebase above), other budgets, #782 on top, NVIDIA, a full Written with Claude Code from runs on this machine. |
|
Test report for #640 (head Measured by an agent (omp, DeepSeek V4.1 Flash); I (Claude Code, Claude Sonnet 5.5) re-read the run logs, checked
Not tested
AI use: an agent (omp, DeepSeek V4.1 Flash) ran and measured; Claude Code, Claude Sonnet 5.5 verified and wrote this report. |
|
@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
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. 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. |
Empirical test report (5d6fac8)Hardware / environment
Commands and results
Observed behavior The title-texture test logged 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. |
|
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
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 AI use |
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
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, withXCL_ACTIVITY=1and 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 perPagesascap, so tests can set it). At the cap,take_tiletakes the tiles the last eviction round gave back first; only when there are none does it callevict_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 texturestitle_textureskeeps in step with the title's memory (set_evictablefromregister), 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.revivemaps an evicted texture again and takes it out of the evicted set only when that worked. The budget needs late release (XCL_LATE_RELEASE=0turns it off with a warning): evicting unmaps a texture from another thread, which is safe only while a texture's lastReleasereachesvram::forgetbefore the object goes.crates/xcl/src/hle/d3d12x/title_textures.rs: evicted textures are mapped again before the work that uses them.revive_listedruns before a submit, ahead ofrefresh, for the textures its lists transition (references taken under theTEXTURESlock), and marks them pending so this submit's refresh uploads them whole. A texture written again by the CPU is mapped again inrefresh_oncebefore 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_contentdrops 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: callrevive_listedbeforerefreshinExecuteCommandListsandKickoffX(inKickoffXthe refresh moved afterreclaim_for_kickoff, which only does bookkeeping, so the segments split before it are covered).crates/xcl/src/host.rs: onepage budget: N textures evicted, M mapped againline next to theXCL_ACTIVITYmemory 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
vramcode 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; texturestitle_texturesrefused are never evicted; a copy into an evicted texture maps it first;pin/touchreturn 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
cargo build --workspace && cargo test --workspace -- --test-threads=4(debug) on5d6fac8: 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 byrevive_listed, pending, its content hash forgotten; a copy recorded into an evicted texture maps it again with no upload pending.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).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:
this PR:
Both runs drop presents in their last seconds, the
mainrun more than this PR's, so the drop is not from this PR (on thismainthe recompiler output changed, and the title's shaders were compiling again).Not tested
5d6fac8.AI use
🤖 Generated with Claude Code