Skip to content

D3D12.X: add opt-in XCL_SPARSE_VRAM_CAP_MB to overflow sparse pools to L0 system memory - #3112

Draft
iggyvilla wants to merge 1 commit into
xcl-dev:amd-devfrom
iggyvilla:amd-sparse-vram-cap
Draft

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

Conversation

@iggyvilla

@iggyvilla iggyvilla commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Adds opt-in XCL_SPARSE_VRAM_CAP_MB=<N> (unset: no change). Once N MiB of sparse pool heaps live in local video memory, further 4 MiB sparse pools are allocated as D3D12_HEAP_TYPE_CUSTOM (write-back, MEMORY_POOL_L0) system memory, keeping an 8 GB card under its DXGI local budget when sparse pools grow large. If CreateHeap for an L0 pool fails, a DEFAULT pool is made as before.

TL;DR — Before vs After

Scenario Metric Before (cap unset) After (PR #3112) Delta
60 s smoke (41aa60ce, cap unset) Frames shown / Peak commit 1,618 / 15,479 MB (main d8bd9a38) 1,643 / 15,430 MB (a0f65e2f) +1.5% frames / 0.997x commit
RX 7800 XT retail run (XCL_SPARSE_VRAM_CAP_MB=1024, moombathepilot) Peak local sparse pools / Peak local VRAM 2,236 MB / 6,896 MB 1,024 MB / 5,784 MB −1,212 MB sparse / −1,112 MB local VRAM
L0 visibility & test coverage (vs b0077129) memory_report & GPU overflow test Hidden from memory_report; no overflow test "sparse pools in system memory" on NonLocal + GPU test Review items resolved

Rebased onto amd-dev 41aa60ce (replacing b0077129): resolves the retired tuple conflict, exposes L0 sparse pools in memory_report.rs, and adds unit + GPU tests covering parsing, L0 overflow allocation, retired-pool kind matching, and split memory reporting.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: parse_sparse_vram_cap_pools / sparse_vram_cap_pools, State::pool_is_sys (parallel to pools), retired entries carry is_sys so retired pools are only reused for the same kind, take_tile_with_cap overflows past the cap to CUSTOM/L0 with DEFAULT fallback, pool_bytes() counts only local VRAM pools/tiles, State::memory_bytes / memory_bytes_for splits local VRAM pools from L0 system-memory pools, plus unit (sparse_vram_cap_parses_pool_counts) and GPU (sparse_vram_cap_overflows_to_l0_and_reports_separately) tests.
  • crates/xcl/src/hle/d3d12x/memory_report.rs: reports "sparse pools in system memory" on Kind::NonLocal and updates device_snapshot_has_budget_and_all_owners.
  • Related, not the same: D3D12.X: sparse tiles outside the GPU heaps can live in system memory #2987 puts non-GPU-heap sparse tiles in system memory by what a range holds (XCL_SPARSE_SYSMEM, targets main); D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget #3587 (XCL_VRAM_BUDGET) targets texture page pools by DXGI budget headroom; this PR is an explicit MiB cap for sparse buffer pools on amd-dev.

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), debug test build on origin/amd-dev 41aa60ce + this commit.
  • cargo test -p xcl --lib -- hle::d3d12x::sparse:: hle::d3d12x::memory_report --test-threads=4: 156 passed, 1 failed (sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, pre-existing on origin/amd-dev 41aa60ce), 1 ignored, 0 SKIPPED. Both new tests (sparse_vram_cap_parses_pool_counts and GPU overflow/retirement/accounting test sparse_vram_cap_overflows_to_l0_and_reports_separately) pass, as does memory_report::tests::device_snapshot_has_budget_and_all_owners.
  • Earlier retail runs on 7c795f5e (RX 6650 XT, 3 × 600 s, cap 1024 MB) and RDNA3 (moombathepilot, RX 7800 XT, cap 1024 MB: local sparse pools capped at 1,024 vs 2,236 MB, peak local VRAM 5,784 vs 6,896 MB) exercised the L0 overflow path in-game. On 41aa60ce, the 60 s smoke below covers the unset (no-change) path and the GPU test above covers the L0 overflow + retirement + memory_report split path.

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

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: a0f65e2f2b54cdee2d2b19f3429625a398459290
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15430 MB

Not tested

  • cargo test --workspace on this commit (targeted sparse + memory_report suite run instead), NVIDIA GPUs, RDNA4, Wine/Proton, and retail world soak with XCL_SPARSE_VRAM_CAP_MB set on 41aa60ce.

