D3D12.X: plain physical page homes, residency trim, lazy level pages, async texture upload #3747
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3747"
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 Kalmarv on 2026-12-03T00:35:28Z.
Coordinates four VRAM residency and texture-upload improvements into one coherent change: plain write-watched physical page homes, watermarked residency trimming with lazy shared depth UAV twins, opt-in mip-class demotion and mip-scoped overlap unmapping for lazy level pages, and an opt-in bounded background texture-upload preparation worker. Shipping these four commits together keeps the sparse-window budget, residency trimming, lazy tile-page mapping, and async upload synchronization aligned (for example,
residency.rsreclaims completed async upload jobs before trimming pools, andasync_texture_upload.rsrespectsvram::has_unmapped_levelsandkernelxfree/unmap paths). Part of #2697 (and keepsXCL_TEXTURE_LEVEL_PAGESopt-in while the #3188 render-target aliasing gap remains open).In the paired 60 s smoke on
origin/maine99b0bdfc(title: ea3b5e4d, default settings whereXCL_TEXTURE_LEVEL_PAGES,XCL_MIP_DEMOTE, andXCL_ASYNC_TEX_UPLOADare all opt-in): local VRAM drops by 153 MB (6,567 -> 6,414 MB), depth UAV twins drop to0 MB(lazy shared reserved), frames shown are1,638vs1,342(1.22xmain,60 60 60presents/2 s), texel residency stays at97%(307.8M / 316.9M, matchingmain), async textures queue0(zero overhead when off), and peak process commit is17,592 MBvs15,850 MB(1.11xmain, settling at16,828 MB) with 0 device removals and 0 crashes. Passed cross-model Opus adversarial review (all blockers and follow-ups resolved and verified LGTM).What is in it
XCL_PHYS_HOME_PLAIN, default ON):AllocateTitlePhysicalPagesreserves write-watched plain memory instead of sparse UMA windows (=0restores UMA homes and> uma::WINDOWMEM_64K_PAGESplacement), unregistering plain homes fromGRAPHICS_RESERVATIONSonFreeTitlePhysicalPages. WhenMapTitlePhysicalPagesreceives aNULLdestination address for pages whose home is outside UMA, it maps them into a GPU-visible sparse UMA slot (reusing only dedicatednull_mapsslots — never a title-ownedMEM_GRAPHICSmapping — kept alive while any other live page is mapped in the slot, and released once empty onFreeTitlePhysicalPagesorVirtualFree). Under defaultXCL_PHYS_HOME_PLAIN=1, multi-windowMEM_64K_PAGESreservations larger thanuma::WINDOW(4 GiB) overflow to write-watched plain memory (gpu_visible_fallback) instead of capturing sparse windows 1–2 freed by plain homes.XCL_RESIDENCY_TRIM, default ON):residency.rswakes a dedicatedxcl-residencybackground worker from the presentationWM_TIMER(never blocking the window message pump on GPU queries, pool locks, or COM releases) to sample OS commit headroom and DXGI local VRAM usage and trim idle staging pools, readback buffers, compute-split scratch (XCL_SCRATCH_POOL_TRIM), shared lazy reserved depth UAV twins (XCL_DEPTH_UAV_SHARE), and reset-count retired command allocators (XCL_ALLOC_RETIRE_RESETS) under Elevated/Critical pressure. Depth UAV twin trimming takesvram::unmap_completion_snapshot()before lockingCell::innerand executes deferred queue signals/releases after droppingCell::inner, caps shared twin tiles to each buffer's console byte size (xg::Texture::size, withleast_texture_bytesfallback) so PC overflow tiles stay private, tracks active UAV use across both DIRECT and compute lists, stampslast_used_msand clearsenteredon UAV leave, and never trims barrierlessCOMMON/UNORDERED_ACCESS-initial twins.XCL_TEXTURE_LEVEL_PAGES=1andXCL_MIP_DEMOTE=1, both default OFF): KeepsXCL_TEXTURE_LEVEL_PAGESopt-in (matchingmain, while #3188 remains open). When enabled, segregates large texture tile heaps by mip class (Mip0/Mip1/Tail) with heap-aware quarantine and opt-in cold top-mip demotion under pressure, scopes overlappingTable::insertunmapping to overlapping mip levels only (falling back to whole-resource unmap when level pages are off), and adds rate-limited residency logging.XCL_ASYNC_TEX_UPLOAD=1, default OFF;XCL_ASYNC_TEX_DEFER_FULL, default ON when async is enabled):async_texture_upload.rshashes and detiles sampled textures (> 64 KiB, up to16 MiB) on a bounded background worker (64 snapshots, 64 MiB staging cap each) and drains prepared copies on their originating DIRECT queue. When off (default),partition,drain,requeue_deferred_for,forget_queue,wait_if_reading_resource,guard_source_free, andallocation_lenall fast-path out, and synchronoustexture_upload::submit()does not retainJob::resources(preservingmain's exact texture lifetimes and sync upload semantics). When enabled (=1), unmapped lazy levels stay synchronous, saturated queues defer per-queue with a 16 ms same-device DIRECT queue strand-rescue timeout,SourceGuardStateserializes worker reads of contiguous and paged (PageMap) title memory against free/protect/unmap paths, andJob::resourcesretains destination resources until GPU copy completion.#2905(physical page homes /alloc_physical_home),#3742(sparse physical-page heaps through L0 budget),#3098and#2385(dropping top mips under VRAM budget, similar area to opt-inXCL_MIP_DEMOTE),#3740(residency/VRAM overlap),#3651(GPU compute detiling),#3653/#3696(UMA view/heap windows),#3648(dispatch-chain mutex drop),#3612(allocator size trim vs reset-count retirement),#3587/#3682(adapter VRAM budget / opt-in two-tier texture budget), and#3678/#3679/#3691/#3718(separate upload/overlap/SRV-mip changes).Tested
rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.cargo build --release -p xcl: succeeded on4b00e738bwith 39 warnings inxcllib (0 new warnings vsorigin/maine99b0bdfc, which also has 39 warnings).cargo test -p xcl --lib -- --test-threads=4on4b00e738b: 2,898 passed, 1 failed, 37 ignored (0error 487aborts — fixed by rebasing ontoorigin/maine99b0bdfcwith#3743and isolating global-state tests in child processes). The sole failure is pre-existing and unrelated to this PR (gpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads;crates/xcl/src/gpu/dxil/has 0 diff vsorigin/main).cargo bench -p xcl --bench '*' -- --testandcargo test --workspace --test '*' -- --test-threads=4: 0 failed across all benchmark targets and workspace integration test binaries, includingtesttitlee2e withtests/testtitle/unmodified vsorigin/main(strict singleread_back).MapTitlePhysicalPages(NULL)sparse UMA reuse restricted tonull_maps(asserting it never returns a title-ownedMEM_GRAPHICSreservation), child-processXCL_PHYS_HOME_PLAIN=0opt-out (physical_home_plain_opt_out_returns_uma_home_on_null_map),FreeTitlePhysicalPagesunregistration, and multi-windowMEM_64K_PAGESoverflow.residency::tests::forced_pressure_passes_exercise_all_trim_paths, verifying bothElevatedretention belowELEVATED_POOL_CAPandCriticaldrain to 0) anddepth_uav::tests::reserved_depth_twin_lazy_maps_shares_and_trims(shared lazy reserved twin mapping, console-size tile cap, UAV protection, and idle trim).title_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used, mip-scoped overlap unmapping, allocator retirement, scratch pool trimming, and async upload eligibility / 16 ms strand rescue /SourceGuardStateserialization (with all existing synctitle_texturestests unmodified — norefresh_and_drain_asyncorreclaim_completed_uploadsworkarounds).LGTM) by Claude Opus 5.5 after fixing all findings from@Foniass's merge-check and Opus's review.Regression run
main:
PR:
Notes on the paired 60 s run (
title: ea3b5e4d, default settings):6,414 MBvs6,567 MBonmain(-153 MB); depth UAV twins used0 MB(lazy shared reserved); target pools dropped from3,648 MBto3,584 MB(-64 MB).mainat97%(307.8M / 316.9M) becauseXCL_TEXTURE_LEVEL_PAGES=1is opt-in;async textureslogged0 queued, 0 uploadedbecauseXCL_ASYNC_TEX_UPLOAD=1is opt-in.17,592 MB(1.11xmain, settling at16,828 MB; sparse pools1,704 MB/1,544 MBmapped vs840 MB/838 MBmapped onmain, because> 4 GiBMEM_64K_PAGESpools overflow to plain write-watched memory while a3.3 GiBMEM_64K_PAGESreservation fits inside sparse window 1).Not tested
XCL_MIP_DEMOTE=1on a title under real VRAM/commit pressure (the 60 s smoke on a 16 GB RTX 5070 Ti stays at Normal pressure; these paths are exercised by GPU unit tests only).XCL_ALLOC_RETIRE_RESETS, default 256 resets) re-creation cost under sustained gameplay load.XCL_ASYNC_TEX_UPLOAD=1live title runs (including the one-submit-late reactivation edge case whenJob::resourcesretains COM refs on the opt-in async path) and opt-inXCL_TEXTURE_LEVEL_PAGES=1live title runs after flipping both to opt-in.> 4 GiBMEM_64K_PAGESplain-memory overflow beyond the 60 s smoke on one title (XCL_PHYS_HOME_PLAIN=0restoresmainplacement).XCL_HEAP_WINDOWS=1tests.XCL_SAMPLE_*game-data tests (unset).AI use
origin/maine99b0bdfc, addressed all merge-check and Opus adversarial review findings (flippedXCL_ASYNC_TEX_UPLOADandXCL_TEXTURE_LEVEL_PAGESto opt-in, reverted all test loosenings intests/testtitleandtitle_textures.rs, isolated global-state GPU tests in child processes with"1 passed"checks, removed the global allocator frommain.rs, tightenedMapTitlePhysicalPages(NULL)tonull_mapsonly, tied> 4 GiB64K overflow tophys_home_plain(), restoredorigin/maincoherent-UMAVirtualFreeorder, capped shared depth-twin tiles to console byte size, movedunmap_completion_snapshotand signals outsideCell::inner, and ensured default sync uploads never retainJob::resources), and ran the release builds, test suite, and paired 60 s smokes.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T08:07:27Z.
merge-check
base:
078358a058head:
f2d9073715merge: clean
build: ok
tests: did not finish: the
-p xcl --libbinary aborted after 152 tests in both of two runs (finding 1); the other test binaries passedreview: 2 critical, 3 high, 7 medium, 3 nits (below)
performance: 60 s smoke run: 1669 → 1602 frames (95 % of main), peak commit 17577 → 19789 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 234 s there, 0 device removals, 0 crashes, 2.2 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: not yet: 2 critical findings (the library test binary aborts at the same point in both runs on this merge, and async texture uploads let the next submit sample old texels) and 3 high (below)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: Six default-on VRAM and upload changes in one PR (plain physical-page homes; residency trimming with allocator retirement, shared depth twins and scratch trimming; lazy level pages turned on by default with mip-class heaps; async texture preparation), plus a Rust heap counting allocator: about 5,900 lines added. Reading the code: the async worker takes eligible textures out of the submit that follows the CPU write, so that submit's GPU work samples old texels, and the e2e and unit tests were changed to retry until the upload lands; level pages go on by default with the aliasing gap #3188 found still open. The async latency, the loosened tests, the aliasing gap and the size block it.
Critical
-p xcl --libtest binary stopped after 152 tests in two separate runs on an RTX 5070 Ti, both times right after the vram tests, with "coherent window could not be restored at 0x... (268435456 bytes, got 0x0, Windows error 487) after segment 2 (64 MB CUSTOM): Map gave 0x..., wanted 0x...; stopping before guest memory is used". Every other PR tonight passed the whole library suite on the same base (one hit a different, known early crash once). This PR changes where large MEM_64K_PAGES reservations and physical-page homes go (kernelx.rs VirtualAlloc ~957/~991, map_pages ~2645), which is likely what now takes the address the coherent-window restore needs. Runcargo test -p xcl --lib -- --test-threads=4on the merge and fix the reservation that lands in the window before anything else.High
Medium
Nit
21bded11freplaces source_going(a, n, true, || ()) in VirtualFree's UMA branch with a bare u.free(a);f2d90737restores it as source_going(.., || u.free(a)). The first three commits on their own release a paired view without telling sparse, so they do not each stand for bisect. Fold the fix into21bded11f.Checked and fine
078358a0; smoke blocks name078358a0andf2d90737: 1636 vs 1711 frames (96 %), peak commit 18670 vs 16563 MB (113 %), no removals or crashesHow this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 61 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T17:35:25Z.
Thanks for the thorough merge-check, @Foniass! Rebased onto
origin/maine99b0bdfcand pushed4b00e738baddressing every critical, high, medium, and nit finding (keeping the 4 bisect-clean commits together in this PR):Critical
error 487): Rebased ontoorigin/maine99b0bdfc(pulling in#3743/864628216, which isolates the mixed-window remake tests in child processes) and isolated our global-state GPU tests (residency::tests::forced_pressure_passes_exercise_all_trim_pathsandtitle_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used) in child processes as well.cargo test -p xcl --lib -- --test-threads=4now runs all tests to completion with 0error 487aborts (2,898passed; only 1 unrelated pre-existing failure ingpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads, with 0 diff undercrates/xcl/src/gpu/dxil/).XCL_ASYNC_TEX_UPLOADto opt-in (=1, default OFF). When off,partition,drain,requeue_deferred_for,forget_queue,wait_if_reading_resource,guard_source_free, andallocation_lenall fast-path out, and synchronoustexture_upload::submit()passesretain_resources = falsesoJob::resourcesnever extends destination COM lifetimes on the default path.High
tests/testtitle/src/gpu.rscompletely (0 diff vsorigin/main, restoring the strict singleread_back) and removedrefresh_and_drain_asyncand allreclaim_completed_uploads()test additions fromtitle_textures.rs. All workspace integration tests (includingtesttitlee2e) pass unmodified.#3188open: FlippedXCL_TEXTURE_LEVEL_PAGESback to opt-in (=1, default OFF, matchingmain), withXCL_MIP_DEMOTEalso opt-in (=1).XCL_TEXTURE_LEVEL_PAGES=1/XCL_MIP_DEMOTE=1andXCL_ASYNC_TEX_UPLOAD=1off by default so the default-on footprint is strictly plain physical homes + residency trimming/shared depth twins).Medium
MapTitlePhysicalPages(NULL)returning a title-owned mapping: Removed theaway.pageshortcut inkernelx.rssoNULLmaps only reuse dedicatedaway.null_mapsslots, and added a regression assertion verifyingMapTitlePhysicalPages(NULL)never returns a title-ownedMEM_GRAPHICSreservation.XCL_PHYS_HOME_PLAIN=0NULL-map test &skip_test: Addedskip_test("no UMA")to the plain-home tests and added child-process testphysical_home_plain_opt_out_returns_uma_home_on_null_map(XCL_PHYS_HOME_PLAIN=0, assertingoutput.status.success()and"1 passed").> 4 GiBMEM_64K_PAGESoverflow tied to opt-out: BothVirtualAllocoverflow checks inkernelx.rsnow checkphys_home_plain(), soXCL_PHYS_HOME_PLAIN=0restoresmain's placement completely; documented in README and Not tested.forced_pressure_passes_exercise_all_trim_pathsin a child process (forwardingSKIPPEDlines to stderr and asserting"1 passed"), addedskip_test("no D3D12 device"), and asserted thatElevatedretains 4 MiB underELEVATED_POOL_CAP(elev_trimmed == 0) whileCriticaldrains to0.main.rs: RemovedCountingAllocfromcrates/xcl/src/main.rs(0 diff vsorigin/main) and removed"Rust heap"frommemory_report.rs.Part of #2697/#3188context and listed#2905,#3742,#3098,#2385,#3740alongside the other overlapping PRs in the PR description.Nits & additional follow-ups from Opus re-review
VirtualFreesparse notice & ordering: Restoredorigin/main's exact coherent-UMAVirtualFreesequence (source_going->mirrors::released->sparse::remapped->u.free) in commit 1 (68c7466bf), preserving bisect cleanliness and preventing any reuse race beforemirrors::released.XCL_TEXTURE_LEVEL_PAGES=1opt-in.allocation_lenoverhead: Gated behindasync_source_guard_enabled()(XCL_ASYNC_TEX_UPLOAD=1) soVirtualFree/VirtualFreeExincur zeroVirtualQuerywalks under default settings.depth_uavreserved twin tiles to each buffer's console byte size (xg::Texture::size, withleast_texture_bytesfallback) so PC overflow tiles stay private, and movedvram::unmap_completion_snapshot()+ deferred queue signals/releases outsideCell::innerindepth_uav::trim_idle_twins.Fresh paired 60 s smoke (
e99b0bdfcvs4b00e738b, RTX 5070 Ti,title: ea3b5e4d)main(e99b0bdfc):1,342frames (60 60 60),15,850 MBpeak commit,6,567 MBlocal VRAM,97%texel residency,0removals,0crashes.4b00e738b):1,638frames (60 60 60,1.22x),17,592 MBpeak commit (1.11x),6,414 MBlocal VRAM (-153 MB,0 MBdepth UAV twins),97%texel residency,0async uploads queued (default off),0removals,0crashes.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.