Repository navigation
D3D12.X: sparse tiles outside the GPU heaps can live in system memory - #2987
treybertram06 wants to merge 1 commit into
Conversation
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. 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>
|
Independent RTX 3080 Ti check of I extended the existing synthetic lazy first-write test to first verify L0 support with an eager control tile and then assert the lazy tile's pool class. On Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, I set Candidate fix and focused regression diffdiff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index 979b4d04..4f161733 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -1301,6 +1301,11 @@ impl State {
Some(((h, 0), false))
}
+ /// Choose backing by the title reservation that owns this tile.
+ unsafe fn take_tile_for(&mut self, t: usize) -> Option<((u32, u32), bool)> {
+ if sysmem_tiles() && !is_hot(t) { self.take_sys_tile() } else { self.take_tile() }
+ }
+
/// The heap of pool index `h` (video memory, or a system-memory pool with `SYS`).
fn pool_heap(&self, h: u32) -> ID3D12Heap {
if h & SYS != 0 {
@@ -1607,7 +1612,7 @@ impl State {
if self.mapped.get(&t).is_some_and(|e| e.pool == LAZY) {
let at_hand = !self.free.is_empty() || cooled(&self.cooling, std::time::Instant::now()) || !self.retired.is_empty();
let wait = left > 0 || (!force && self.short_of_memory() && !at_hand);
- match if wait { None } else { self.take_tile() } {
+ match if wait { None } else { self.take_tile_for(t) } {
Some((tile, used)) => {
if let Some(e) = self.mapped.get_mut(&t) {
e.pool = tile;
@@ -1665,7 +1670,7 @@ impl State {
self.to_zero.insert((t, TILE));
unparked = true;
} else {
- let got = if sysmem_tiles() && !is_hot(t) { self.take_sys_tile() } else { self.take_tile() };
+ let got = self.take_tile_for(t);
let Some((tile, reused)) = got else { break };
self.mapped.insert(t, TileEntry::with_holes(tile, initial_holes(t)));
early_add(&mut self.runs, t, t + TILE);
@@ -6083,7 +6088,10 @@ mod tests {
fn a_lazy_tile_gets_memory_at_its_first_bytes_and_keeps_them() {
let lazy = Lazy::on(true);
unsafe {
- let Some((base, mut s, queue)) = lazy_state(2) else { return crate::gpu::recomp::runner::skip_test("no GPU with tiled resources tier 2") };
+ let Some((base, mut s, queue)) = lazy_state(3) else { return crate::gpu::recomp::runner::skip_test("no GPU with tiled resources tier 2") };
+ let cold_control = base + 2 * TILE;
+ s.ensure_mapped(cold_control, TILE, |_| 0);
+ assert_ne!(s.mapped[&cold_control].pool.0 & SYS, 0, "eager cold tile uses system memory on this adapter");
s.commit_range(base, 2 * TILE);
assert_eq!(s.mapped[&base].pool, LAZY, "committed: listed with no video memory");
assert_eq!(s.mapped[&(base + TILE)].pool, LAZY);
@@ -6092,6 +6100,7 @@ mod tests {
let dirty = write_tile(base, 7);
s.before_execute_on(&queue, &dirty, PAGE);
assert_ne!(s.mapped[&base].pool, LAZY, "its first bytes gave it a pool tile");
+ assert_ne!(s.mapped[&base].pool.0 & SYS, 0, "lazy cold tile also uses system memory");
assert_eq!(s.mapped[&(base + TILE)].pool, LAZY, "the tile never written has none");
let cpu = std::slice::from_raw_parts(base as *const u8, TILE).to_vec();
assert!(window_bytes(&mut s, base, TILE) == cpu, "the bytes reached the GPU");The broader policy still needs the lazy path's |
|
8 GB VRAM / 16 GB RAM data point with Tested
Results
Not tested: repeats, AI use: build, run and log analysis by Claude Code agents (Claude Sonnet 5.5), report written and checked against the run logs by Claude Code (Claude Opus 5.5). |
|
RX 9070 / Wine: an eager sparse-window system-memory readback works in a focused native GPU fixture at Tested RX 9070 16 GB, RADV GFX1201 / Mesa 26.3.1, Ryzen 7 7700, CachyOS 7.3.0-5, GE-Proton11-12 / Wine 11.0 Staging, vkd3d-proton Compared the exact head with its actual parent
The fixture maps eagerly through
These are actual pool tags and native Every window word was checked after CPU upload, after partial native GPU writes with untouched regions retained, and after an owned wave64 shader loaded, transformed and stored every word through the same window. A separate width buffer verified lane count 64 and its 15 untouched guards. Independent Python verification checked all 10,223,872 readback words, including 39 MiB of window payload, across 64 native readbacks and 16 wave64 dispatches. Data, guards and shader containers match across sources, switches and fresh repeats. No device removal occurred. Not tested Lazy first-write materialization, including the bypass already reported here, the full kernelx AI use OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the public change, wrote and ran the fixture and independent verifier, and drafted this report. Publication authorized by the account owner. |
|
New, separate finding on #2987 head I added a synthetic one-tile GPU regression that commits cold, flushes the mapping, verifies the SYS pool bit, decommits, calls The candidate acquires a video-memory replacement before touching the parked mapping, then unmaps and quarantines the old tile behind the existing queue fences. It leaves pinned tiles on their existing backing so placed-buffer aliases remain intact. It is a focused local candidate, not a full proof of safe retirement under every queue schedule; the author should review and extend the pinned/blocked-queue tests before merging. Candidate correction and regression diffdiff --git a/crates/xcl/src/hle/d3d12x/sparse.rs b/crates/xcl/src/hle/d3d12x/sparse.rs
index 979b4d04..cae3e6a3 100644
--- a/crates/xcl/src/hle/d3d12x/sparse.rs
+++ b/crates/xcl/src/hle/d3d12x/sparse.rs
@@ -1658,8 +1658,26 @@ impl State {
let mut t = first;
while t < end {
if !self.mapped.contains_key(&t) && !self.mirror_src.contains_key(&t) && self.window_index(t).is_some() {
- // still mapped there: no new mapping, what it held is cleared
- if let Some(tile) = self.parked.remove(&t).or_else(|| self.kept.remove(&t)) {
+ // A new GPU heap at this address cannot inherit a parked system-memory tile.
+ // Acquire its replacement first; keep the old mapping if video memory is unavailable.
+ if let Some(old) = self.parked.get(&t).copied().filter(|tile| is_hot(t) && tile.0 & SYS != 0 && !self.pinned.contains_key(tile)) {
+ let Some((tile, reused)) = self.take_tile() else { break };
+ let wi = self.window_index(t).expect("mapped window");
+ let (b, r) = (self.windows[wi].0, self.windows[wi].1.clone());
+ self.unmap_tiles(&r, b, &[t]);
+ TILE_WORK[2].fetch_add(1, Ordering::Relaxed);
+ self.signal();
+ self.quarantine_tiles(vec![old]);
+ self.parked.remove(&t);
+ self.mapped.insert(t, TileEntry::with_holes(tile, initial_holes(t)));
+ early_add(&mut self.runs, t, t + TILE);
+ if reused {
+ self.to_zero.insert((t, TILE));
+ }
+ self.pending.push(t);
+ new = true;
+ } else if let Some(tile) = self.parked.remove(&t).or_else(|| self.kept.remove(&t)) {
+ // still mapped there: no new mapping, what it held is cleared
self.mapped.insert(t, TileEntry::with_holes(tile, initial_holes(t)));
early_add(&mut self.runs, t, t + TILE);
self.to_zero.insert((t, TILE));
@@ -5506,6 +5524,38 @@ mod tests {
assert_eq!(system.0 & !SYS, video.0);
}
+ #[test]
+ fn a_parked_cold_tile_does_not_back_a_new_hot_heap() {
+ use windows_sys::Win32::System::Memory::MEM_RELEASE;
+
+ if !sysmem_tiles() {
+ return crate::gpu::recomp::runner::skip_test("XCL_SPARSE_SYSMEM=1 required");
+ }
+ let _lazy = Lazy::on(false);
+ unsafe {
+ let (base, mut s) = test_state_with_reserved(1);
+ s.commit_range(base, TILE);
+ s.flush_pending();
+ let cold = s.mapped[&base].pool;
+ if cold.0 & SYS == 0 {
+ s.wait_for(s.value);
+ drop(s);
+ assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
+ return crate::gpu::recomp::runner::skip_test("system-memory pool unavailable");
+ }
+ s.decommit_range(base, TILE);
+ assert_eq!(s.parked.get(&base), Some(&cold));
+ note_hot(base, TILE);
+ s.commit_range(base, TILE);
+ assert_eq!(s.mapped[&base].pool.0 & SYS, 0, "a hot heap must use video memory");
+ s.flush_pending();
+ s.wait_for(s.value);
+ drop(s);
+ HOT.lock().unwrap().retain(|&(a, n)| a != base || n != TILE);
+ assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
+ }
+ }
+
#[test]
fn aligned_tile_addresses_spread_across_hash_buckets() {
use std::hash::BuildHasher;Separate test-coverage note: with No game files or title executable were used. AI use: Codex (GPT-6.2 Sol) wrote and ran the red/green test and candidate; Codex (GPT-6.2 Astra) checked the mapping and fence sequence. |
|
Independent desktop NVIDIA verification of PR #2987 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib -- hle::d3d12x::sparse::tests::the_title_gpu_heaps_are_hot_and_nothing_around_them --exact --nocapture (3 consecutive runs) |
1 passed; 0 failed; 0 ignored; 1727 filtered out × 3 (0.00s × 3, 0 skipped) |
cargo test --release -p xcl --lib -- hle::d3d12x::sparse:: --test-threads=1 --nocapture (3 consecutive runs) |
67 passed; 0 failed; 1 ignored; 1660 filtered out × 3 (5.20s, 4.74s, 4.98s, 0 skipped; 1 #[ignore]: early_commit_timing) |
cargo test --release -p xcl --lib -- hle::kernelx:: --test-threads=1 --nocapture (3 consecutive runs) |
61 passed; 0 failed; 1 ignored; 1666 filtered out × 3 (1.25s, 1.25s, 1.26s, 0 skipped; 1 #[ignore]: scatter_timing) |
cargo build --release -p xcl |
Clean build (2m 16s, exit 0, 0 new warnings in sparse.rs / kernelx.rs; pre-existing rbq_value warning unchanged from a5e2d851) |
Paired quiet 60 s retail smokes (title: 29640639, XCL_PREPARE=0 XCL_NETWORK=0)
Exact parent & merge-base (a5e2d851a503fc0e04609f773ea53f2d2c4e3269, XCL_PREPARE=0 XCL_NETWORK=0):
xcl-smoke v1
commit: a5e2d851a503fc0e04609f773ea53f2d2c4e3269
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1556)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14755 MB
PR #2987 default (6c5904f9426ffdfd4772399c92bfa84ddf29f6e2, XCL_SPARSE_SYSMEM unset, XCL_PREPARE=0 XCL_NETWORK=0):
xcl-smoke v1
commit: 6c5904f9426ffdfd4772399c92bfa84ddf29f6e2
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1568 (PresentX 1568)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14740 MB
PR #2987 opt-in (6c5904f9426ffdfd4772399c92bfa84ddf29f6e2, XCL_SPARSE_SYSMEM=1, XCL_PREPARE=0 XCL_NETWORK=0):
xcl-smoke v1
commit: 6c5904f9426ffdfd4772399c92bfa84ddf29f6e2
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1541 (PresentX 1541)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14637 MB
Runtime memory & sparse-pool telemetry (xcl.log steady-state ~48–58 s)
| Run | Local VRAM | Non-local | Sparse VRAM pools (mapped) | Peak commit | Avg submit cost |
|---|---|---|---|---|---|
Parent a5e2d851 (default) |
6115 MB |
4741 MB |
896 MB (838 MB mapped) |
14755 MB |
0.17–0.18 ms |
PR #2987 default (XCL_SPARSE_SYSMEM unset) |
6116 MB |
4782 MB |
896 MB (838 MB mapped) |
14740 MB |
0.18–0.19 ms |
PR #2987 opt-in (XCL_SPARSE_SYSMEM=1) |
5218 MB (-898 MB / -14.7%) |
5597 MB (+815 MB) |
0 MB (0 MB mapped) |
14637 MB |
0.15–0.16 ms |
Under XCL_SPARSE_SYSMEM=1, the runtime log confirmed activation (sparse windows: XCL_SPARSE_SYSMEM=1 - tiles outside the title's GPU heaps in system memory) and system-memory pool heap growth (64 -> 128 -> 256 -> 512 MB logged at power-of-two checkpoints), keeping VRAM sparse pools at 0 MB and reducing RTX 4060 local VRAM usage by 898 MB with 0 device removals and 0 crashes.
Limits of coverage
- Verified the
note_hot/is_hotrange boundary predicate (the_title_gpu_heaps_are_hot_and_nothing_around_them3/3),hle::d3d12x::sparse::(67/0/1× 3),hle::kernelx::(61/0/1× 3), default-off non-regression, and liveXCL_SPARSE_SYSMEM=1L0 pool routing (-898 MBlocal VRAM) on RTX 4060 (8 GB). - The opt-in 60 s smoke ran with
XCL_SPARSE_SYSMEM=1alone (withoutXCL_COHERENT_HEAPS=sparse); did not run a combinedXCL_COHERENT_HEAPS=sparse+XCL_SPARSE_SYSMEM=1multi-minute post-menu world-load stress test. - Paired 60 s retail smokes ran with
XCL_PREPARE=0(XCL_NETWORK=0), bypassing startupprepare_for_launch, and the 2#[ignore]timing tests (early_commit_timing,scatter_timing) were not executed.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Target:
nvidia-dev. Part of #2688. Related: gefydev's planned budget-triggered L0 sparse pools (#2688), and #1702 (texture pages in system memory).With
XCL_COHERENT_HEAPS=sparsethe title's GPU heaps live in the sparse windows instead of the coherent window. These heaps are committed memory with aPAGE_GRAPHICS_*protection, about 4.5 GB in a retail title. Shaders read and write them every frame. In the coherent window (system RAM, read over PCIe), one retail compute program took 1,364 ms per frame on an RTX 3080; with the heaps in video memory it falls under 33 ms (XCL_GPU_TIMES). An RTX 4080 report on #2688 found the same factor. But with the heaps in video memory, the sparse windows hold about 7.5 GB of tiles. On a 10 GB card the device runs out of budget: 19 GB in use against 8.9 GB, removed at 659 s.XCL_SPARSE_SYSMEM=1(off by default) keeps the GPU heaps' tiles in video memory and puts every other sparse-window tile in system memory:sparse::alloc_as) before its commit maps its tiles;MEMORY_POOL_L0, write-back), which the GPU reads over PCIe.gefydev's plan moves new pools past the budget. This one decides by what a range holds, so the heaps the shaders depend on are never the ones moved.
What is in it
D3D12.X: sparse tiles outside the GPU heaps can live in system memory(hle/d3d12x/sparse.rs,hle/kernelx.rs):note_hot/is_hot/alloc_asmark the hot ranges;SysPools, pool index tagged withSYS) with their own free and cooling lists;pool_heapresolves either kind.the_title_gpu_heaps_are_hot_and_nothing_around_them.Tested
xcl.exe(xcl run:xcl nvprofileputs xcl.exe in an NVIDIA profile with a bigger shader heap (#2403) #2590). Debug tests, release title runs.cargo test --workspace --no-fail-fast -- --test-threads=4, withXCL_DXC_DIRset to DXC 1.9, at this PR's head6c5904f9: 1822 passed, 11 failed, 48 ignored.nvidia-deva5e2d851without this change (the same list as in D3D12.X: empty shader slots keep a two-pass mesh pipeline's cache key #2975).SKIPPED: theno wave64tests, plus one that needsXCL_HEAP_WINDOWS=1.cargo test -p xcl --lib the_title_gpu_heaps_are_hot: 1 passed.XCL_COHERENT_HEAPS=sparse XCL_SPARSE_SYSMEM=1 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PREPARE_WORKERS=6, scripted presses. Over the 400 s after the menus: 0.72 presents/s, video memory 15.1 GB local / 5.0 GB non-local (budget 9.2 GB), commit 41.5 GB, no device removal.XCL_GPU_TIMESwith the heaps in the coherent window: the top programcs 10eaefe801508781took 1,364 ms per frame. With them in video memory, the top program is under 70 ms.Regression run
Base, a commit of
main:b49be183, the lastmaincommit before #2555's launch preparation gate, which takes hours with this title on this card. The switch is off in both runs.This PR's head:
Not tested
XCL_COHERENT_HEAPS=sparseisn't onamd-dev. A 16 GB RDNA3 card stays under its budget anyway (oni-swr on [OFFICIAL] Swarm: RAM and VRAM use down, towards stable 30 FPS on AMD and NVIDIA #2688).0x887a0006, at 48 s and 202 s); the cause is not known. Runs without these switches also lose it on this title ([OFFICIAL] Swarm: RAM and VRAM use down, towards stable 30 FPS on AMD and NVIDIA #2688).AI use