D3D12.X: budget sampled L0 textures with a physical RAM floor #3740
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3740"
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 jeroenhaentjens on 2026-12-02T23:06:13Z.
What & Why
This splits sampled texture admission and the physical RAM floor out of #3682. Under local DXGI pressure, new sampled backing may use system memory while leaving local space for render target, depth and UAV pools. The default soft caps of up to 4,350 MiB for committed textures and 4,000 MiB for sampled tile pools are tuned for 6–8 GB discrete cards. XCL_TEXTURE_SOFT_CAP_MIB adjusts both caps. #3620 offers a related spill policy and overlaps this allocator.
What is in it
Tested
2ff3383881. Intel Core i7-9750H, NVIDIA Quadro RTX 3000 (driver 597.06 / 32.0.15.9706), Windows 11 25H2 build 26200.9974, Rust MSVC 1.100.0 and DXC 1.9.2609.5.Regression run
Baseline (main)
PR head
Not tested
AMD, Intel discrete GPUs, and Linux.
AI use
OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR update. The author reviewed the diff and the recorded test results.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:16:06Z.
Review of
3940fe38(code reading only, not a merge-check; draft) · 1 high, 5 mediumIn short: This PR splits the sampled-texture budget and the physical RAM floor out of #3682, rewritten into a new
texture_budget.rs. BehindXCL_TEXTURE_BUDGET=1, committed sampled textures and sampled tile pools move to CUSTOM/L0 once the local soft limit is reached. With the variable unset, the default path is unchanged, and it merges cleanly onmainwithout #3734. Under the opt-in, three things go wrong:High
Lazy-level textures are refused on L0 pages and lose their uploads.
map_levelsstill callsbind_range(..., false)(vram.rs~3622). The lazy shape at ~3585 is the same astexture_budget::sampled, so withXCL_TEXTURE_LEVEL_PAGES=1these sampled textures count as local-only aliases.return Noneat ~2642, andmap_levelscontinues. The level gets no pages, its upload goes to unmapped tiles, and it reads as zeros until a later upload. The L0 page can be another texture's live page or an idle one (kept 2 s).Fix: pass the same
sampledflag frommap_levelsthatbindnow passes, and add a test with both switches on.Medium
A refused admission now fails the title's allocation.
RequiredLocalall refuse,committed_sampled(texture_budget.rs~264) returnsE_OUTOFMEMORYwithout callingCreateCommittedResource. Both the committed path inreal.rsand the committed fallback ofCreatePlacedResourceX(device_x.rs~1307) then fail.mainwould have created the resource, and WDDM can serve it over budget. L0 is refused whenever free physical RAM minus in-flight L0 is under 3,072 MiB, which can happen under the pressure the feature is for.Fix: try a plain local allocation as the last step, or say in the README that the call fails.
Idle L0 pages force render targets into arenas.
vram.rs~2642 also refuses pages withusers == 0that wait outIDLEbeforesweep_idledrops them.main, a render target, depth or UAV texture placed within 2 s on memory a sampled texture just released reuses those tiles. With the opt-in it falls back toplace's arena path: an extra heap, and no sharing with later aliases at that address.Fix: treat an idle L0 page as missing and refuse only pages that still have users. The README's "usual placement fallback" sentence should mention the idle window.
The default soft limits are fixed sizes, not shares of the budget.
Admission::limit(texture_budget.rs~30-31) usesmin(4350 MiB, budget - 800 MiB)for textures andmin(4000 MiB, budget - 1150 MiB)for pools. On a 12 or 16 GB GPU, sampled textures and pools go to system memory at about 4 GB, with most of the budget free. Derive the default from the budget, or document the fixed defaults and the cards they suit.This overlaps #3620. #3620 also changes
alloc_pool_heaptoalloc_pool_heap(dev, evictable) -> Option<(ID3D12Heap, bool)>, sends sampled-only tile pools to L0 underXCL_L0_VRAM_MARGIN_MB, and promotes L0 pages to local memory when a target aliases them instead of refusing. The two conflict invram.rsand implement the same spill differently, so one has to be chosen or rebased on the other.The new
vram.rsrouting has no test, and one test claim is broader than the code.bindpassing the sampled class, thenon_localslot tracking inPoolHeaps, and the local-only alias refusal.l0_physical_ram_floor_includes_in_flight_backingonly passesin_flightas an argument tofits_physical_ram. Nothing tests howreserveadds up unfinished L0 requests (~131).Fix: a CPU-only test of
PoolHeapsand the guard, and one ofreservewith an outstanding L0 reservation.Checked and fine
XCL_TEXTURE_BUDGETunset,enabled()is false. Both committed paths callcreatewith the original heap properties,bindpassesfalse, andalloc_pool_heap(dev, false)builds the same heap.non_localstays empty, so the guard never triggers.create.PoolHeaps::take_heapclearsnon_local, so a reused slot does not inherit the L0 mark.D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES, andsampled()requiresFlags == NONE, so no RT, DS or UAV texture goes there.CreateCommittedResourcecall with a nullppvreturnsS_FALSEand is not charged.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 jeroenhaentjens on 2026-12-03T07:32:21Z.
@Foniass Lazy mip mapping now uses the same sampled classification as eager mapping. An idle L0 page can be replaced at the same address with local backing, while a live page still takes the existing placement fallback. If admission refuses every committed allocation route, the original local driver call decides the result. The README documents the default caps and their override, and the PR records the new CPU and GPU regression checks.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T07:37:45Z.
Follow-up review of
1a2bef64, since3940fe38(code reading only, not a merge-check) · 1 high, 3 mediumIn short: Since
3940fe38, the PR:map_levels;PoolHeaps,reserveand the alias cases.Five of the six earlier points are fixed. But the live-L0 refusal now leaves a superseded render target unmapped when it is used again, the overlap with #3620 is still open, and the PR has grown to 598+/35- with no reason given.
High
A superseded render target that is mapped again over a live L0 page gets no tiles.
remap_if_unmapped(vram.rs~3091) callspages.bind, which now returnsNonewhen any page in the range is on an L0 heap and still has users (~2649).remap_if_unmappedthen returnsfalse.placements::map_again(~480, fromnote_use~550) andtitle_textures::forget(~1043).use_again(~558) has already setmapped = trueby then.main,bindshares the pages at that address.Fix: handle
Nonehere, for example by giving the target private local tiles for the conflicting pages, or leaving it superseded in the registry. Add a test.Medium
alloc_pool_heapto the same(dev, bool) -> Option<(ID3D12Heap, bool)>shape, sends sampled tile pools to L0, and promotes L0 pages to local memory when a target aliases them, instead of refusing. The description now names it, but the two still conflict invram.rsand implement the same spill differently. One has to be chosen, or one rebased on the other.bind_rangeor the physical RAM floor, or say why it cannot be split.hle::d3d12x::texture_budget::testsandhle::d3d12x::vram::tests(91 passed). Add the whole suite's counts and skips.Checked and fine
bind_range(sampled_page_backing,vram.rs~3639-3642).lazy_texture_levels_share_l0_and_idle_aliases_get_local_tilesruns with both switches on.E_OUTOFMEMORY(allocate_committed,texture_budget.rs~279), with a test.take_batchsucceeds, and the old tile goes throughcooling(~2647-2673). Whentake_batchfails, nothing is removed.XCL_TEXTURE_SOFT_CAP_MIB.pool_heaps_clear_non_local_when_a_slot_is_reusedtests the slot tracking, andreserve_charges_in_flight_l0_against_physical_ram_across_adapterstestsreserveadding up an unfinished L0 reservation from another adapter.XCL_TEXTURE_BUDGETunset, the default path is unchanged.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 vasanex on 2026-12-03T07:43:39Z.
Review: COMMENTED
Review of
1a2bef64(code reading and the tests named below, not a merge-check) - 1 finding, 2 notesIn short: this adds to Foniass's follow-up review of the same head and does not repeat it. I agree with its point 1 (the remap over a live L0 page), which my reading found as well. One point is new: under the opt-in, a tile-pool admission that both segments refuse has no last step, and a lazily mapped level then loses its upload. The whole suite and a smoke run on a merge with current main are below (their point 4 asks for the suite).
Measured (RTX 3080, Windows 11, merge of
1a2bef64onto main16c2fd08= afd22f6a; the PR's base is078358a0, the merge is clean):cargo build --workspace: ok.cargo test --workspace --no-fail-fast -- --test-threads=4(debug): 3018 passed, 0 failed, 56 ignored; 25 SKIPPED, the same tests as on main (main: 3012 / 0 / 56).scripts/smoke.ps1, 60 s, offline, release, switch unset: 1699 frames (main 1696), no device removal, no crash, peak commit 17819 MB (main 18885 MB; two runs of the same runtime code differed by 4 % here tonight).XCL_TEXTURE_BUDGET=1beyond the PR's own tests in the suite.Finding (in its own thread):
map_levelsskips the level: its upload is dropped. The committed route got a "driver decides" last step in this head, the pool route did not.Notes, not blocking:
committed_sampledcharges the admission withdev.GetResourceAllocationInfoon the title's device. That call goes through XCL's own hook (get_resource_allocation_info_x), which answers with the console's size for a texture it models and reads the description as a console one.real.rshaspc_allocation_sizefor the PC driver's size. Accounting only; I did not measure how far the two sizes are apart.TextureBudget::samplemakes a DXGI factory and looks the adapter up again (memory_report::video_memory): once per committed sampled texture, and once per new pool heap withPAGESlocked. Not measured; keeping the adapter would avoid it.Checked and fine, beyond what is listed there: no reachable panic in the registry's
unwraps and indexing (an adapter's entry lives as long as one of its samples,retainnever removes a request that is not committed), the registry lock is not held acrosscreate, and a render target cannot get a tile of a heap made withALLOW_ONLY_NON_RT_DS_TEXTURES(L0 heaps are only made for the sampled class, andpick_heapkeeps the classes apart, also after a slot is reused).Not checked: a title run with the switch on and the card over its budget, AMD and Intel (whether their drivers take tile mappings onto CUSTOM/L0 heaps), how often the RAM floor refuses in a real run, the overlap with #3620.
Review by Claude Code (Claude Fable 5.2), with an independent second read by a subagent (Claude Fable 5.2) whose points were checked before use, posted without a human check of each point. An automated PR review workflow is running at the request of the user.
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T07:43:40Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 3642Medium, read (not measured). Needs
XCL_TEXTURE_BUDGET=1andXCL_TEXTURE_LEVEL_PAGES=1.A refused tile-pool admission has no last step. The committed route now ends in the driver's own call (
allocate_committed:None => create(properties)), butsampled_poolhandsallocate'sNonestraight back:alloc_pool_heapreturnsNone,take_batchfails,bind_rangereturnsNone, and here the level is skipped.Scenario: a lazy sampled level needs fresh tiles and no heap of its class has free ones. Local usage plus 64 MiB is over budget minus 72 MiB (
PoolandPoolFallbackboth refuse), and L0 is refused too (free physical RAM under 3072 MiB plus the request, or the non-local budget is full). The level then has no pages, and its upload goes to unmapped tiles, which drops it (title_textures.rs, the comment overmap_levels_from_present): it reads as zeros until the title writes that memory again. main callsCreateHeapin the same state and loses the level only if the driver refuses.That state is the one the switch is for: a card at its budget on a machine short of RAM. The warning "sampled tile pool admission denied in both memory segments" already counts it. With the switch on it also comes up more often than a new heap does on main, because sampled textures now take tiles only from heaps of their own class (
pick_heap), so free tiles in the other class's local heaps no longer serve them.An eager sampled placement is not hit the same way:
place_on_pagesreturnsNoneand the committed fallback ends in the driver's call.Suggested fix: give
sampled_poolthe same last step as the committed route (a local heap, the driver decides), at least when the caller ismap_levels. A test of the refused route would be good: the GPU test takes its fresh tiles from the L0 heap it made itself and never gets tosampled_pool.Imported from ivall/xcl. Originally posted by jeroenhaentjens on 2026-12-03T11:25:02Z.
@Foniass @vasanex A superseded GPU target can now remap over live sampled L0 backing using private local tiles for the conflicting pages. A denied remap stays eligible for retry. Sampled pool allocation now has the same final local driver path as committed textures. The PR contains the complete workspace result and the exact-head smoke.
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-03T11:27:49Z.
Code review location:
crates/xcl/src/hle/d3d12x/vram.rs; line 3642Fixed in
2ff33838.sampled_poolnow ends in the driver's own call when both admissions refuse (allocate_sampled_pool:unwrap_or_else(|| create(false))), soalloc_pool_heapgets a local heap or the driver's error, as the committed route does, and a lazy level is skipped only when the driver itself refuses. The new unit test pins the refused route (attempts == [false]), and the GPU test now goes through it with a realCreateHeap.Measured on the merge of
2ff33838with main0c725d5d(a7edc19c), RTX 3080:cargo test -p xcl --lib -- --test-threads=4 texture_budget hle::d3d12x::vram: 92 passed, 0 failed, 1 ignored. With the private tile key put back to the shared(va, i), the GPU testlazy_texture_levels_share_l0_and_idle_aliases_get_local_tilesfails (the private-key assertion), so the new remap is covered too. The suite and the smoke were not rerun on this head.Follow-up by Claude Code (Claude Fable 5.2), posted without a human check of each point. An automated PR review workflow is running at the request of the user.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T11:31:25Z.
Follow-up review of
2ff33838, since1a2bef64(code reading only, not a merge-check) · 5 mediumIn short: Since
1a2bef64:The earlier High is fixed: the private tiles are released on every path, their keys cannot collide with shared keys, and the registry counts stay consistent. But the private tiles end the memory sharing the use-again path exists for. The overlap with #3620 is still open, now joined by the stacked #3745, and the size has grown.
Medium
note_use(placements.rs~553-557) maps a superseded target again because the title "may use both over one memory when it knows they share it". Under the opt-in,bind_rangenow gives the target private tiles for each live L0 page (vram.rs~2649-2656, key ~2701) instead of sharing it, asmaindoes. The target and the sampled texture then stop sharing memory on those pages. What the target renders never reaches the sampled texture, and the target starts with whatever the pool tile held. The README only says the target "gets private local tiles". Say in the README that they stop sharing memory, or move the L0 page to local memory instead, as #3620 and #3745 do.1a2bef6) promotes live L0 aliases with their contents kept. This push handles the same case with private tiles, and changedbind_range's signature (private_live_l0), so #3745 no longer applies cleanly. Choose one approach, then rebase #3742 and #3745 on the current head.bind_range), or say why it cannot be split.map_again(placements.rs~477-489) now marks a placement unmapped again and counts it whenremap_if_unmappedfails, andnote_use(~564-569) skipsuse_againthen. The new GPU test callsremap_if_unmappeddirectly on aTargetinserted by hand (vram.rs~4983-4990), so neither path is reached. Add a test where the remap fails: the placement stays superseded,SUPERSEDEDandunmappedstay in step, and a later successful use clears it.PAGESand callsreal::adopton its own device, so the crash could come from this PR. Name the test that crashed, and say whether it also happens onmain.Checked and fine
remap_if_unmappedpassesprivate_live_l0for GPU-owned resources (vram.rs~3095-3098), and every placement that can be superseded isKind::Target. If a remap still fails, the placement stays superseded anduse_againis not called (placements.rs~481-485, ~567-569).(resource, i | PRIVATE_TILE_INDEX). Bit 63 is never set in a shared(va, i)key, so they cannot collide, andsweep_idlenever queues one.release_tilessends one tocoolingwhen its users reach 0, without the idle window (~2587). This happens on the held unmap,forget_pagesandunmap_superseded. A pendingHeldUnmapkeeps a COM reference until the tiles are released.non_localslot.unmappedand is uncounted byreleaseoruse_again.SUPERSEDEDis stored aftermap_againinplacedandsettle. The lock order is still registry, thenPAGES.allocate_sampled_poolcallscreate(false)when there is no sample or both reservations are refused, with two tests.XCL_TEXTURE_BUDGETunset,non_localstays empty. The only default-path change: a remap that fails (out of memory) now stays superseded and is retried, instead of being marked mapped with no tiles.Written by Claude Code (Claude Opus 5.5) and 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.