Skip to content

D3D12.X: opt-in XCL_L0_VRAM_MARGIN_MB spills sparse and sampled texture pools to L0 - #3620

Open
saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:d3d12x/budget-l0-spillover
Open

saintwolf wants to merge 1 commit into
xcl-dev:mainfrom
saintwolf:d3d12x/budget-l0-spillover

Conversation

@saintwolf

@saintwolf saintwolf commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

On 12 GiB non-UMA discrete GPUs during heavy world loads, sparse tile pools (sparse.rs) and sampled-only texture tile pools (vram.rs) can push local VRAM over the DXGI budget, forcing WDDM to evict render targets, depth buffers, and hot arenas across PCIe / into the pagefile.

This PR adds a single opt-in DXGI budget-headroom control (XCL_L0_VRAM_MARGIN_MB, default 0 = disabled) that dynamically spills new sparse tile pools and sampled-only (!gpu_owned) texture tile pools into D3D12_MEMORY_POOL_L0 (system memory) only when DXGI local VRAM usage is within the configured headroom margin of budget.

Relation to existing PRs

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs:
    • XCL_L0_VRAM_MARGIN_MB (parse_l0_vram_margin_bytes, default 0 = disabled), vram_within_margin, and 250 ms cached should_spill_l0_for_vram() using super::real::video_memory().
    • L0_TEX_HEAP_UNSUPPORTED / note_l0_heap_error: caches non-OOM CreateHeap L0 refusals per heap class so unsupported adapters go straight to DEFAULT.
    • alloc_pool_heap: sampled-only (evictable) 64 MiB texture pools spill to D3D12_MEMORY_POOL_L0 (D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS) when within margin, with clean fallback to DEFAULT (and DEFAULT -> L0 fallback when XCL_L0_VRAM_MARGIN_MB > 0). When XCL_L0_VRAM_MARGIN_MB is unset/0, behavior and TilePool allocation classes are identical to main.
    • In-place L0 -> local promotion (bind_range + remap_promoted): PoolHeaps::is_l0 tracks L0 heaps and keep_pools skips them. When a non-evictable target (RT/DS/UAV) binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range allocates a local VRAM tile, promotes p.tile in-place, cools the old L0 tile, and calls remap_promoted to re-map every live mapped resource in Pages::targets referencing that page onto the promoted local tile — preserving 100% shared page identity with zero stale aliased reads.
    • Unit tests:
      • l0_vram_margin_parses_opt_in_default_and_checks_budget (parsing, budget boundaries, texture_pool_heap_desc).
      • pool_heaps_tracks_l0_flag_across_slot_reuse_and_l0_heap_creates (slot reuse + hardware D3D12 L0 texture and L0 buffer CreateHeap).
      • l0_page_promotes_in_place_to_local_when_target_binds_same_va (real hardware D3D12 bind_range test: binds a reserved sampled texture onto an L0 pool, then binds a reserved RT at the exact same VA, verifying in-place promotion to local VRAM, users == 2, zero extra_pages split, old L0 tiles cooled, and device health).
  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • Reuses vram::l0_vram_margin(), vram::should_spill_l0_for_vram(), and vram::note_l0_heap_error with its own L0_SPARSE_HEAP_UNSUPPORTED flag to spill new 4 MiB sparse tile pools (D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES) to L0 when within the DXGI headroom margin, skipping set_heap_priority on L0 heaps.

Tested

  • Hardware: NVIDIA GeForce RTX 4070 SUPER (12 GiB, driver 32.0.16.2140), AMD Ryzen 7 7800X3D, 31.1 GB RAM, Windows 11 build 26300, rustc 1.100.0, DXC 1.8.2502.11.
  • cargo test -p xcl --lib -- l0_vram_margin_parses_opt_in_default_and_checks_budget pool_heaps_tracks_l0_flag_across_slot_reuse_and_l0_heap_creates l0_page_promotes_in_place_to_local_when_target_binds_same_va --nocapture --test-threads=1 on 476983d4: 3 passed, 0 failed, 0 skipped.
  • cargo test -p xcl --lib hle::d3d12x::vram::tests -- --test-threads=1 and sparse::tests: 213 passed, 0 failed (plus full workspace test check by reviewer on prior head: 2,911 passed, 0 failed).

Regression run
Matched 60 s smoke runs with identical settings (XCL_DIRECT_DXIL=1, default XCL_PSO_PRELOAD, smoke.ps1 default XCL_PREPARE=0):

main (f07e426d):

