Skip to content
Draft
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
1 change: 1 addition & 0 deletions crates/xcl/src/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ fn is_writable(va: usize, bytes: usize) -> bool {
if bytes > 0 && crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(va, bytes)) {
return true;
}
let _trap = crate::hle::d3d12x::watch_trap::guard(va, bytes);
let mut m: MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() };
let found = unsafe { VirtualQuery(va as *const std::ffi::c_void, &mut m, std::mem::size_of_val(&m)) } != 0;
found
Expand Down
3 changes: 3 additions & 0 deletions crates/xcl/src/hle/d3d12x/cpu_writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn worker() -> &'static Mutex<mpsc::Sender<Job>> {
unsafe fn write_now(va: usize, words: &[u32]) {
let bytes = 4 * words.len();
if !crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(va, bytes)) {
let _trap = super::watch_trap::guard(va, bytes);
use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_EXECUTE_READWRITE, PAGE_READWRITE};
let mut m: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
if VirtualQuery(va as *const c_void, &mut m, std::mem::size_of_val(&m)) == 0 || m.State != MEM_COMMIT {
Expand All @@ -115,6 +116,7 @@ unsafe fn u64_writable_now(va: usize) -> bool {
if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(va, 8)) {
return true;
}
let _trap = super::watch_trap::guard(va, 8);
use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_EXECUTE_READWRITE, PAGE_GUARD, PAGE_READWRITE};
let mut m: MEMORY_BASIC_INFORMATION = std::mem::zeroed();
if VirtualQuery(va as *const c_void, &mut m, std::mem::size_of_val(&m)) == 0 || m.State != MEM_COMMIT {
Expand Down Expand Up @@ -147,6 +149,7 @@ pub(super) fn writable(va: usize, bytes: usize) -> bool {
return true;
}
crate::hle::kernelx::lazy::ensure(va, bytes);
let _trap = super::watch_trap::guard(va, bytes);
use windows_sys::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT, PAGE_EXECUTE_READWRITE, PAGE_READWRITE};
let mut m: MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() };
let found = unsafe { VirtualQuery(va as *const c_void, &mut m, std::mem::size_of_val(&m)) } != 0;
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/hle/d3d12x/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ mod standin;
pub mod title_list;
pub mod title_textures;
pub mod vram;
pub mod watch_trap;

use std::ffi::c_void;
use std::sync::OnceLock;
Expand Down
2 changes: 2 additions & 0 deletions crates/xcl/src/hle/d3d12x/sparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ pub unsafe fn committed(a: usize, n: usize) {
if n == 0 {
return;
}
super::watch_trap::changed(a, n);
let mut g = lock_state();
let Some(s) = g.as_mut() else {
let (start, end) = page_span(a, n);
Expand All @@ -1343,6 +1344,7 @@ pub unsafe fn decommitted(a: usize, n: usize) {
if n == 0 {
return;
}
super::watch_trap::changed(a, n);
let mut g = lock_state();
let Some(s) = g.as_mut() else {
let (start, end) = page_span(a, n);
Expand Down
11 changes: 9 additions & 2 deletions crates/xcl/src/hle/d3d12x/title_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,11 +746,18 @@ unsafe fn refresh_once(queue: *mut c_void) {
if buf.len() < 16384 {
buf.resize(16384, std::ptr::null_mut());
}
for &(base, size) in ranges.iter() {
take_written(base, size, &mut buf, &mut dirty, &mut page);
if super::watch_trap::on() {
let mut p = page;
super::watch_trap::look(&ranges, &mut dirty, 0x1000, |a, n, d| take_written(a, n, &mut buf, d, &mut p));
page = p;
} else {
for &(base, size) in ranges.iter() {
take_written(base, size, &mut buf, &mut dirty, &mut page);
}
}
});
dirty.sort_unstable();
dirty.dedup();
dirty.len()
});
super::sparse::note_watch(watch_t0.elapsed(), dirty_len);
Expand Down
Loading
Loading