Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions crates/xcl/src/hle/d3d12x/title_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec<usize>) {
}
}

/// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mark_hot makes a block hot without bumping WALK_FOUND, but the XCL_LOOK_SKIP check (closed_before_last_look_in) uses WALK_FOUND to know a block became hot after the last look began. With XCL_LOOK_SKIP=1, a look begins, the title runs CopyIntoSubresource during or right after it, then submits lists closed before that look in the same frame. walk_found < began, so the look is skipped and the copied texels miss the submit, the delay this PR fixes, even though the block was just made hot. Bumping WALK_FOUND in mark_hot would close it.

if len == 0 || !hot_looks() {
return;
}
Expand Down
33 changes: 33 additions & 0 deletions crates/xcl/src/hle/xg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain about this one: mark_hot gets the CopyIntoSubresource destination address, but for a texture read through its pages (Entry::paged / Due::pages) the written pages are watched where they're kept, not at the view's own address. A title that calls CopyIntoSubresource into the GPU-view VA of a paged texture and submits right away gets the view VA's blocks marked hot but not the blocks where the pages live, so the copy still reaches the GPU one submit late. The existing tests at title_textures.rs:4780-4808 mark home/kept, not the view address. Relatedly, title_textures::note_known_write already exists for "XCL wrote these bytes itself" and hands the exact pages to the next look without keeping whole blocks hot for 1.5 s.

S_OK
}

Expand Down Expand Up @@ -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() {
Expand Down
Loading