xcl-smoke v1
commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1668 (PresentX 1668)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16731 MB

this PR (476983d4, default XCL_L0_VRAM_MARGIN_MB unset):

xcl-smoke v1
commit: 476983d49ad441e3bff6364ee5b3426eaa163405
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16006 MB

this PR (476983d4, active spillover path with XCL_L0_VRAM_MARGIN_MB=12288):

xcl-smoke v1
commit: 476983d49ad441e3bff6364ee5b3426eaa163405
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1668 (PresentX 1668)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16566 MB

Not tested

  • AMD / Intel GPUs, Linux / Wine (vkd3d-proton), and full workspace test suite locally on 476983d4 (covered by CI).

AI use

  • Antigravity (Gemini 4 Neon) assisted with designing the unified DXGI-headroom L0 spillover and in-place L0 -> local page promotion + alias remapping, writing the hardware D3D12 bind_range promotion test, running unit tests and matched default + active-spillover smokes, and drafting this description. Reviewed by me.

@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 c42d20c, diff read, not a merge-check):

  • With the variable set, targets and textures at one address stop sharing memory. In bind_range (vram.rs ~2036, ~2345, ~2384), a render target, depth buffer or UAV placed over a sampled texture whose page went to an L0 heap gets its own tile in extra_pages instead of the title page. And once XCL_L0_VRAM_MARGIN_MB is set, a sampled texture and a target at the same va get different extra_pages keys (local_only false vs true, ~2336), so their extra tiles are no longer shared even when nothing has spilled. A title that writes a target and reads the same memory through a texture alias (what placements remaps for, and what shared_page_identity_is_the_title_address_not_allocation_class ~4418 guards) then reads stale data.
  • No test covers the new page-sharing logic. The new tests check the helpers (parse_l0_vram_margin_bytes, vram_within_margin, texture_pool_heap_desc, can_share_own_page, PoolHeaps) and create L0 heaps (~5899, ~5935), but nothing calls bind_range with an L0 pool, places two resources at one address, or maps a reserved texture onto an L0 heap.
  • The whole suite was not run. Tested lists only the vram::tests and sparse::tests filters and leaves the rest to CI, which has no GPU.
  • Overlaps open PRs not mentioned. D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget #3587 (on amd-dev) samples the DXGI budget every 250 ms and moves new sampled-texture pool heaps to L0, never targets, with is_sys tracking in PoolHeaps; D3D12.X: allow title texture pages in system memory #1702 (on main) moves texture page pools to L0 behind an opt-in.

Fine: with XCL_L0_VRAM_MARGIN_MB unset every caller passes evictable = false and every extra_pages key is (va, i, true), so the default path is as on main; lazily mapped level textures only reach the L0 path with Flags == NONE, and keep_pools skips L0 heaps.

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

@saintwolf
saintwolf force-pushed the d3d12x/budget-l0-spillover branch from c42d20c to 3008ae0 Compare December 1, 2026 22:35
@saintwolf

Copy link
Copy Markdown
Contributor Author

Updated to 3008ae08 (single commit, both default and active-spillover 60 s smokes re-run on 3008ae08):

  • Preserved local extra_pages sharing: Added extra_page_key so targets (!evictable) and sampled textures share (va, i, false) whenever that slot is unmapped or backed by local VRAM, and only split to (va, i, true) if the existing tile is actually backed by an L0 heap (where D3D12's DENY_RT_DS_TEXTURES requires a local tile). Added unit assertions for extra_page_key.
  • Related PRs: Added #3587 (amd-dev) and #1702 to the PR description.

The remaining points (full workspace suite beyond CI and vram/sparse module suites, and additional synthetic bind_range fixtures beyond the unit tests + live XCL_L0_VRAM_MARGIN_MB=12288 smoke) are documented under Not tested; leaving this ready for human maintainer review.

AI use: Antigravity (Gemini 4 Neon) applied the extra_page_key tweak, ran the head smokes, and drafted this reply.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 3008ae0, since c42d20c, diff read, not a merge-check):

  • Targets and textures at one address stop sharing memory: partly fixed. The new extra_page_key (vram.rs ~2040-2046, used at ~2353 and ~2394) keeps targets and sampled textures on one (va, i, false) extra tile unless that tile is in an L0 heap, so nothing splits while nothing has spilled. Once a sampled texture's page is in L0, a target at the same address still gets its own tile, both for the own page (can_share_own_page, ~2037) and for the extra page ((va, i, true)), so a title that renders to that memory and samples it through the texture alias still reads stale data whenever the spill path is taken. After the L0 page is released and swept, a later target at that address gets a fresh (va, i, false) tile while the earlier target keeps (va, i, true), so two targets can also diverge.
  • No test covers the page-sharing logic: partly fixed. extra_page_key has a unit test of the key choice, but nothing still calls bind_range with an L0 pool or places two resources at one address.
  • The whole suite was not run: still open; Tested lists the vram::tests and sparse::tests filters and two named tests, and leaves the rest to CI, which has no GPU.
  • Overlaps D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget #3587 / D3D12.X: allow title texture pages in system memory #1702: addressed; the description now explains how this differs.

