Repository navigation
D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory - #3039
treybertram06 wants to merge 2 commits 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 <[email protected]>
…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 <[email protected]>
|
Independent RTX 3080 Ti check on #3039 head 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 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 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 boundarydiff --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. |
|
I checked shader reads from the system-memory level pages on RTX 5070 / NVIDIA 616.92 at head
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. |
|
RTX 3060 12 GB (NVIDIA), this PR's head Same build, both runs with
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 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. |
|
AMD run for the Not tested line (also covers #2987, whose three new tests are part of this diff). Tested: pass, head
#2987 at The sparse and vram tests make their device on the first adapter ( 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. |
|
I checked the creation-order overlap question on RTX 5070 / NVIDIA 616.92 at head
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. |
|
merge-check Not tested here: a new retail-title run, AMD, Intel, or a production change on this trial merge. |
|
merge-check claim |
|
merge-check |
|
@throny One coverage correction for the merge check: the earlier RTX 5070 test did exercise native shader sampling from the 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. |
|
Independent native validation of Tested
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. |
|
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 Codex (GPT-6) prepared this scoped adaptation and report. Optional temporary contributor/testing coordination: https://discord.gg/gK3y7WRRY |
Target:
nvidia-dev. 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_intakes new pages from the system-memory pools for lazy levels;SYS_TILEin its heap index, and freed ones cool in their own pool (cool);mapresolves either heap.a_system_memory_page_is_told_apart_and_cools_in_its_own_pool.Tested
xcl.exe. 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 head7cce7d3d: 1825 passed, 11 failed, 48 ignored.nvidia-devwithout this change (the same list as in D3D12.X: empty shader slots keep a two-pass mesh pipeline's cache key #2975 and D3D12.X: sparse tiles outside the GPU heaps can live in system memory #2987).SKIPPED: theno wave64tests, plus one that needsXCL_HEAP_WINDOWS=1.cargo test -p xcl --lib -- hle::d3d12x::vram --test-threads=4: 23 passed, 0 failed, 1 ignored.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.XCL_TEXTURE_SYSMEMunset): 0.72 presents/s, 15.1 GB local.0x887a0006, no DRED breadcrumbs); the prototype these come from lost it in 2 of 7 runs, and runs without these switches lose it on this title too ([OFFICIAL] Swarm: RAM and VRAM use down, towards stable 30 FPS on AMD and NVIDIA #2688).Regression run
Base, a commit of
main:b49be183, the lastmaincommit before #2555's launch preparation gate. The switch is off in both runs.This PR's head:
Not tested
reclaim_empty_heaps).AI use