AI use

  • The first version (against 7c795f5e) was written and tested by Antigravity with Gemini 4 Neon (High). The port to f33df5a7 was done by Claude Code (Claude Sonnet 5.5). This rebase to amd-dev 41aa60ce, memory_report L0 reporting, unit + GPU overflow tests, smoke run, and description update were done by Antigravity with Gemini 4 Neon (High).

@JJAutoCompare

Copy link
Copy Markdown

Tested

Exact 5ca76771ad326f8df7f68731bd7fa8112883ef2a on the amd-dev PR, Windows 11 x64 build 26200.9974, Ryzen 7 3800X, and Rust 1.100.1 MSVC. I reran the pinned standalone CPU harness after verifying that TILE, POOL_TILES, and sparse_vram_cap_pools matched the Git source byte-for-byte. The harness used a print-only stand-in for xlog_info!.

I ran sparse_cap.exe --exact fresh_process_cap --nocapture --test-threads=1 once per setting in 12 fresh processes with child-only environments. Each process returned the same result on its second call.

XCL_SPARSE_VRAM_CAP_MB Result
Unset, empty, invalid, -1, 4.5 None
0, 3 Some(0)
4, 7 Some(1)
8 Some(2)
1024, space-padded " 1025 " Some(256)

The process readbacks distinguished Err(NotPresent) from Ok("") and showed both spaces in " 1025 ". 12 passed, 0 failed, 0 ignored, 0 runtime skips. Every native process exited 0 with zero tests filtered out.

Not tested

Device or GPU behavior, heap allocation or fallback, tile mapping, VRAM accounting, production logging, performance, retail smoke, and the full suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified the source and executable, reran the cases, and wrote this report.

@moombathepilot

Copy link
Copy Markdown

RX 7800 XT comparison

I compared release builds of the latest amd-dev (7c795f5eefa0661eaf3f9f696d0cba3a75ce9628) and this PR (5ca76771ad326f8df7f68731bd7fa8112883ef2a), whose parent is that amd-dev commit. Both source trees were clean. Neither build included the local XG compatibility patch.

Hardware: RX 7800 XT, AMD driver 32.0.32029.2010, Ryzen 7 5700X3D, 64 GiB RAM, Windows 11 build 26300.9974. I used separate title-data folders and separate copies of the same starting warm DXIL cache. There was one run per revision.

Common settings: XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RT_GATE=miss XCL_PRESS_A_AT=20,24,30,45,60,90,120,150,180,210,240,270 XCL_RUN_SECONDS=300 XCL_PIPELINE_MAX_KB=1150 XCL_PSO_MAX_KB=1150 XCL_DRED=1 XCL_PREPARE=0 XCL_COHERENT_CAP_MB=2048 XCL_TEXTURE_LEVEL_PAGES=1. Each run also set XCL_DATA_ROOT and XCL_DXIL_CACHE to its own folder. XCL_SPARSE_VRAM_CAP_MB was unset on the amd-dev baseline and 1024 on the PR. Both logs confirmed a 2,048 MB coherent window and the first scripted A press at 20.003 s.

Measure amd-dev baseline (cap unset) PR #3112 (1,024 MB cap)
Peak reported local sparse pools 2,236 MB 1,024 MB
Peak local video memory 6,896 MB 5,784 MB
Peak non-local video memory 2,792 MB 4,041 MB
Peak process commit 21,440 MB 21,338 MB
Presents counted 2,289 2,039
Last interval with a present 200.238 s 198.947 s
Last console code so far 24,132 draws (512 skipped), 3,057 dispatches (0 skipped) 21,085 draws (513 skipped), 2,871 dispatches (0 skipped)
Exit 0xe06d7363; stack includes xboxbvhbuilder.dll+0xd2538 Same
Device removal / DRED removal None None

The PR log confirms the cap setting and reports local sparse pools staying at 1,024 MB. The drop in local video memory and rise in non-local use are consistent with overflow to system memory. These counters do not directly count L0 heaps. Both runs ended at the same earlier BVH builder exception, so this test shows the memory cap taking effect on RDNA3, not improved world-load progress. With one run per revision, I cannot attribute the frame-count difference to the PR.

cargo test -p xcl --lib hle::d3d12x::sparse:: -- --test-threads=4 on the PR: 39 passed, 0 failed, 1 ignored. I did not run the full workspace suite or scripts/smoke.ps1.

Driver compile starts without a logged finish at exit: amd-dev baseline, one MS PSO (339,108 B DXIL); PR, two MS PSOs (376,292 B and 265,320 B DXIL). Those start lines contain no hashes and do not establish a driver hang.

