Skip to content

D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget - #3587

Open
iggyvilla wants to merge 1 commit into
xcl-dev:amd-devfrom
iggyvilla:amd-vram-budget
Open

iggyvilla wants to merge 1 commit into
xcl-dev:amd-devfrom
iggyvilla:amd-vram-budget

Conversation

@iggyvilla

@iggyvilla iggyvilla commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Adds opt-in XCL_VRAM_BUDGET=1 (off by default: no change) to keep XCL's texture page pools and parked sparse tiles under DXGI's local video memory budget on 8 GB cards (#1337, #1585). Supersedes #3335 (always-on XCL_TEXTURE_SYSMEM port on amd-dev) with a budget-triggered L0 spillover that stays in local VRAM while under budget.

TL;DR — Before vs After (RX 6650 XT 8 GB, DXGI local budget ~6,808 MB)

Scenario Metric Before (XCL_VRAM_BUDGET off) After (XCL_VRAM_BUDGET=1) Delta
60 s smoke (41aa60ce, opt-in off) Frames shown / Peak commit 1,618 / 15,479 MB (main d8bd9a38) 1,654 / 15,943 MB (08f61a9a) +2.2% frames / 1.03x commit
Loading phase (41aa60ce, default 2048 MiB margin) Local target pools / L0 pools 2,879 MB / 0 MB 2,687 MB / 256 MB −192 MB local (+256 MB L0, exact split)
Loading phase (41aa60ce, default 2048 MiB margin) Peak local / Peak commit 5,746 MB / 23,819 MB 5,629 MB / 20,737 MB −117 MB local / −3,082 MB commit
Full 3D world load (36e16cf4, 600 MiB margin) Peak local / Over-budget warns 7,688 MB (+880) / 85 warns 7,197 MB (+406) / 35 warns (448 MB L0) −491 MB local / −59% warns
Full 3D world load (36e16cf4, BUDGET_MB=2500) Peak local / Over-budget warns 7,688 MB (+880) / 85 warns 6,024–6,534 MB (−257 to −783) / 0 warns (896–1,152 MB L0) −1,154 to −1,664 MB local (under budget, 300 s clean)

When enabled, XCL samples DXGI's local segment via memory_report::local_segment() every 250 ms and sets a target of Budget - XCL_VRAM_BUDGET_MARGIN_MB (default 2048 MiB; XCL_VRAM_BUDGET_MB sets a fixed target instead). At or past the target (Pressure::Near / Over, with 256 MiB hysteresis back to Room):

  • New pages for sampled textures (never render targets, depth buffers, or UAVs) take free tiles of existing video-memory pool heaps first, then 64 MiB pool heaps in L0 system memory (D3D12_HEAP_TYPE_CUSTOM, CPU_PAGE_PROPERTY_NOT_AVAILABLE, MEMORY_POOL_L0, same properties as D3D12.X: allow title texture pages in system memory #1702). Nothing is left unbacked (unlike D3D12.X: bound target-page pools by title and adapter VRAM budgets #2357's NULL tiles).
  • Empty pool heaps are reclaimed every 250 ms instead of 1 s, with 0 warm spares.
  • Parked sparse tiles flush at 256 (16 MiB) instead of 4096 (256 MiB).
  • If CreateHeap for a video-memory pool heap fails while XCL_VRAM_BUDGET=1, it falls back to an L0 system-memory heap.

The default 2048 MiB margin starts spilling streaming sampled textures before the ~2 GiB world-entry burst of render targets, two-pass buffers, and driver pipelines hits an 8 GB adapter, while remaining dormant on 16 GB+ adapters under typical 8–10 GB workloads.

What is in it

  • crates/xcl/src/hle/d3d12x/vram_budget.rs: XCL_VRAM_BUDGET / XCL_VRAM_BUDGET_MARGIN_MB / XCL_VRAM_BUDGET_MB settings, pressure/hysteresis state machine, lock-free try-locked 250 ms DXGI sampler, and unit tests.
  • crates/xcl/src/hle/d3d12x/vram.rs: pool_heap_properties, alloc_pool_heap L0 allocation and OOM fallback, per-device PoolHeaps L0 tracking (is_sys, sys_live), Pages::page_bytes_split / page_bytes_split_for, spare_pools_for / reclaim_every, two-step free-VRAM-first then L0 placement in bind_range, budget hooks in place_on_pages / remap_if_unmapped / map_levels / before_execute, plus unit and GPU round-trip tests.
  • crates/xcl/src/hle/d3d12x/sparse.rs: PARKED_MAX_TIGHT (256) and parked_max_for at the four parked-tile flush sites, plus unit test.
  • crates/xcl/src/hle/d3d12x/memory_report.rs: splits video target pages/free pools from non-local "target pools in system memory" so neither segment is double-counted, and updates device_snapshot_has_budget_and_all_owners.
  • crates/xcl/src/hle/d3d12x/mod.rs: exposes pub mod vram_budget.

Tested

  • Hardware / OS / Rust: AMD Radeon RX 6650 XT (8 GB RDNA2, driver 32.0.21045.29003), AMD Ryzen 7 5700X, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09).
  • Targeted suite (cargo test -p xcl --lib -- hle::d3d12x::vram_budget hle::d3d12x::vram:: hle::d3d12x::sparse:: hle::d3d12x::memory_report --test-threads=4, debug): 233 passed, 1 failed (sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, pre-existing on origin/amd-dev 41aa60ce), 2 ignored, 0 SKIPPED. All 6 new tests (including GPU round-trip + per-device split accounting in vram::tests::system_memory_pages_have_their_own_heap_and_hold_what_the_gpu_copies) pass.
  • Full workspace suite (cargo test --workspace -- --test-threads=4, debug): 2,826 passed, 9 failed (all 9 pre-existing on origin/amd-dev 41aa60ce on this RDNA2 GPU: 3 gpu::recomp float-compare NaN tests, sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels plus 4 cascading PoisonErrors that pass 4/4 when run separately), 29 ignored. SKIPPED: gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu (4 subcases: unsupported V_MUL_F16/V_PK_MUL_F16), hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap (opt-in XCL_HEAP_WINDOWS=1), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode not enabled).
  • Retail title runs (lockhart, XCL_COHERENT_MB=4095, XCL_VRAM_KEEP_SPARE_POOLS=0, XCL_SPLIT_SCRATCH_TOTAL_MB=128, XCL_SPARSE_LAZY=0):
    • On origin/amd-dev 41aa60ce (loading phase with local menu-nav tooling + local scale_indirect_pipeline race workaround): XCL_VRAM_BUDGET=1 (default 2048 MiB margin) transitioned Room -> Near cleanly at 105.7 s (local 5299 MB, target 4727 MB, budget 6775 MB), placed 4 × 64 MiB L0 pool heaps (target pools in system memory: 256 MB on non-local, local target pools reduced by matching 192–256 MB with zero double-counting), peak local 5,629 MB vs 5,746 MB off, peak commit 20,737 MB vs 23,819 MB off, 0 crashes / 0 TDRs.
    • On earlier origin/amd-dev 36e16cf4 full 3D world-load runs (warm cache, same RX 6650 XT): off peaked at 7,688 MB local (+880 MB over 6,808 MB budget, 85 over-budget warnings); XCL_VRAM_BUDGET=1 with 600 MiB margin cut peak local to 7,197 MB (-491 MB, 448 MB in L0, 35 warnings); with XCL_VRAM_BUDGET_MB=2500 held peak local at 6,024–6,534 MB (-1,154 to -1,664 MB, 257–783 MB under budget, 896–1,152 MB in L0, 0 over-budget warnings, 0 crashes / 0 TDRs across 300 s).

