Repository navigation
D3D12.X: the driver heap's grooming reserves stretches a smaller window fits in - #2977
Conversation
Since xcl-dev#2555 every start on main runs the shader preparation before the title's code, and it has no way out: on a retail title with a shader pack of 26,503 records and a cold cache that is hours on an RTX 3060 Ti, for a look at a change that needs a minute of play, and a regression run of main or of a PR's head sits through it first. nvidia-dev has the switch (present/preparation.rs, the same place): with XCL_PREPARE=0 the preparation is left out and the title builds the shaders it uses as it goes, standing still for those builds, as before xcl-dev#2555. Unset, or any other value, prepares as now. Test: only_xcl_prepare_0_leaves_the_preparation_out. README: the switch, next to the preparation's description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ow fits in The driver-heap remake of the coherent window (xcl-dev#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>
|
Independent RTX 3080 Ti check of #2977 head Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, debug. For each tree I ran
All 38 test binaries ran in both suites. The sole failure on both trees is No retail title run was performed here. This is a same-machine parent/head test comparison, not a claim that the full suite is green or that the grooming change improves a title on this adapter. AI use: Codex (GPT-6.2 Sol) checked the exact trees, ran the builds and tests on the hardware above, inspected the failures, and drafted this report. |
|
Follow-up to my parent/head test report, still against #2977 head I found two address-placement edges in the grooming path and tested a candidate correction:
All six UMA driver tests passed, including the new near-hole and tiny-window cases: The suite failure in my earlier report has a separate test-only resolution on current main: With both local candidates applied to #2977, AI use: Codex (GPT-6.2 Sol) wrote and ran the candidates and drafted this report. Codex (GPT-6.2 Astra) independently reviewed the grooming edge cases and correction. Candidate grooming correction and regressions for #2977diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index e4c4b8b7..1e485718 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -94,8 +94,12 @@ unsafe fn groom(hole: usize, len: usize) -> Vec<usize> {
if m.State != MEM_FREE || m.RegionSize < least {
continue;
}
- let s = ((base + 0xFFFF) & !0xFFFF) + margin;
- for (s, e) in [(s, end.min(hole)), (s.max(hole + len), end)] {
+ let first = (base + 0xFFFF) & !0xFFFF;
+ let s = first + margin;
+ // A free granule immediately before the hole lets a window-sized mapping start there.
+ // Keep the driver's margin, but reserve that granule when the margin reaches the hole.
+ let left = if first < hole && hole < end { s.min(hole - 0x1_0000) } else { s };
+ for (s, e) in [(left, end.min(hole)), (s.max(hole + len), end)] {
let mut s = s;
while s < e {
let n = (e - s).min(1 << 40);
@@ -121,6 +125,11 @@ 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> {
+ // Grooming has no room to leave a driver allocation margin around a single granule.
+ // Keep that small window in its original allocation for open_uma to import.
+ if size <= crate::gpu::uma::GRAIN {
+ return Err("single-granule window stays imported".into());
+ }
remake_with_after_release(device, base, size, || Ok(()))
}
@@ -248,7 +257,7 @@ mod tests {
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;
+ const SIZE: usize = 2 * crate::gpu::uma::GRAIN;
unsafe {
let base = VirtualAlloc(std::ptr::null(), SIZE, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) as usize;
assert_ne!(base, 0);
@@ -259,7 +268,8 @@ mod tests {
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 error = remake(&dev.unwrap(), base, SIZE).unwrap_err();
+ assert!(error.contains("GetWriteWatch"), "{error}");
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);
@@ -269,11 +279,36 @@ mod tests {
}
}
+ #[test]
+ fn a_single_granule_window_stays_committed_for_import() {
+ use super::*;
+ use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+ const SIZE: usize = crate::gpu::uma::GRAIN;
+ 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 error = remake(&dev.unwrap(), base, SIZE).unwrap_err();
+ assert_eq!(error, "single-granule window stays imported");
+ 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_eq!((base as *const u8).read(), 0x5a);
+ 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 SIZE: usize = 2 * crate::gpu::uma::GRAIN;
const CODE: i32 = 0x7C1_0003;
if std::env::var_os("XCL_TEST_RESTORE_COLLISION").is_some() {
unsafe {
@@ -348,4 +383,44 @@ mod tests {
let transcript = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
assert_eq!(output.status.code(), Some(0), "{transcript}");
}
+
+ /// A free allocation granule immediately before the target must not let a full window
+ /// land one granule too early. Run alone because grooming reserves other free VA ranges.
+ #[test]
+ fn grooming_blocks_a_window_starting_one_granule_before_its_hole() {
+ use super::*;
+ const LEN: usize = 512 << 20;
+ const GRAIN: usize = 0x1_0000;
+ const RUN: &str = "XCL_TEST_GROOM_NEAR_HOLE";
+ if std::env::var_os(RUN).is_some() {
+ unsafe {
+ let reserve = |at: usize, n: usize| VirtualAlloc(at as *const c_void, n, MEM_RESERVE, PAGE_NOACCESS) as usize;
+ let block = reserve(0, LEN + 3 * GRAIN);
+ assert_ne!(block, 0);
+ assert_ne!(VirtualFree(block as *mut c_void, 0, MEM_RELEASE), 0);
+ let hole = block + 2 * GRAIN;
+ let high = hole + LEN;
+ assert_eq!(reserve(block, GRAIN), block);
+ assert_eq!(reserve(high, GRAIN), high);
+ let got = groom(hole, LEN);
+ let wrong = reserve(hole - GRAIN, LEN);
+ assert_eq!(wrong, 0, "a window-sized mapping fit across the hole boundary at {wrong:#x}");
+ let right = reserve(hole, LEN);
+ assert_eq!(right, hole, "the intended hole was blocked");
+ assert_ne!(VirtualFree(right as *mut c_void, 0, MEM_RELEASE), 0);
+ ungroom(got);
+ for p in [block, high] {
+ assert_ne!(VirtualFree(p as *mut c_void, 0, MEM_RELEASE), 0);
+ }
+ }
+ return;
+ }
+ let output = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["--exact", "hle::d3d12x::uma_driver::tests::grooming_blocks_a_window_starting_one_granule_before_its_hole", "--nocapture"])
+ .env(RUN, "1")
+ .output()
+ .unwrap();
+ let transcript = format!("{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
+ assert!(output.status.success(), "{transcript}");
+ }
}Separate test-only cache isolation candidate for maindiff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs
index 5d000775..2b784c35 100644
--- a/crates/xcl/src/gpu/recomp/pso.rs
+++ b/crates/xcl/src/gpu/recomp/pso.rs
@@ -1943,6 +1943,20 @@ mod shader_cache_tests {
#[test]
fn console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk() {
use std::sync::atomic::{AtomicUsize, Ordering};
+ const RUN: &str = "XCL_TEST_CONSOLE_MESH_CACHE_RUN";
+ if std::env::var_os(RUN).is_none() {
+ // The public entry point uses process-wide caches. Parallel tests can change their
+ // state between the first call and the cached-only assertion.
+ let dir = std::env::temp_dir().join(format!("xcl-mesh-cache-isolated-{}", std::process::id()));
+ let output = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["gpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk", "--exact", "--nocapture"])
+ .env(RUN, "1")
+ .env("XCL_DXIL_CACHE", &dir)
+ .output().unwrap();
+ let _ = std::fs::remove_dir_all(&dir);
+ assert!(output.status.success(), "{}\n{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr));
+ return;
+ }
let blob = synthetic_mesh_container();
let dir = std::env::temp_dir().join(format!("xcl-mesh-hlsl-cache-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir); |
|
Independent desktop NVIDIA verification of PR #2977 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib -- hle::d3d12x::uma_driver::tests::grooming_leaves_a_window_under_1_gib_only_its_hole --exact --nocapture (3 consecutive runs) |
1 passed; 0 failed; 0 ignored; 1356 filtered out × 3 (1.37s, 1.36s, 1.35s, 0 skipped — isolated subprocess verified 512 MB reservation lands at the target hole rather than a 768 MB stretch below it) |
cargo test --release -p xcl --lib -- hle::d3d12x::uma_driver:: --test-threads=1 --nocapture (3 consecutive runs) |
4 passed; 0 failed; 0 ignored; 1353 filtered out × 3 (1.91s, 1.89s, 1.89s, 0 skipped: driver_windows_by_default_on_nvidia_outside_wine, failed_restore_stops_before_importing_an_unbacked_window, failed_write_watch_does_not_release_the_original_window, grooming_leaves_a_window_under_1_gib_only_its_hole) |
cargo test --release -p xcl --lib -- hle::d3d12x::real:: --test-threads=1 --nocapture (3 consecutive runs) |
63 passed; 0 failed; 0 ignored; 1294 filtered out × 3 (2.07s, 2.08s, 2.07s, 0 runtime skips) |
cargo build --release -p xcl |
Clean build (1m 41s, exit 0, 0 new warnings in uma_driver.rs) |
Paired quiet 60 s retail smoke (title: 29640639, XCL_PREPARE=0 XCL_NETWORK=0)
Exact parent & merge-base (8617577b67c3b2c67542ff3d47d6e631967c16c6, XCL_PREPARE=0 XCL_NETWORK=0):
xcl-smoke v1
commit: 8617577b67c3b2c67542ff3d47d6e631967c16c6
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1613 (PresentX 1614)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14030 MB
PR #2977 (f78e05bcc2803becade7e5368b2f0008e5d7c74b, XCL_PREPARE=0 XCL_NETWORK=0):
xcl-smoke v1
commit: f78e05bcc2803becade7e5368b2f0008e5d7c74b
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14023 MB
Runtime log check on both runs confirmed identical driver-heap placement on RTX 4060:
8617577b:D3D12.X: the coherent window at 0x700000000 (4095 MB) is a driver CUSTOM write-back L0 heap mapped at its address, write-watched (131 reservations, 0 pages kept, 0 KB, 295 ms)f78e05bc:D3D12.X: the coherent window at 0x700000000 (4095 MB) is a driver CUSTOM write-back L0 heap mapped at its address, write-watched (131 reservations, 0 pages kept, 0 KB, 290 ms)
Limits of coverage
- Directly verified the
< 1 GiBgrooming fix (512 MBwindow vs a768 MBfree VA stretch) viagrooming_leaves_a_window_under_1_gib_only_its_hole(3/3,0skipped) along with all 4hle::d3d12x::uma_driver::tests (3/3) andhle::d3d12x::real::(63/63× 3) on Windows 11 + RTX 4060. - In the paired 60 s smoke runs on
title: 29640639, the title uses a4095 MBcoherent window (already>= 1 GiB), so both parent8617577band PR D3D12.X: the driver heap's grooming reserves stretches a smaller window fits in #2977 mapped the driver CUSTOM write-back L0 heap at0x700000000cleanly; a live< 1 GiB/ 16-window retail fallback (Map gave ..., not the window's ...) was not reproduced outside the subprocess unit test. - Paired 60 s retail smokes ran with
XCL_PREPARE=0(XCL_NETWORK=0), bypassing startupprepare_for_launchshader precompilation.
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
|
Linux (Wine) dual-lane run at
Head Both lanes panic at the same spot: Suite: AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting. |
|
Follow-up after #2977 merged as
These are follow-up boundary fixes; reopening the merged PR is not possible. The linked diff keeps them together with their regressions so they can be applied or adapted without reconstructing the report. AI use: Codex (GPT-6.2 Sol) checked the merged source and drafted this follow-up. |
|
Update on Both tests ran alone 3 times each, and
So 16 GB alone does not make them fail on native Windows. I did not run a release build or Wine, so I cannot say what differs there. After the merge (
The two new ones: So the fix does what it says on this card: the window that stayed imported before is now a driver heap. The warnings' address AI use: Claude Code (Claude Opus 5.5) ran the comparison and wrote this note. |
|
Post-merge Wine check on main We flagged pre-merge (above) that
Ties in with the 16 GiB-cap reproduction above ( Suite/solo: AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting. |
Requested by Prime · project thread
Stacked on #2976; only the top commit belongs here.
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. Stretches the window fits in are reserved now, with a margin under half the window left free for the driver's own mappings.
Why
In a retail title on an RTX 3060 Ti (
nvidia-devwith #2844 ported, 512 MB coherent window) the remake failed with "coherent window 3 stays imported: Map gave 0x4a720000, not the window's 0x1300000000 (133 reservations)", so the window stayed an imported heap, the slow case #2844 is about. With this change the same setup logged "the coherent window at 0x1300000000 (512 MB) is a driver CUSTOM write-back L0 heap mapped at its address".What is in it
crates/xcl/src/hle/d3d12x/uma_driver.rs:groomreserves the free stretches the window fits in (least = min(len, 1 GiB), marginmin(256 MiB, len / 2)).grooming_leaves_a_window_under_1_gib_only_its_hole(in a process of its own, as the restore test: while grooming no other thread could reserve more than the margins): 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 (checked by running the test against the old rule).Tested
cargo test --locked --workspace --no-fail-fast -- --test-threads=4withXCL_DXC_DIRset to DXC 1.9.2609.5: 1455 passed, 3 failed, 47 ignored. The 3 failures are tests that fail onmainc2ee10e4itself (1453passed,3failed,47ignored there, same command):test_title_draws_with_a_root_signature_under_the_debug_layer,test_title_runs_and_game_folder_is_untouched,test_title_runs_under_the_debug_layer_with_dred.Regression run
A commit of
main(b49be183, the last one before the shader preparation of #2555, which prepares every record before the title and does not fit a 60 s run):This PR's head (with
XCL_PREPARE=0, the switch of #2976):Not tested
mainitself in a title run: the smoke below runsmain's default layout, whose coherent window size comes from the title's stored size; the failure and the fix above were seen onnvidia-dev's 16-window layout.AI use
Claude Code (Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W
🤖 Generated with Claude Code