New: none. The new smoke block runs with XCL_L0_VRAM_MARGIN_MB=12288, so it reaches the spill path.

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

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels 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).
@github-actions github-actions Bot removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 1, 2026
@saintwolf
saintwolf force-pushed the d3d12x/budget-l0-spillover branch from 3008ae0 to 476983d Compare December 1, 2026 23:15
@saintwolf

Copy link
Copy Markdown
Contributor Author

Fixed the aliased target/texture sharing issue cleanly in 476983d4 (single commit, both default and active-spillover 60 s smokes re-run on 476983d4):

  • In-place L0 -> local page promotion (bind_range + remap_promoted): Reverted extra_pages back to (usize, usize) (removing all splitting). When a non-evictable target (RT/DS/UAV) binds a console page currently backed by an L0 heap (DENY_RT_DS_TEXTURES), bind_range allocates a local VRAM tile, promotes p.tile in-place, cools the old L0 tile, and calls remap_promoted to re-map every live mapped alias in Pages::targets onto the promoted local tile before the next submit — so targets and sampled aliases at the same console address always share the exact same physical local tile and never read stale data.
  • Real hardware D3D12 bind_range test: Added l0_page_promotes_in_place_to_local_when_target_binds_same_va which seeds an L0 pool, binds a reserved sampled texture onto L0, then binds a reserved render target at the exact same VA, verifying in-place local promotion, users == 2, zero extra_pages split, old L0 tiles cooled, and device health (3/3 L0 tests passed on RTX 4070 SUPER).

AI use: Antigravity (Gemini 4 Neon) implemented the in-place L0 -> local promotion, added the hardware bind_range test, ran the head smokes, and drafted this reply.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 476983d, since 3008ae0, diff read, not a merge-check):

  • Targets and textures at one address stop sharing memory: fixed for live aliases. extra_pages is back to one (va, i) key; when a target binds a page held in an L0 heap, bind_range (vram.rs ~2384-2453) moves the page to a new local tile and remap_promoted (~2313) points every mapped alias at it, so target and texture keep one tile and two targets cannot drift apart after a sweep. The two new points below are gaps in that promotion.
  • No test covers the page-sharing logic: fixed. l0_page_promotes_in_place_to_local_when_target_binds_same_va (~6046) binds a sampled texture onto an L0 pool and then a render target at the same address through bind_range; it checks the bookkeeping, not the alias's actual mapping, and the extra-page and level-group paths are untested.
  • The whole suite was not run: still open; the 2,911-pass count is from a reviewer on an earlier head and Not tested leaves this head's full suite to CI, which has no GPU.

New:

  • Promotion throws away what the page held. At ~2417-2421 and ~2440-2445 the page gets a new tile from take_batch and the L0 tile goes to cooling, but nothing copies the L0 tile's contents across. The target placed over the texture and the sampled alias remap_promoted moves both start from whatever the recycled tile last held instead of the uploaded texels; on main they share one tile and the texels stay. register_gpu_owned marks the entry gpu_written, so nothing uploads them again.
  • A cancelled deferred unmap brings back the old L0 tile. remap_promoted skips targets with !t.mapped (~2316), which includes a sampled texture whose unmap is waiting in held_unmaps. If remap_if_unmapped then cancels that unmap (~2781-2795), it gives the page keys back without calling map, assuming a deferred unmap never changed the resource's tiles, so that texture stays mapped to the old L0 tile, which returns to the pool after COOL and can be handed to another resource. Narrow window (a sampled texture superseded at that address with its unmap still pending).

Fine: with XCL_L0_VRAM_MARGIN_MB unset the extra key is (va, i) and every caller passes evictable = false, as on main; non-evictable pool heaps are never created in L0, so a promoted tile is always local; missing counts the promoted pages; before_execute orders the remap before the next title work.

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

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