Skip to content

D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory - #3039

Open
treybertram06 wants to merge 2 commits into
xcl-dev:mainfrom
treybertram06:nv-texture-levels-sysmem
Open

treybertram06 wants to merge 2 commits into
xcl-dev:mainfrom
treybertram06:nv-texture-levels-sysmem

Conversation

@treybertram06

@treybertram06 treybertram06 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Target: main (opened against nvidia-dev, which #3203 merged into main; rebased onto main d52ff48c). Stacked on #2987; only the top commit belongs here. Part of #2688. Related: #1702.

With XCL_TEXTURE_LEVEL_PAGES=1, a streamed texture's levels get video memory pages as their texels arrive. On a 10 GB card a retail world holds 1.5–2 GB of them, beside about 3 GB of render targets and the title's other GPU memory, past the budget Windows gives the process, which then pages whatever it likes.

XCL_TEXTURE_SYSMEM=1 (off by default; only with level pages) gives those levels pages from pool heaps in system memory (custom heaps, MEMORY_POOL_L0, write-back), which the GPU samples over PCIe. Render targets and every other texture keep video memory, since they're written every frame. #1702 moves all texture page pools instead, render targets included.

What is in it

  • D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory (hle/d3d12x/vram.rs):
    • bind_range_in takes new pages from the system-memory pools for lazy levels. Since the rebase it passes on main's evictable packing class too;
    • a page of those heaps has SYS_TILE in its heap index, and freed ones cool in their own pool (cool);
    • map resolves either heap.
  • New test a_system_memory_page_is_told_apart_and_cools_in_its_own_pool.

Tested

  • RTX 3080 10 GB (driver 621.40), Ryzen 9 5900X, 64 GB RAM, Windows 11 26300, NVIDIA profile with the 2 GiB shader heap for xcl.exe. Debug tests, release title runs.
  • cargo test --workspace --no-fail-fast -- --test-threads=4, with XCL_DXC_DIR set to DXC 1.9, at this PR's head 97715129: 2880 passed, 1 failed, 51 ignored.
    • The one failure, gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, also fails on main d52ff48c without this change (2876 passed, 1 failed, 51 ignored there).
    • 24 SKIPPED: 22 no wave64, 2 no heap windows. The same on main.
  • cargo test -p xcl --lib vram -- --test-threads=4: 73 passed, 0 failed, 1 ignored.
  • throny's merge-check on the old head had one extra failure, gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark (out of memory with GPU tests side by side, then passed on reruns). It passed in the full run above.
  • Retail title, release build, 610 s, at 7cce7d3d (before the rebase; not rerun since), XCL_COHERENT_HEAPS=sparse XCL_SPARSE_SYSMEM=1 XCL_TEXTURE_LEVEL_PAGES=1 XCL_TEXTURE_SYSMEM=1 XCL_PREPARE_WORKERS=6, scripted presses. Over the 400 s after the menus: 1.35 presents/s, video memory at the end 11.9 GB local / 8.9 GB non-local (budget 9.0 GB), commit 41.3 GB, no device removal.

Regression run
Base, a commit of main: d52ff48c. smoke.ps1 now sets XCL_PREPARE=0, so main's launch preparation gate no longer holds the run, and the base is current main again. The switch is off in both runs. A 60 s warm-up run of main came first.

xcl-smoke v1
commit: d52ff48caade1f5350d513bfffd370396dadfeb6
gpu: NVIDIA GeForce RTX 3080
title: 4ba6c38e
seconds: 60
exit: 0x0
frames shown: 1578 (PresentX 1578)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15677 MB

This PR's head:

xcl-smoke v1
commit: 97715129a6df100b489ff8d8b59c9438a90e2952
gpu: NVIDIA GeForce RTX 3080
title: 4ba6c38e
seconds: 60
exit: 0x0
frames shown: 1581 (PresentX 1582)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16884 MB

Not tested

  • AMD and Intel GPUs.
  • Other titles.
  • Sessions longer than 610 s on this head (900 s with the prototype).
  • The system-memory pool heaps are never given back (the video-memory ones are, reclaim_empty_heaps).
  • No GPU fixture that samples a level from a system-memory page.

AI use

  • Claude Code with Claude Opus 5.5. It measured the placement, wrote the code, the test and this description, and ran the tests and title runs. The author reviewed the diff.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent RTX 3080 Ti check on #3039 head 7cce7d3d.

The PR already notes that empty system-memory pool heaps are retained. I reproduced that in a focused D3D12 test: with one tile live, a fully free 64 MiB L0 heap was not reclaimed after a sweep. After the final tile cooled, another empty L0 heap was still retained. The regression failed on the untouched head and passed with the candidate below. The change reclaims empty sys_pool slots, takes their handles from sys_pools, and sends them through the existing queue-fence retirement batch. The local VRAM heap with the same numeric slot remains live.

Tested: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti 12 GB / driver 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11. With XCL_TEXTURE_LEVEL_PAGES=1 and XCL_TEXTURE_SYSMEM=1, cargo build --workspace passed on the candidate. cargo test --workspace --no-fail-fast -- --test-threads=4 on the untouched head: 1,823 passed, 13 failed, 48 ignored, 26 GPU SKIPPED notices. On the isolated candidate build after cargo build --workspace: 1,824 passed, the same 13 failed, 48 ignored, 26 GPU skip notices. The failure names match exactly; the extra pass is the new reclaim regression. The existing 11-mip synthetic texture GPU fixture passed, including byte-exact copy readback. A temporary assertion confirmed its mapped tiles carried SYS_TILE, rather than silently falling back to VRAM; that assertion is omitted from the diff because the fixture also runs with the switch off.

Source-review note: the statement that render targets keep VRAM has an alias exception. If a streamed level first maps a page in L0, a later render target at the same title page reuses that tile; the reverse order retains VRAM. This preserves page aliasing. I would qualify the description as “new pages use the selected pool; aliases keep their first backing,” and test both placement orders before promising strict render-target VRAM placement. I did not measure an in-game performance effect of this case.

The candidate is local and uncommitted. A real title smoke pair, AMD/Intel coverage, and shader sampling from an L0-backed level remain to be checked on a clean author commit. AI use: Codex (GPT-6.2 Sol) wrote and ran the regression/candidate and this report; Codex (GPT-6.2 Astra) independently reviewed the alias and fence-lifetime paths.

Candidate diff: reclaim cooled system-memory heaps and cover the pool boundary
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 2e6566b5..17dcf103 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -753,6 +753,20 @@ impl Pages {
                 self.pools.len()
             );
         }
