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; }