From 70a26dd652a6e2e7d8cd3b5519b42b3240bf2ad6 Mon Sep 17 00:00:00 2001 From: 427001 <189743735+427001@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:45:22 +0100 Subject: [PATCH] D3D12.X: the log shows what memory is left when video memory is refused When a pool heap for title textures is refused, the log said "no video memory for more pages of title textures", and the activity line gave the process's commit and the video memory in use. Neither says what ran out: the card, the memory the system shares with it, or the system's commit, which a PC charges video memory to as well. The warning now ends with the system's free commit and its limit, and the local and the non-local video memory in use with their budgets. The activity line (XCL_ACTIVITY) gets the commit and the two budgets at its end; what scripts/smoke.ps1 reads from it is unchanged. What they showed in runs of a retail title on a 10 GB card with 16 GB of RAM (a local tree with #495 and #615, Series S profile), up to the title's own check at +0x193e00f (#333): the first refusal came with 779 MB of commit free in one run and with 31764 MB and 32252 MB free in two runs with a larger page file, each time at 12541 - 12552 MB of local video memory in use against a budget of 9260 - 9285 MB. In the last run non-local video memory stood at 4708 MB of a 7465 MB budget. So the commit is not what stops that machine, which the first run alone suggested. Logging only: no test. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/gpu/uma.rs | 9 +++++++++ crates/xcl/src/hle/d3d12x/real.rs | 27 ++++++++++++++++++++++++--- crates/xcl/src/hle/d3d12x/vram.rs | 2 +- crates/xcl/src/host.rs | 11 ++++++++--- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs index 7592d044b0..b05641e2b2 100644 --- a/crates/xcl/src/gpu/uma.rs +++ b/crates/xcl/src/gpu/uma.rs @@ -822,6 +822,15 @@ fn free_commit() -> usize { m.ullAvailPageFile as usize } +/// The system's commit: (free, limit) bytes. A PC charges video memory to it too, so video +/// memory can be refused with room left on the card. None when it is not known. +pub fn system_commit() -> Option<(u64, u64)> { + use windows_sys::Win32::System::SystemInformation::{GlobalMemoryStatusEx, MEMORYSTATUSEX}; + let mut m: MEMORYSTATUSEX = unsafe { std::mem::zeroed() }; + m.dwLength = std::mem::size_of::() as u32; + (unsafe { GlobalMemoryStatusEx(&mut m) } != 0).then_some((m.ullAvailPageFile, m.ullTotalPageFile)) +} + /// The title has asked for `bytes` of graphics memory XCL places in the coherent window: the /// next run makes the window that large (this one has the size it was made with). pub fn note_coherent_need(bytes: usize) { diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 781a4b435a..08f6ba4ec6 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -423,8 +423,9 @@ pub fn device_raw() -> *mut c_void { DEVICE.load(Ordering::Acquire) as *mut c_void } -/// The process's video memory on the device's adapter: (local, non-local) bytes in use. -pub fn video_memory() -> Option<(u64, u64)> { +/// The process's video memory on the device's adapter, local and non-local: (bytes in use, the +/// budget the system gives the process) of each. +pub fn video_memory() -> Option<((u64, u64), (u64, u64))> { use windows::Win32::Graphics::Dxgi::*; let raw = device_raw(); let dev = unsafe { ID3D12Device::from_raw_borrowed(&raw) }?; @@ -436,7 +437,27 @@ pub fn video_memory() -> Option<(u64, u64)> { let mut non_local = DXGI_QUERY_VIDEO_MEMORY_INFO::default(); adapter.QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &mut local).ok()?; adapter.QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &mut non_local).ok()?; - Some((local.CurrentUsage, non_local.CurrentUsage)) + Some(((local.CurrentUsage, local.Budget), (non_local.CurrentUsage, non_local.Budget))) + } +} + +/// What was left when video memory was refused, for the log: the system's commit, and the +/// local and non-local video memory against their budgets (any of them can be what ran out). +pub fn memory_left() -> String { + let mb = |b: u64| b >> 20; + let commit = match crate::gpu::uma::system_commit() { + Some((free, limit)) => format!("system commit {} MB free of {} MB", mb(free), mb(limit)), + None => "system commit not known".into(), + }; + match video_memory() { + Some(((local, budget), (non_local, non_local_budget))) => format!( + "{commit}, video memory in use: {} MB local of a {} MB budget, {} MB non-local of a {} MB budget", + mb(local), + mb(budget), + mb(non_local), + mb(non_local_budget) + ), + None => commit, } } diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 6ac17631f7..6883a2302a 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -421,7 +421,7 @@ unsafe fn alloc_pool_heap(dev: &ID3D12Device) -> Option { }; let mut heap: Option = None; if let Err(e) = super::title_textures::own_work(|| dev.CreateHeap(&desc, &mut heap)) { - crate::xlog_warn!("D3D12.X: no video memory for more pages of title textures ({e})"); + crate::xlog_warn!("D3D12.X: no video memory for more pages of title textures ({e}); {}", super::real::memory_left()); return None; } heap diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index f3e57ce5fb..126ffe390d 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -62,13 +62,14 @@ pub fn host_main(boot_path: &Path) -> i32 { K32GetProcessMemoryInfo(windows_sys::Win32::System::Threading::GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb); c.PrivateUsage }; - let (local, non_local) = crate::hle::d3d12x::real::video_memory().unwrap_or((0, 0)); + let ((local, budget), (non_local, non_local_budget)) = crate::hle::d3d12x::real::video_memory().unwrap_or(((0, 0), (0, 0))); + let (commit_free, commit_limit) = crate::gpu::uma::system_commit().unwrap_or((0, 0)); let (arenas, arenas_made) = crate::hle::d3d12x::vram::arena_bytes(); let (pools, pools_mapped) = crate::hle::d3d12x::sparse::pool_bytes(); let (pages, page_pools) = crate::hle::d3d12x::vram::page_bytes(); let mb = |b: u64| b >> 20; crate::xlog_info!( - "memory: {} MB committed by the process; video memory {} MB local, {} MB non-local; target pages {} MB (pools {} MB); arenas {} MB in use, {} MB made; sparse pools {} MB ({} MB mapped)", + "memory: {} MB committed by the process; video memory {} MB local, {} MB non-local; target pages {} MB (pools {} MB); arenas {} MB in use, {} MB made; sparse pools {} MB ({} MB mapped); system commit {} MB free of {} MB; video memory budgets {} MB local, {} MB non-local", mb(private as u64), mb(local), mb(non_local), @@ -77,7 +78,11 @@ pub fn host_main(boot_path: &Path) -> i32 { mb(arenas as u64), mb(arenas_made as u64), mb(pools as u64), - mb(pools_mapped as u64) + mb(pools_mapped as u64), + mb(commit_free), + mb(commit_limit), + mb(budget), + mb(non_local_budget) ); last = now; }