From df1efcd42b7a9f8bb98207b388b12f9eb72a9bcf Mon Sep 17 00:00:00 2001 From: kw Date: Mon, 23 Nov 2026 23:56:04 +0100 Subject: [PATCH] Console CPU instructions: no VirtualQuery for CLZERO into the coherent window On a CPU without CLZERO (Intel), every emulated CLZERO / CLZERO loop checked its target with is_writable, which calls VirtualQuery. VirtualQuery sizes the region by walking it to its end, and the coherent window is one committed region of up to 4 GiB: ~40 ms a call (the cost uma::in_committed_window already notes for DirectStorage). The retail game runs about 25 emulated instructions a second, nearly all of them CLZERO loops into that window, and two thread dumps 5 s apart found its main thread in the exception handler both times: 1-2 presents a second. The coherent window is committed and read-write as a whole, so a target inside it is writable without asking; readable() and read_committed() already take this path. Measured on the retail game (RTX 5080, i5-12600K): ~1.5 fps -> 30 fps (the title's frame clock) on its first-run and account screens, and it reaches the Navigation menu. --- crates/xcl/src/eh.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/xcl/src/eh.rs b/crates/xcl/src/eh.rs index fca299989..cde978dc0 100644 --- a/crates/xcl/src/eh.rs +++ b/crates/xcl/src/eh.rs @@ -247,6 +247,11 @@ unsafe fn bounded_cstr(p: usize, max: usize) -> String { fn is_writable(va: usize, bytes: usize) -> bool { use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_EXECUTE_READWRITE, PAGE_READWRITE}; + // VirtualQuery walks the 4 GiB coherent window to size it (~40 ms): a title's clzero loops + // into it ran at a frame or two a second + if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(va, bytes)) { + return true; + } let mut m: MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() }; let found = unsafe { VirtualQuery(va as *const std::ffi::c_void, &mut m, std::mem::size_of_val(&m)) } != 0; found