D3D12.X: evict top texture mips under local VRAM budget #3098
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3098"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by O5-7 on 2026-11-28T05:08:17Z.
Implements opt-in automatic top-mip VRAM budget eviction (
XCL_TEXTURE_BUDGET_EVICT=1) on top of the Workstream 5 SRV-tracking and tile-class foundation already inmain. Default behavior withXCL_TEXTURE_BUDGET_EVICTunset is unchanged.Part of #2688
What is in it
crates/xcl/src/hle/d3d12x/console_heap.rs: exposeViewSlotLease::device(&self) -> &ID3D12Device.crates/xcl/src/hle/d3d12x/real.rs: add unhookednative_create_srvandnative_copy_descriptors_simplehelpers for quiescent SRV descriptor clamping, applyresident_min_mipclamp on new SRV creation indev_create_srv_x, and updatenote_srvlast-touch tracking whensrv_tracking_enabled().crates/xcl/src/hle/d3d12x/vram.rs:XCL_TEXTURE_BUDGET_PCT(default85, clamped50..=98),XCL_TEXTURE_BUDGET_MBoverride,Levels::evictable_chain,TilePool::mark_heap_pinned,Pages::unmap_range,clamp_srv_min_lod,default_srv_desc,resident_min_mip, heap-draining candidate selection (pick_evict_candidates_by_heap), and quiescentevict_under_budgetexecuted periodically inbefore_executeusingwith_exact_tracked_srv_mutations(failing closed if any descriptor generation or raw word changed or gained an untracked SRV before mutation).Target::last_touchandTarget::min_resident_mip, isolate evictable top mips from packed tails and pinned aliases, updateresident_texelsandEVICT_STATS(TexelStats::evicted_mips/evicted_tiles), and add unit + GPU verification tests (clamp_srv_min_lod_raises_clamp_without_lowering_existing,heap_draining_eviction_empties_coldest_heaps_first_and_skips_pinned,gpu_unmap_top_mip_with_srv_min_lod_clamp_samples_resident_mip).crates/xcl/src/host.rs: append; evicted {} mips ({} MB)toXCL_ACTIVITY=1texture residency:logging when evictions occur.Tested
32.0.15.9579), AMD Ryzen 7 9700X, Windows 11 Pro10.0.26100,rustc 1.100.0 (0ef1bc386 2026-11-09).cargo test -p xcl --lib vram::tests -- --nocapture --test-threads=1: 65 passed, 0 failed, 1 ignored (churn_update_tile_mappings_timing), 0 skipped.cargo test -p xcl --lib console_heap::tests -- --nocapture --test-threads=1: 15 passed, 0 failed, 0 ignored, 0 skipped.cargo build --release -p xcl: clean build with 0 new warnings (26 pre-existing warnings onmain).title: 9cc6a39e, run withXCL_PREPARE=0per8617577b,XCL_TEXTURE_*unset):60f1a222matchedmaine429936ccleanly (944vs895frames shown,13703vs13711MB peak commit,0crashes,0device removals).XCL_PREPARE=0 XCL_TEXTURE_BUDGET_EVICT=1 XCL_TEXTURE_BUDGET_MB=4096):exit: 0x0,923frames shown (PresentX 923),13773MB peak commit,0crashes,0device removals; loggedD3D12.X: texture budget eviction: evicted 71 mip groups (22 MB) at 6046 / 4096 MB local VRAMandtexture residency: 514 sampled (508 with SRV); texels 275.0M resident / 314.0M srv-sampled / 314.0M virtual (87% resident); evicted 71 mips (22 MB).Regression run
Not tested
cargo test --workspaceat60f1a222(onlyvram::testsandconsole_heap::testsran after final edits;benches/runtime.rson basemaine429936cfails to compile due to upstreamConfig.input_profilevisibility).XCL_TEXTURE_BUDGET_EVICT=1to confirm multi-heap reclamation after 2 s cooling during longer sessions.AI use
main's SRV-lease primitives, resolved test/lock ordering issues, ran tests, release build, and smokes (default andXCL_TEXTURE_BUDGET_EVICT=1), and drafted this description with Antigravity (Gemini 4 Neon).Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T05:10:05Z.
I found a candidate-selection starvation case on head
60f1a222with an exact-source Rust harness forpick_evict_candidates_by_heapand the downstream tracked-SRV check.For a 64-tile target, heap A had 64 mapped tiles and no tracked SRV; heap B had 128 mapped tiles and a tracked SRV. The picker chose A, after which the tracked set for the selection was empty and the pass returned before unmapping. A second identical tick chose A again, leaving B untouched. Removing A selected B; marking both resources tracked preserved the intended preference for A.
Filtering the raw candidates against a snapshot of tracked resources before selection could avoid this starvation, while retaining the final quiescence and descriptor-generation revalidation. This is selection/control-flow evidence; I did not run actual GPU eviction, prove retail incidence, or measure reclamation.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the controls; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T05:12:36Z.
I checked a distinct SRV-range boundary on RTX 5070 / NVIDIA 616.92 at head
60f1a222with a test-only native fixture. A two-mip texture had red mip 0 and green mip 1. The fixture used the production clamp helper, unmapped mip 0, then sampled through explicit SRVs after queue completion.Mip 1 remained resident in all cases, but it is outside the top-only view. The production
all_clampablecheck appears to require a descriptor to exist without checking whether its exposed mip range intersects the surviving chain. A resource with any live SRV whose range ends before the proposed resident mip may need to be excluded, unless its view can be safely changed to expose a surviving level.The fixture exercised the actual clamp helper, tile unmap, fence, and native sampling; candidate selection was source-reviewed rather than exercised end to end. No driver pressure, retail title, image-quality frequency, or performance was measured.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-28T05:15:55Z.
AMD run on an RX 9070 XT (with an RTX 3060 in the same PC): the three new tests pass, and nothing else in
vram/console_heapchanges.Tested: at the PR head
60f1a22against its merge-base,maine429936. Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X. RX 9070 XT (RDNA4) driver 32.0.32029.2010; RTX 3060 driver 32.0.16.1088.cargo test -p xcl --lib -- hle::d3d12x::vram::tests hle::d3d12x::console_heap::tests --test-threads=1 --nocapture, once withXCL_ADAPTER=Radeonand once with=3060: merge-base 77 passed, 0 failed, 1 ignored; PR 80 passed, 0 failed, 1 ignored, no SKIPPED, both times.clamp_srv_min_lod_raises_clamp_without_lowering_existing,heap_draining_eviction_empties_coldest_heaps_first_and_skips_pinnedandgpu_unmap_top_mip_with_srv_min_lod_clamp_samples_resident_mip, all ok.gpu_unmap_top_mip_with_srv_min_lod_clamp_samples_resident_mipmakes its device withD3D12CreateDevice(None, ..), which takes the first adapter and ignoresXCL_ADAPTER. On this PC that's the RX 9070 XT, so both runs exercised the tiled tier-2 unmap and the min-LOD clamp on AMD. Neither run covers the RTX 3060's GPU.Not tested: the whole suite, a title,
XCL_TEXTURE_BUDGET_EVICT=1outside the unit tests, the RTX 3060 for the GPU test (see above), Intel.AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-28T05:22:41Z.
Tested
Exact
60f1a2225d5e34d4d69b96abcae5a0b8d8b0262don Windows 11 25H2 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC debug. I reran the pinned libtest from a verified Git archive with one private test added. All 393 original files matched their Git blobs when the fixture was excluded.I ran
<libtest.exe> --exact <test> --nocapture --test-threads=1separately for two tests underhle::d3d12x::vram::tests.default_texture_srvs_preserve_view_fields_when_clamping_lodcalleddefault_srv_descandclamp_srv_min_lodfor a four-mip, three-slice 2D array and a five-mip 3D texture. Both started at zero. Higher requests raisedResourceMinLODClamp, and lower or repeated requests left it unchanged. Format, dimension, component mapping, mip range, and the array's slice and plane fields stayed intact. The default-descriptor helper returnedNonefor the four-sample 2D input.clamp_srv_min_lod_raises_clamp_without_lowering_existingpassed.2 passed, 0 failed, 0 ignored, 0 runtime skips. Both native processes exited 0.
Not tested
GPU or device behavior, sampling, runtime eviction, allocator pressure, performance, retail titles, the base revision, and the full suite.
AI use
T3 Code through the Codex harness (
gpt-6.2-sol) verified the archive, fixture and executable, ran the tests and wrote this report.Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-28T06:12:10Z.
Full workspace suite on NVIDIA (listed under Not tested): no new failure. The 9 that fail are the ones current
maine429936fails here too (#3093). Each new test catches its part when that part is reverted.Tested:
60f1a22(its base is currentmaine429936, so head = merged). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.cargo test --workspace --no-fail-fast -- --test-threads=4SKIPPEDlines. The 9 aremain's: the 3e2etitle tests (post-Wait32/64 write failed (0x0)) and 6 split-wave64 GPU tests, all listed in #3093hle::d3d12x::vram::(65 tests) at--test-threads=8, 30 runsSKIPPED); 30 of 30e2edebug-layer messages (the title fails as onmain)main: 3× error id 93, 1× error id 1046, 1× warning id 820, 2× warning id 926, 8× id 0; notexture budget evictionline, so the default path does not evictclamp_srv_min_lodsets the clamp instead of raising itclamp_srv_min_lod_raises_clamp_without_lowering_existingfails (left: 1.0)clamp_srv_min_lodleaves the clamp aloneleft: 0.5), andgpu_unmap_top_mip_with_srv_min_lod_clamp_samples_resident_mipfails:with mip 0 unmapped and SRV clamped to mip 1, sampling LOD 0 reads green,left: 0!evmoved to the end of the heap sort keyheap_draining_eviction_empties_coldest_heaps_first_and_skips_pinnedfails (left: [1, 31, 30])Not tested:
XCL_TEXTURE_BUDGET_EVICT=1in a title (no title here), a release build, AMD / Intel.AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch mutations and wrote this report.
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-28T06:39:38Z.
Test report for
60f1a222on an RTX 3060 12 GB, againstmaine429936c. Same title (a newer retail game), 300 s, release,XCL_PREPARE=0as in your runs,XCL_PRESS_A_ATfor the menus.Default (
XCL_TEXTURE_BUDGET_EVICTunset): no regression.That's 97 % of
main's frames and 106 % of its peak commit. Peak local video memory: 15 056 MB onmain, 14 852 MB on the PR.XCL_TEXTURE_BUDGET_EVICT=1: memory runs away on this card. Twice, my RAM watchdog (free < 4 GB) ended the run about 90 s in, before the smoke script got its summary. The second timexcl.exeheld 51.4 GB. The log of that run, every 2 s near the end:At 86.7 s the residency line says
evicted 418 mips (401 MB), and it still says 418 at 88.8 s. So eviction frees a few hundred MB, while the target-page pools grow by 2.5–5 GB every 2 s, and most of that is free pool memory. A possible mechanism from readingvram.rsat60f1a222(not confirmed by a run). When a pinned (non-evictable) placement finds one of its pages already on heaph,mark_heap_pinned(h)flips the whole heap to the pinned class, free tiles included, and nothing flips it back short of the heap emptying.pick_heaponly takes heaps of the requesting class, so the evictable class can't use those free tiles andtake_batchmakes a new 64 MiB heap. If pinned placements keep landing on pages of fresh evictable heaps (title placements that share addresses), every new heap gets pinned while it's still mostly free. That would match free pool memory growing much faster than eviction frees anything.Edit, a run that checks that: the same head with one local change,
mark_heap_pinnedreturning at once (so no heap changes class),XCL_TEXTURE_BUDGET_EVICT=1, the same 300 s run. It ran to the end:(
92fc7f57is that local test commit on top of60f1a222, not a commit of this PR.) At 299 s: target-page pools 9 472 MB, against 28 800 MB at 89 s with the flip; eviction had freed 9 091 mips (3 774 MB); local video memory peaked at 14 977 MB, about wheremainand the PR's default run peak, so still above the 11 GB budget. So the heap flip is what made the pools run away here. Skipping it is only a test, not a fix: a pinned tail can then sit on a heap that eviction drains. The default run never gets near this: its peak local video memory is 14.9 GB.Edit, @thehollowedone's candidate (comment patch on
60f1a222, local commit7e29ee63, not a commit of this PR):hle::d3d12x::vram::tests66 passed, 0 failed, 1 ignored on the 3060. Same retail run,XCL_TEXTURE_BUDGET_EVICT=1,XCL_PREPARE=0, 300 s planned:XCL_TEXTURE_BUDGET_EVICTunset, same run, climbs the same way ("other" 27.3 GB at 122 s, 41.8 GB at 166 s, local video memory 15.0 GB) and my watchdog ended it at ~170 s too. So on this machine today the RAM runs out with or without eviction, in "other", not in anything #3098 owns. (My first runs above reached 300 s at 39–41 GB; I don't know yet what differs.)So the candidate fixes the stranding this report was about, and eviction on doesn't add RAM growth of its own here.
RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200. Not tested: the whole suite, AMD, a run longer than 300 s.
AI use: Claude Code (Claude Opus 5.5) ran the builds and tests, applied the candidate patch, read the logs and wrote this report.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T13:51:16Z.
Follow-up to the RTX 3060 memory-growth report, checked against head
60f1a222.The reported
mark_heap_pinnedpath changes an evictable heap's allocation class when a pinned placement shares one page. Its remaining free tiles then cannot serve evictable requests, sotake_batchcan allocate another 64 MiB heap while that one has space. I tested a scoped correction: keep the heap's fresh-allocation class, record pinned occupancy separately for eviction priority, and clear that record when a fully cooled heap is reused. New pinned tiles still go to the pinned class; shared-page ownership remains governed byusersinrelease_tiles, and a whole heap is reclaimed only after every tile is free.A new allocator regression failed under the original relabeling behavior (0 passed, 1 failed) and passed with the candidate (1 passed, 0 failed). On the corrected candidate,
cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::vram::tests -- --test-threads=4reported 66 passed, 0 failed, 1 ignored, 0 GPU skips on Windows 11 build 26300, RTX 3080 Ti 621.35, Ryzen 7 9800X3D, Rust 1.99.1 MSVC.git diff --checkpassed.This covers the free-tile stranding mechanism. The candidate has not had a retail active-eviction run or paired smoke, and the top-only SRV range finding also remains to be resolved before merge.
Candidate diff and regression
AI use: Codex (GPT-6.2 Sol) traced the allocator, wrote and ran the candidate regression, and checked the diff; Codex (GPT-6.2 Astra) independently reviewed ownership and warm-heap reuse.
Update — tail residency, same head. With lazy level mapping, a top group can be mapped before the packed tail.
Levels::evictable_chaincurrently returns that top group even when the tail group is unmapped; eviction could then clamp the view toward a mip with no tiles. A new two-group regression failed on the original predicate (0 passed, 1 failed: it returnedSome((1, 1))with the tail unmapped). Requiring the tail to be mapped before selecting the chain made that test pass;cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::vram::tests -- --test-threads=4reported 66 passed, 0 failed, 1 ignored, 0 GPU skips, andgit diff --checkpassed.This is a separate candidate guard, not a complete resolution of the top-only SRV issue. Descriptor changes and tile mappings still need their existing lifetime checks; I did not run an active retail eviction test for this update.
Tail-residency regression and candidate guard
AI use for this update: Codex (GPT-6.2 Sol) traced, wrote, and ran the focused test; Codex (GPT-6.2 Astra) reviewed the lazy-map and descriptor paths.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T14:01:45Z.
One remaining correctness boundary for head
60f1a222, following the top-only SRV report: checking only views live at eviction cannot cover a top-only view created afterward.Eviction unmaps and releases the top-level tiles. A later CreateShaderResourceView raises
ResourceMinLODClampto the saved floor, but a mip-0-only view hasMostDetailedMip=0, MipLevels=1; mip 1 is outside its D3D12 view range.map_levelscan bind replacement tiles without restoring their texels, and under budget pressure it skips levels below the saved floor. The normal upload path can skip unchanged CPU bytes, while GPU-write tracking retains submission provenance rather than the resulting texture contents. A CPU source is therefore not necessarily the current mip after GPU writes.To preserve the resource's contents, eviction eligibility needs a guarantee that each discarded subresource can be restored before any later use requiring it, or a lifetime guarantee ruling that use out. A restore path would need authoritative versioned contents, mapping and upload even under continued pressure, and a queue wait before the first dependent submission. Until such a path exists for a resource, keeping its top mips resident is the correctness-preserving option. A live-view range guard still addresses views already present, but does not establish this future-use guarantee.
Suggested regression: upload red mip 0 and green mip 1, overwrite mip 0 with blue through a GPU copy, run the production eviction with only a broad SRV live, then create a mip-0-only SRV under sustained pressure. The sample must still be blue; if that source is not restorable, assert that eviction left mip 0 mapped.
This is a source-path finding and a test design; I have not run that late-view GPU regression. AI use: Codex (GPT-6.2 Sol) traced the source and checked the conclusion; Codex (GPT-6.2 Astra) independently reviewed the SRV and texture-lifetime paths.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T18:50:01Z.
I tested a narrow candidate for the top-only SRV finding on head
60f1a222. It checks the ranges of currently tracked views before ranking heaps, then repeats the range check in the existing descriptor-mutation pass. A broad view and a top-only view of the same resource together disqualify that resource.With a 64-tile request, the existing picker initially preferred heap A (64 tiles). With both those views on A, the candidate picked heap B (128 eligible tiles). Removing A’s top-only view restored the preference for A. A zero-tile request selected neither. This uses synthetic candidate metadata and the production selection helpers.
Native RTX 5070, NVIDIA 616.92, two-mip reserved texture. The fixture exercised the new range predicate, native SRV rewrite, tile unmap when eligible, fence, and shader readback:
The focused VRAM module run with the fixture overlay completed 66 passed, 0 failed, 1 ignored (opt-in tile-mapping timing test). The native fixture made the eviction decision directly with the predicate. DXGI pressure and the full production eviction tick were outside this test.
This addresses the live-view and heap-selection cases. The later-created view finding still applies: a view may be created after eviction and require content previously written by the GPU. I would keep the opt-in restriction and treat a mapped tail and reliable restoration or lifetime guarantees as separate prerequisites before enabling this generally. The candidate is attached here for the author to use independently of the allocator changes.
Candidate and selection regression against
60f1a222AI use: OpenAI Codex prepared the candidate, ran the selection and native readback controls, and wrote this report.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-28T22:04:16Z.
Review: CHANGES_REQUESTED
map_levelscan restore an evicted top mip and lowerTarget.min_resident_mip, but existing live SRV descriptors remain clamped to the packed tail. Eviction rewrites them usingclamp_srv_min_lod, which only raisesResourceMinLODClamp; the remapping path at lines 3128-3175 never rewrites those descriptors with a lower clamp. Sampling through an SRV created before eviction can therefore remain permanently restricted to lower-resolution mips after mip 0 is resident again.Please make descriptor clamp state reversible when residency is restored, while preserving an application-specified original clamp. Add a GPU regression that creates an SRV, evicts mip 0, remaps mip 0 after budget recovery, and verifies that the same SRV samples mip 0 again.
Reviewed at
60f1a2225dwith Codex (GPT-5).Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:29:48Z.
Triage (#1607) – head
60f1a22main has only the SRV-tracking groundwork for
XCL_TEXTURE_BUDGET_EVICT; this PR adds the eviction itself. #2385 and #2968 address the same VRAM overrun differently: #2385 withholds top mips from new textures when memory is full, and #2968 drops a fixed number of levels. Problem found:vram.rs::evict_under_budgetcalls the newunmap_range, which unmaps the top mips at once on the mapping queue. It also rewrites the live SRV descriptors. It does not use themark_unmap/held_unmapsguard thatunmap_supersededuses, so title work already submitted on other queues can still sample the unmapped mips or read the rewritten descriptors. Off by default.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:36:20Z.
Review (head
60f1a222, diff read, not a merge-check; conflicts with main invram.rs/real.rs):map_levelsis behindXCL_TEXTURE_LEVEL_PAGES(title_textures.rs~609, ~737, ~1691). With onlyXCL_TEXTURE_BUDGET_EVICT=1, which is how the PR's smoke ran, top mips are gone for good. With level pages on, they return only when the texture is written again. Even then existing SRVs keep their raised clamp (clamp_srv_min_lodonly raises), as bmjask found.track_srvskips views outside the shared heap (vram.rs~389), and the "all views clamped" check (~2737-2778) counts only tracked views. Those views, and a view of only the top mip, read NULL tiles, which return zeros; andrewDoing measured this on an RTX 5070.mark_unmap/held_unmaps, so copy-queue work on those tiles isn't guarded (partly unverified).mark_heap_pinned(~1926) changes the class of a whole heap, against main's3b5bc7b8("class is only a packing hint"); Anon64 measured pools reaching 28.8 GB and 51 GB of commit on an RTX 3060.benches/runtime.rs(input_profileprivate), not this PR.Fine: off by default, and the default path matched main in both smokes. Render targets and UAVs are excluded (
Flags == NONE), and SRV rewrites go through the unhooked native slots. Related approaches: #2385, #2968, #640, #782.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.