D3D12.X: CopyMemoryToMemoryX from the title's own memory into unified memory is dropped #319

Closed
opened 2026-11-26 04:19:56 +00:00 by github-bot · 3 comments
Owner

@⁠emirduran707 on GitHub · 2026-11-23 23:14 UTC · original

CopyMemoryToMemoryX (#60) is dropped when its source is the title's own CPU memory and its destination is in unified memory: copy_memory_x only copies when both ends are in a UMA window.

Seen: a retail title (RX 9060 XT, XCL_NETWORK=0), once per run, ~26–48 s in, while DirectStorage loads. Not every run: 7 of 14 runs on builds from 9ab7d76 to 4017f8f logged it; 0 of 2 on 21b8723 (after #252 / #283), so whether it still happens on current main is not settled yet:

D3D12.X: CopyMemoryToMemoryX: 0x1fe7f080000 → 0x729ffd900 (0x4000 bytes) is not in unified memory – not done

The coherent window is at 0x400000000 (4095 MB) in that run; 0x729ffd900 is in the sparse windows, 0x1fe7f080000 is plain committed memory of the title. So the GPU copy of 16 KiB from CPU memory into GPU memory never happens. What the title uses that memory for is not known yet.

Plan (one small PR, test first):

  1. copy_memory_x: source outside the windows but CPU-readable, destination in a window → record the copy from an upload buffer of the list's, with the destination's usual transitions.
  2. Fill those upload buffers from the source right before the list is submitted (ExecuteCommandLists and KickoffX), the latest moment the title's data can be there; keep the buffers alive until the queue's fence (the cpu_writes worker).
  3. Test: the test title copies from its heap into its graphics memory, writing the heap after recording and before submitting.

The other directions (destination outside the windows) stay as they are.

AI-assisted: Claude Code (Claude Opus 5.5) found this in my run's log and wrote this issue.

**@⁠emirduran707** on GitHub · 2026-11-23 23:14 UTC · [original](https://github.com/xcl-dev/xcl/issues/319) `CopyMemoryToMemoryX` (#60) is dropped when its source is the title's own CPU memory and its destination is in unified memory: `copy_memory_x` only copies when both ends are in a UMA window. **Seen:** a retail title (RX 9060 XT, `XCL_NETWORK=0`), once per run, ~26–48 s in, while DirectStorage loads. Not every run: 7 of 14 runs on builds from 9ab7d76 to 4017f8f logged it; 0 of 2 on 21b8723 (after #252 / #283), so whether it still happens on current `main` is not settled yet: ``` D3D12.X: CopyMemoryToMemoryX: 0x1fe7f080000 → 0x729ffd900 (0x4000 bytes) is not in unified memory – not done ``` The coherent window is at `0x400000000` (4095 MB) in that run; `0x729ffd900` is in the sparse windows, `0x1fe7f080000` is plain committed memory of the title. So the GPU copy of 16 KiB from CPU memory into GPU memory never happens. What the title uses that memory for is not known yet. **Plan** (one small PR, test first): 1. `copy_memory_x`: source outside the windows but CPU-readable, destination in a window → record the copy from an upload buffer of the list's, with the destination's usual transitions. 2. Fill those upload buffers from the source right before the list is submitted (`ExecuteCommandLists` and `KickoffX`), the latest moment the title's data can be there; keep the buffers alive until the queue's fence (the `cpu_writes` worker). 3. Test: the test title copies from its heap into its graphics memory, writing the heap after recording and before submitting. The other directions (destination outside the windows) stay as they are. AI-assisted: Claude Code (Claude Opus 5.5) found this in my run's log and wrote this issue.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:56 +00:00
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-23 23:32 UTC · original

Update: on current main this no longer shows at the first menu.

builds runs logging the dropped copy
9ab7d76 … 4017f8f 7 of 10 (~26–48 s in)
21b8723, 85bdf21 (after #252 / #283) 0 of 5

Same title, RX 9060 XT, scripts/smoke.ps1 (60 s, XCL_NETWORK=0, no input, so the title stays at its first menu). My guess is that #252 or #283 changed what the title does up to there; I have not checked which, nor whether the copy comes back past the menus.

So I am not opening a PR for it now. The fix is ready if it shows up again: emirduran707:copy-from-title-memory (33adeb5, on 85bdf21, +120 lines). It does what the plan above says; the test title's new check (copy from its heap, written after recording) fails on main and passes with it, and cargo test --workspace -- --test-threads=4 gives 665 passed, 0 failed, 41 ignored, no SKIPPED, on the RX 9060 XT. It logs CopyMemoryToMemoryX from memory outside unified memory goes through an upload buffer… once when the path is taken.

AI-assisted: Claude Code (Claude Opus 5.5) made the runs' counts and wrote this comment.

**@⁠emirduran707** on GitHub · 2026-11-23 23:32 UTC · [original](https://github.com/xcl-dev/xcl/issues/319#issuecomment-7117078249) Update: on current `main` this no longer shows at the first menu. | builds | runs logging the dropped copy | |---|---| | 9ab7d76 … 4017f8f | 7 of 10 (~26–48 s in) | | 21b8723, 85bdf21 (after #252 / #283) | 0 of 5 | Same title, RX 9060 XT, `scripts/smoke.ps1` (60 s, `XCL_NETWORK=0`, no input, so the title stays at its first menu). My guess is that #252 or #283 changed what the title does up to there; I have not checked which, nor whether the copy comes back past the menus. So I am not opening a PR for it now. The fix is ready if it shows up again: [`emirduran707:copy-from-title-memory`](https://github.com/emirduran707/xcl/tree/copy-from-title-memory) (33adeb5, on 85bdf21, +120 lines). It does what the plan above says; the test title's new check (copy from its heap, written after recording) fails on `main` and passes with it, and `cargo test --workspace -- --test-threads=4` gives 665 passed, 0 failed, 41 ignored, no `SKIPPED`, on the RX 9060 XT. It logs `CopyMemoryToMemoryX from memory outside unified memory goes through an upload buffer…` once when the path is taken. AI-assisted: Claude Code (Claude Opus 5.5) made the runs' counts and wrote this comment.
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 01:01 UTC · original

I hit the same shape of problem and want to check the intended fix before writing one, because the obvious one is wrong.

copy_memory_x (crates/xcl/src/hle/d3d12x/list_x.rs:971) requires both ends in a UMA window:

let (Some((d, doff)), Some((s, soff))) = (
    real::uma_window_buffer(dst as usize, size as usize),
    real::uma_window_buffer(src as usize, size as usize),
) else {
    note_gpu_write("CopyMemoryToMemoryX", dst as usize, size);
    return warn(&N, W, format_args!("{src:#x} -> {dst:#x} ({size:#x} bytes) is not in unified memory"));
};

With the source in the title's own CPU memory the whole command is dropped, which is #319.

The tempting fix is a CPU copy_nonoverlapping straight into the destination, since the windows are the title's coherent memory and dst is already a CPU-visible address. I do not think that is correct here: command lists recorded by console code can be replayed, so a copy performed while recording would read the source as it was at record time, not at execution time.

So the fix I would propose, unless you would rather do it another way:

  1. when src is not in a window, copy size bytes out of src into an upload-heap buffer at record time (a small staging pool, like PATTERNS for fills);
  2. emit the GPU copy from that staging buffer to the destination window, which is the path that already exists;
  3. keep note_gpu_write/note_write where they are now, so the tracking stays the same.

Two questions:

  • is a record-time staging copy the intended answer, or is the source expected to stay valid until execution in every case you have seen?
  • is the staging buffer allowed to be one size-sized allocation per call (freed when the list is reset), or should it come out of the same bounded pool as pattern_buffer?

I have no copy of the game, so I cannot reproduce it here; I can write the unit test (window plus a source outside any window, checking that the destination bytes arrive after execution) once the direction is clear.

AI-assisted.

**@⁠Luislariosss** on GitHub · 2026-11-24 01:01 UTC · [original](https://github.com/xcl-dev/xcl/issues/319#issuecomment-7118669027) I hit the same shape of problem and want to check the intended fix before writing one, because the obvious one is wrong. `copy_memory_x` (`crates/xcl/src/hle/d3d12x/list_x.rs:971`) requires **both** ends in a UMA window: ```rust let (Some((d, doff)), Some((s, soff))) = ( real::uma_window_buffer(dst as usize, size as usize), real::uma_window_buffer(src as usize, size as usize), ) else { note_gpu_write("CopyMemoryToMemoryX", dst as usize, size); return warn(&N, W, format_args!("{src:#x} -> {dst:#x} ({size:#x} bytes) is not in unified memory")); }; ``` With the source in the title's own CPU memory the whole command is dropped, which is #319. The tempting fix is a CPU `copy_nonoverlapping` straight into the destination, since the windows are the title's coherent memory and `dst` is already a CPU-visible address. I do not think that is correct here: command lists recorded by console code can be **replayed**, so a copy performed while recording would read the source as it was at record time, not at execution time. So the fix I would propose, unless you would rather do it another way: 1. when `src` is not in a window, copy `size` bytes out of `src` into an upload-heap buffer at record time (a small staging pool, like `PATTERNS` for fills); 2. emit the GPU copy from that staging buffer to the destination window, which is the path that already exists; 3. keep `note_gpu_write`/`note_write` where they are now, so the tracking stays the same. Two questions: - is a record-time staging copy the intended answer, or is the source expected to stay valid until execution in every case you have seen? - is the staging buffer allowed to be one `size`-sized allocation per call (freed when the list is reset), or should it come out of the same bounded pool as `pattern_buffer`? I have no copy of the game, so I cannot reproduce it here; I can write the unit test (window plus a source outside any window, checking that the destination bytes arrive after execution) once the direction is clear. AI-assisted.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 11:03 UTC · original

Closing for now: the reported dropped copy did not recur in five later first-menu runs. This does not rule it out beyond the menus; please reopen if it recurs.

**@⁠ivall** on GitHub · 2026-11-24 11:03 UTC · [original](https://github.com/xcl-dev/xcl/issues/319#issuecomment-7129590345) Closing for now: the reported dropped copy did not recur in five later first-menu runs. This does not rule it out beyond the menus; please reopen if it recurs.
This discussion has been locked. Commenting is limited to contributors.
No description provided.