D3D12.X: XCL's render-target arenas and window pools get a residency priority #3156
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3156"
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 Raul-Paiva on 2026-11-28T13:37:15Z.
On an 8 GB card a retail title's world holds about 16 GB of local video memory against a 7.25 GB DXGI budget (10 GB with
XCL_TEXTURE_LEVEL_PAGES=1 XCL_SPARSE_LAZY=1). Windows then demotes allocations to system memory with no hint which ones matter, so per-frame render targets and the title's buffers can be paged out while idle texture pages stay resident. XCL never callsID3D12Device1::SetResidencyPriorityon its own heaps; #3007 does it only for theGPU_UPLOADsegment underXCL_UMA_DRIVER=mixed, and this builds on the rest.With
XCL_RESIDENCY_PRIORITY=1(off by default so it can be measured first) XCL's own heaps get a priority by role, once; nothing runs per frame. By defaultvram::placeputs a render target or depth buffer on texture pages, not in an arena (andrewDoing's measurement), so a 64 MiB texture page pool getsHIGHonce it holds pages of a render target, depth buffer or UAV texture; a pool of only sampled textures stays at the default. Related: the "residency under a budget" work in #2688 and #3098 (evicting texture mips): this does not evict anything, it only tells Windows what to demote last.What is in it
crates/xcl/src/hle/d3d12x/vram.rs:HeapRole(target arena, window pool, texture pages holding a target, other texture pages),pages_roleand the pure mappingrole_priority: the first threeHIGH, other texture pagesNORMAL(the default, no call); nothingMAXIMUM, which stays #3007's.set_heap_prioritybehind the switch, called fromarena_heapandalloc_pool_heap; a failure is logged once and leaves the default; the heaps givenHIGHare counted by role and logged at each power of two of the total.Pages::keep_pools: when a target is mapped onto texture pages (place_on_pages, andremap_if_unmappedwhen a superseded target comes back), the pools holding its pages getHIGH, each pool once (newly_high); a reclaimed pool's slot forgets it.role_priority_keeps_targets_and_windows_over_texture_pagesanda_target_on_texture_pages_gets_its_pools_high_once.crates/xcl/src/hle/d3d12x/sparse.rs: a new sparse-window tile pool getsHIGH; a retired pool taken back keeps the priority it got.Tested
main5b0d5fa3(same commands, same machine). The head pushed here is the same change rebased ontomain9dfbe3eawithout conflicts;main's newer commits also changevram.rs, which the rebase merged. CI on this head stopped with an access violation (0xc0000005) in the lib test binary whileeh::tests::the_process_ends_while_another_thread_holds_the_heapwas running, a test of code this PR does not touch (it changes onlysparse.rsandvram.rs); I cannot rerun it from my side. The test counts below were measured before that rebase.2a96db19(the same change onmaind52ff48c), the lib tests of the modules this PR touches (hle::d3d12x::sparse,hle::d3d12x::vram), release, serial, with the 20 skips: 199 passed, 0 failed, 2 ignored.cargo test --release --workspace --no-fail-fast -- --test-threads=4: the lib test binary ends early onmaintoo (exit 0x80004005 aftersparse upload preparation still failed after bounded retries), so the lib was also run alone, serially (--test-threads=1), with--skipfor the 20 tests that end the binary onmain(6list_x, 12sparse, 1texture_upload, 1uma_driver; each passes alone).main5b0d5fa3):main: 139 passed, 0 failed, 20 ignored. The failure,gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs("releasing the title PSOs releases their two-pass state", 1 vs 0), is intermittent onmaintoo: run 8 times alone, it failed 2 times on this head and 2 times onmain.main: 2604 passed, 13 failed, 29 ignored. The 13 failures aremain's except thatvram::d32s8_targets_take_their_own_size_of_video_memory(which fails onmainin the long run) ended the binary here instead and was skipped, andalloc_pool::tests::a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_readsfailed. The first passes alone 2/2 on this head and onmain; the second passes alone 3/3 onmainand failed the same way in the serial run of #3119, whose change does not reach it. The first needs about 1 GB of depth targets and depends on what the run before left in video memory.XCL_RESIDENCY_PRIORITY, so the change is off there; the two new unit tests pass.main): the wave64 forms (no wave64), three f16/f32 per-lane forms refused by the recompiler, and the heap-window tests (no heap windows).Regression run
scripts/smoke.ps1 -Seconds 120 -Title 'retail title A', release builds of clean trees, one after the other on the machine in Tested, withXCL_DEVICE_TYPE=lockhart XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_WATCH_HOT=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=60000. The title is left on its own, with no input; the shader cache was warmed by two runs ofmainbefore.main:This PR:
Not tested
HIGHin it.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T17:48:08Z.
On an RTX 5070, enabling residency priority alone issued no HIGH request for the three target placements I tested. All three went through tiled texture pages under the default backing policy. Forcing arena backing supplied a positive control: the native driver accepted HIGH for each of the three arena heaps.
I tested exact head
599a31dc95214c06f3f6d71e93318bb17fa76532, native Windows, RTX 5070 12 GB, NVIDIA 616.92. Each fresh process called productionvram::placefor three live, nonoverlapping 256×256 single-sample targets: RGBA8 render target, D32_FLOAT depth target, and R32_UINT UAV. Test-only logging recorded the heap role on creation and the result of each actualSetResidencyPrioritycall. I also checked the arena registry and individual tile mappings after each placement.TexturePagesXCL_VRAM_ARENAS=1XCL_VRAM_ARENAS=1For the proposed world-load comparison, counting target placements by actual backing would help interpret an on/off result: a hot render or depth target can share a default-priority texture-page pool on this adapter. This was a bounded placement test, four passes and zero skips. It did not exercise sparse-window buffer pools or measure OS eviction order, residency under pressure, frame time, or a retail workload.
AI use: OpenAI Codex (GPT-6) prepared the test-only fixture, ran the native controls, and wrote this report.
Imported from ivall/xcl. Originally posted by Raul-Paiva on 2026-11-30T00:14:26Z.
Thanks @andrewDoing, the placement test and the arena control made this clear. Confirmed:
vram::placeputs a target on texture pages (place_on_pages) unlessXCL_VRAM_ARENAS=1is set or the target cannot be reserved, and those 64 MiB pools were NORMAL, so with the default backing the switch gave HIGH to no target.What changed (amended into the single commit; rebased onto
main, head nowa067891d):place_on_pages, andremap_if_unmappedwhen a superseded target comes back), once per pool and never per frame; a pool of only sampled textures stays NORMAL, and a reclaimed pool's slot forgets itrole_prioritycovers the new role, and a new test checks that render, depth and UAV flags give their pools HIGH, each pool onceThe full suite was run against
main(counts in the description, no new failure); the world run with the switch off/on and the smoke runs are still to come.Written with Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by claudetools-gh on 2026-12-01T09:26:31Z.
World test of
81377895withXCL_RESIDENCY_PRIORITY=1, which the PR lists under Not tested. Not a merge-check: I cherry-picked the commit cleanly onto an older lab line of mine, not ontomain, and ran its two new unit tests (2 passed). I did not run the full suite orsmoke.ps1.HIGH given to 21 render-target arenas, 1956 window tile pools, 71 texture page pools holding targets. No crash or device removal in 4 runs.Seconds per 100 world frames (frames 50→150), same exe, the write-combined GPU heaps in video memory as #505 describes:
XCL_RESIDENCY_PRIORITY=1(595)XCL_RESIDENCY_PRIORITY=1+ the heaps in the sparse windows (597/598/599/600)Without the priorities, Windows demotes per-frame targets and tile pools while over budget, and the GPU sits at ~59 W with ~4.6 GB/s read over PCIe. On this card the switch is the larger half of a ~2.2× gain. Not tested:
mainitself, AMD, and cards that are not over budget.AI-assisted.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:38:26Z.
Triage (#1607) – head
8137789No open or merged PR sets residency priorities on these heaps. The merged #3007 (
XCL_UMA_UPLOAD_PRIORITY) covers only the UMA upload segment, and #3098 / #3037 handle VRAM pressure by evicting mips or gating uploads, not through residency priority.No problems found in the diff. It is opt-in (
XCL_RESIDENCY_PRIORITY=1). Minor: theset_heap_priority(.., HeapRole::TexturePages)call inalloc_pool_heap(vram.rs) never does anything becauserole_priorityreturnsNonefor that role.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 throny on 2026-12-01T10:13:53Z.
Queued an in-world A/B of this on an RTX 4080 16 GB:
9dfbe3ea+ this head81377895, same build withXCL_RESIDENCY_PRIORITYunset vs=1, 900 s each withXCL_GPU_PROFILE=1. Our runs sit 3.3–4 GB over the video-memory budget in the world (render targets ~6.4 GB of it), so this is exactly the situation it targets; numbers here when done.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:42:44Z.
merge-check
base:
493dbd3dd0head:
813778957emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+150/-1). With
XCL_RESIDENCY_PRIORITYunset it returns early. With it set, XCL's render-target arenas, window pools and texture-page pools getID3D12Device1::SetResidencyPriority(HIGH)once per heap (vram.rs~1029, throughID3D12Pageable), neverMAXIMUM, which stays #3007's. Findings: (1) The HIGH set only grows. A texture-page pool keeps HIGH after its target's pages are freed and it fills with sampled textures; the mark goes only when the whole heap is reclaimed (keep_pools~2183,take_heap~1724). In claudetools' log, 1956 window pools x 4 MiB plus 71 page pools x 64 MiB plus 21 arenas come to about 12 GiB against a 14.9 GB budget. On the author's 8 GB card the HIGH set alone would pass the budget, and the priority would stop separating anything (unverified). (2) Only the pure helpers are tested; nothing checks thatplace_on_pages(~2486) orremap_if_unmapped(~2616) reachkeep_pools. (3) The only on / off measurement (81 -> 44 s per 100 frames in a world cell) was a cherry-pick onto a lab branch, not this head. The README doesn't mention the switch. Nit: theTexturePagescall at ~1684 never does anything. The PR's red CI is the lib-binary access violation in the eh / agility tests (#1487), seen on unrelated PRs too. Fine: off by default, one call per heap and never per frame, the level-pages path covers only flagless textures so no targets are missed, and a retired window pool taken back keeps its heap and priority.performance: 60 s smoke of a retail title, main
493dbd3dvs this merge (b108d492): 1670 -> 1696 frames shown (101 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17174 MB, 0 device removals, 0 crashes. A second 60 s run of the same merge withXCL_RESIDENCY_PRIORITY=1: 1676 frames shown (last presents per 2 s: 60 60 60), peak commit 18004 MB, 0 device removals, 0 crashes; the log shows HIGH given to window tile pools. On this 16 GB card a 60 s run stays under budget, so it shows only that turning it on breaks nothing.verdict: safe to merge (opt-in; a README line for
XCL_RESIDENCY_PRIORITYand a test thatplace_on_pages/remap_if_unmappedreachkeep_poolswould round it off)hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T11:02:45Z.
First in-world pair, RTX 4080 16 GB (621.40),
9dfbe3ea+ this head81377895(plus our local input-timing patch), same build, same save and inputs, 900 s each,XCL_TWO_PASS_MB=512,XCL_GPU_PROFILE=1:XCL_RESIDENCY_PRIORITYNo device removal or crash in either. That is the largest single gain we have measured from a switch (+52 %), while video memory stays just as far over budget, which fits the switch deciding what stays resident rather than how much. A repeat pair in reverse order is running to rule out run-to-run noise; I'll add it here.
AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T11:34:13Z.
Repeat pair in reverse order confirms it (same build and settings as above):
XCL_RESIDENCY_PRIORITYSo about +50 % presents/s and half the GPU time per call for the most expensive program on an RTX 4080 16 GB, with video memory just as far over budget either way; no device removal or crash in four runs. I'm doing a merge check on this head next.
AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T11:34:15Z.
merge-check claim
head:
813778957eImported from ivall/xcl. Originally posted by throny on 2026-12-01T11:44:05Z.
merge-check
base:
493dbd3dd0head:
813778957e(unchanged since the claim)merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 0 failed, 51 ignored; failing: none (25 SKIPPED lines in the log: 22 gpu, 1 hle, 1 shaders, 1 heap_window_out_of_memory test; skips are not coverage); no test binary ended abnormally; no base comparison needed
review: Read the whole diff (sparse.rs +2, vram.rs +~140 with two tests). Heaps XCL creates (render-target arenas, sparse window tile pools, texture page pools that hold a render target / depth buffer / UAV texture) get D3D12_RESIDENCY_PRIORITY_HIGH through ID3D12Device1::SetResidencyPriority once, when made or when a target's pages first land in a pool (
newly_highkeeps each pool to one call; the entry is removed intake_heap); a failure is logged once and leaves the default, nothing is called per frame. Both tests are pure logic (role to priority mapping, the once-per-pool set) and run without a GPU, so they do not exercise SetResidencyPriority itself or the driver's behaviour; that rests on the in-world measurement. Minor: a pool that got HIGH keeps it after its target pages are freed until the heap is released; theGIVENlog counters are process-wide statics.performance: in-world on this RTX 4080, four 900 s runs of
9dfbe3ea+ this head (not this merge base): XCL_RESIDENCY_PRIORITY=1 gave 3.37 and 3.49 presents/s vs 2.22 and 2.39 unset, the most expensive program's GPU time per call halved (39 -> 19 ms); off by default, so merging changes nothing until the switch is set.verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300; Claude Code, Claude Sonnet 5.5 ran the build and the suite and read the diff; Claude Opus 5.5 checked this report and made the in-world runs
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:23:10Z.
Merged at the checked head
81377895onmain493dbd3d: two merge checks (Foniass, ours: 2902 passed, 0 failed, 51 ignored on that base), CI green, and +50 % presents/s in four world runs withXCL_RESIDENCY_PRIORITY=1(above). It stays off by default; worth considering turning it on by default once someone with an AMD card has run it.AI use: Claude Code (Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by lucsoft on 2026-12-01T14:01:51Z.
A/B on AMD under Linux, for the "default on AMD too?" question:
Setup: AMD Radeon RX 7800 XT (16 GB, RADV NAVI32), Mesa 26.3.1, Linux 7.3, Wine 11.21 (staging), vkd3d-proton 3.1, Ryzen 7 7800X3D. The build is
mainb2b1f109(with this PR) plus three not-yet-merged crash fixes (#3536, #3553/#3566 and an allocator leak fix), so that 600 s runs survive on this card. The same build was run twice, 600 s each, same title and input script, onlyXCL_RESIDENCY_PRIORITYchanged.XCL_RESIDENCY_PRIORITYThe switch was active: the log shows
HIGH given to 20 render-target arenas, 942 window tile pools, 62 texture page pools holding targets, and no failedSetResidencyPriority.Result: no measurable effect on this AMD/Linux setup. Frames are within run-to-run noise (+0.8 %), and the memory curve is the same: it stays far over budget on both sides and spills to system memory either way. That matches an earlier measurement here: on vkd3d-proton + RADV, residency priorities do not change what gets demoted. It does no harm either: no extra faults or crashes. So on AMD under Linux there is no reason for or against a default; whether it helps AMD on Windows (AMD's own driver) is untested here.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T15:31:55Z.
@lucsoft thanks for the RADV A/B. Since it changes nothing there and gives +50 % on our RTX 4080, I opened #3582 to make it the default (
XCL_RESIDENCY_PRIORITY=0turns it off); a Windows + AMD run would settle it.AI use: Claude Code (Claude Opus 5.5).