AI use: OpenAI Codex (GPT-6) verified the commits, prepared the builds and runs, analyzed the logs, and drafted this report. I ran the test on my PC.

@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) gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) and removed gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Triage (#1607) – head a0f65e2

Related, not the same: #2987 (against main) puts sparse tiles outside the title's GPU heaps into L0 system-memory pools (XCL_SPARSE_SYSMEM), choosing by what a range holds. This PR caps video-memory sparse pools by size on amd-dev. The change is not on amd-dev yet.
No correctness problems found in sparse.rs. pool_is_sys is kept alongside pools, retired heaps are reused only for the same kind, and pool_bytes leaves L0 pools out. sparse_vram_cap_overflows_to_l0_and_reports_separately now covers the L0 overflow path (take_tile_with_cap), reuse of a retired L0 pool, and the separate byte counts.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head b007712, diff read, not a merge-check; draft, base amd-dev, conflicts with it):

  • Pools past the cap go to system memory whatever they hold, and never move back. Placement is first-come: GPU-written buffers can land in L0 and are then read and written over PCIe. Render targets can't, since the heaps are buffer-only (sparse.rs ~1554). moombathepilot's RDNA3 run had fewer frames, but with one run per side it can't be put on the PR.
  • L0 use is invisible. pool_bytes (~1226) leaves L0 pools out, and nothing else reports them.
  • No test covers the overflow path, and NVIDIA is untested. It conflicts with amd-dev, where the retired tuple changed shape (~2746 there).
  • The red CI comes from the base: release_tests::the_last_release_drops_entries_before_the_object_goes and exit 0x887a0005 fail the same way on D3D12.X: drop CopyScratch resources outside COPY_SCRATCH lock and skip own-work reset hooks #3111 at the same base f33df5a. The description check fails on peak commit, which the author shows is amd-dev's own number.

Fine: off when unset (parsing checked by JJAutoCompare), retired heaps are reused only for the same kind, and a failed L0 heap creation falls back to video memory. #3335 / #3039 put texture levels in system memory, a different path; #2987 (main) overlaps in what it does.

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

…o L0 system memory

With XCL_SPARSE_VRAM_CAP_MB=<N> set (unset: no change), sparse pool heaps
past N MiB of local video memory are allocated in custom L0 write-back
system memory. Video-memory pool counts exclude L0 pools, and
memory_report exposes them on the non-local side as "sparse pools in
system memory". Retired pool reuse matches the heap kind, and a failed
L0 heap allocation falls back to video memory.

Assisted-by: Antigravity (Gemini 4 Neon High)
@iggyvilla
iggyvilla force-pushed the amd-sparse-vram-cap branch from b007712 to a0f65e2 Compare December 1, 2026 17:13
@iggyvilla

Copy link
Copy Markdown
Collaborator Author

Rebased onto amd-dev 41aa60ce (a0f65e2f) addressing the review points:

  • Resolved the sparse.rs retired tuple merge conflict.
  • Exposed L0 sparse pools in memory_report.rs as "sparse pools in system memory" on Kind::NonLocal (while keeping video-memory counts local-only).
  • Added unit test sparse_vram_cap_parses_pool_counts and GPU test sparse_vram_cap_overflows_to_l0_and_reports_separately covering L0 overflow allocation, retired-pool kind matching, and split accounting.
  • Refreshed the 60 s smoke.ps1 regression run (1,643 frames, 15,430 MB peak commit — now under main's 15,479 MB).

Note: first-come placement past the cap remains intentional for this opt-in MiB cap (workload-aware placement is tracked separately by #2987 and #3587).

@github-actions github-actions Bot added the gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) label Dec 1, 2026
@github-actions github-actions Bot removed the gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) label Dec 1, 2026
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, never share L0-backed pages (isolated via ExtraKey = (va, tile_index, local_only)), and keep_pools skips L0 heaps. Non-OOM adapter refusals of custom L0 heaps are cached per heap class so subsequent allocations go straight to DEFAULT.

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), and xcl-dev#3039 (unconditional streamed texture sysmem).
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, never share L0-backed pages (isolated via ExtraKey = (va, tile_index, local_only)), and keep_pools skips L0 heaps. Non-OOM adapter refusals of custom L0 heaps are cached per heap class so subsequent allocations go straight to DEFAULT.

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), and xcl-dev#3039 (unconditional streamed texture sysmem).
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).
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.

4 participants