Skip to content
3 changes: 2 additions & 1 deletion crates/xcl/src/hle/d3d12x/cpu_writes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ pub(super) fn writable(va: usize, bytes: usize) -> bool {
if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(va, bytes)) {
return true;
}
crate::hle::kernelx::lazy::ensure(va, bytes);
// (held while the protection is asked: a view of a physical page is not guarded again meanwhile)
let _open = crate::hle::kernelx::lazy::ensure(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
52 changes: 52 additions & 0 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6123,6 +6123,7 @@ unsafe fn queue_dispatch(slot: usize, this: *mut c_void, a1: usize, a2: usize, a
f(this, a1)
}
23 => q_signal_x(this, a1 as *mut c_void, a2 as u64, a3 as u32) as u32 as usize,
29 => q_copy_page_mappings(a1 as u32, a2, a3, a4 as u32) as u32 as usize,
30 => super::present::present_x(this, a1 as u32, a2 as *const u8, a3 as *const u8) as u32 as usize,
// the newer layout's #35: ExecuteCommandListsX(count, lists, a value, flags) – a retail
// game submits all its command lists this way (flags 3; 0 for the one it recorded at
Expand Down Expand Up @@ -6169,6 +6170,57 @@ macro_rules! queue_slots {
}
queue_slots!(14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35);

/// command queue #29 (#31 in the newer layout) `CopyPageMappingsBatchX(count, batches, pool,
/// pool pages, flags)`: the title maps pages of its memory into GPU views – a retail game the
/// pages its texture streaming fills (a 6 GB pool) into the GPU views its textures are in,
/// tens of thousands of them while its world loads. Recorded per page (`kernelx::mirrors`);
/// as a stub every mapping was dropped (#1031).
unsafe fn q_copy_page_mappings(count: u32, batches: usize, pool: usize, pool_pages: u32) -> HRESULT {
static CALLS: AtomicU64 = AtomicU64::new(0);
static MAPPED: AtomicU64 = AtomicU64::new(0);
static UNMAPPED: AtomicU64 = AtomicU64::new(0);
static ELSEWHERE: AtomicU64 = AtomicU64::new(0);
static PHYSICAL: AtomicU64 = AtomicU64::new(0);
let n = CALLS.fetch_add(1, Ordering::Relaxed) + 1;
// physical pages alias (`XCL_PAGE_ALIAS`): the GPU-view pages show the pool pages' physical
// pages for real, instead of a record of them
if crate::hle::kernelx::alias::enabled() {
static EMPTY: AtomicU64 = AtomicU64::new(0);
let done = crate::hle::kernelx::mirrors::decode_batches(count, batches, pool, pool_pages).and_then(|changes| {
crate::hle::kernelx::note_gpu_view_mapping(changes.first().map_or(0, |c| c.0));
crate::hle::kernelx::alias::apply_page_mappings(&changes)
});
match done {
Some(d) => {
let add = |total: &AtomicU64, k: u64| total.fetch_add(k, Ordering::Relaxed) + k;
let (m, u, e) = (add(&MAPPED, d.mapped), add(&UNMAPPED, d.unmapped), add(&EMPTY, d.empty_pool));
if n == 1 || n.is_power_of_two() {
crate::xlog_info!("D3D12.X: queue CopyPageMappingsBatchX: {n} calls; pages mapped so far: {m} showing a physical page, {u} unmapped ({e} of them for a pool page with nothing mapped; pool {pool:#x}, {pool_pages} pages of 64 KiB)");
}
}
None => {
static ONCE: std::sync::Once = std::sync::Once::new();
ONCE.call_once(|| crate::xlog_warn!("D3D12.X: queue CopyPageMappingsBatchX({count}, {batches:#x}, {pool:#x}, {pool_pages}): a batch or range is unreadable or leaves the pool, or a page could not be mapped"));
}
}
return S_OK;
}
match crate::hle::kernelx::mirrors::apply_batches(count, batches, pool, pool_pages) {
Some(d) => {
let add = |total: &AtomicU64, k: u64| total.fetch_add(k, Ordering::Relaxed) + k;
let (m, p, u, e) = (add(&MAPPED, d.mapped), add(&PHYSICAL, d.physical), add(&UNMAPPED, d.unmapped), add(&ELSEWHERE, d.elsewhere));
if n == 1 || n.is_power_of_two() {
crate::xlog_info!("D3D12.X: queue CopyPageMappingsBatchX: {n} calls; GPU-view pages so far: {m} mapped ({p} to a physical page the title mapped there), {u} unmapped; {e} pages elsewhere ignored (pool {pool:#x}, {pool_pages} pages of 64 KiB)");
}
}
None => {
static ONCE: std::sync::Once = std::sync::Once::new();
ONCE.call_once(|| crate::xlog_warn!("D3D12.X: queue CopyPageMappingsBatchX({count}, {batches:#x}, {pool:#x}, {pool_pages}): a batch or range is unreadable or leaves the pool – the call is ignored"));
}
}
S_OK
}

/// command queue #23 SignalX(fence, value, flush flags): Signal with the console's cache flush
/// options – the PC's Signal makes the queue's writes visible itself. (A stub that signalled
/// nothing left Fortnite's render fences pending: its render thread waited, textures were
Expand Down
3 changes: 3 additions & 0 deletions crates/xcl/src/hle/d3d12x/title_textures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ unsafe fn refresh_once(queue: *mut c_void) {
take_written(base, size, &mut buf, &mut dirty, &mut page);
}
});
// views of physical pages are not write-watched: their writes are caught by guards
// (`XCL_PAGE_ALIAS`), a write through one view counting for all of them
crate::hle::kernelx::guards::take_dirty(&mut dirty, page as usize);
dirty.sort_unstable();
dirty.len()
});
Expand Down
4 changes: 3 additions & 1 deletion crates/xcl/src/hle/dstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,9 @@ unsafe fn read_own(at: usize, out: *mut u8, len: usize) -> bool {
/// Whether `n` bytes at `p` are committed, writable memory.
fn writable(p: usize, n: usize) -> bool {
let Some(end) = p.checked_add(n) else { return false };
crate::hle::kernelx::lazy::ensure(p, n);
// (held while the protection is asked: a view of a physical page is not guarded again
// meanwhile; the copy that follows faults into the guard if one is)
let _open = crate::hle::kernelx::lazy::ensure(p, n);
if crate::gpu::uma::get().is_some_and(|u| u.in_committed_window(p, n)) {
return true;
}
Expand Down
Loading
Loading