Skip to content

D3D12.X: budget sampled L0 textures with a physical RAM floor - #3740

Draft
jeroenhaentjens wants to merge 1 commit into
xcl-dev:mainfrom
jeroenhaentjens:feat/l0-texture-budget-and-ram-guard
Draft

jeroenhaentjens wants to merge 1 commit into
xcl-dev:mainfrom
jeroenhaentjens:feat/l0-texture-budget-and-ram-guard

Conversation

@jeroenhaentjens

@jeroenhaentjens jeroenhaentjens commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What & Why

Following the review by @Foniass, this draft splits sampled texture admission and the physical RAM floor out of #3682. Under local DXGI pressure, new eligible sampled backing may use system memory while leaving room for render-target, depth and UAV pools. Related work in #3620 covers a separate DXGI-margin control.

What is in it

  • Opt in with XCL_TEXTURE_BUDGET=1. Sample DXGI usage per adapter and charge concurrent admissions to the matching memory segment.
  • Route eligible committed textures and sampled tile-pool heaps to CUSTOM/L0 after their local soft limits. A denied L0 allocation can fall back to local memory up to DXGI budget minus 8 MiB for committed textures. Pool fallback leaves another 64 MiB free for target backing.
  • Guard new L0 backing with GlobalMemoryStatusEx and in-flight reservations. XCL_L0_MIN_FREE_PHYS_MIB defaults to 3072 and accepts 0 to disable the floor. The denial counter is reported at powers of two.
  • Cover the physical RAM floor, concurrent L0 backing, and the sampled-pool fallback limit with unit tests.

Tested

  • Commit 3940fe3. 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.
  • git diff --check passed. cargo test --locked --workspace -- --test-threads=4 reported 3008 passed, 0 failed, 52 ignored and 26 SKIPPED diagnostics. The workspace run recorded 0 D3D12 validation warnings or errors during execution and 8 live-object reporting warnings during shutdown of an existing integration fixture.
  • Both 60-second runs used the same reference input schedule and existing shader cache. Both smoke runs set XCL_TEXTURE_BUDGET=1.

Regression run

Baseline (main)

xcl-smoke v1
commit: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a
gpu: NVIDIA Quadro RTX 3000
title: 0ba91dcb
seconds: 60
exit: 0x0
frames shown: 1480 (PresentX 1480)
presents per 2 s (last 3): 48 59 62
device removals: 0
crashes: 0
peak commit: 13962 MB

PR head

xcl-smoke v1
commit: 3940fe383a92347887c2b7444689f1fa0eb52929
gpu: NVIDIA Quadro RTX 3000
title: 0ba91dcb
seconds: 60
exit: 0x0
frames shown: 1499 (PresentX 1499)
presents per 2 s (last 3): 60 58 60
device removals: 0
crashes: 0
peak commit: 13771 MB

Not tested

AMD, Intel discrete GPUs, and Linux.

AI use

OpenAI Codex (GPT-6, specific revision unavailable) assisted with the implementation, tests and PR draft.

Split sampled admission from Draft xcl-dev#3682. Keep the 8 MiB DXGI headroom for committed fallback and another 64 MiB for render-target backing when a sampled pool falls back to local memory.
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review of 3940fe38 (code reading only, not a merge-check; draft) · 1 high, 5 medium

In short: This PR splits the sampled-texture budget and the physical RAM floor out of #3682, rewritten into a new texture_budget.rs. Behind XCL_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 on main without #3734. Under the opt-in, three things go wrong:

  • the new local-only alias refusal drops uploads of lazy-level textures;
  • a refused admission now fails the title's call;
  • the default limits move textures to system memory early on large GPUs.

High

  1. Lazy-level textures are refused on L0 pages and lose their uploads.

    • map_levels still calls bind_range(..., false) (vram.rs ~3622). The lazy shape at ~3585 is the same as texture_budget::sampled, so with XCL_TEXTURE_LEVEL_PAGES=1 these sampled textures count as local-only aliases.
    • A level whose address still has a page on an L0 heap hits return None at ~2642, and map_levels continues. 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).
    • These textures also never get budgeted L0 backing.

    Fix: pass the same sampled flag from map_levels that bind now passes, and add a test with both switches on.

Medium

  1. A refused admission now fails the title's allocation.

    • When the local limit, L0 and RequiredLocal all refuse, committed_sampled (texture_budget.rs ~264) returns E_OUTOFMEMORY without calling CreateCommittedResource. Both the committed path in real.rs and the committed fallback of CreatePlacedResourceX (device_x.rs ~1307) then fail.
    • main would 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.

  2. Idle L0 pages force render targets into arenas.

    • The guard at vram.rs ~2642 also refuses pages with users == 0 that wait out IDLE before sweep_idle drops them.
    • On 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 to place'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.

  3. The default soft limits are fixed sizes, not shares of the budget. Admission::limit (texture_budget.rs ~30-31) uses min(4350 MiB, budget - 800 MiB) for textures and min(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.

  4. This overlaps D3D12.X: opt-in XCL_L0_VRAM_MARGIN_MB spills sparse and sampled texture pools to L0 #3620. D3D12.X: opt-in XCL_L0_VRAM_MARGIN_MB spills sparse and sampled texture pools to L0 #3620 also changes alloc_pool_heap to alloc_pool_heap(dev, evictable) -> Option<(ID3D12Heap, bool)>, sends sampled-only tile pools to L0 under XCL_L0_VRAM_MARGIN_MB, and promotes L0 pages to local memory when a target aliases them instead of refusing. The two conflict in vram.rs and implement the same spill differently, so one has to be chosen or rebased on the other.

  5. The new vram.rs routing has no test, and one test claim is broader than the code.

    • Untested: bind passing the sampled class, the non_local slot tracking in PoolHeaps, and the local-only alias refusal.
    • The description says the tests cover "concurrent L0 backing", but l0_physical_ram_floor_includes_in_flight_backing only passes in_flight as an argument to fits_physical_ram. Nothing tests how reserve adds up unfinished L0 requests (~131).

    Fix: a CPU-only test of PoolHeaps and the guard, and one of reserve with an outstanding L0 reservation.

Checked and fine
  • With XCL_TEXTURE_BUDGET unset, enabled() is false. Both committed paths call create with the original heap properties, bind passes false, and alloc_pool_heap(dev, false) builds the same heap. non_local stays empty, so the guard never triggers.
  • A reservation that is not committed is removed on drop. A committed one is kept while an older sample is alive. The registry lock is not held across create.
  • PoolHeaps::take_heap clears non_local, so a reused slot does not inherit the L0 mark.
  • L0 pool heaps use D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES, and sampled() requires Flags == NONE, so no RT, DS or UAV texture goes there.
  • A CreateCommittedResource call with a null ppv returns S_FALSE and is not charged.
  • A UMA adapter, or no local budget from DXGI, falls back to the plain allocation.
  • Independent of D3D12.X: retain reserved backing through the final tile mapping #3734 except for a README conflict. 381+/23-, README updated.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants