diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index d809b1c2a2..7095045d0d 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec) { } } -/// Memory the title just committed or placed something in: the looks take its blocks for a -/// while, as they do a block new to the ranges (a write made right after the commit is there -/// for the next submit). -pub(super) fn mark_hot(at: usize, len: usize) { +/// Whether the block of `at` is hot now; with `forget`, it is not any more. +#[cfg(test)] +pub(crate) fn hot_block(at: usize, forget: bool) -> bool { + let mut g = HOT.lock().unwrap_or_else(|e| e.into_inner()); + let h = g.get_or_insert_with(HotBlocks::default); + let b = at & !(HOT_BLOCK - 1); + if forget { h.hot.remove(&b).is_some() } else { h.hot.contains_key(&b) } +} + +/// Memory the title just committed or placed something in, or XCL just wrote for it (an XG +/// copy): the looks take its blocks for a while, as they do a block new to the ranges (a write +/// made right after it is there for the next submit). The write watch is left as it is: the +/// next look takes the written pages from it. +pub(crate) fn mark_hot(at: usize, len: usize) { if len == 0 || !hot_looks() { return; } diff --git a/crates/xcl/src/hle/xg.rs b/crates/xcl/src/hle/xg.rs index dd8b0a792d..1ea7c639ce 100644 --- a/crates/xcl/src/hle/xg.rs +++ b/crates/xcl/src/hle/xg.rs @@ -719,6 +719,7 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su to.copy_from_slice(std::slice::from_raw_parts(src.add(from), row)); } t.chain.tile_volume(std::slice::from_raw_parts_mut(dst.add(at as usize), t.size() as usize), i, &linear); + crate::hle::d3d12x::title_textures::mark_hot(dst as usize + at as usize, t.size() as usize); return S_OK; } let mut linear = vec![0u8; row * m.height]; @@ -727,6 +728,9 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su } let slice = std::slice::from_raw_parts_mut(dst.add(at as usize + k * t.chain.slice_bytes), t.chain.slice_bytes); t.chain.tile_level(slice, i, k, &linear); + // (a title submits right after this: the looks take these blocks now, not once the walk + // finds them, which can be after that submit for a block idle longer than `hot_for`) + crate::hle::d3d12x::title_textures::mark_hot(slice.as_ptr() as usize, slice.len()); S_OK } @@ -804,6 +808,35 @@ mod tests { } } + /// CopyIntoSubresource makes the write-watch blocks it wrote hot at once, both of them when + /// the texture spans two: a title submits right after it, before the walk finds the pages of + /// a block idle longer than `hot_for` (#3382). + #[test] + fn a_subresource_copy_makes_its_blocks_hot() { + use crate::hle::d3d12x::title_textures::hot_block; + if std::env::var("XCL_WATCH_HOT").is_ok_and(|v| v.trim() == "0") { + return; + } + type Six = unsafe extern "system" fn(*mut c_void, *mut u8, u32, u32, *const u8, u32, u32) -> HRESULT; + const BLOCK: usize = 2 << 20; + let d = desc(64, 32, 1, 1, 28, 0x109); + let mut c: *mut c_void = std::ptr::null_mut(); + unsafe { + assert!(XGCreateTextureComputer(d.as_ptr(), &mut c) >= 0); + let size = Texture::new(&d).unwrap().size() as usize; + let lin = vec![0x5Au8; 64 * 4 * 32]; + let into: Six = std::mem::transmute(*(*(c as *const *const usize)).add(8)); + // a destination across a block boundary, in neither block's hot list + let mut mem = vec![0u8; 2 * BLOCK + size]; + let dst = ((mem.as_mut_ptr() as usize + BLOCK) & !(BLOCK - 1)) - size / 2; + hot_block(dst, true); + hot_block(dst + size - 1, true); + assert_eq!(into(c, dst as *mut u8, 0, 0, lin.as_ptr(), 64 * 4, 0), S_OK); + assert!(hot_block(dst, false) && hot_block(dst + size - 1, false), "both blocks it wrote are hot"); + release(c); + } + } + /// As the console's library answers (seen on it): RGBA8 256×256, full chain, 64KB_S. #[test] fn rgba8_64kb_s_layout() {