diff --git a/README.md b/README.md index e35903a1cf..cc35496922 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder `null` if its format cannot be decoded. Intermediate render-target dumps do not update it. Sampling uses every fourth pixel in each direction (`XCL_FRAME_DUMP_FULL=1`: every pixel). A coarse sample can miss detail; a non-dark sample does not establish correct rendering or gameplay. +- `XCL_ACTIVITY=1` logs rendering, streaming and memory activity every two seconds. Under Wine on Linux, + missing private usage falls back to an estimate from anonymous resident memory and swap. - Title data: `%LOCALAPPDATA%\XCL\\` (`%XCL_DATA_ROOT%`): `xcl.toml`, `overlay\`, `saves\`, `pls\` (the title's `S:\`), `temp\` (`T:\`), `cache\`, `logs\xcl.log`, `logs\report.json` (the previous run's: `xcl.prev.log`, `report.prev.json`). diff --git a/crates/xcl/src/hle/kernelx.rs b/crates/xcl/src/hle/kernelx.rs index c0b8c236ac..3d74082204 100644 --- a/crates/xcl/src/hle/kernelx.rs +++ b/crates/xcl/src/hle/kernelx.rs @@ -732,14 +732,21 @@ pub struct TitleMemoryStatusT { } fn process_private_bytes() -> u64 { + // Keep the guest title-memory APIs' existing PagefileUsage fallback. + process_commit_bytes(true) +} + +fn commit_bytes(private: usize, pagefile: usize, allow_pagefile: bool) -> u64 { + if private == 0 && allow_pagefile { pagefile as u64 } else { private as u64 } +} + +pub(crate) fn process_commit_bytes(allow_pagefile: bool) -> u64 { use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX}; unsafe { let mut c: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed(); c.cb = std::mem::size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32; if K32GetProcessMemoryInfo(thr::GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb) != 0 { - // Wine fills the fields before PrivateUsage only; PagefileUsage is the same number - // on Windows (the commit charge) - if c.PrivateUsage != 0 { c.PrivateUsage as u64 } else { c.PagefileUsage as u64 } + commit_bytes(c.PrivateUsage, c.PagefileUsage, allow_pagefile) } else { 0 } @@ -2653,6 +2660,15 @@ mod tests { } } + #[test] + fn activity_commit_uses_pagefile_only_when_allowed() { + assert_eq!(commit_bytes(123, 456, false), 123); + assert_eq!(commit_bytes(123, 456, true), 123); + assert_eq!(commit_bytes(0, 456, true), 456); + // CrossOver reports the virtual size, including uncommitted reservations. + assert_eq!(commit_bytes(0, 50169 << 20, false), 0); + } + #[test] fn title_memory_status_reports_budget() { let mut s: TitleMemoryStatusT = unsafe { std::mem::zeroed() }; diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index ba5dcb4737..664583f655 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -49,13 +49,7 @@ pub fn host_main(boot_path: &Path) -> i32 { d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10] ); // where the memory is: the process's commit, video memory, and XCL's parts of it - let private = unsafe { - use windows_sys::Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX}; - let mut c: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed(); - c.cb = std::mem::size_of_val(&c) as u32; - K32GetProcessMemoryInfo(windows_sys::Win32::System::Threading::GetCurrentProcess(), &mut c as *mut _ as *mut _, c.cb); - c.PrivateUsage - }; + let private = crate::hle::kernelx::process_commit_bytes(crate::util::linux_wine()); let (local, non_local) = crate::hle::d3d12x::real::video_memory().unwrap_or((0, 0)); let (arenas, arenas_made) = crate::hle::d3d12x::vram::arena_bytes(); let (pools, pools_mapped) = crate::hle::d3d12x::sparse::pool_bytes(); @@ -63,7 +57,7 @@ pub fn host_main(boot_path: &Path) -> i32 { 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)", - mb(private as u64), + mb(private), mb(local), mb(non_local), mb(pages as u64), diff --git a/crates/xcl/src/util.rs b/crates/xcl/src/util.rs index e72db3ac44..94b6b5ed25 100644 --- a/crates/xcl/src/util.rs +++ b/crates/xcl/src/util.rs @@ -132,6 +132,23 @@ pub fn under_wine() -> bool { }) } +/// Wine on Linux reports anonymous resident bytes and swap in PagefileUsage. +pub(crate) fn linux_wine() -> bool { + use std::ffi::{c_char, CStr}; + use std::sync::OnceLock; + use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress}; + static LINUX_WINE: OnceLock<bool> = OnceLock::new(); + *LINUX_WINE.get_or_init(|| unsafe { + let ntdll = GetModuleHandleA(c"ntdll.dll".as_ptr().cast()); + let Some(proc) = GetProcAddress(ntdll, c"wine_get_host_version".as_ptr().cast()) else { return false }; + // Wine exports this C function and returns a pointer to a static host name. + let host_version: unsafe extern "C" fn(*mut *const c_char, *mut *const c_char) = std::mem::transmute(proc); + let mut name = std::ptr::null(); + host_version(&mut name, std::ptr::null_mut()); + !name.is_null() && CStr::from_ptr(name) == c"Linux" + }) +} + /// Normalised DLL key: lower-case file name, ".dll" appended when no extension. pub fn dll_key(name: &str) -> String { let base = name.rsplit(['\\', '/']).next().unwrap_or(name);