Repository navigation
D3D12.X: UMA windows in a driver heap on NVIDIA, 4.9x FPS (0.62 -> 3.03) - #2844
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. |
|
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. |
|
Tested on a slower CPU: RTX 4060 Ti 16 GB with an i7-8700. #2844 halved the GPU's busy time in the world, but the present rate did not move, because this machine is held by the write-watch looks. One run per arm, head Setup
Not tested: AI use: Claude Code (Claude Opus 5.5) ran the runs, read the logs and wrote this. |
|
Follow-up to the Wine/NVIDIA failures on head The guard-page test reaches a new fast path in Candidate diff against 50ae2eb--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -1405,8 +1405,16 @@ unsafe fn read_committed_into(at: usize, out: &mut [u8]) {
- // `ReadProcessMemory` refuses a range with a page that is not committed, no-access or a guard
- // page (and leaves the guard in place: `title_bytes_leave_guard_pages_alone`).
+ // On native Windows, `ReadProcessMemory` refuses a range with a page that is not committed,
+ // no-access or guarded (and leaves the guard in place).
+ if len == 0 {
+ return;
+ }
+ // Under Wine, retain the original query-first path so protection checks cannot be
+ // bypassed by a successful whole-range read.
let mut read = 0usize;
- if len == 0 || ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0 {
+ if !crate::util::under_wine()
+ && ReadProcessMemory(GetCurrentProcess(), at as *const c_void, out.as_mut_ptr() as *mut c_void, len, &mut read) != 0
+ {
return;
}On Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, For AI use: Codex (GPT-6.2 Sol) traced the code, prepared the candidate, ran the Windows tests, and drafted this report. |
|
@Kalmarv a port of this PR to Runs: RTX 4070 Ti 12 GB, driver 621.40, 2 GiB shader heap (#2590), Series S profile,
Not tested: the suite on the port; the 4 GB layout on a tree where it survives; a second card. AI use: Claude Code (Claude Opus 5.5) ported the commit, ran the runs on the hardware above and wrote this. |
|
8 GB card (RTX 3070, Ampere) on an Intel i9-9900K: with this PR the title presents 2.5–3.2x as often in its world (0.74 and 0.93 presents/s against 0.29 with Setup
Results (the world from the first
Presents per 30 s in the world:
Not tested: this PR on AI use: Claude Code (Claude Opus 5.5) built the tree, ran the runs on my machine, read the logs and wrote this; I watched the runs and checked the report. |
|
RTX 3090 24 GB at Setup
For comparison, not the same tree: on Tests at Not tested: the write-watch time with the PR; this PR on AI use: Claude Code (Claude Opus 5.5) ran the runs and tests on my machine, read the PresentMon captures and the logs, and drafted this. Checked by me before posting. |
50ae2eb to
342bf7d
Compare
… 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. Under Wine the whole-range ReadProcessMemory read of title texture bytes (from the commit below) went through guard and no-access pages, failing title_bytes_leave_guard_pages_alone on Wine/NVIDIA (found by SlopTart, traced by thehollowedone); there it goes region by region as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
342bf7d to
f2248f0
Compare
|
Independent Windows/NVIDIA recheck of #2844 at head
This confirms the current head on native Windows. It does not resolve the NVIDIA-under-Wine report: the new query-first Wine path still needs a Wine rerun, and the failed-restore child test's exit code AI use: Codex (GPT-6.2 Sol) ran and checked the suite and drafted this report; Codex (GPT-6.2 Sol) independently reviewed the Wine failure and current code. |
A look copied the read-only spans into a new map and then made two map queries per span to find the pieces still to look at. In the late world of title ea3b5e4d that is about 9,000 spans a look and 20 looks a present. hot_pieces now walks the spans once, under the lock, while the ranges ascend (a look's are sorted and disjoint), and starts the walk again for a range that does not. Measured without a GPU, a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at: 336 us before, 40 us after (RTX 5070 Ti machine, release build). In the title, on a tree with the driver-heap windows of xcl-dev#2844 (one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Every submit looks at all watched memory with GetWriteWatch, and the call is paid per byte looked at (about 0.5 ms per GiB). In a streamed world 17.6 GB are watched, and most of it is written once when it streams in and not again. With XCL_WATCH_TRAP=1 a 2 MiB block of a watched range that 64 looks in a row found clean is made read-only and left out of the looks. Its first write faults into a vectored handler, which gives the block its protection back and returns it to the looks; the write happens after that, so write-watch reports it as before. A block that cannot be made read-only (pinned, nothing committed, not all read-write) is tried again after another 64 looks, not at every look, and a block with nothing committed leaves the looks as a hole until a commit in it. A kernel write into a read-only page fails instead of faulting, so the title's ReadFile buffers get their protection back and stay pinned until the read is over, and their pages are then reported as written. Commits, decommits and protection changes through kernelx, lazy pages and sparse commits give the blocks they meet their protection back first, and so do XCL's own checks whether memory is writable. Off by default; without the variable only a sorted list gets a dedup. Measured on title ea3b5e4d on a tree with the driver-heap windows of xcl-dev#2844 (RTX 5070 Ti, one timed run per arm, the trap the only change): 5.79 against 4.01 presents/s over 107-223 s of the run, 8.45 against 4.60 over 187-229 s, the same draws per present, no device removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A look copied the read-only spans into a new map and then made two map queries per span to find the pieces still to look at. In the late world of title ea3b5e4d that is about 9,000 spans a look and 20 looks a present. hot_pieces now walks the spans once, under the lock, while the ranges ascend (a look's are sorted and disjoint), and starts the walk again for a range that does not. Measured without a GPU, a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at: 336 us before, 40 us after (RTX 5070 Ti machine, release build). In the title, on a tree with the driver-heap windows of xcl-dev#2844 (one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...] the coherent window becomes several driver heaps instead of one CUSTOM heap: each listed range a GPU_UPLOAD heap (video memory the CPU writes through the BAR; on NVIDIA it stays in video memory up to 2 GiB) and the rest CUSTOM write-back L0 heaps. Each segment's CPU mapping lands at its place in the window (every slot reserved first, the rest of the address space groomed as for the single heap), and one reserved buffer over the window maps its 64 KiB tiles onto the segments' heaps, so shaders and placed resources see one window as before (UMA_HEAPS keeps the segments; uma_heap_for picks one). - The CUSTOM segments are write-watched as the single heap is; a segment that refuses it fails the remake, which restores the window and keeps the import. The GPU_UPLOAD segments are not write-watched: their write-combined pages refuse the watch trap's read-only protection. Uma::watch_regions lists only the watched segments. - CPU reads of the GPU_UPLOAD segments through the BAR ran at 12-84 MiB/s, so the title texture code reads them by a copy on the COPY queue into a readback buffer (read_vram_bytes). - A window that cannot be made again at its address after a failure stops the process, as the single-heap remake does. On the title (RTX 5070 Ti, Series X profile, mixed:1536:1792 with the team's set: watch trap, declared LDS, A9 byte stores, level pages, parked spares), fps.py over 187-229 s: 25.28 fps (TX1) and 24.15 (CB2m3), against 11.99 with one CUSTOM heap (CB2) in the same set. Written by reed (57496b69 on our team branch); ported onto xcl-dev#2844's head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...] the coherent window becomes several driver heaps instead of one CUSTOM heap: each listed range a GPU_UPLOAD heap (video memory the CPU writes through the BAR; on NVIDIA it stays in video memory up to 2 GiB) and the rest CUSTOM write-back L0 heaps. Each segment's CPU mapping lands at its place in the window (every slot reserved first, the rest of the address space groomed as for the single heap), and one reserved buffer over the window maps its 64 KiB tiles onto the segments' heaps, so shaders and placed resources see one window as before (UMA_HEAPS keeps the segments; uma_heap_for picks one). - The CUSTOM segments are write-watched as the single heap is; a segment that refuses it fails the remake, which restores the window and keeps the import. The GPU_UPLOAD segments are not write-watched: their write-combined pages refuse the watch trap's read-only protection. Uma::watch_regions lists only the watched segments. - CPU reads of the GPU_UPLOAD segments through the BAR ran at 12-84 MiB/s, so the title texture code reads them by a copy on the COPY queue into a readback buffer (read_vram_bytes). - An adapter without GPU_UPLOAD heaps (D3D12_OPTIONS16; Resizable BAR off) gets the single CUSTOM heap: this is asked before the window is released. A GPU_UPLOAD segment refused anyway becomes a write-watched CUSTOM segment, because the segments mapped before it cannot be given back: a dropped segment's pages stay with the driver (VirtualQuery still shows them committed seconds later, and a new heap of that size maps there again), so the window could not be reserved again (Windows error 487). - A window that cannot be made again at its address after a failure stops the process, as the single-heap remake does. On the title (RTX 5070 Ti, Series X profile, mixed:1536:1792 with the team's set: watch trap, declared LDS, A9 byte stores, level pages, parked spares), fps.py over 187-229 s: 25.28 fps (TX1) and 24.15 (CB2m3), against 11.99 with one CUSTOM heap (CB2) in the same set. Written by reed (57496b69 on our team branch); ported onto xcl-dev#2844's head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
On Linux + NVIDIA under Wine 11.21, Setup: RTX 4060 Ti 16 GB, NVIDIA 615.71.09, Wine 11.21 Staging, vkd3d-proton
Not tested: this tree without the switch; the two tests at the earlier head AI use: Claude Code (Claude Opus 5.5) picked the commit onto our tree, ran the two tests, read the runs and Wine's source, and wrote this. Posted without review by a person: the account owner was away and reads replies later. |
With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...] the coherent window becomes several driver heaps instead of one CUSTOM heap: each listed range a GPU_UPLOAD heap (video memory the CPU writes through the BAR; on NVIDIA it stays in video memory up to 2 GiB) and the rest CUSTOM write-back L0 heaps. Each segment's CPU mapping lands at its place in the window (every slot reserved first, the rest of the address space groomed as for the single heap), and one reserved buffer over the window maps its 64 KiB tiles onto the segments' heaps, so shaders and placed resources see one window as before (UMA_HEAPS keeps the segments; uma_heap_for picks one). - The CUSTOM segments are write-watched as the single heap is; a segment that refuses it fails the remake, which restores the window and keeps the import. The GPU_UPLOAD segments are not write-watched: their write-combined pages refuse the watch trap's read-only protection. Uma::watch_regions lists only the watched segments. - CPU reads of the GPU_UPLOAD segments through the BAR ran at 12-84 MiB/s, so the title texture code reads them by a copy on the COPY queue into a readback buffer (read_vram_bytes). - An adapter without GPU_UPLOAD heaps (D3D12_OPTIONS16; Resizable BAR off) gets the single CUSTOM heap: this is asked before the window is released. A GPU_UPLOAD segment refused anyway becomes a write-watched CUSTOM segment, because the segments mapped before it cannot be given back: a dropped segment's pages stay with the driver (VirtualQuery still shows them committed seconds later, and a new heap of that size maps there again), so the window could not be reserved again (Windows error 487). - A console buffer XCL places in the window whose first fit crosses two segments (no one heap holds it) goes to the next fit; the crossing block is given back instead of staying charged (alloc_in_one_heap). - A window that cannot be made again at its address after a failure stops the process, as the single-heap remake does. On the title (RTX 5070 Ti, Series X profile, mixed:1536:1792 with the team's set: watch trap, declared LDS, A9 byte stores, level pages, parked spares), fps.py over 187-229 s: 25.28 fps (TX1) and 24.15 (CB2m3), against 11.99 with one CUSTOM heap (CB2) in the same set. Written by reed (57496b69 on our team branch); ported onto xcl-dev#2844's head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every submit looks at all watched memory with GetWriteWatch, and the call is paid per byte looked at (about 0.5 ms per GiB). In a streamed world 17.6 GB are watched, and most of it is written once when it streams in and not again. With XCL_WATCH_TRAP=1 a 2 MiB block of a watched range that 64 looks in a row found clean is made read-only and left out of the looks. Its first write faults into a vectored handler, which gives the block its protection back and returns it to the looks; the write happens after that, so write-watch reports it as before. A block that cannot be made read-only (pinned, nothing committed, not all read-write) is tried again after another 64 looks, not at every look, and a block with nothing committed leaves the looks as a hole until a commit in it. A kernel write into a read-only page fails instead of faulting, so the title's ReadFile buffers get their protection back and stay pinned until the read is over, and their pages are then reported as written. A pending read is over when a look sees its OVERLAPPED done, or when the title uses that OVERLAPPED for its next read. Commits, decommits and protection changes through kernelx, lazy pages and sparse commits give the blocks they meet their protection back first, and so do XCL's own checks whether memory is writable. Off by default; without the variable only a sorted list gets a dedup. Measured on title ea3b5e4d on a tree with the driver-heap windows of xcl-dev#2844 (RTX 5070 Ti, one timed run per arm, the trap the only change): 5.79 against 4.01 presents/s over 107-223 s of the run, 8.45 against 4.60 over 187-229 s, the same draws per present, no device removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A look copied the read-only spans into a new map and then made two map queries per span to find the pieces still to look at. In the late world of title ea3b5e4d that is about 9,000 spans a look and 20 looks a present. hot_pieces now walks the spans once, under the lock, while the ranges ascend (a look's are sorted and disjoint), and starts the walk again for a range that does not. Measured without a GPU, a look with a take that does nothing, 18 GiB watched in 64 ranges, 8,861 spans, 355 blocks left to look at: 336 us before, 40 us after (RTX 5070 Ti machine, release build). In the title, on a tree with the driver-heap windows of xcl-dev#2844 (one untimed run per arm): the write-watch part of a look 1.06 ms against 1.29 ms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Compatibility data point: the CUSTOM heap takes effect on a Turing card without Resizable BAR (RTX 2060 SUPER 8 GB), and a 300 s scripted run had no device removal or crash.
AI use: run by a Claude Code agent (Claude Sonnet 5.5), note by Claude Code (Claude Opus 5.5). |
|
Regression check on merged #2844: Main
Good news: your second test from yesterday's runs, Context for the axis: at merge time the Windows+NVIDIA full suite was all-green (RTX 3080 Ti report on this thread); the deterministic red is the NVIDIA-under-Wine corner, while AMD+Wine is only intermittently red (and at a different assertion). Suite cmd: AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting. |
…ow fits in The driver-heap remake of the coherent window (#2844) reserves every free stretch of 1 GiB or more so that the driver's mapping of the new heap can only land in the window's hole. A window under 1 GiB (XCL's 512 MB before a title's size is known, and the 16-window layout's) fits in a stretch between its size and 1 GiB that stays free: in a retail title on an RTX 3060 Ti the driver mapped the heap at 0x4a720000, not the window's 0x1300000000, and the window stayed imported ("Map gave ..., not the window's ..."). Stretches the window fits in are reserved now, with a margin under half the window left free for the driver's own mappings. With the fix the window was remade at its address ("a driver CUSTOM write-back L0 heap mapped at its address"). Test: grooming_leaves_a_window_under_1_gib_only_its_hole (in a process of its own): with a 768 MB free stretch between two reservations below the hole, a 512 MB reservation after grooming lands in the hole; with the old 1 GiB rule it landed in the stretch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@SlopTart a 16 GiB memory limit gives the same assertion here: under it,
Not tested: wine-10.0; driver 550; a GTX 1070; a machine with 16 GB of RAM and swap (the limit here was a cgroup, without swap). AI use: Claude Code (Claude Opus 5.5) ran the tests, read their output, the memory samples, the kernel log and Wine's source, and wrote this. Posted without review by a person: the account owner was away and reads replies later. |
…ev#2844) `uma_driver::tests::gpu_memory_home_probe` (runs with XCL_MEMORY_HOME_PROBE=1, asserts nothing): ns per loop iteration of InterlockedAdd and Load on one 16 MiB buffer in video memory, in the title's own pages opened with OpenExistingHeapFromAddress (as XCL opens the coherent window; plain and with write watch), and in a driver CUSTOM write-back L0 heap (as xcl-dev#2844's driver window; plain and with write watch), for 1 / 256 / 4096 / 65536 boxes 256 B apart. The table of PR xcl-dev#2844's description, for the adapter it runs on: to see whether imported host pages are slow under Wine / vkd3d-proton as they are on Windows / NVIDIA, before xcl-dev#2844's driver window is made to work there. Platform: all Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Kalmarv on the green flashes (7205897747): I reran H3 from my comment above with Setup: the same exe as H1–H3 ( Dumped frames (every 10th presented frame, frames 9 to 1889):
This run lost the device; H1–H3 did not. From 296.9 s there were 82 Log linesNot tested: a second rerun; full-size dumps ( AI use: Claude Code (Claude Opus 5.5) wrote the run script, read the log and the dumps and wrote this; I watched the run. |
With XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...] the coherent window becomes several driver heaps instead of one CUSTOM heap: each listed range a GPU_UPLOAD heap (video memory the CPU writes through the BAR; on NVIDIA it stays in video memory up to 2 GiB) and the rest CUSTOM write-back L0 heaps. Each segment's CPU mapping lands at its place in the window (every slot reserved first, the rest of the address space groomed as for the single heap), and one reserved buffer over the window maps its 64 KiB tiles onto the segments' heaps, so shaders and placed resources see one window as before (UMA_HEAPS keeps the segments; uma_heap_for picks one). - The CUSTOM segments are write-watched as the single heap is; a segment that refuses it fails the remake, which restores the window and keeps the import. The GPU_UPLOAD segments are not write-watched: their write-combined pages refuse the watch trap's read-only protection. Uma::watch_regions lists only the watched segments. - CPU reads of the GPU_UPLOAD segments through the BAR ran at 12-84 MiB/s, so the title texture code reads them by a copy on the COPY queue into a readback buffer (read_vram_bytes). - An adapter without GPU_UPLOAD heaps (D3D12_OPTIONS16; Resizable BAR off) gets the single CUSTOM heap: this is asked before the window is released. A GPU_UPLOAD segment refused anyway becomes a write-watched CUSTOM segment, because the segments mapped before it cannot be given back: a dropped segment's pages stay with the driver (VirtualQuery still shows them committed seconds later, and a new heap of that size maps there again), so the window could not be reserved again (Windows error 487). - A console buffer XCL places in the window whose first fit crosses two segments (no one heap holds it) goes to the next fit; the crossing block is given back instead of staying charged (alloc_in_one_heap). - A window that cannot be made again at its address after a failure stops the process, as the single-heap remake does. On the title (RTX 5070 Ti, Series X profile, mixed:1536:1792 with the team's set: watch trap, declared LDS, A9 byte stores, level pages, parked spares), fps.py over 187-229 s: 25.28 fps (TX1) and 24.15 (CB2m3), against 11.99 with one CUSTOM heap (CB2) in the same set. The two tests that remake a mixed window take one lock: run side by side (4 test threads), one remake's release of its reserved stretches let the other's segment map elsewhere, and the process stopped in 8 of 10 runs of the uma_driver tests (0 of 3 with one thread). Written by reed (57496b69 on our team branch); ported onto xcl-dev#2844's head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…times CPU access `gpu_memory_home_probe` (opt-in, `XCL_MEMORY_HOME_PROBE=1`) adds a CUSTOM L1 write-combine heap, which vkd3d-proton makes DEVICE_LOCAL | HOST_VISIBLE (video memory mapped through the BAR; refused without resizable BAR), and for every home the CPU can map, the CPU's write and read speed over the whole buffer. Under Wine on NVIDIA, xcl-dev#2844's CUSTOM L0 write-back heap is host memory like imported pages (GPU atomics 35-90x slower than video memory), so only such a heap could give xcl-dev#2844's gain there. Platform: all Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.hle/d3d12x/title_textures.rs: under Wine,read_committed_intogoes region by region instead of one whole-rangeReadProcessMemory(from D3D12.X: title texture reads outside the coherent window use the safe copy #751's commit below), which under Wine read through guard and no-access pages and failedtitle_bytes_leave_guard_pages_aloneon Wine/NVIDIA (found by @SlopTart, traced by @thehollowedone, their candidate applied). Native Windows keeps the one copy.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
f2248f0, debug:cargo test -p xcl --lib hle::d3d12x::title_textures::tests:: -- --test-threads=1: 21 passed, 0 failed;cargo test -p xcl --lib hle::d3d12x::uma_driver::tests:: -- --test-threads=1: 3 passed, 0 failed. It differs from50ae2ebonly in the under-Wine branch above, so the full suite below is from50ae2eb.On
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
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). On this headf2248f0, the same: 2,939 frames, 0 device removals, 0 crashes, peak commit 39,360 MB (block below). A first run on this head stopped presenting at ~591 s (about 470 s into play):Write64 Signal ... would close a GPU cyclelines, then no submits, and the device was found removed when the run ended (0x887a0006, no DRED page fault). On Windows this head runs the same code as50ae2eb, whose run had 4 of those lines and no removal; the rerun had none. One hang in the three runs of this PR's two latest heads, cause not known.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. The under-Wine read change is not run under Wine here.nvidia-devport), which ran to its 900 s cap.Unmapand dropping it do not give the address back (VirtualQuery still shows it committed seconds later). So ifGetWriteWatchcannot read a mapping that landed at the right address, the restore cannot succeed, and the process stops with0x7C10003instead of keeping the import. The doc comment's "the window is the title's memory again" holds for the other failures. Not reached in any run here, as the heap is made withD3D12_HEAP_FLAG_ALLOW_WRITE_WATCH.failed_restore_stops_before_importing_an_unbacked_windowexits 1 instead of0x7C10003on Wine/NVIDIA (@SlopTart); the child's output is not known yet.AI use
🤖 Generated with Claude Code