Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/xcl/src/gpu/uma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MEMORYSTATUSEX>() 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) {
Expand Down
27 changes: 24 additions & 3 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }?;
Expand All @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/hle/d3d12x/vram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ unsafe fn alloc_pool_heap(dev: &ID3D12Device) -> Option<ID3D12Heap> {
};
let mut heap: Option<ID3D12Heap> = 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
Expand Down
11 changes: 8 additions & 3 deletions crates/xcl/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
Expand Down
Loading