+        let sys_ids = self.sys_pool.reclaim_empty_heaps(keep_spare_pools(), POOL_PAGES);
+        let sys_count = sys_ids.len();
+        for idx in sys_ids {
+            if let Some(h) = self.sys_pools.take_heap(idx) {
+                dropped.push(h);
+            }
+        }
+        if sys_count > 0 {
+            let mb = (sys_count * POOL_PAGES as usize * PAGE) >> 20;
+            crate::xlog_info!(
+                "D3D12.X: reclaimed {sys_count} empty 64 MiB system-memory pool heap(s) ({mb} MiB; {} pools active)",
+                self.sys_pools.len()
+            );
+        }
         dropped
     }
 
@@ -1763,6 +1777,59 @@ mod tests {
         assert_eq!((pool.free_total, sys_pool.free_total), (free + 1, sys_free + 1), "each back in its own pool");
     }
 
+    #[test]
+    fn cooled_system_memory_pool_heaps_are_reclaimed_independently() {
+        let _guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+        use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+        use windows::Win32::Graphics::Dxgi::*;
+        unsafe {
+            let factory: IDXGIFactory4 = CreateDXGIFactory1().expect("DXGI factory");
+            let Ok(adapter) = factory.EnumAdapters1(0) else {
+                return crate::gpu::recomp::runner::skip_test("no adapter");
+            };
+            if adapter.GetDesc1().is_ok_and(|d| d.Flags & DXGI_ADAPTER_FLAG_SOFTWARE.0 as u32 != 0) {
+                return crate::gpu::recomp::runner::skip_test("software adapter");
+            }
+            let mut device: Option<ID3D12Device> = None;
+            let _ = D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_11_0, &mut device);
+            let Some(device) = device else {
+                return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+            };
+            let Some(mut pages) = Pages::new(&device) else {
+                return crate::gpu::recomp::runner::skip_test("tiled resources tier < 2");
+            };
+            let spare = keep_spare_pools();
+            if spare > 4 {
+                return crate::gpu::recomp::runner::skip_test("test's 64 MiB heap budget exceeded by keep-spare setting");
+            }
+            let Some(local) = alloc_pool_heap(&device) else {
+                return crate::gpu::recomp::runner::skip_test("cannot allocate local pool heap");
+            };
+            let local_slot = pages.pools.push_heap(local);
+            pages.pool.add_heap_at(local_slot, POOL_PAGES);
+            let t0 = Instant::now();
+            let local_tile = pages.pool.take_batch(1, None, t0, POOL_PAGES, || None).unwrap()[0];
+            for _ in 0..spare + 2 {
+                let Some(heap) = alloc_sys_pool_heap(&device) else {
+                    return crate::gpu::recomp::runner::skip_test("cannot allocate system pool heap");
+                };
+                let slot = pages.sys_pools.push_heap(heap);
+                pages.sys_pool.add_heap_at(slot, POOL_PAGES);
+            }
+            let sys_tile = pages.sys_pool.take_batch(1, None, t0, POOL_PAGES, || None).unwrap()[0];
+            let first = pages.sweep_and_reclaim(t0);
+            assert_eq!(first.len(), 1, "one fully free system heap retires while another has a live tile");
+            assert_eq!(pages.sys_pools.len(), spare + 1);
+            assert_eq!(pages.pools.len(), 1, "the same-index local heap stays live");
+            pages.sys_pool.push_cooling(sys_tile, t0);
+            let second = pages.sweep_and_reclaim(t0 + COOL + Duration::from_millis(1));
+            assert_eq!(second.len(), 1, "another empty heap retires after the last tile cools");
+            assert_eq!(pages.sys_pools.len(), spare);
+            assert_eq!(pages.pools.len(), 1);
+            assert!(pages.pool.live[local_tile.0 as usize]);
+        }
+    }
+
     /// The levels of a texture with lazy levels: a group of tiles for each level with tiles of its
     /// own and one for the packed levels; a level past the last standard one is in the packed
     /// group; a tiling that does not add up to the resource's tiles gives none.

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked shader reads from the system-memory level pages on RTX 5070 / NVIDIA 616.92 at head 7cce7d3d4625ac8f90f146f1f89f25a613e32e76. A test-only extension of the existing native level-pages fixture used a 1024×1024 RGBA8 texture with 11 mip levels and explicit 2D views. Both cases enabled XCL_TEXTURE_LEVEL_PAGES=1; the same binary ran in fresh processes with XCL_TEXTURE_SYSMEM=1 and 0 (in that order).

  • System-memory case: all 86 referenced tiles carried SYS_TILE, and their native heap descriptions reported D3D12_MEMORY_POOL_L0.
  • Local control: all 86 referenced tiles used XCL's local pool, with no system-memory tags.
  • In both cases, SampleLevel(1) returned the expected value 48 for all 2,048 pixels of its half, and Load from mip 0 returned 25 for all 2,048 pixels of the other half. Both focused runs passed without skips.

This establishes shader-visible contents in this synthetic fixture and verifies the backing heap descriptions. It does not measure physical residency, PCIe traffic, frame time, or retail memory savings.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the checks; Codex reviewed and prepared this report.

@Anon64

Anon64 commented Nov 27, 2026

Copy link
Copy Markdown

RTX 3060 12 GB (NVIDIA), this PR's head 7cce7d3d, retail title, 300 s: with XCL_TEXTURE_SYSMEM=1, peak local video memory falls from 12 967 MB to 10 362 MB, so it fits on the card. It's the only run on this card so far that stays under 12 GB.

Same build, both runs with XCL_TEXTURE_LEVEL_PAGES=1, release, XCL_ACTIVITY=1, A pressed every 4 s from 20 s, warm caches, one run each.

XCL_TEXTURE_SYSMEM off XCL_TEXTURE_SYSMEM=1
end exit 0x0 exit 0x0
frames 1 783 1 738
last present ~137 s ~214 s
peak commit 36 592 MB 39 487 MB
peak local video memory 12 967 MB 10 362 MB
peak non-local 5 720 MB 8 370 MB

About 2.6 GB moves from local to non-local, and process commit goes up by about 2.9 GB. Frame counts are about the same. In neither run does presenting go past world load. In earlier runs on this card that stop came from title-thread driver compiles (#2595), so the later last present with the switch on may not be due to the switch. Neither run had device removals or crashes.

For comparison, the nvidia-dev tip e0821b12 without level pages peaked at 16 840 MB local on this card.

RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200.

AI use: Claude Code (Claude Opus 5.5) built the PR, ran the title and wrote this report.

@DarkPanda69

Copy link
Copy Markdown

AMD run for the Not tested line (also covers #2987, whose three new tests are part of this diff).

Tested: pass, head 7cce7d3 applied on its base nvidia-dev d1be810, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X.
cargo test -p xcl --lib -- hle::d3d12x::sparse hle::d3d12x::vram hle::kernelx --test-threads=4 --nocapture:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: 153 passed, 0 failed, 3 ignored, 0 SKIPPED (nvidia-dev alone: 149 passed). New and ok: a_lazy_tile_outside_the_gpu_heaps_gets_system_memory, a_parked_system_memory_tile_gives_way_to_a_gpu_heap, the_title_gpu_heaps_are_hot_and_nothing_around_them, a_system_memory_page_is_told_apart_and_cools_in_its_own_pool.

#2987 at f8e75bc alone, same base, hle::d3d12x::sparse hle::kernelx: 130 passed, 0 failed (127 without), its three new tests ok.

The sparse and vram tests make their device on the first adapter (D3D12CreateDevice(None, ..)), the RX 9070 XT here.

Not tested: a title run or a session longer than a test, the system-memory pool heaps being given back, Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the creation-order overlap question on RTX 5070 / NVIDIA 616.92 at head 7cce7d3d4625ac8f90f146f1f89f25a613e32e76. A test-only native fixture used CreatePlacedResourceX to place a 1024×1024 RGBA8 sampled texture (11 mips) and a one-mip render target at the same guest start, in both orders. Four fresh processes covered both orders with XCL_TEXTURE_SYSMEM=1 and 0; level pages were enabled throughout.

Setting and creation order First resource backing Newer resource backing
System memory on, sampled then RT Sampled: 86 L0 tiles RT: 64 L0 tiles
System memory on, RT then sampled RT: 64 local tiles Sampled: 64 local + 22 L0 tiles
System memory off, sampled then RT Sampled: 86 local tiles RT: 64 local tiles
System memory off, RT then sampled RT: 64 local tiles Sampled: 86 local tiles

After the newer placement, the superseded resource had zero tracked tiles in each case. While the RT was active, a native clear and copy readback matched all 1,048,576 pixels, including when its 64 tiles were L0-backed. Sampled mip-1 copy readback also matched in every case. All four focused runs passed without skips.

This confirms that an RT can inherit L0 backing when it replaces a streamed texture, despite the intended placement distinction; the reverse order can leave sampled tiles local. It does not establish OS physical residency, simultaneous-alias correctness, retail frequency, or frame-time impact.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.

@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: d1be8103644791b7a65f068954324e93d4b1b565 (nvidia-dev)
head: 7cce7d3d4625ac8f90f146f1f89f25a613e32e76
merge: clean trial merge of the #2987 + #3039 stack into the current nvidia-dev tip; #2987 is an ancestor and #3039's own commit changes only vram.rs (+123/-12). The combined merge changes three intended files (+362/-22).
build: cargo build --locked --workspace -> ok.
tests: cargo test --locked --workspace --no-fail-fast -- --test-threads=4 -> first run 1,827 passed, 9 failed, 48 ignored, 27 GPU SKIPPED notices; repeat 1,828 passed, 8 failed, 48 ignored, 27 skips. All four tests added by the stack passed. Eight failures in the repeat are a subset of the nine on the untouched exact base: both texture-upload tests, the console-MS test, the async-compute PSO test, split-compute in two targets, and two-pass driver-cache in two targets. The first run also failed memory_under_a_shown_page_is_told_to_sparse_before_it_goes; it passed alone (1/0), in the kernelx group (59/0, 1 ignored), and in the full-suite repeat. Its cause is unresolved, so I am not attributing that one result to this PR.
review: Fully unused L0 texture pool heaps remain allocated after cooling. sweep_and_reclaim drains sys_pool.cooling but reclaims only pool/pools, leaving every sys_pools heap at the streaming high-water mark. My earlier exact-head RTX 3080 Ti regression and collapsed candidate diff show an unused 64 MiB L0 heap retained above the configured spare, then passing after the cooled system pools join the existing fence-aware retirement path. That test also keeps the same-index local heap live. This is avoidable system-memory commitment, not evidence that it caused a device removal. #2987 has a separate system-memory pool that needs its own follow-up.
review: a render target placed over an already mapped streamed page inherits its L0 backing, as the creation-order GPU check confirms. This preserves title-page aliasing; please qualify the description's blanket statement that render targets keep video memory. Do not split one aliased page into two backings to make that statement true.
performance: the new switch is off by default. With it on, system-memory sampling trades local VRAM pressure for non-local access and process commit. An independent RTX 3060 run reports lower local VRAM and higher commit, but I did not measure retail frame time or memory on this trial merge.
verdict: not yet: reclaim cooled, fully free L0 texture pool heaps through the existing deferred retirement path, then rerun the focused regression. The prior linked diff is a small candidate for this top commit; the parent pool should be handled separately.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), rustc 1.99.1 MSVC, SDK DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the trial merge, build, two full suites and focused kernelx reruns, reviewed the merged diff, and wrote this check; Codex (GPT-6.2 Astra) independently traced allocator and heap-retirement lifetimes.

Not tested here: a new retail-title run, AMD, Intel, or a production change on this trial merge.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 7cce7d3

@throny

throny commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: d1be810 (nvidia-dev)
head: 7cce7d3
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1827 passed, 9 failed, 48 ignored (27 SKIPPED lines). Eight are the base's own failures on this GPU (the same six names with and without the PR; base alone: 1824 passed, 8 failed, 48 ignored). The ninth, hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark, failed once in the full run with an out-of-memory result (0x8007000E) from a create call in the test; rerun on the same merge result it passed 6 of 6 alone and 2 of 2 with the whole vram module, and 6 of 6 on the base. I read it as memory pressure from GPU tests running side by side, possibly a little higher with this PR's own tests, not as a defect of the change.
review: opt-in confirmed: it needs both XCL_TEXTURE_LEVEL_PAGES=1 and XCL_TEXTURE_SYSMEM=1. Open points, none blocking for an opt-in: system-memory heaps are never reclaimed (the sweep reclaims only the video-memory pool); a render target placed after a sampled texture on the same pages keeps that texture's system-memory pages (raised in the thread, still on this head); with the sparse switch on, pool_bytes counts system-memory tiles in quarantine as free video memory; the suite has no GPU test of sampling from the vram.rs path (corrected after a note in the thread: a tester did exercise it on this exact head with a synthetic fixture, all sampled pixels matching the control; it is not a title or performance result). The diff here includes #2987 (XCL_SPARSE_SYSMEM). For whoever merges: it conflicts with #2898 in sparse.rs in text and in meaning (its system-memory tiles must not go into #2898's per-heap free table, which would be resized to a huge index): merge #2898 first and rebase this on it.
performance: with the switch off, nothing measurable (a OnceLock read and an empty-queue drain per sweep; note_hot always records the title's GPU heaps in a small Vec). With it on, sampled levels are read from system memory across the bus and commit rises (a tester measured about +2.9 GB), which matters on machines without a page file. Not measured here.
verdict: safe to merge (as opt-in, after a rebase on #2898)
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build, suite and reruns by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@andrewDoing

Copy link
Copy Markdown
Contributor

@throny One coverage correction for the merge check: the earlier RTX 5070 test did exercise native shader sampling from the vram.rs level-page path on exact head 7cce7d3d. It verified all 86 texture tiles as SYS_TILE on L0 heaps and compared SampleLevel(1) and mip-0 Load output with the local-pool control; all 2,048 pixels in each output half matched.

That is a synthetic explicit-2D-view fixture, not a retail sampling or performance result, and it does not resolve the heap-reclamation, alias-placement, or #2898 integration concerns.

@razormontana

Copy link
Copy Markdown
Contributor

Independent native validation of 7cce7d3d4625ac8f90f146f1f89f25a613e32e76 with #2987 f8e75bca1ea903b1cf0e9d4f9387b73f359e5051 on d1be8103. Windows 11 Pro build 22631, Core i7-10700K, RTX 3070 8 GB with NVIDIA 617.42, Rust 1.100.0 x64 MSVC.

Tested

  • cargo test --offline --locked -j 1 -p xcl --lib --no-run --message-format=json-render-diagnostics succeeded. Three selected CPU and three native GPU cases passed on the exact clean stack. This includes the stock a_placed_texture_gets_the_pages_of_a_level_with_its_texels fixture with level pages and texture sysmem enabled. The library test executable used exact names with --exact --nocapture --test-threads=1.
  • Two fresh test-only runs added tag and D3D12 heap descriptor assertions to that fixture. With XCL_TEXTURE_LEVEL_PAGES=1 in both, the same 86 mapped tiles used one default heap with texture sysmem off and one custom L0 write-back heap with it on. The 1024×1024 texture's 11 mips read back byte-for-byte in both runs. The overlay changed only test code.
  • 6 exact-head passes plus 2 test-only passes, 0 failed, 0 ignored, 0 explicit skips.

Not tested

These focused checks leave shader sampling, mixed render-target placement order, whole L0 heap reclamation, and retail VRAM savings open.

AI use

Codex GPT-6.2 ran the focused validation, checked the results, and prepared this report.

@Prime1997

Copy link
Copy Markdown
Collaborator

I reused the texture-level part of this proposal for the NVIDIA candidate, preserving attribution rather than opening another PR. The adaptation is a4e83a1eb411e4d3e6cf6e8f202f1f2c42a1d16a: optional L0 texture backing, symmetric empty-heap reclamation for the system pool, and pool accounting that includes both local and system capacity. It follows the fail-closed retirement adaptation from #2538. Existing shared pages retain their backing; allocation failure falls back locally. The sparse/kernel changes in your stacked #2987 are not included. Global defaults remain off; the isolated 8 GB launch explicitly enables the switch as a memory-placement experiment, not a total-memory reduction or guaranteed budget cap.

The combined candidate a4e83a1eb411e4d3e6cf6e8f202f1f2c42a1d16a compiled successfully with cargo build --locked --release -p xcl --target-dir <isolated target> on Windows x64 (230 seconds). This is combined-tree compilation, not an individual-PR build or GPU validation. Source review completed; regression fixtures are present but were not run after the user explicitly waived further shader/memory checks and requested an interactive launch. Hardware behavior, paired title regression and actual sustained memory savings remain unvalidated. No merge-readiness claim.

Codex (GPT-6) prepared this scoped adaptation and report. Optional temporary contributor/testing coordination: https://discord.gg/gK3y7WRRY

@pvfreis

pvfreis commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Plan, on top of #2987 + this PR (nothing written yet): a budget value for XCL_TEXTURE_SYSMEM / XCL_SPARSE_SYSMEM that picks VRAM or L0 for each new pool heap from DXGI's live local budget (one watcher thread: budget-change event + poll; room reserved for the title's GPU heaps and the two-pass buffers), so a card with room keeps levels in VRAM and a smaller one stays under budget by XCL's choice, not Windows'.
First PR: only the probe and the pure decision function with unit tests, not called. Then the texture gate, then sparse.
@treybertram06 @Prime1997: should this stack on these two PRs or on a4e83a1, and does it collide with anything unposted (gefydev's past-budget sparse plan, #3112, #3098's probe)? Planned with Claude Code (Claude Opus 5.5, checked by Claude Fable 5.2).

@andrewDoing

Copy link
Copy Markdown
Contributor

@pvfreis A public-tree overlap check for your budget-mode plan:

This is a source/ancestry check. I can't speak for unposted branches or which integration base the owners intend to merge. AI use: OpenAI Codex checked the commits and PRs and prepared this reply.

@treybertram06
treybertram06 force-pushed the nv-texture-levels-sysmem branch from 7cce7d3 to 9771512 Compare November 30, 2026 07:12
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 30, 2026
@treybertram06

Copy link
Copy Markdown
Contributor Author

Rebased onto main d52ff48c on top of the rebased #2987 (new head 97715129). The full suite and smoke runs are in the description.

@pvfreis: stack on these two PRs (#2987 15b74314, this one 97715129). Prime1997's a4e83a1e is a combined candidate with only the texture-level part, not #2987's sparse part. We have nothing unposted on a budget mode, so nothing of ours collides. One thing that matters for yours: the system-memory pool heaps here are never given back (only the video-memory ones are), so a mode that moves levels back to VRAM when there is room would want that added.

AI use: Claude Code (Claude Opus 5.5) did the rebase and the runs, and wrote this comment.

treybertram06 and others added 2 commits November 30, 2026 06:47
With XCL_COHERENT_HEAPS=sparse the title's GPU heaps (committed memory with
a PAGE_GRAPHICS_* protection, ~4.5 GB in a retail title) live in the sparse
windows. Those are the data the title's shaders read and write every frame;
in the coherent window (system memory, read over PCIe) one retail compute
program took 1,364 ms a frame on an RTX 3080, under 33 ms in video memory.
With them in video memory the windows hold ~7.5 GB of tiles and the device
ran out of its budget (19 GB in use against 8.9 GB, removed at 659 s).

XCL_SPARSE_SYSMEM=1 (off by default): kernelx registers a GPU heap's range
as hot before its commit maps its tiles (sparse::alloc_as); every other
sparse-window tile takes a pool tile in system-memory pool heaps (custom
heaps, L0, write-back), which the GPU reads over PCIe. A pool tile of those
heaps has SYS in its pool index; freed ones cool in their own lists, kept by
the heap's number without SYS (the free table is indexed by heap number).

RTX 3080, retail title, 400 s of its world after the menus: heaps in video
memory alone 0.98 presents/s and 19 GB of video memory; with this and the
texture-level counterpart 1.70 presents/s, 12.7 GB, no device removal in
900 s. An RTX 4080 report on xcl-dev#2688 found the same with a port of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mory

With XCL_TEXTURE_LEVEL_PAGES=1 a streamed texture's levels get video memory
pages as their texels arrive. On a 10 GB card a retail world holds 1.5-2 GB
of them beside 3 GB of render targets and the title's GPU heaps, past the
budget Windows gives the process, which then pages whatever it likes.

XCL_TEXTURE_SYSMEM=1 (off by default, with level pages): those levels take
their pages from pool heaps in system memory (custom heaps, L0, write-back),
which the GPU samples over PCIe. Render targets and every other texture keep
video memory: they are written every frame (xcl-dev#1702 moves all pages instead).
A page of those heaps has SYS_TILE in its heap index; freed ones cool in
their own pool.

RTX 3080 10 GB, retail title, XCL_COHERENT_HEAPS=sparse with
XCL_SPARSE_SYSMEM=1 (xcl-dev#2987), 610 s: video memory at the end 15.1 -> 11.9 GB
local, presents in the 400 s after the menus 0.72 -> 1.35 a second (one run
each). Without the sparse part it is slower (0.15): the heaps the GPU reads
over PCIe share the bus with the levels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

thehollowedone commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 86e86fc
head: 9771512
merge: clean (local merge d4b8f128f6da2c4816d4be280b9382441bf1b475; this head includes the still-open #2987 stack)
build: cargo build --workspace --target-dir ..\target -> ok; clean release builds for base and merge -> ok
tests: cargo test --workspace --no-fail-fast --target-dir ..\target -- --test-threads=4 -> 2,893 passed, 0 failed, 51 ignored across 43 targets; SKIPPED: 24 (22 require wave64, 2 require heap-window opt-in); failing: none
review: The three changed files contain only the stacked sparse and texture-pool changes. On this head, a test-only extension of the existing 11-mip native GPU fixture passed in separate XCL_TEXTURE_SYSMEM=1 and 0 processes (1 passed, 0 failed, 0 skipped each). It checked every allocated streamed-level page's pool tag and the fixture's GPU copy readbacks against expected mip bytes. This covers placement and contents, not shader sampling. The previously reported L0 heap-retention finding and tested candidate diff still apply: after all tiles cool, sweep_and_reclaim reclaims only VRAM pool heaps. The same prior report explains the alias-order exception to the description's render-target VRAM claim. No other source-level issue found.
performance: With the opt-in switches off, paired 60 s smokes on the same title and RTX 3080 Ti exited normally: base 1,661 frames / 16,900 MB peak commit; merge 1,696 frames / 16,643 MB. Both had zero crashes and device removals. These short runs do not establish a speed or memory benefit. I did not run an opt-in world load or measure long-session commit, VRAM, PCIe cost, or frame pacing on this head.
verdict: not yet: the opt-in world-load memory and pacing effect remains unmeasured on this head, and empty system-memory texture heaps still retain their peak allocation (candidate fix linked above).
hardware / tool and model: RTX 3080 Ti 12 GB / driver 621.40, Ryzen 7 9800X3D, Windows 11 build 26300 / OpenAI Codex (GPT-6 Sol)

Generated paired smoke blocks
xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1661 (PresentX 1661)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16900 MB
xcl-smoke v1
commit: d4b8f128f6da2c4816d4be280b9382441bf1b475
gpu: NVIDIA GeForce RTX 3080 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1696 (PresentX 1696)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16643 MB

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Source-accounting follow-up on current head 97715129: the opt-in L0 texture pools need their own owner totals in the memory report. page_bytes_for counts mapped pages from both backing types but reports only local pool capacity. snapshot then assigns all those pages to local video memory. On a discrete GPU, one fully used 64 MiB L0 texture heap with no local texture heap would appear as 64 MiB of local target pages; other(Kind::Video) subtracts that amount from the wrong DXGI segment. The raw DXGI usage totals are unaffected.

Please preserve page_bytes_for's aggregate count for existing callers, but supply memory_report with used bytes and capacity split by local/L0 pool. Classify L0 with the report's existing discrete/integrated segment rule. A focused regression can give the two pools the same numeric heap slot, map one shared page in each, and check per-segment used/free bytes and other. This is separate from the earlier combined-capacity candidate.

This is a source-accounting review; I did not run a new build or GPU test. AI use: OpenAI Codex (GPT-6.2 Sol) checked the accounting path; OpenAI Codex (GPT-6.2 Astra) independently reviewed the pool and segment ownership.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 9771512

Stacked on #2987 (its first commit, sparse tiles in system memory); only 97715129 belongs here, so the shared lines with #2987 are not a duplicate.
#1702 (D234) also puts texture pages in D3D12 L0, but it switches every title-texture page pool, render targets included, while this keeps a second L0 pool for streamed texture levels only and leaves render targets in video memory. The two take different approaches, so neither duplicates the other.
No problems found in the diff.
Recommendation: keep open.

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

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).
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).
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:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants