From 4e93173413fed5f2d079ae4f2da37f07996e9727 Mon Sep 17 00:00:00 2001 From: guinpereira Date: Thu, 26 Nov 2026 15:31:36 -0300 Subject: [PATCH] D3D12.X: copy title bytes instead of borrowing in texture workers --- crates/xcl/src/hle/d3d12x/title_textures.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index 6d97bc6e4e..31301763e8 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1456,8 +1456,12 @@ unsafe fn subresources_on(picked: &[(usize, &xg::Texture)], threads: usize) -> V /// The title's bytes at `at`: where they are when all of them are readable (a copy first cost /// as much as the detile of a video frame), else read page run by page run. +// Title memory is borrowed only for the UMA committed windows, whose pages cannot be +// decommitted underneath us; everything else is copied page by page. A borrowed view of +// ordinary title memory can fault on a worker thread if the title releases or decommits +// pages between the readability check and the copy (#2841), so never borrow it there. unsafe fn title_bytes(at: usize, len: usize) -> std::borrow::Cow<'static, [u8]> { - if crate::gpu::shader::readable(at, len) { + if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(at, len)) { std::borrow::Cow::Borrowed(std::slice::from_raw_parts(at as *const u8, len)) } else { std::borrow::Cow::Owned(read_committed(at, len)) @@ -1826,8 +1830,8 @@ mod tests { std::ptr::write_bytes((base + (page << 12)) as *mut u8, 0xA0 + page as u8, 1 << 12); } let whole = title_bytes(base, 1 << 12); - assert!(matches!(whole, std::borrow::Cow::Borrowed(_)), "a committed page is not copied"); - assert_eq!(whole.as_ptr() as usize, base); + assert!(matches!(whole, std::borrow::Cow::Owned(_)), "a non-UMA range is copied, not borrowed"); + assert_eq!(&whole[..], &read_committed(base, 1 << 12)[..]); assert!(whole.iter().all(|&b| b == 0xA0)); let holed = title_bytes(base, 3 << 12); assert!(matches!(holed, std::borrow::Cow::Owned(_)), "a range with a reserved page is read");