Skip to content
Open
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
10 changes: 7 additions & 3 deletions crates/xcl/src/hle/d3d12x/title_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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");
Expand Down
Loading