From 0f77bf18498dae6497b539db2b5ded8ed96a744d Mon Sep 17 00:00:00 2001 From: Enrique Villa Date: Tue, 24 Nov 2026 11:44:44 +0800 Subject: [PATCH] D3D12.X: the present copy is XCL's own work and does not look again present_now submits its copy with q.ExecuteCommandLists, which is XCL's own hook: it re-entered q_execute_command_lists -> title_textures::refresh outside own_work, so every presented frame paid a second full look at the title's memory (GetWriteWatch over every watched range, then a copy of each dirty texture to hash it). On a retail title at 125 s that second look (refresh reached from present_now) was 26.7 % of the submit thread, profiled on f44cc79 (#693's head), where the submit thread is the limit. The copy reads only the presented resource. Render targets are the GPU's (vram::place, not kept in step), so no look can bring a CPU write to them; what the CPU wrote elsewhere since the title's last submit stays dirty (GetWriteWatch resets only in a look) and is uploaded before the title's next ExecuteCommandLists, the first work that can read it. A presented resource that is kept in step with title memory still gets the look, as before. The skipped look also made the queue wait for the pages mapped since its last work (vram::before_execute); the copy now calls it itself, as XCL's other own_work submits do. The look also runs sparse::before_execute (CPU writes into mapped sparse tiles); the copy skips it, and the title's next submit does it. (Hypothesis: no title presents a sparse-window resource that is not kept in step.) The title-texture GPU test now checks that a refresh under own_work uploads nothing and the next refresh uploads the write. AI-assisted. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/present.rs | 14 +++++++++++++- crates/xcl/src/hle/d3d12x/title_textures.rs | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs index 01b3c92a4a..6df9d83b6d 100644 --- a/crates/xcl/src/hle/d3d12x/present.rs +++ b/crates/xcl/src/hle/d3d12x/present.rs @@ -733,7 +733,19 @@ unsafe fn present_now(min_interval: Duration, frame: Option<(usize, usize)>) { let qraw = queue as *mut c_void; let Some(q) = ID3D12CommandQueue::from_raw_borrowed(&qraw) else { return }; let Ok(cl) = p.list.cast::() else { return }; - q.ExecuteCommandLists(&[Some(cl)]); + // The copy reads only `src`, a GPU resource (render targets are not kept in step with title + // memory): XCL's own submit, with no second look at the title's memory – what the CPU wrote + // since the title's last submit stays dirty and goes up before its next one. That look cost + // a quarter of the submit thread in profiling. A `src` kept in step is looked at as before. The + // queue still waits for the pages mapped since its last work, as XCL's other own work does. + if super::title_textures::address(src.as_raw() as usize).is_some() { + q.ExecuteCommandLists(&[Some(cl)]); + } else { + super::title_textures::own_work(|| { + super::vram::before_execute(q); + q.ExecuteCommandLists(&[Some(cl)]); + }); + } p.copy_source = Some(src); p.dumps = dumps; p.value += 1; diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index ada439cbaa..9d7557a3b2 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1327,8 +1327,14 @@ mod tests { let key = texture.as_raw() as usize; register(raw_device, texture.as_raw(), va, &console, D3D12_RESOURCE_STATE_COMMON).unwrap(); let _registered = RegisteredTexture(key); - for value in [0x3D, 0x9A] { + for (k, value) in [0x3D, 0x9A].into_iter().enumerate() { std::ptr::write_bytes(src as *mut u8, value, PAGE); + if k > 0 { + // XCL's own submits (the present copy) do not look: the write waits for the + // title's next submit and is not lost + own_work(|| refresh(queue.as_raw())); + assert_eq!(read_r8(dev, &queue, &texture), vec![0x3D; 64 * 64], "XCL's own work does not upload"); + } refresh(queue.as_raw()); assert_eq!(read_r8(dev, &queue, &texture), vec![value; 64 * 64], "GPU contents follow CPU writes"); assert_eq!(address(key), Some(va), "the title address stays in the GPU view");