Repository navigation
D3D12.X: ~43x FPS over main on Series X (0.58 -> 25.3 fps, ~7x over #2844): XCL_UMA_DRIVER=mixed keeps part of the coherent window in VRAM - #2938
Conversation
A formatted byte store normally updates the containing word with atomic AND and OR. Let one selected compute translation use a byte UAV spanning the same raw windows. Keep wider stores on the existing lowering and distinguish the translation in the offline and runtime cache keys.
A title list's extra segments (mid-list splits) are parked as spares at the list's next Reset, and the segments KickoffX takes back become spares too. A spare records again only after its own later Reset, but alloc_pool still counted it as a user of the PC allocator it last recorded on, so that allocator was never free: each later Reset of the title's allocator while those were "in use" put another PC allocator aside, and none was ever reused or released. The previous recording a stand-in replaces at Reset pinned its allocator the same way. alloc_pool::park_list drops the list from its allocator's users (its submit marks stay, so the allocator is reused only once the GPU is past them). title_list::reset parks the moved segments and the replaced recording; KickoffX parks its reclaimed segments after both submits. Measured on the title (RTX 5070 Ti, Series X profile, 240 s untimed runs, object counts from 100 to 240 s): PC allocators 1,137 -> 1,928 without, 728-753 -> 862-897 with; non-local video memory 6.2 -> 9.6 GB without, 5.0 -> 5.4-5.5 GB with (about 4 GB less at 240 s). Timed pairs showed no frame-rate cost (late window 11.99 / 10.76 fps without, 10.76 / 11.76 with; run-to-run spread ~10 %). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The direct DXIL translator gave every compute program that uses LDS the whole 8,192-dword groupshared block D3D12 allows, with the split form's exchange words at its top. With XCL_DECLARED_LDS=1 it declares what the program's header asks for instead: the static workgroup LDS from COMPUTE_PGM_RSRC2 (CsInterface::lds_dwords), plus the exchange words and counters of the split form (or the arrival counter of a native 2-D/3-D group) placed after it. A header with no size, or one too big to leave room for them, keeps the 8,192-dword layout. LDS addresses are clamped to the declared top. The translated-shader caches key the switch apart. Less groupshared memory per group lets more groups run at once. On the title (RTX 5070 Ti, Series X profile, per-program GPU timestamps over 187-229 s), the late frame's compute went from about 89 to about 78 ms per present with the switch on; 66 of the late programs translate differently (the split family and wave32 programs), and with the switch off the translation is byte-identical. Tests: compute_lds_reservation_matches_descriptor_and_lane_storage (the declared size and lane storage per mode), and declared_lds_disk_cache_separates_both_direct_routes (the cache keys). Written by reed on our team branch; split out on main. 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. 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>
|
@Kalmarv, a test report from a machine without Resizable BAR: here, a failed What ran: Result: 5 of the module's tests pass. Then the test process exits with Reading of it (not verified):
Setup: RTX 3090 24 GB, driver 616.56, AI use: Claude Code, model Claude Opus 5.5. It ran the test, read the code and wrote and posted this. The person running these tests authorized overnight posts but has not reviewed this text. |
|
I reproduced the restore failure from the comment above on Windows, RTX 5070 Ti Laptop, NVIDIA 621.24, at A local guard checks OpenAI Codex (6.2sol) assisted with reproduction and verification. |
|
Independent mixed-memory check on the 12 GB RTX 5070, driver 616.92, using PR head A separate test-only fixture used five alternating 64 MiB segments. CPU-written markers survived remapping, GPU copies recovered the expected data, and four 32-byte reads crossing segment boundaries matched the CPU pattern. One test passed, no reported skips. These bounded synthetic tests do not establish full-size residency, sustained throughput or GTA VI performance. AI use: OpenAI Codex with GPT-6.2 Astra constructed and ran the checks; Codex coordinated and prepared this report. |
|
Thanks @CharlyRien, @ettehn, and @andrewDoing for testing and tracking down the ReBAR-off restore issue so quickly!\n\nFor anyone without Resizable BAR: we are working on the clean fallback fix so XCL_UMA_DRIVER=mixed falls back cleanly instead of aborting startup—we will push that update shortly.\n\nAlso, if you are on RTX 30-series / RX 6000+ with a compatible CPU and motherboard (such as RTX 3090 + Ryzen 5000), it is worth checking your motherboard BIOS for Above 4G Decoding and Resizable BAR—it is often disabled by default, and turning it on unlocks GPU_UPLOAD heaps.\n\n*(Posted by Kalmarv's AI assistant at his direction.)* |
|
On a card without Resizable BAR, the Setup: RTX 2060 SUPER 8 GB (driver 617.14), i5-9400F, Windows 11 26300. What happened: Why it may matter beyond the test: AI use: build, test and analysis by Claude Code agents (Claude Sonnet 5.5), this note by Claude Code (Claude Opus 5.5). |
bc4252d to
9f99282
Compare
|
Thanks @CharlyRien, @ettehn and @3L1A5-1 for the reports and the reproduction, and @andrewDoing for the extra segment-layout check. Fixed in 9f99282 (squashed into this PR's commit; head force-pushed from bc4252d). Cause. Reproduced here (RTX 5070 Ti, 610.74) with an injected refusal. Once a CUSTOM segment has been mapped, Fix.
Tested on 9f99282: RTX 5070 Ti (610.74), Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug, DXC 1.9. Not tested: an adapter without Resizable BAR (the guard takes the single-heap path before anything is released there, but I could not run it). A run of the title on this head: the smoke pair is queued. AI use: Claude Code (Claude Opus 5.5) reproduced the cause, wrote the fix and test, ran the suite and wrote this comment. |
|
Independent Windows retest of the fallback at I also ran a test-only variant forcing the initial OPTIONS16 support check false, with OpenAI Codex (6.2sol) assisted with verification. |
|
Separate placement issue on I reproduced this on Windows using the PR’s UMA allocator and placement code in a standalone fixture, with a 256 MiB window split 64/128/64 MiB. After reserving the first 63 MiB, a 2 MiB buffer returned Native D3D12 follow-up. On Windows / RTX 5070 Ti Laptop (621.24), I repeated the 63 MiB + 2 MiB case with the PR’s actual 256 MiB mixed window and native OpenAI Codex (6.2sol) assisted with verification. Originally posted by @ettehn in #2938 (comment) |
9f99282 to
0567c71
Compare
|
Thanks @ettehn, confirmed and fixed in 0567c71 (squashed into this PR's commit). In Tested on 0567c71: RTX 5070 Ti (610.74), Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug, DXC 1.9. New test Not tested: native placement of a crossing buffer through AI use: Claude Code (Claude Opus 5.5) wrote the fix and test, ran the suite and wrote this comment. |
|
Retested There is a remaining exact-fit corner in the next-fit strategy. With the same setup, a 128 MiB request can fit the middle segment exactly at offset 64 MiB. The initial unbounded fit starts at 63 MiB and crosses the boundary. Holding that whole failed fit hides the valid overlapping start, so OpenAI Codex (6.2sol) assisted with verification. |
|
@Kalmarv can you message us on discord to collaborate |
|
@bmjask I'm in it, I DMd ivall as well. My username is the same on discord. |
|
Follow-up to the exact-fit failure reported here, checked against PR head The first-fit allocator can reserve a block that crosses a mixed-heap boundary. While that crossing block is held, it hides a valid exact fit at the next segment's start. A synthetic 4 MiB regression failed on the unchanged PR head ( Verification on Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (NVIDIA 621.35), Rust 1.99.1:
This is a local candidate, not a title run or a merge-readiness claim. If adopted, the runtime change still needs the repository's paired clean-commit smoke blocks. The patch changes three files, with 120 insertions and 33 deletions. AI use: Codex (GPT-6.2 Sol) investigated, wrote the candidate and tests, ran them, and drafted this report. Codex (GPT-6.2 Astra) reviewed the low-level allocator invariants. Candidate diffdiff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs
index 3b0e70e7..40cdf3f0 100644
--- a/crates/xcl/src/gpu/uma.rs
+++ b/crates/xcl/src/gpu/uma.rs
@@ -627,21 +627,32 @@ impl Uma {
/// first).
#[track_caller]
pub fn alloc(&self, size: usize, align: usize) -> Option<*mut u8> {
- self.alloc_where(size, align, None, true)
+ self.alloc_where(size, align, None, None, true)
}
/// `alloc` for reserved address space: not zeroed (a large reservation is not touched –
/// what the title commits or maps there it writes; never-used memory is zero anyway).
#[track_caller]
pub fn reserve(&self, size: usize, align: usize) -> Option<*mut u8> {
- self.alloc_where(size, align, None, false)
+ self.alloc_where(size, align, None, None, false)
}
/// `alloc` inside window `k` (memory the console addresses with 32 bits, e.g. descriptor
/// heaps: window 0).
#[track_caller]
pub fn alloc_in(&self, k: usize, size: usize, align: usize) -> Option<*mut u8> {
- self.alloc_where(size, align, Some(k), true)
+ self.alloc_where(size, align, Some(k), None, true)
+ }
+
+ /// Allocate only inside this range of a committed window (for a placed resource in one heap).
+ #[track_caller]
+ pub(crate) fn alloc_in_range(&self, start: usize, len: usize, size: usize, align: usize) -> Option<*mut u8> {
+ let k = self.window_of(start)?;
+ if !self.is_committed_window(k) { return None; }
+ let end = start.checked_add(len)?;
+ let (window_start, window_len) = self.window(k);
+ if end > window_start.checked_add(window_len)? { return None; }
+ self.alloc_where(size, align, Some(k), Some((start - self.base, end - self.base)), true)
}
/// `XCL_TRACE_MEM`: each committed-window allocation of 1 MB or more and each one that
@@ -661,13 +672,15 @@ impl Uma {
}
#[track_caller]
- fn alloc_where(&self, size: usize, align: usize, window: Option<usize>, zero: bool) -> Option<*mut u8> {
+ fn alloc_where(&self, size: usize, align: usize, window: Option<usize>, range: Option<(usize, usize)>, zero: bool) -> Option<*mut u8> {
let size = size.max(1).checked_next_multiple_of(GRAIN)?;
let align = align.max(GRAIN).checked_next_power_of_two()?;
let mut g = self.inner.lock().unwrap();
let found = g.free.iter().filter(|(&o, _)| window.is_none_or(|k| o / WINDOW == k)).find_map(|(&o, &l)| {
- let at = self.base.checked_add(o)?.checked_next_multiple_of(align)? - self.base;
- (at.checked_add(size).is_some_and(|end| end <= o + l)).then_some((o, l, at))
+ let lo = range.map_or(o, |(lo, _)| o.max(lo));
+ let hi = range.map_or(o + l, |(_, hi)| (o + l).min(hi));
+ let at = self.base.checked_add(lo)?.checked_next_multiple_of(align)? - self.base;
+ (at.checked_add(size).is_some_and(|end| end <= hi)).then_some((o, l, at))
});
let Some((start, len, at)) = found else {
if Self::tracing() {
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index ec65f634..8998ff9b 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -1370,25 +1370,12 @@ const COHERENT_FLOOR: usize = 16 << 20;
/// committed textures leave (`COHERENT_KEPT`) is kept for these: with the textures at that
/// limit (Unicorn Overlord's), a second 128 MB of headroom sent every readback buffer to the
/// sparse windows.
-/// A block of `size` bytes from `u` that one heap holds (`heap_of(p)`). A block across two
-/// segments of a mixed window has none: it is held while the next fit is tried (which then starts
-/// past it), and given back either way.
-fn alloc_in_one_heap<T>(u: &crate::gpu::uma::Uma, size: usize, heap_of: impl Fn(usize) -> Option<T>) -> Option<(usize, T)> {
- let mut held = Vec::new();
- let found = loop {
- let Some(p) = u.alloc(size, 0x1_0000).map(|a| a as usize) else { break None };
- if let Some(h) = heap_of(p) {
- break Some((p, h));
- }
- held.push(p);
- if held.len() == 4 {
- break None;
- }
- };
- for p in held {
- u.free(p);
- }
- found
+/// Allocate within one heap segment; a crossing first fit cannot hide an exact fit at a boundary.
+fn alloc_in_one_heap<T: Copy>(u: &crate::gpu::uma::Uma, size: usize, segments: &[(usize, usize, T)]) -> Option<(usize, T, usize)> {
+ segments.iter().find_map(|&(start, len, heap)| {
+ let p = u.alloc_in_range(start, len, size, 0x1_0000)? as usize;
+ Some((p, heap, p - start))
+ })
}
fn has_coherent_headroom(u: &crate::gpu::uma::Uma, rounded: usize) -> bool {
@@ -1479,8 +1466,17 @@ unsafe fn place_console_buffer(this: *mut c_void, props: usize, desc: usize, sta
return Some(hr);
}
}
- let heap_of = |p: usize| u.window_of(p).and_then(|k| uma_heap_for(k, p - u.window(k).0, rounded).map(|h| (k, h)));
- let Some((p, (k, (heap, heap_off)))) = alloc_in_one_heap(u, rounded, heap_of) else {
+ let mut segments = Vec::new();
+ {
+ let heaps = UMA_HEAPS.lock().unwrap();
+ for (k, window_heaps) in heaps.iter().enumerate() {
+ let (base, _) = u.window(k);
+ for &(off, len, heap) in window_heaps {
+ segments.push((base + off, len, (k, heap)));
+ }
+ }
+ }
+ let Some((p, (k, heap), heap_off)) = alloc_in_one_heap(u, rounded, &segments) else {
if prefer_coherent && u.has_sparse() {
return place_console_buffer_sparse(this, &d, bytes, st, readback_on_null_map, riid, ppv);
}
@@ -9201,8 +9197,7 @@ void main() {
mod uma_heap_tests {
use super::*;
- /// A console buffer whose first fit crosses two segments of a mixed window goes to the next
- /// fit, and the crossing block is given back (it stayed charged to the window).
+ /// A console buffer whose first fit crosses two segments uses the next segment directly.
#[test]
fn a_block_across_two_segments_is_given_back_and_the_next_fit_used() {
let u = crate::gpu::uma::Uma::with_windows(1, 4 << 20).expect("one UMA window");
@@ -9211,12 +9206,29 @@ mod uma_heap_tests {
assert_eq!(first, w0);
let used = u.used();
let boundary = w0 + (1 << 20);
- let heap_of = |p: usize| (p + (128 << 10) <= boundary || p >= boundary).then_some(());
- let (p, ()) = alloc_in_one_heap(&u, 128 << 10, heap_of).expect("a block in one segment");
- assert_eq!(p, w0 + (1088 << 10));
+ let segments = [(w0, 1 << 20, ()), (boundary, 3 << 20, ())];
+ let (p, (), offset) = alloc_in_one_heap(&u, 128 << 10, &segments).expect("a block in one segment");
+ assert_eq!(p, boundary);
+ assert_eq!(offset, 0);
assert_eq!(u.used(), used + (128 << 10));
assert_eq!(u.alloc(64 << 10, 0x1_0000).map(|a| a as usize), Some(w0 + (960 << 10)));
- assert!(alloc_in_one_heap(&u, 64 << 10, |_| None::<()>).is_none());
+ assert!(alloc_in_one_heap(&u, 64 << 10, &[] as &[(usize, usize, ())]).is_none());
assert_eq!(u.used(), used + (192 << 10));
}
+
+ #[test]
+ fn a_segment_exact_fit_is_not_hidden_by_a_crossing_first_fit() {
+ let u = crate::gpu::uma::Uma::with_windows(1, 4 << 20).expect("one UMA window");
+ let (w0, _) = u.window(0);
+ let first = u.alloc(960 << 10, 0x1_0000).expect("first block") as usize;
+ assert_eq!(first, w0);
+ let before = u.used();
+ let middle = w0 + (1 << 20);
+ let end = middle + (2 << 20);
+ let segments = [(w0, 1 << 20, ()), (middle, 2 << 20, ()), (end, 1 << 20, ())];
+ let (p, (), offset) = alloc_in_one_heap(&u, 2 << 20, &segments).expect("exact fit in middle segment");
+ assert_eq!(p, middle);
+ assert_eq!(offset, 0);
+ assert_eq!(u.used(), before + (2 << 20));
+ }
}
diff --git a/crates/xcl/src/hle/d3d12x/uma_driver.rs b/crates/xcl/src/hle/d3d12x/uma_driver.rs
index 8879d114..ae43dbef 100644
--- a/crates/xcl/src/hle/d3d12x/uma_driver.rs
+++ b/crates/xcl/src/hle/d3d12x/uma_driver.rs
@@ -668,6 +668,8 @@ pub(super) unsafe fn read_vram_bytes(at: usize, len: usize) -> Option<Vec<u8>> {
mod tests {
use super::{build_segments, decide, parse_mixed};
+ static MIXED_GPU_TEST: std::sync::Mutex<()> = std::sync::Mutex::new(());
+
/// On by default for NVIDIA outside Wine only; the switch overrides either way.
#[test]
fn driver_windows_by_default_on_nvidia_outside_wine() {
@@ -705,6 +707,7 @@ mod tests {
fn mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment() {
use super::*;
use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0;
+ let _serial = MIXED_GPU_TEST.lock().unwrap();
let mut dev: Option<ID3D12Device> = None;
if unsafe { D3D12CreateDevice(None, D3D_FEATURE_LEVEL_12_0, &mut dev) }.is_err() {
return crate::gpu::recomp::runner::skip_test("no D3D12 device");
@@ -753,6 +756,64 @@ mod tests {
}
}
+ /// A buffer that exactly fills the middle heap must be placed at its start even when the
+ /// unbounded first fit would cross the preceding segment boundary.
+ #[test]
+ fn exact_middle_heap_fit_maps_and_reads_back() {
+ use super::*;
+ use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0;
+ let _serial = MIXED_GPU_TEST.lock().unwrap();
+ let mut dev: Option<ID3D12Device> = None;
+ if unsafe { D3D12CreateDevice(None, D3D_FEATURE_LEVEL_12_0, &mut dev) }.is_err() {
+ return crate::gpu::recomp::runner::skip_test("no D3D12 device");
+ }
+ let dev = dev.unwrap();
+ if !unsafe { gpu_upload_heaps(&dev) } {
+ return crate::gpu::recomp::runner::skip_test("no GPU_UPLOAD heaps");
+ }
+ let u = crate::gpu::uma::Uma::with_windows(1, 128 << 20).expect("one UMA window");
+ let (base, size) = u.window(0);
+ let first = u.alloc(31 << 20, 0x1_0000).expect("first block") as usize;
+ assert_eq!(first, base);
+ unsafe {
+ let remade = match remake_mixed(&dev, base, size, &[(32 << 20, 64 << 20)]) {
+ Ok(r) => r,
+ Err(e) if e.contains("CreateHeap") => return crate::gpu::recomp::runner::skip_test("no GPU_UPLOAD heap"),
+ Err(e) => panic!("remake_mixed: {e}"),
+ };
+ let (off, len, raw_heap) = remade.heaps[1];
+ assert_eq!((off, len), (32 << 20, 64 << 20));
+ let p = u.alloc_in_range(base + off, len, 64 << 20, 0x1_0000).expect("exact middle fit") as usize;
+ assert_eq!(p, base + off);
+ let heap_raw = raw_heap as *mut c_void;
+ let heap = ID3D12Heap::from_raw_borrowed(&heap_raw).unwrap();
+ let mut placed: Option<ID3D12Resource> = None;
+ dev.CreatePlacedResource(heap, 0, &buffer_desc(64 << 20), D3D12_RESOURCE_STATE_COMMON, None, &mut placed).expect("native exact-fit placement");
+ let placed = placed.unwrap();
+ let mut mapped: *mut c_void = std::ptr::null_mut();
+ placed.Map(0, None, Some(&mut mapped)).expect("map placed buffer");
+ assert_eq!(mapped as usize, p);
+ std::ptr::write_volatile(mapped as *mut u32, 0xA1B2_C3D4);
+ placed.Unmap(0, None);
+ let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC { Type: D3D12_COMMAND_LIST_TYPE_DIRECT, ..Default::default() }).unwrap();
+ let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
+ let list: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &alloc, None).unwrap();
+ let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
+ let (rb, ptr) = make_readback(&dev, 4).unwrap();
+ let src_raw = remade.buf_raw as *mut c_void;
+ let src = ID3D12Resource::from_raw_borrowed(&src_raw).unwrap();
+ list.CopyBufferRegion(&rb, 0, src, off as u64, 4);
+ list.Close().unwrap();
+ queue.ExecuteCommandLists(&[Some(list.cast::<ID3D12CommandList>().unwrap())]);
+ queue.Signal(&fence, 1).unwrap();
+ crate::gpu::fence::wait(&fence, 1, &dev, None, 2000).unwrap();
+ assert_eq!(std::ptr::read_volatile(ptr as *const u32), 0xA1B2_C3D4);
+ assert_eq!(u.used(), 95 << 20);
+ assert!(u.free(p) && u.free(first));
+ assert_eq!(u.used(), 0);
+ }
+ }
+
/// A `GPU_UPLOAD` segment refused after a CUSTOM one was mapped (an adapter without Resizable
/// BAR, or one out of BAR space): the window stays whole, that segment a write-watched CUSTOM
/// heap. (It stopped the process: the mapped segment's pages stay with the driver after its
@@ -761,6 +822,7 @@ mod tests {
fn a_refused_gpu_upload_segment_becomes_custom() {
use super::*;
use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_12_0;
+ let _serial = MIXED_GPU_TEST.lock().unwrap();
let mut dev: Option<ID3D12Device> = None;
if unsafe { D3D12CreateDevice(None, D3D_FEATURE_LEVEL_12_0, &mut dev) }.is_err() {
return crate::gpu::recomp::runner::skip_test("no D3D12 device"); |
|
@Kalmarv, one more segment-boundary case at
Regression test (test-only, on
We don't know yet whether the retail title places a buffer across Your loyal testing minion has now poked every seam of this window except the one holding up the coffee machine. Test diff (on 0567c71)diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index ec65f634..0fbee7a8 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -9201,6 +9201,105 @@ void main() {
mod uma_heap_tests {
use super::*;
+ #[test]
+ fn fixed_address_buffer_crossing_a_mixed_window_boundary_aliases_uma() {
+ const CHILD: &str = "XCL_TEST_MIXED_FIXED_PLACEMENT";
+ if std::env::var_os(CHILD).is_none() {
+ let status = std::process::Command::new(std::env::current_exe().unwrap())
+ .args(["--exact", "hle::d3d12x::real::uma_heap_tests::fixed_address_buffer_crossing_a_mixed_window_boundary_aliases_uma", "--nocapture"])
+ .env(CHILD, "1").env("XCL_NETWORK", "0")
+ .env("XCL_UMA_DRIVER", "mixed:64:128").env("XCL_UMA_WINDOWS", "4")
+ .env("XCL_UMA_MB", "256").env("XCL_COHERENT_MB", "256").env("XCL_UMA_CHECK", "0")
+ .status().unwrap();
+ assert!(status.success(), "mixed fixed-placement regression failed in the child");
+ return;
+ }
+
+ assert!(init_with_remap(true).is_ok(), "D3D12 device initialization failed");
+ let uma = crate::gpu::uma::get().expect("test UMA");
+ let window = uma.committed_window().expect("test coherent window");
+ let (base, size) = uma.window(window);
+ assert_eq!(size, 256 << 20);
+ const TILE: usize = 64 << 10;
+ const BOUNDARY: usize = 64 << 20;
+ let upload_is_mapped = {
+ let heaps = UMA_HEAPS.lock().unwrap();
+ heaps.get(window).is_some_and(|segments| segments.iter().any(|&(offset, len, heap)| {
+ offset == BOUNDARY && len == 128 << 20 && unsafe {
+ ID3D12Heap::from_raw_borrowed(&(heap as *mut c_void))
+ .is_some_and(|h| h.GetDesc().Properties.Type == D3D12_HEAP_TYPE_GPU_UPLOAD)
+ }
+ }))
+ };
+ if !upload_is_mapped {
+ return crate::gpu::recomp::runner::skip_test("requires a mixed window with a GPU_UPLOAD segment");
+ }
+
+ unsafe {
+ let raw = device_raw();
+ let dev = ID3D12Device::from_raw_borrowed(&raw).unwrap();
+ let address = base + BOUNDARY - TILE;
+ let mut desc = [0u8; 0x38];
+ desc[..4].copy_from_slice(&(D3D12_RESOURCE_DIMENSION_BUFFER.0 as u32).to_le_bytes());
+ desc[0x10..0x18].copy_from_slice(&((2 * TILE) as u64).to_le_bytes());
+ desc[0x18..0x1C].copy_from_slice(&1u32.to_le_bytes());
+ desc[0x1C..0x1E].copy_from_slice(&1u16.to_le_bytes());
+ desc[0x1E..0x20].copy_from_slice(&1u16.to_le_bytes());
+ desc[0x24..0x28].copy_from_slice(&1u32.to_le_bytes());
+ let mut result = std::ptr::null_mut();
+ let iid = &ID3D12Resource::IID as *const windows::core::GUID as *const GUID;
+ let hr = super::super::device_x::create_placed_resource_x(raw, address as u64,
+ desc.as_ptr(), D3D12_RESOURCE_STATE_COMMON.0 as u32, std::ptr::null(), iid, &mut result);
+ assert!(hr >= 0 && !result.is_null(), "CreatePlacedResourceX: {hr:#x}");
+ let placed = ID3D12Resource::from_raw(result);
+
+ // A copy from the shader-visible UMA buffer is the positive control for the markers.
+ let (window_raw, offset) = uma_window_buffer(address, 2 * TILE).unwrap();
+ let window_raw = window_raw as *mut c_void;
+ let window_buf = ID3D12Resource::from_raw_borrowed(&window_raw).unwrap();
+ let want = [0x0BAD_C0DEu32, 0xCAFE_BABE];
+ std::ptr::write_volatile(address as *mut u32, want[0]);
+ std::ptr::write_volatile((address + TILE) as *mut u32, want[1]);
+
+ let buffer = D3D12_RESOURCE_DESC {
+ Dimension: D3D12_RESOURCE_DIMENSION_BUFFER, Width: 16, Height: 1, DepthOrArraySize: 1, MipLevels: 1,
+ SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
+ Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
+ ..Default::default()
+ };
+ let mut readback: Option<ID3D12Resource> = None;
+ dev.CreateCommittedResource(&D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_READBACK, ..Default::default() },
+ D3D12_HEAP_FLAG_NONE, &buffer, D3D12_RESOURCE_STATE_COPY_DEST, None, &mut readback).unwrap();
+ let readback = readback.unwrap();
+ let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
+ let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap();
+ let mut list_raw = std::ptr::null_mut();
+ let iid = &ID3D12GraphicsCommandList::IID as *const windows::core::GUID as *const GUID;
+ let hr = dev_create_command_list(raw, 0, D3D12_COMMAND_LIST_TYPE_DIRECT.0 as usize,
+ alloc.as_raw() as usize, 0, iid, &mut list_raw);
+ assert!(hr >= 0 && !list_raw.is_null(), "native test command list: {hr:#x}");
+ let list = ID3D12GraphicsCommandList::from_raw(list_raw);
+ let fence: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();
+ let copy: unsafe extern "system" fn(*mut c_void, *mut c_void, u64, *mut c_void, u64, u64) =
+ std::mem::transmute(orig_fn(list_raw, slot_of(list_raw, "CopyBufferRegion")));
+ for (i, src_offset) in [0, TILE as u64].into_iter().enumerate() {
+ let dst_offset = 4 * i as u64;
+ copy(list_raw, readback.as_raw(), dst_offset, window_buf.as_raw(), offset + src_offset, 4);
+ copy(list_raw, readback.as_raw(), 8 + dst_offset, placed.as_raw(), src_offset, 4);
+ }
+ list.Close().unwrap();
+ super::super::title_textures::own_work(|| queue.ExecuteCommandLists(&[Some(list.cast::<ID3D12CommandList>().unwrap())]));
+ queue.Signal(&fence, 1).unwrap();
+ crate::gpu::fence::wait(&fence, 1, dev, None, 5000).unwrap();
+ let mut mapped = std::ptr::null_mut();
+ readback.Map(0, None, Some(&mut mapped)).unwrap();
+ let got = *(mapped as *const [u32; 4]);
+ readback.Unmap(0, None);
+ assert_eq!(&got[..2], &want, "the UMA buffer sees both markers");
+ assert_eq!(&got[2..], &want, "fixed-address placement must alias both UMA segments");
+ }
+ }
+
/// A console buffer whose first fit crosses two segments of a mixed window goes to the next
/// fit, and the crossing block is given back (it stayed charged to the window).
#[test]AI use: Codex (GPT-6.2-Sol) found the path and wrote the test; Claude Code (Claude Opus 5.5) ran it on the RTX 5090 (t12), checked the code path and wrote this comment. |
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>
|
In-title A/B of this exact head ( Result: in the #2844 world window (world +10 to +130 s), the stack with Setup: RTX 5090 32 GB, driver 621.24, Ryzen 7 9800X3D, Windows 11, Series X profile, release.
Things worth knowing:
Not tested: visible frames; a second valid main run; other range layouts; the switches one at a time; why our absolute numbers sit below your 25.28 on a faster GPU (possibly the A/B setup differences above, not checked). AI use: Claude Code (Claude Opus 5.5) ran and measured the arms (t12) and wrote this comment; Codex (GPT-6.2-Sol) reviewed the stack for safety and fairness; Gemini (Antigravity) collected your recipe from the threads. |
|
Tested PR #2938 ( Unit Tests (
|
| Configuration | Guest entry / World load | Frames shown | World presents (2 s windows) | Peak commit | Peak local / non-local VRAM | Crashes / Removals |
|---|---|---|---|---|---|---|
main (8b957bec) |
67.2 s / 188.4 s |
1240 |
14 / 28w (last 3: 0 1 1) |
29,411 MB |
14,281 / 2,241 MB |
0 / 0 (exit: 0x0) |
#2844 (f2248f06) |
69.3 s / 189.2 s |
1266 |
22 / 28w (last 3: 1 1 0) |
30,006 MB |
14,537 / 2,316 MB |
0 / 0 (exit: 0x0) |
#2938 (XCL_UMA_DRIVER=custom) |
68.1 s / 174.3 s |
1504 |
31 / 34w (last 3: 1 2 1) |
25,005 MB |
9,797 / 2,052 MB |
0 / 0 (exit: 0x0) |
#2938 (mixed:1536:1792, outside 512 MB Series S window) |
69.9 s / 175.9 s |
1532 |
46 / 36w (last 3: 2 2 3) |
25,215 MB |
9,676 / 2,120 MB |
0 / 0 (exit: 0x0) |
#2938 (mixed:128:256, active GPU_UPLOAD in 512 MB window) |
69.9 s / 180.0 s |
1605 |
52 / 35w (last 3: 3 2 1) |
24,880 MB |
9,874 / 1,746 MB |
0 / 0 (exit: 0x0) |
Notes
- With
XCL_UMA_DRIVER=mixed:1536:1792, Series S (lockhart) has a single512 MBcoherent window (0x700000000), so the range1536:1792fell outside it and loggedWARN D3D12.X: coherent window 3 stays imported: no GPU_UPLOAD range inside the window. - With
XCL_UMA_DRIVER=mixed:128:256inside that512 MBwindow, the coherent window remapped cleanly to[0x0+128MB CUSTOM, write-watched, 0x8000000+256MB GPU_UPLOAD, 0x18000000+128MB CUSTOM, write-watched](139 reservations, 115 ms), lowering peak non-local VRAM (2,052 -> 1,746 MB) and raising world presents (31 -> 52over ~70 s post-world) with zero crashes or device removals. (XCL_WATCH_TRAP=1andXCL_TEXTURE_LEVEL_PAGES=1account for most of the ~4.5 GB commit / local-VRAM reduction relative to the unflaggedmain/#2844baselines.)
Not tested: Multi-minute sustained world traversal (>180 s), isolated #2938 (custom vs mixed:128:256) without XCL_WATCH_TRAP=1 / XCL_TEXTURE_LEVEL_PAGES=1 / XCL_DECLARED_LDS=1, or full workspace test suite on 0567c713.
|
RTX 3090 24 GB (Ampere, Resizable BAR on) at Setup
Tests: Not tested: the open world; other range layouts; the smoke pair; a second steady AI use: Claude Code (Claude Opus 5.5) ran the runs and the suite and drafted this; checked by me before posting. |
0567c71 to
a76cc3e
Compare
|
The head moved from 0567c71 to a76cc3e for a test race, not a runtime change. Only
The suite and the regression pair in the description are on a76cc3e. Claude Code (Claude Opus 5.5) found the race, wrote the lock and ran the tests on the RTX 5070 Ti named in the description. |
Stacked on #2844, #2926, #2936, #2937 and #2934; only the top commit (0567c71) belongs here. The others are in the head so that it reproduces the measured tree.
With
XCL_UMA_DRIVER=mixed:<start_mb>:<size_mb>[,...]the coherent window becomes several driver heaps instead of #2844's one CUSTOM heap: each listed range aGPU_UPLOADheap (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 #2844 does), and one reserved buffer over the window maps its 64 KiB tiles onto the segments' heaps, so shaders and placed resources still see one window.Headline (RTX 5070 Ti, Series X profile, same title, timed runs alone; fps over 187-229 s / 107-223 s)
XCL_UMA_DRIVER=mixed:1536:1792 XCL_WATCH_TRAP=1 XCL_DECLARED_LDS=1 XCL_BYTE_STORE_CS=e166372fa54a77c7 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PARK_SPARES=1XCL_PARK_SPARESand without the look-walkXCL_UMA_DRIVER=customXCL_PARK_SPARES=1was D3D12.X: segments parked as spares stop holding their PC allocator (~4 GB less non-local memory) #2936's switch then; D3D12.X: segments parked as spares stop holding their PC allocator (~4 GB less non-local memory) #2936 has none). This commit's own share is CB2 -> CB2m3 on the older base, everything else equal: 11.99 -> 24.15 fps late (2.01x). TX1 is the combined result.GPU_UPLOADpart cut PCIe traffic by about two thirds.What is in it (0567c71)
uma_driver.rs:mixed:parsing (parse_mixed, anddecidetakes it as on),build_segments,remake_window(the mixed remake or D3D12.X: UMA windows in a driver heap on NVIDIA, 4.9x FPS (0.62 -> 3.03) #2844's),remake_mixed, and the reader of theGPU_UPLOADsegments (read_vram_bytes: a copy on the COPY queue into a readback buffer, as CPU reads of that memory through the BAR ran at 12-84 MiB/s).GPU_UPLOADsegments are not write-watched: their write-combined pages refuse the watch trap's read-only protection.Uma::watch_regionslists only the watched segments (gpu/uma.rs).remake_windowasksD3D12_OPTIONS16.GPUUploadHeapSupportedbefore the window is released, and without itmixedfalls back to D3D12.X: UMA windows in a driver heap on NVIDIA, 4.9x FPS (0.62 -> 3.03) #2844's single CUSTOM heap (a warning in the log). AGPU_UPLOADsegment refused anyway becomes a write-watched CUSTOM segment in its place. A segment that was mapped cannot be given back: afterUnmapand the heap's release its pages stay with the driver (stillMEM_COMMITseconds later; a new heap of the same size maps there again), so the earlier rollback could not reserve the window again (Windows error 487) and stopped the process (found by @CharlyRien, @ettehn and @3L1A5-1).alloc_in_one_heapinreal.rs.real.rs:UMA_HEAPSkeeps each window's segments anduma_heap_forpicks the one a placed resource falls in.title_textures.rs:with_title_bytesreadsGPU_UPLOADsegments throughread_vram_bytes.mixed_ranges_parse_in_order,mixed_segments_cover_the_window, the GPU testmixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment(the title's bytes survive in every segment, the GPU reads later CPU writes to each segment through the one buffer,read_vram_bytesreads only theGPU_UPLOADone; skipped withoutGPU_UPLOADheaps), anda_refused_gpu_upload_segment_becomes_custom(a refusal injected after the first CUSTOM segment is mapped: the window stays whole and fully watched, its bytes kept, the GPU sees later CPU writes; without the fallback the test process exits 0x7C10003), anda_block_across_two_segments_is_given_back_and_the_next_fit_used(real.rs).Tested
XCL_DXC_DIR.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4on a76cc3e (the whole stack, withCARGO_PROFILE_DEV_DEBUG=0for disk space): 1476 passed, 0 failed, 47 ignored. 25SKIPPED: 21 no wave64, 3 refused per-lane f16 forms, 1 no heap windows. The five new tests pass without skips.a_refused_gpu_upload_segment_becomes_customfails without the fallback (exit 0x7C10003, the log's "could not be restored ... Windows error 487"). Not run on an adapter without Resizable BAR: there the guard takes the single-heap path before anything is released, and the GPU test skips.Regression run
480 s runs, same title, same env (
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, DXC 1.9, the same button presses every 4 s from 14 s), each from a hard-link copy of one DXIL cache. NoXCL_UMA_DRIVER:mixedis opt-in, so the pair checks the default path (#2844's single heap on NVIDIA).A commit of
main(8b957bec):This PR's head:
Not tested
mixed:1536:1792. Cards with less than 16 GB of video memory. Titles other than this one. The remake reserves the process's other free stretches so the driver maps each segment at its place; a thread of the title that frees 64 MB or more of address space during it can still let a segment map elsewhere, which stops the process (as the tests did before the lock). Not seen in title runs; the switch is opt-in.AI use