Repository navigation
Conversation
… copy The unchanged-content hash, the detile of title textures and the frame-trace sampler read the title's memory in place once it looked readable (xcl-dev#602). That bypasses the ReadProcessMemory copy of read_committed (xcl-dev#484): the title can decommit or unmap those pages from another thread at any moment, and the read then faults with 0xC0000005. with_title_bytes replaces title_bytes. A range inside the coherent committed window is still read in place: XCL's VirtualFree never decommits that window (MEM_DECOMMIT there zeroes the block in place). Everything else is read as read_committed reads it, into a buffer kept per thread and dropped after a read that grew it past 64 MiB. read_committed_into now writes every byte (copied, or zero for a page that is not readable), so the reused buffer needs no memset and nothing of an earlier read shows through a hole. Only long-lived threads reuse the buffer: the scoped workers of a parallel batch detile allocate one per batch. title_bytes_survive_concurrent_decommit hashes 1 MiB while another thread decommits and recommits its 64 KiB pages; it checks that every decommit and recommit succeeded, that some happened during the hashing and that each read holds the title's bytes or zeros. title_bytes_leave_guard_pages_alone reads a guard and a no-access page as zeros and checks that the guard stays. read_committed_into first copies the whole range with one ReadProcessMemory and walks it region by region with VirtualQuery only when that is refused (a page not committed, no-access or a guard page; the guard stays). VirtualQuery scans from the page asked about to the end of its run of like pages, and the title's memory is a few runs of hundreds of MiB: in a release microbenchmark (7600X), reading 16 KiB / 256 KiB / 4 MiB of a fully committed 64 MiB region took 128 / 125 / 280 us with the walk and 1.3 / 6.9 / 156 us now (512 MiB region: 1629 / 1179 / 1753 us, now 1.4 / 7.5 / 128 us). A range with holes pays one refused copy on top of the walk (4 MiB with one hole: ~158 us before, ~230 us now).
|
Focused review of #2844 at I forced this path with a synthetic 64 KiB This is a forced failure-path test, not an observed Candidate diff and regression testdiff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index 213b76b9..5afeed28 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -51,15 +51,16 @@ fn vendor(device: &ID3D12Device) -> Option<u32> {
}
/// The written pages of `[base, base + size)` that hold anything but zeros, with their bytes.
-unsafe fn written_pages(base: usize, size: usize) -> Vec<(usize, Vec<u8>)> {
+unsafe fn written_pages(base: usize, size: usize) -> Result<Vec<(usize, Vec<u8>)>, String> {
let mut out = Vec::new();
let mut buf: Vec<*mut c_void> = vec![std::ptr::null_mut(); 1 << 16];
let end = base + size;
let mut at = base;
while at < end {
let (mut n, mut page) = (buf.len(), 0u32);
- if GetWriteWatch(0, at as *const c_void, end - at, buf.as_mut_ptr(), &mut n, &mut page) != 0 {
- break;
+ let status = GetWriteWatch(0, at as *const c_void, end - at, buf.as_mut_ptr(), &mut n, &mut page);
+ if status != 0 {
+ return Err(format!("GetWriteWatch at {at:#x} failed ({status})"));
}
for &p in &buf[..n] {
let s = std::slice::from_raw_parts(p as *const u8, page as usize);
@@ -72,7 +73,7 @@ unsafe fn written_pages(base: usize, size: usize) -> Vec<(usize, Vec<u8>)> {
}
at = buf[n - 1] as usize + page as usize;
}
- out
+ Ok(out)
}
/// Reserves every free stretch of 1 GiB or more (but its first 256 MiB, room for the driver's own
@@ -116,7 +117,7 @@ unsafe fn ungroom(got: Vec<usize>) {
/// good. On failure the window is the title's memory again, its pages as they were.
pub(super) unsafe fn remake(device: &ID3D12Device, base: usize, size: usize) -> Result<(ID3D12Heap, ID3D12Resource), String> {
let t0 = std::time::Instant::now();
- let pages = written_pages(base, size);
+ let pages = written_pages(base, size)?;
let kept: usize = pages.iter().map(|p| p.1.len()).sum();
if VirtualFree(base as *mut c_void, 0, MEM_RELEASE) == 0 {
return Err(format!("VirtualFree of the window at {base:#x} failed"));
@@ -207,4 +208,29 @@ mod tests {
assert!(decide(Some("custom"), || true, || Some(0x1002)));
assert!(decide(Some(" 1 "), || false, || None));
}
+
+ #[test]
+ fn failed_write_watch_does_not_release_the_original_window() {
+ use super::*;
+ use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+ const SIZE: usize = 1 << 16;
+ unsafe {
+ let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize;
+ assert_ne!(base, 0);
+ std::ptr::write_bytes(base as *mut u8, 0x5a, SIZE);
+ let mut dev = None;
+ if D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut dev).is_err() {
+ VirtualFree(base as *mut c_void, 0, MEM_RELEASE);
+ return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+ }
+ // A regular VirtualAlloc block lacks MEM_WRITE_WATCH, forcing GetWriteWatch to fail.
+ assert!(remake(&dev.unwrap(), base, SIZE).is_err());
+ let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
+ assert_ne!(VirtualQuery(base as *const c_void, &mut info, std::mem::size_of_val(&info)), 0);
+ assert_eq!(info.AllocationBase as usize, base);
+ assert_eq!(info.State, MEM_COMMIT);
+ assert!(std::slice::from_raw_parts(base as *const u8, SIZE).iter().all(|&b| b == 0x5a));
+ assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
+ }
+ }
}AI use: Codex (GPT-6.2 Sol) traced the page-snapshot and fallback paths, wrote and ran the local candidate and test, and drafted this review. I checked the source path, diff, and test output. |
25dfc2c to
fc007a9
Compare
|
Thanks, confirmed and applied as posted in fc007a9 (squashed into the PR commit, with your test and credit in the commit message): The same push also changes one other thing: the driver heap is now created with AI use: Claude Code (Claude Opus 5.5) checked the finding, applied the diff and wrote this reply. |
|
Independent Windows/NVIDIA check of #2844 at
Two lifecycle points remain after reading the current code. I did not trigger either failure; these are execution paths to cover before treating the remap as safe for concurrent title code:
I did not run a retail title or measure FPS on this card. AMD/Intel and post-reset write-watch behavior on this card remain untested here. AI use: Codex (GPT-6.2 Sol) reviewed the current source and ran the tests; I checked each point and the output before posting. |
|
Follow-up to my RTX 3080 Ti report on head This verifies the write-watch reset path on this NVIDIA driver. It does not resolve the two remap lifecycle concerns in my prior comment. The probe was local-only and has been removed from the worktree. AI use: Codex (GPT-6.2 Sol) wrote and ran the probe; I checked its assertions and result. |
|
Follow-up to my lifecycle review on head The test writes A bounded resolution would complete backend initialization and any remap before Local failing regression diff (test instrumentation only)diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index 8b0dab98..fb34ee0a 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -118,8 +118,18 @@ unsafe fn ungroom(got: Vec<usize>) {
/// of it, mapped for good. On failure the window is the title's memory again, its pages as they
/// were.
pub(super) unsafe fn remake(device: &ID3D12Device, base: usize, size: usize) -> Result<(ID3D12Heap, ID3D12Resource), String> {
+ remake_with_after_snapshot(device, base, size, || {})
+}
+
+unsafe fn remake_with_after_snapshot(
+ device: &ID3D12Device,
+ base: usize,
+ size: usize,
+ after_snapshot: impl FnOnce(),
+) -> Result<(ID3D12Heap, ID3D12Resource), String> {
let t0 = std::time::Instant::now();
let pages = written_pages(base, size)?;
+ after_snapshot();
let kept: usize = pages.iter().map(|p| p.1.len()).sum();
if VirtualFree(base as *mut c_void, 0, MEM_RELEASE) == 0 {
return Err(format!("VirtualFree of the window at {base:#x} failed"));
@@ -246,4 +256,35 @@ mod tests {
assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
}
}
+
+ #[test]
+ fn write_after_snapshot_survives_remake() {
+ use super::*;
+ use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+ const SIZE: usize = 1 << 16;
+ unsafe {
+ let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) as usize;
+ assert_ne!(base, 0);
+ (base as *mut u8).write(0x5a);
+ let mut dev = None;
+ if D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut dev).is_err() {
+ VirtualFree(base as *mut c_void, 0, MEM_RELEASE);
+ return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+ }
+ let result = remake_with_after_snapshot(&dev.unwrap(), base, SIZE, || (base as *mut u8).write(0xa5));
+ let mut info: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
+ assert_ne!(VirtualQuery(base as *const c_void, &mut info, std::mem::size_of_val(&info)), 0);
+ let committed = info.State == MEM_COMMIT;
+ let byte = if committed { Some((base as *const u8).read()) } else { None };
+ let remade = result.is_ok();
+ if let Ok((heap, buf)) = result {
+ buf.Unmap(0, None);
+ drop((buf, heap));
+ } else if committed {
+ assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
+ }
+ assert!(committed, "the original window is no longer committed");
+ assert_eq!(byte, Some(0xa5), "write made while the original window was still mapped; remade={remade}");
+ }
+ }
}The test was local only; no retail title, private game data or FPS measurement was used. AI use: Codex (GPT-6.2 Sol) traced the current source, wrote and ran the test, and drafted this report. I checked the source path, diff and failures before posting. |
|
Candidate for the snapshot-boundary failure on #2844 head A new assertion in the existing synthetic title e2e test checks backend initialization precedes the dependent DLL's The synthetic title attempted early remap but this driver's mapping landed elsewhere, so it used the imported fallback. This run proves startup ordering and fallback, not successful CUSTOM mapping or a retail FPS effect. I did not run matched clean-tree retail smoke, AMD or Intel. The separate failed-rollback path in my earlier review remains unresolved; if the old VA cannot be reacquired, initialization must stop rather than continue with an unbacked window. Local candidate diffdiff --git a/crates/xcl/src/hle/d3d12x/mod.rs b/crates/xcl/src/hle/d3d12x/mod.rs
index 4666c0e7..b7c2e38c 100644
--- a/crates/xcl/src/hle/d3d12x/mod.rs
+++ b/crates/xcl/src/hle/d3d12x/mod.rs
@@ -73,15 +73,16 @@ pub enum Backend {
}
/// Decided once: the real backend unless disabled or the driver refuses.
-pub fn backend() -> Backend {
- static B: OnceLock<Backend> = OnceLock::new();
- *B.get_or_init(|| {
+static BACKEND: OnceLock<Backend> = OnceLock::new();
+
+fn backend_with_remap(allow_driver_remap: bool) -> Backend {
+ *BACKEND.get_or_init(|| {
let cfg = crate::state::config();
if cfg.graphics.eq_ignore_ascii_case("null") {
crate::xlog_info!("D3D12.X: backend 'null' (from the config)");
return Backend::Null;
}
- match real::init() {
+ match real::init_with_remap(allow_driver_remap) {
Ok(desc) => {
crate::xlog_info!("D3D12.X: backend 'real' – {desc}");
Backend::Real
@@ -94,6 +95,14 @@ pub fn backend() -> Backend {
})
}
+pub fn backend() -> Backend {
+ backend_with_remap(false)
+}
+
+pub(crate) fn backend_before_guest() -> Backend {
+ backend_with_remap(true)
+}
+
/// Call a function of the system d3d12.dll by name.
unsafe fn sys(name: &str) -> Option<usize> {
crate::resolver::system_proc("d3d12.dll", &crate::pe::ImportName::Name { hint: 0, name: name.into() })
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index 8ab89e34..19eedfe6 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -298,14 +298,14 @@ unsafe fn check_uma_import(device: &ID3D12Device, u: &crate::gpu::uma::Uma, bufs
Ok(format!("ok, {} window(s), {} µs", probes.len(), t0.elapsed().as_micros()))
}
-unsafe fn open_uma(device: &ID3D12Device) {
+unsafe fn open_uma(device: &ID3D12Device, allow_driver_remap: bool) {
let Some(u) = crate::gpu::uma::get() else {
*UMA_ERROR.lock().unwrap() = "no UMA region".into();
return;
};
let open = |k: usize| -> Result<(usize, u64, usize), String> {
let (base, size) = u.window(k);
- if super::uma_driver::wanted(device) {
+ if allow_driver_remap && super::uma_driver::wanted(device) {
match super::uma_driver::remake(device, base, size) {
Ok((heap, buf)) => {
u.set_driver_window(k);
@@ -478,6 +478,10 @@ fn graphics_wave32(device: *mut c_void) -> bool {
/// by default the high-performance GPU → WARP); once – later calls
/// return the existing device's adapter.
pub fn init() -> Result<String, String> {
+ init_with_remap(false)
+}
+
+pub(super) fn init_with_remap(allow_driver_remap: bool) -> Result<String, String> {
if !device_raw().is_null() {
return Ok(ADAPTER.lock().map(|a| a.clone()).unwrap_or_default());
}
@@ -554,7 +558,7 @@ pub fn init() -> Result<String, String> {
let _ = q.RegisterMessageCallback(Some(debug_message), D3D12_MESSAGE_CALLBACK_FLAG_NONE, std::ptr::null_mut(), &mut cookie);
}
}
- open_uma(&device);
+ open_uma(&device, allow_driver_remap);
super::device_x::probe_dynamic_depth_bias(&device);
let raw = device.into_raw(); // one reference kept for the process lifetime
adopt(raw, Kind::Device);
diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs
index a9412c65..1f5d3f49 100644
--- a/crates/xcl/src/host.rs
+++ b/crates/xcl/src/host.rs
@@ -107,18 +107,6 @@ pub fn host_main(boot_path: &Path) -> i32 {
}
});
}
- // `XCL_RUN_SECONDS=n`: the title ends itself after n seconds – the GPU drained, the log and
- // report written (a process killed from outside with GPU work in flight can hang in the driver)
- if let Some(secs) = std::env::var("XCL_RUN_SECONDS").ok().and_then(|v| v.parse::<u64>().ok()) {
- std::thread::spawn(move || {
- std::thread::sleep(std::time::Duration::from_secs(secs));
- let (shown, presented) = crate::hle::d3d12x::present::counters();
- crate::xlog_info!("XCL_RUN_SECONDS: {secs} s – ending the title ({shown} frames shown, {presented} PresentX calls)");
- crate::report::write_final(None);
- crate::log::flush();
- crate::hle::d3d12x::real::end_title(0);
- });
- }
crate::stubs::init_db(&boot.config.stub_returns);
crate::hle::init(&boot.config);
crate::hle::kernelx::fine_timer();
@@ -144,8 +132,22 @@ pub fn host_main(boot_path: &Path) -> i32 {
}
crate::eh::install_crash_handler();
crate::eh::start_probes();
+ crate::hle::d3d12x::backend_before_guest();
HOST_MODE.store(true, Ordering::Release);
+ // `XCL_RUN_SECONDS=n`: the title ends itself after n seconds – the GPU drained, the log and
+ // report written (a process killed from outside with GPU work in flight can hang in the driver)
+ if let Some(secs) = std::env::var("XCL_RUN_SECONDS").ok().and_then(|v| v.parse::<u64>().ok()) {
+ std::thread::spawn(move || {
+ std::thread::sleep(std::time::Duration::from_secs(secs));
+ let (shown, presented) = crate::hle::d3d12x::present::counters();
+ crate::xlog_info!("XCL_RUN_SECONDS: {secs} s – ending the title ({shown} frames shown, {presented} PresentX calls)");
+ crate::report::write_final(None);
+ crate::log::flush();
+ crate::hle::d3d12x::real::end_title(0);
+ });
+ }
+
let main = match crate::loader::load_main(&boot.exe_path) {
Ok(m) => m,
Err(e) => {
diff --git a/crates/xcl/tests/e2e.rs b/crates/xcl/tests/e2e.rs
index 4f238248..8e7109f6 100644
--- a/crates/xcl/tests/e2e.rs
+++ b/crates/xcl/tests/e2e.rs
@@ -161,6 +161,9 @@ fn test_title_runs_and_game_folder_is_untouched() {
assert!(out.status.success(), "exit code {:?}", out.status.code());
let log = std::fs::read_to_string(data.join("XCL.TestTitle/logs/xcl.log")).unwrap();
+ let backend_init = log.find("D3D12.X: backend '").expect("backend initialized");
+ let dll_init = log.find("DllMain(").expect("dependent DLL initialized");
+ assert!(backend_init < dll_init, "D3D12 backend initialized after title DLL code ran");
let window = |tag| log.lines().find_map(|line| line.split_once(tag).map(|(_, hwnd)| hwnd)).unwrap();
assert_eq!(window("Shader preparation window "), window("present: swap chain window "));
AI use: Codex (GPT-6.2 Sol) traced the current code, wrote and ran the local candidate and tests, and drafted this report. Codex (GPT-6.2 Astra) provided a read-only architecture check. I independently checked every point and the output before posting. |
|
Follow-up on the second #2844 lifecycle point, checked on head In the local candidate below, an unsuccessful exact-address restoration logs the cause, flushes, and terminates the process with On Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC:
This is a forced failure-path test, not evidence that an address collision occurred in a retail run. No title or paired clean-tree smoke was run for this local candidate; the separate pre-guest remap timing candidate remains in my earlier comment. Local candidate diff and child-process regressiondiff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index 8b0dab98..e68ac4d9 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -118,6 +118,15 @@ unsafe fn ungroom(got: Vec<usize>) {
/// of it, mapped for good. On failure the window is the title's memory again, its pages as they
/// were.
pub(super) unsafe fn remake(device: &ID3D12Device, base: usize, size: usize) -> Result<(ID3D12Heap, ID3D12Resource), String> {
+ remake_with_after_release(device, base, size, || Ok(()))
+}
+
+unsafe fn remake_with_after_release(
+ device: &ID3D12Device,
+ base: usize,
+ size: usize,
+ after_release: impl FnOnce() -> Result<(), String>,
+) -> Result<(ID3D12Heap, ID3D12Resource), String> {
let t0 = std::time::Instant::now();
let pages = written_pages(base, size)?;
let kept: usize = pages.iter().map(|p| p.1.len()).sum();
@@ -127,7 +136,16 @@ pub(super) unsafe fn remake(device: &ID3D12Device, base: usize, size: usize) ->
let restore = |why: String| -> String {
let p = VirtualAlloc(base as *const c_void, size, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE);
if p as usize != base {
- return format!("{why}; and the window could not be made again at {base:#x} (got {p:?})");
+ let os_error = windows_sys::Win32::Foundation::GetLastError();
+ crate::xlog_error!(
+ "D3D12.X: coherent window could not be restored at {base:#x} ({size} bytes, got {p:?}, Windows error {os_error}) after {why}; stopping before guest memory is used"
+ );
+ crate::log::flush();
+ windows_sys::Win32::System::Threading::TerminateProcess(
+ windows_sys::Win32::System::Threading::GetCurrentProcess(),
+ 0x7C1_0003,
+ );
+ std::process::abort();
}
for (a, bytes) in &pages {
std::ptr::copy_nonoverlapping(bytes.as_ptr(), *a as *mut u8, bytes.len());
@@ -137,6 +155,7 @@ pub(super) unsafe fn remake(device: &ID3D12Device, base: usize, size: usize) ->
let groomed = groom(base, size);
let reservations = groomed.len();
let made = (|| -> Result<(ID3D12Heap, ID3D12Resource, usize), String> {
+ after_release()?;
let properties = D3D12_HEAP_PROPERTIES {
Type: D3D12_HEAP_TYPE_CUSTOM,
CPUPageProperty: D3D12_CPU_PAGE_PROPERTY_WRITE_BACK,
@@ -246,4 +265,41 @@ mod tests {
assert_ne!(VirtualFree(base as *mut c_void, 0, MEM_RELEASE), 0);
}
}
+
+ #[test]
+ fn failed_restore_stops_before_importing_an_unbacked_window() {
+ use super::*;
+ use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+ const SIZE: usize = 1 << 16;
+ const CODE: i32 = 0x7C1_0003;
+ if std::env::var_os("XCL_TEST_RESTORE_COLLISION").is_some() {
+ unsafe {
+ let mut dev = None;
+ D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut dev).unwrap();
+ let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) as usize;
+ assert_ne!(base, 0);
+ (base as *mut u8).write(0x5a);
+ let result = remake_with_after_release(&dev.unwrap(), base, SIZE, || {
+ let occupied = VirtualAlloc(base as *const c_void, SIZE, MEM_RESERVE, PAGE_NOACCESS);
+ assert_eq!(occupied as usize, base);
+ Err("synthetic post-release failure".into())
+ });
+ eprintln!("continued after failed restore: {result:?}");
+ }
+ return;
+ }
+ let mut dev: Option<ID3D12Device> = None;
+ if unsafe { D3D12CreateDevice(None, D3D_FEATURE_LEVEL_11_0, &mut dev) }.is_err() {
+ return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+ }
+ let output = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["--exact", "hle::d3d12x::uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window", "--nocapture"])
+ .env("XCL_TEST_RESTORE_COLLISION", "1")
+ .output()
+ .unwrap();
+ let transcript = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
+ assert_eq!(output.status.code(), Some(CODE), "{transcript}");
+ assert!(transcript.contains("coherent window could not be restored"), "{transcript}");
+ assert!(!transcript.contains("continued after failed restore"), "{transcript}");
+ }
}AI use: Codex (GPT-6.2 Sol) traced the recovery path, wrote and ran the candidate and tests, and drafted this report. I checked the code and outputs before posting. |
… on NVIDIA The title's GPU code reads and writes the coherent window (4 GiB of host memory) through a heap opened with OpenExistingHeapFromAddress. On an RTX 5070 Ti, GPU loads from such imported pages ran 8-24x and atomics 13-22x slower than from a driver CUSTOM write-back L0 heap in host memory, at the same CPU caching. A whole-frame replay of a captured title frame took 172 ms of GPU time with the window in a CUSTOM L0 heap and 1,427 ms with it imported as XCL does, the hot compute programs 18-39x slower each. At open_uma the window's written pages are copied out, the window is released, every other free stretch of 1 GiB or more is reserved for a moment so that the driver's CPU mapping of a new CUSTOM L0 heap can only land in the hole the window left, and the pages are copied back. The title keeps its pointers. If the mapping lands anywhere else, or a step fails, the window is made again at its address with its pages and imported as before; if the snapshot of its written pages fails, the window is not released at all (found in review by thehollowedone, with the test failed_write_watch_does_not_release_the_original_window). Buffers placed in it drop ALLOW_CROSS_ADAPTER. The heap is made with D3D12_HEAP_FLAG_ALLOW_WRITE_WATCH, and GetWriteWatch reads the mapped window on an RTX 5070 Ti (driver 610.74), so the window stays in the write-watched regions and the title's CPU writes reach its textures as with the import; a driver that refuses the flag, or whose mapping GetWriteWatch cannot read, keeps the import. The backend (and with it the window and any driver remap) is made once before load_main, before a title DLL's TLS callbacks or DllMain can hold a window pointer; a backend first made later only imports, so no remap happens under guest threads. A write between the snapshot and the release could otherwise be lost. If the window cannot be made again at its address after it was released, XCL logs it and ends the process rather than run the title on an unbacked window. Both found in review by thehollowedone, with their tests (the e2e order check and failed_restore_stops_before_importing_an_unbacked_window). On by default for an NVIDIA adapter outside Wine; XCL_UMA_DRIVER=0 turns it off, XCL_UMA_DRIVER=1 (or custom) turns it on elsewhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested — RTX 4090, one pair in the world: GPU time of the console's work per frame 5,080 ms → 91 ms, 0.27 → 2.66 fps.
Seen: green flashes over the whole picture with Not tested: the test suite and AI use: Claude Code (Claude Sonnet 5.5) built the tree, read the logs and wrote this report; I played the runs. |
fc007a9 to
50ae2eb
Compare
|
@thehollowedone thank you, both lifecycle points confirmed and taken as posted, squashed into the PR commit in 50ae2eb with credit in its message:
Tested on 50ae2eb, RTX 5070 Ti, Windows 11, Rust stable MSVC:
AI use: Claude Code, Claude Opus 5.5 checked both candidates against the code, applied them, ran the tests and the title run, and wrote this reply. |
|
Independent Windows/NVIDIA recheck of #2844 at On Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11:
The full-suite synthetic title log shows one successful pre-guest remap: a 512 MB coherent window became a driver CUSTOM write-back L0 heap at its original address, remained write-watched, kept 0 pages, and passed the UMA import check. The backend log precedes the dependent DLL's I checked the current diff and test output. No retail title, visual output, FPS comparison, or AMD/Intel run was performed here. AI use: Codex (GPT-6.2 Sol) inspected the revision, ran the tests, and drafted this report. |
|
Linux (Wine) dual-lane run at head
Suite: AMD Wine lane: 611/2. Their 5 new tests all green, red set identical to base. Clean PR on RADV. NVIDIA Wine lane: 608/5. Base three plus two failures introduced here, both reproducible in isolation 3/3 with
Both tests are new in this PR (they don't exist at main Caveats: we measure suite-level behavior only - the headline 4.9x FPS number is an in-game result we cannot reproduce here. Single suite run plus the solo confirmations above; nothing else moved in the red set. AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting. |
Stacked on #751; only the top commit belongs here (#751 fixes the detile crash that otherwise ends every world run before a two-minute window). Part of #2688.
Result: 3.03 FPS instead of 0.62 in the world (4.9x), RTX 5070 Ti, title ea3b5e4d, same 2-minute window, no device removal or crash. The GPU time of a replayed world frame drops 8.7x (1,427 ms -> 165 ms), the hot compute programs 18-39x each.
On NVIDIA the coherent UMA window is the bottleneck: the title's GPU code reads and writes it through a heap opened with
OpenExistingHeapFromAddress, and the GPU's loads and atomics on those imported pages are an order of magnitude slower than on a driver heap in the same host memory. This PR puts the window in a driverCUSTOMwrite-back L0 heap mapped at the window's own address, so the title keeps its pointers.How it was found: locum
locum (MIT) is a standalone D3D12 capture and replay tool: a wrapper DLL records every call, resource and descriptor of a frame, and
locum-clireplays that frame offline, optionally with one thing changed, timing every draw and dispatch on the GPU (locum-cli verify --times). It is only used as an external tool here; no code of it is in XCL. Live, the title is too slow and noisy to tell causes apart (shader form, tile remaps, video memory over budget, paging and sync stalls all looked plausible). With locum:OpenExistingHeapFromAddress): 1,427.3 ms, 8.7x, reproducing the live per-op times. b78fa10b 19.7 -> 350.6 ms (18x), 24de2aef's three dispatches 10.2 -> 393.6 ms (39x), 1b5466f2 1.4 -> 246.5 ms. Same capture, same replay code, one queue, no tile remaps: the cost is in how the window's memory is made, not in the live run. (Both replays ran at the same low clocks, since a replay feeds the GPU slowly: the ratio is the result, not the absolute times.)Evidence beyond the replay
A standalone probe on the same card (one 1024x64x16 dispatch per memory home, ns per loop iteration, atomics / load):
OpenExistingHeapFromAddress)Write watch is not the cause (imported without it: same rows), and neither are the cross-adapter flags (a DEFAULT heap with SHARED_CROSS_ADAPTER runs at CUSTOM L0 speed). Plain stores at 256-4096 boxes are the one row where the driver heap is slower (4-7x); the frame totals above include that.
What is in it
hle/d3d12x/uma_driver.rs(new): atopen_uma, the window's written pages are copied out, the window is released, every other free stretch of 1 GiB or more is reserved for a moment so that the driver's CPU mapping of a new CUSTOM L0 heap can only land in the hole the window left, and the pages are copied back. If the mapping lands anywhere else, or any step fails, the window is made again at its address with its pages and imported as before (logged ascoherent window N stays imported: ...). If the snapshot of the written pages fails, the window is not released at all (found in review by @thehollowedone, with their testfailed_write_watch_does_not_release_the_original_window).hle/d3d12x/mod.rs,real.rs,host.rs: the backend, and with it the window and any remap, is made once inhost_mainbeforeload_main, before a title DLL's TLS callbacks orDllMaincan hold a window pointer; a backend first made later, andreal::init(), only import. Otherwise a title write between the snapshot and the release could be lost. If the window cannot be made again at its address after the release, XCL logs it and ends the process (0x7C10003) rather than run the title on an unbacked window. Both found in review by @thehollowedone (review), with their candidates and tests applied as posted: the order check in the e2e testtest_title_runs_and_game_folder_is_untouched, andfailed_restore_stops_before_importing_an_unbacked_window.hle/d3d12x/real.rs: buffers placed in a driver window dropALLOW_CROSS_ADAPTER.gpu/uma.rs: which windows are driver heaps.D3D12_HEAP_FLAG_ALLOW_WRITE_WATCH. On the RTX 5070 TiGetWriteWatchreads the mapped window (4 KiB pages reported, reset, reported again after a new write; all 16,386 written pages of the 4 GiB window found once), so the window stays inwatch_regionsand the title's CPU writes reach its textures as with the import. A driver that refuses the flag, or a mappingGetWriteWatchcannot read, keeps the import. (A first form without write watch left CPU rewrites of title textures in the window off the GPU:placed_title_textures_share_vram_and_preserve_pixelsrow 6 failed in the full parallel suite, where another test had made the window a driver heap.)util::under_wine); AMD, Intel and Wine keep the import unchanged.XCL_UMA_DRIVER=0turns it off,XCL_UMA_DRIVER=1turns it on anywhere. Unit testsdriver_windows_by_default_on_nvidia_outside_wine,failed_write_watch_does_not_release_the_original_windowandfailed_restore_stops_before_importing_an_unbacked_window.Tested
RTX 5070 Ti (16 GB), driver 610.74, Ryzen 9 9950X, 31 GB RAM, Windows 11 Pro 26200, Rust 1.99.0, release.
On this head
50ae2eb, debug:cargo test --workspace --no-fail-fast -- --test-threads=4: 1448 passed, 3 failed, 47 ignored, the same 144 SKIPPED. The failed ones: the twolink_testsbelow (as on main), andlist_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submitonce, in a suite run beside other jobs; it passed alone 3 of 3 and incargo test -p xcl --lib list_x(40 passed, 0 failed). This PR does not touchlist_x.cargo test -p xcl --lib hle::d3d12x::uma_driver::tests:: -- --test-threads=1: 3 passed, 0 failed;cargo test -p xcl --test e2e test_title_runs_and_game_folder_is_untouched: 1 passed, 0 failed.On the previous head
fc007a9:cargo test --workspace -- --test-threads=4: 1448 passed, 2 failed, 47 ignored; 144 SKIPPED (119 validator 1.7 < 1.8, validation step only; 21 no wave64; 3 refused f16 forms V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32, gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics; 1 no heap windows). The failed ones arelink_tests::gpu_linked_memory_accessorsandlink_tests::linked_programs_keep_their_declarations(DXC: "attribute WaveSize only valid on entry point function"); they fail the same way on main 8b957be (cargo test -p xcl --lib link_tests: 0 passed, 2 failed).Title ea3b5e4d, one paired run each (main and the previous head
fc007a9), 480 s, the GPU alone (no build or other job on the machine). Both arms start from snapshots of one cache made by a singlexcl shaders shaders.rpf --precompile --pipelineson main's translator (this PR changes no shader code; the precompile: 20,748 compiled, 14,842 already cached, 0 errors, 2,689 pipelines made, 0 refused), and neither arm wrote a new loose DXIL cache entry or driver PSO file in play (it still wrote translation records, which can hold DXIL from direct translation: main 866, this PR 868); the startup preparation still rescans the pack on every launch. Env for both:XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_DIRECT_SPLIT_INSTRUCTIONS=0 XCL_PSO_JOURNAL=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=120000 XCL_DXIL_CACHE=<snapshot> XCL_DXC_DIR=<DXC 1.9.2609> XCL_PRESS_AT=14:A,18:A,...(A every 4 s from 14 s). Each arm is scored over 120 s from 10 s after its world starts (the first 2 s with 5,000+ dispatches), FPS as presents over the measured time of the activity intervals: main's world from 108 s, scored 117.7-238.7 s (121.0 s measured); this PR's from 106 s, scored 116.1-236.1 s (120.1 s measured).the coherent window at 0x... (4095 MB) is a driver CUSTOM write-back L0 heap mapped at its address, write-watchedOn this head
50ae2eb, 480 s, the same env and cache snapshot, in the queue's title lane beside other jobs (not timed, so not in the table): 2,937 frames shown (fc007a9: 2,841), 0 device removals, 0 crashes, peak commit 39,371 MB; the window became the driver heap before the title loaded (0 pages kept).A second PR run, on 25dfc2c, an earlier form of this PR whose window was not write-watched and which instead hashed all ~500 MB of the title's textures in it at every look (16-19 ms a look): 1.22 FPS (world from 148 s, scored 158.0-278.1 s; device removals / crashes 0 / 0).
Regression run
Not tested
XCL_UMA_DRIVER=1on them is untested.AI use
🤖 Generated with Claude Code