From 20fd55ccf43a7b0a95d9f3a48d75cc06367eb678 Mon Sep 17 00:00:00 2001 From: Pipodi Date: Thu, 26 Nov 2026 12:47:57 +0100 Subject: [PATCH] D3D12.X: a title buffer may run on into the next sparse window CreatePlacedResourceX of a buffer at 0x5fffd0000 (0x546000 bytes) ran from sparse window 1 into window 2. title_buffer_window returned None once the buffer passed its window's end, so place_at_title_address gave up and the buffer fell back to a committed DEFAULT buffer: every view of it was an empty V#, found in a title run by tracing the placed buffers. A title's reservations may straddle sparse windows (sparse_reserve), shaders already carry across windows, and sparse::place_buffer checks the windows of both ends and maps the tiles of each. So accept a buffer whose windows k..=last are all sparse; a run into a window that is not sparse stays refused. The test a_buffer_may_run_on_into_the_next_sparse_window failed without this (left None, right Some((1, true))); the old assertion that expected None across a sparse window's end now expects Some((0, true)). Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/real.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index ac2d041913..b33a01697e 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -1776,7 +1776,9 @@ fn title_buffer_window(u: &crate::gpu::uma::Uma, va: usize, bytes: usize) -> Opt return (k..=last).all(|j| u.is_view_window(j)).then_some((k, true)); } if va - base + bytes > size { - return None; + // a title's reservation may run across sparse windows (`sparse_reserve`): so may its buffer + let last = u.window_of(va.checked_add(bytes - 1)?)?; + return (u.is_sparse_window(k) && (k..=last).all(|j| u.is_sparse_window(j))).then_some((k, true)); } Some((k, u.is_sparse_window(k))) } @@ -10665,7 +10667,7 @@ mod gpu_view_tests { assert_eq!(title_buffer_window(&u, end - 0x1_0000, 0x2_0000), None, "past the view windows"); // sparse and coherent windows as before: whole in their window assert_eq!(title_buffer_window(&u, u.base() + 0x1_0000, 0x100), Some((0, true))); - assert_eq!(title_buffer_window(&u, u.base() + WINDOW - 0x1_0000, 0x2_0000), None, "across a sparse window's end"); + assert_eq!(title_buffer_window(&u, u.base() + WINDOW - 0x1_0000, 0x2_0000), Some((0, true)), "across a sparse window's end"); let coh = u.committed_window().unwrap(); let (c, c_len) = u.window(coh); assert_eq!(title_buffer_window(&u, c + 0x1_0000, 0x100), Some((coh, false))); @@ -10673,6 +10675,22 @@ mod gpu_view_tests { assert_eq!(title_buffer_window(&u, end + 0x1_0000, 0x100), None, "an empty window"); assert_eq!(u.view_release(g), Some(2 * WINDOW)); } + + /// A buffer over the end of a sparse window runs on into the next sparse window (a title's + /// reservation may straddle them); into a window that is not sparse it stays refused. It fell + /// back to a committed buffer and every view of it was empty. + #[test] + fn a_buffer_may_run_on_into_the_next_sparse_window() { + let (u, g) = sixteen_with_view(WINDOW); + let w1 = u.base() + WINDOW; + assert!(u.is_sparse_window(1) && u.is_sparse_window(2)); + assert_eq!(title_buffer_window(&u, w1 + WINDOW - 0x3_0000, 0x54_6000), Some((1, true))); + // past the last sparse window, into a view window or an empty one + let sparse_last = (0..MAX_HEAP_WINDOWS).rfind(|&j| u.is_sparse_window(j)).unwrap(); + let end = u.base() + (sparse_last + 1) * WINDOW; + assert_eq!(title_buffer_window(&u, end - 0x1_0000, 0x2_0000), None, "into a window that is no sparse window"); + assert_eq!(u.view_release(g), Some(WINDOW)); + } } #[cfg(test)]