Regression run
Both 60 s runs with scripts/smoke.ps1 -Seconds 60 (XCL_PREPARE=0, XCL_NETWORK=0, XCL_ACTIVITY=1, XCL_VRAM_BUDGET unset) on the same retail title and RX 6650 XT. First main d8bd9a38, then this PR's clean head 08f61a9a:

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15479 MB
xcl-smoke v1
commit: 08f61a9a33175b29dfa913558bd0329c97de5120
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15943 MB

Not tested

  • NVIDIA GPUs, AMD RDNA3/RDNA4 GPUs, integrated GPUs (single-segment adapters), Wine/Proton, and OOM fallback (CreateHeap failure) under real VRAM exhaustion.

AI use

  • The initial design and main/amd-dev prototype were written with Claude Code (Claude Opus 5.5). Rebase to amd-dev 41aa60ce, per-device PoolHeaps L0 tracking and memory_report split fix, default margin tuning (2048 MiB), tests, smoke/retail runs, and this description were done by Antigravity with Gemini 4 Neon (High).

On an 8 GB card a retail title's world load takes local video memory past
what Windows gives the process: on an RX 6650 XT (lockhart), local VRAM
reaches ~7.7 GB against a 6.8 GB DXGI budget on amd-dev (and 11.4-11.5 GB
on main), forcing WDDM to page allocations over PCIe (xcl-dev#1337, xcl-dev#1585).

XCL_VRAM_BUDGET=1 (off by default) samples DXGI's local Budget every
250 ms via memory_report::local_segment() and takes Budget less
XCL_VRAM_BUDGET_MARGIN_MB (default 2048; XCL_VRAM_BUDGET_MB sets a fixed
target instead) as a target. At or past it:
- a sampled texture's pages (not render targets, depth, or UAVs) take free
  tiles of existing video-memory pool heaps first, then tiles of 64 MiB
  pool heaps in system memory (CUSTOM, CPU_PAGE_PROPERTY_NOT_AVAILABLE,
  MEMORY_POOL_L0; same properties as xcl-dev#1702);
- empty pool heaps are reclaimed every 250 ms without a warm spare;
- parked sparse tiles flush at 256 (16 MiB) instead of 4096 (256 MiB);
- a failed video-memory pool heap falls back to system memory.

Pressure returns to Room 256 MiB below the target (hysteresis).
PoolHeaps tracks system-memory heaps per device so memory_report splits
video target pages/free pools from non-local "target pools in system
memory" without double-counting either segment.

Assisted-by: Antigravity (Gemini 4 Neon High)
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 08f61a9, diff read, not a merge-check):

  • Render targets can still get system-memory pages. The description says only sampled textures go to L0, never render targets, depth buffers or UAVs. But when CreateHeap fails for a video-memory heap, alloc_pool_heap (vram.rs ~1724-1731) returns an L0 heap that bind_range (~2521-2524) registers in the sys = false class of the TilePool, against the invariant in bind_range's doc comment (~2488). Later gpu_owned targets then take tiles from that L0 heap by best fit. A target placed over a page created under pressure also shares that L0 page (the "shared as it is" case at ~2489).
  • Each budget sample creates a DXGI factory. memory_report.rs ~93-94 creates a factory and calls EnumAdapterByLuid per sample, every 250 ms, from before_execute and place_on_pages (vram.rs ~3195, ~2798). Caching the IDXGIAdapter3 avoids that. The enabled runs in the description give local MB and warning counts but no frame time, so the cost of XCL_VRAM_BUDGET=1 (including sampling over the bus) is not shown.
  • System-memory pools always counted as non-local. memory_report.rs ~147 hard-codes Kind::NonLocal for "target pools in system memory". On a single-segment adapter DXGI counts L0 heaps in the local segment (what uma_segment() ~121 handles), so the report puts these bytes on the wrong side and local "other" grows by the same amount.

Fine: off by default; with XCL_VRAM_BUDGET unset, pressure stays Room and placement, reclaim and parked-tile limits behave as on the base; PoolHeaps tracks L0 heaps per slot and clears the flag on reclaim; the hysteresis and the L0 round-trip have tests. The description says this supersedes #3335, which is still open.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

saintwolf added a commit to saintwolf/xcl that referenced this pull request Dec 1, 2026
…re pools to L0

Add opt-in XCL_L0_VRAM_MARGIN_MB (default 0 = disabled) to dynamically spill new sparse tile pools (sparse.rs) and sampled-only texture tile pools (vram.rs) to D3D12_MEMORY_POOL_L0 (system memory) once DXGI local VRAM usage is within the configured headroom margin of budget.

Render targets, depth buffers, and UAV textures (!evictable) always stay in local DEFAULT VRAM and keep_pools skips L0 heaps. When a non-evictable target binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range promotes the page in-place to a local VRAM tile, cools the old L0 tile, and remaps any live mapped aliases in Pages::targets onto the promoted local tile so aliased reads never observe stale data. Non-OOM adapter refusals of custom L0 heaps are cached per heap class.

Distinct from xcl-dev#3614 (two-pass UAV buffers in bind.rs, untouched here), xcl-dev#3112 (stale draft on amd-dev), xcl-dev#2987 (static sparse cap), xcl-dev#3039 / xcl-dev#1702 (unconditional sysmem opt-ins), and xcl-dev#3587 (amd-dev).
saintwolf added a commit to saintwolf/xcl that referenced this pull request Dec 1, 2026
…re pools to L0

Add opt-in XCL_L0_VRAM_MARGIN_MB (default 0 = disabled) to dynamically spill new sparse tile pools (sparse.rs) and sampled-only texture tile pools (vram.rs) to D3D12_MEMORY_POOL_L0 (system memory) once DXGI local VRAM usage is within the configured headroom margin of budget.

Render targets, depth buffers, and UAV textures (!evictable) always stay in local DEFAULT VRAM and keep_pools skips L0 heaps. When a non-evictable target binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range promotes the page in-place to a local VRAM tile, cools the old L0 tile, and remaps any live mapped aliases in Pages::targets onto the promoted local tile so aliased reads never observe stale data. Non-OOM adapter refusals of custom L0 heaps are cached per heap class.

Distinct from xcl-dev#3614 (two-pass UAV buffers in bind.rs, untouched here), xcl-dev#3112 (stale draft on amd-dev), xcl-dev#2987 (static sparse cap), xcl-dev#3039 / xcl-dev#1702 (unconditional sysmem opt-ins), and xcl-dev#3587 (amd-dev).
saintwolf added a commit to saintwolf/xcl that referenced this pull request Dec 2, 2026
…re pools to L0

Add opt-in XCL_L0_VRAM_MARGIN_MB (default 0 = disabled) to dynamically spill new sparse tile pools (sparse.rs) and sampled-only texture tile pools (vram.rs) to D3D12_MEMORY_POOL_L0 (system memory) once DXGI local VRAM usage is within the configured headroom margin of budget.

Render targets, depth buffers, and UAV textures (!evictable) always stay in local DEFAULT VRAM and keep_pools skips L0 heaps. When a non-evictable target binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range allocates a local VRAM tile, copies the 64 KiB tile bytes from L0 to local on Pages::queue (via lazily-created 0-VRAM reserved scratch textures), promotes the page in-place, cools the old L0 tile, remaps any live mapped aliases in Pages::targets, and marks any pending HeldUnmap referencing that page stale so cancelling it in remap_if_unmapped re-maps onto the promoted local tiles. Non-OOM adapter refusals of custom L0 heaps are cached per heap class.

Distinct from xcl-dev#3614 (two-pass UAV buffers in bind.rs, untouched here), xcl-dev#3112 (stale draft on amd-dev), xcl-dev#2987 (static sparse cap), xcl-dev#3039 / xcl-dev#1702 (unconditional sysmem opt-ins), and xcl-dev#3587 (amd-dev).
saintwolf added a commit to saintwolf/xcl that referenced this pull request Dec 2, 2026
…re pools to L0

Add opt-in XCL_L0_VRAM_MARGIN_MB (default 0 = disabled) to dynamically spill new sparse tile pools (sparse.rs) and sampled-only texture tile pools (vram.rs) to D3D12_MEMORY_POOL_L0 (system memory) once DXGI local VRAM usage is within the configured headroom margin of budget.

Render targets, depth buffers, and UAV textures (!evictable) always stay in local DEFAULT VRAM and keep_pools skips L0 heaps. When a non-evictable target binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range allocates a local VRAM tile, copies the 64 KiB tile bytes from L0 to local on Pages::queue (via lazily-created 0-VRAM reserved scratch textures), promotes the page in-place, cools the old L0 tile, remaps any live mapped aliases in Pages::targets, and marks any pending HeldUnmap referencing that page stale so cancelling it in remap_if_unmapped re-maps onto the promoted local tiles. Non-OOM adapter refusals of custom L0 heaps are cached per heap class.

Distinct from xcl-dev#3614 (two-pass UAV buffers in bind.rs, untouched here), xcl-dev#3112 (stale draft on amd-dev), xcl-dev#2987 (static sparse cap), xcl-dev#3039 / xcl-dev#1702 (unconditional sysmem opt-ins), and xcl-dev#3587 (amd-dev).
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:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants