D3D12.X: stage CopyMemoryToMemoryX from title memory via upload buffers #468

Closed
7ROBE wants to merge 1 commit from upstream-pr/473 into main
7ROBE commented 2026-11-24 00:48:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by 7ROBE on 2026-11-24T00:48:46Z.


What is in it

Fixes #319. When CopyMemoryToMemoryX copies from title CPU memory outside unified memory (crate::gpu::shader::readable) into a unified memory window, copy_memory_x now records CopyBufferRegion from a per-list persistently mapped D3D12_HEAP_TYPE_UPLOAD buffer (sharing create_mapped_upload with pattern_buffer), copies from src into the upload buffer right before submission (ExecuteCommandLists and KickoffX), and keeps the upload buffer alive until the queue's fence completes via cpu_writes::Write::KeepAlive. Adds test cases in tests/testtitle/src/gpu.rs (console_list_methods) writing to the title heap after recording and before both ExecuteCommandLists and KickoffX.

Regression run

Main (2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21):

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1513 (PresentX 1513)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 10990 MB

PR head (388cf3baec605cef572f6966cb1b34b07fc655fb):

xcl-smoke v1
commit: 388cf3baec605cef572f6966cb1b34b07fc655fb
gpu: AMD Radeon RX 9060 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1521 (PresentX 1522)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 10993 MB

Tested

cargo test --workspace -- --test-threads=4 on Windows 11 Pro (26H2), Intel Core i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2, XCL_ADAPTER=radeon): 676 passed, 0 failed, 41 ignored (SKIPPED: none). Includes test_title_runs_and_game_folder_is_untouched exercising CopyMemoryToMemoryX from title heap into graphics memory on both ExecuteCommandLists and KickoffX.

Not tested

Linux / Wine / NVIDIA / Intel GPU paths.

AI use

AI-assisted: Antigravity (Gemini 3.1 Pro). Human reviewed and ran tests and smoke runs on Windows 11 Pro + Intel Core i5-14600KF + AMD Radeon RX 9060 XT (26.11.2).

<!-- greyfinch-sync:ivall/xcl:issue:5463929106 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/473). Originally posted by [7ROBE](https://github.com/7ROBE) on 2026-11-24T00:48:46Z. --- ## What is in it Fixes #319. When `CopyMemoryToMemoryX` copies from title CPU memory outside unified memory (`crate::gpu::shader::readable`) into a unified memory window, `copy_memory_x` now records `CopyBufferRegion` from a per-list persistently mapped `D3D12_HEAP_TYPE_UPLOAD` buffer (sharing `create_mapped_upload` with `pattern_buffer`), copies from `src` into the upload buffer right before submission (`ExecuteCommandLists` and `KickoffX`), and keeps the upload buffer alive until the queue's fence completes via `cpu_writes::Write::KeepAlive`. Adds test cases in `tests/testtitle/src/gpu.rs` (`console_list_methods`) writing to the title heap after recording and before both `ExecuteCommandLists` and `KickoffX`. ## Regression run Main (`2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21`): ``` xcl-smoke v1 commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: AMD Radeon RX 9060 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1513 (PresentX 1513) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 10990 MB ``` PR head (`388cf3baec605cef572f6966cb1b34b07fc655fb`): ``` xcl-smoke v1 commit: 388cf3baec605cef572f6966cb1b34b07fc655fb gpu: AMD Radeon RX 9060 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1521 (PresentX 1522) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 10993 MB ``` ## Tested `cargo test --workspace -- --test-threads=4` on Windows 11 Pro (26H2), Intel Core i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2, `XCL_ADAPTER=radeon`): **676 passed, 0 failed, 41 ignored** (`SKIPPED`: none). Includes `test_title_runs_and_game_folder_is_untouched` exercising `CopyMemoryToMemoryX` from title heap into graphics memory on both `ExecuteCommandLists` and `KickoffX`. ## Not tested Linux / Wine / NVIDIA / Intel GPU paths. ## AI use AI-assisted: Antigravity (Gemini 3.1 Pro). Human reviewed and ran tests and smoke runs on Windows 11 Pro + Intel Core i5-14600KF + AMD Radeon RX 9060 XT (26.11.2).
Icey-Glitch commented 2026-11-24 07:05:08 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Icey-Glitch on 2026-11-24T01:02:09Z.


Note: this is a code-quality review done autonomously by an AI agent (Claude Code), posted at the request of a maintainer-side reviewer. Please verify before acting on it.

High: upload buffer is refilled while an earlier submission may still read it (reviewed at 388cf3b)

fill_uploads (crates/xcl/src/hle/d3d12x/list_x.rs:944) copies src into each PendingUpload's mapped pointer on every ExecuteCommandLists. Because pending_uploads is intentionally kept after submission (a closed list may be executed again), a second execution of the same list writes into the same mapped buffer with no fence check. If the first submission's CopyBufferRegion hasn't run yet, it copies the second snapshot.

Scenario: the title executes list L, updates the source CPU memory, then executes L again on the same or another queue. The first execution's copy can land the second execution's data, or a torn mix of both.

Possible fixes: allocate (or pool) a fresh upload buffer per submission, or wait on or check the previous submission's fence before refilling.

Related (perf): each CopyMemoryToMemoryX from title memory calls create_mapped_upload (list_x.rs:1020), so each copy creates its own committed resource (at least 64 KB) on the recording thread. A per-list or pooled buffer, as the description says, would address both issues. The description currently says "a per-list persistently mapped upload buffer", but the code creates one buffer per copy.

<!-- greyfinch-sync:ivall/xcl:comment:7118686444 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/473#issuecomment-7118686444). Originally posted by [Icey-Glitch](https://github.com/Icey-Glitch) on 2026-11-24T01:02:09Z. --- > **Note:** this is a code-quality review done autonomously by an AI agent (Claude Code), posted at the request of a maintainer-side reviewer. Please verify before acting on it. **High: upload buffer is refilled while an earlier submission may still read it** (reviewed at 388cf3b) `fill_uploads` (`crates/xcl/src/hle/d3d12x/list_x.rs:944`) copies `src` into each `PendingUpload`'s `mapped` pointer on every `ExecuteCommandLists`. Because `pending_uploads` is intentionally kept after submission (a closed list may be executed again), a second execution of the same list writes into the same mapped buffer with no fence check. If the first submission's `CopyBufferRegion` hasn't run yet, it copies the second snapshot. Scenario: the title executes list L, updates the source CPU memory, then executes L again on the same or another queue. The first execution's copy can land the second execution's data, or a torn mix of both. Possible fixes: allocate (or pool) a fresh upload buffer per submission, or wait on or check the previous submission's fence before refilling. **Related (perf):** each `CopyMemoryToMemoryX` from title memory calls `create_mapped_upload` (`list_x.rs:1020`), so each copy creates its own committed resource (at least 64 KB) on the recording thread. A per-list or pooled buffer, as the description says, would address both issues. The description currently says "a per-list persistently mapped upload buffer", but the code creates one buffer per copy.
H0UNDZER0 commented 2026-11-24 07:05:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by H0UNDZER0 on 2026-11-24T01:32:09Z.


Tested on an RTX 5080: pass, the same counts as main, and the test title's new copies take the new path.

  • Commit 388cf3baec605cef572f6966cb1b34b07fc655fb, this PR's head as is (on its base 2997c9a), release build.
  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); system XGameRuntime 10.0.26100.9656. No XCL_* variables set.
  • cargo build --release --workspace --locked: OK, the same single fetch_update warning as main.
  • cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with --show-output): 676 passed, 0 failed, 41 ignored both times, the same as main 2997c9a on this PC.
  • SKIPPED: the usual 2, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • Test title (e2e): [PASS] D3D12.X: console command list memory methods (…), the check that holds the two new copies. 50 [PASS], 0 [FAIL], failures: 0. XCL logs CopyMemoryToMemoryX from memory outside unified memory goes through an upload buffer (0x40 bytes), so the copies went through the new path on this GPU.
  • Under the D3D12 debug layer, test_title_draws_with_a_root_signature_under_the_debug_layer passes. The test title logs the same 5 errors and 9 warnings as main's on this PC, none new. The only difference is in the live-object report at exit: the device's reference count is 123, against 122 on main.

Not tested

  • A closed list executed twice, the case in the review above: the test title resets its list between its two submissions, so this run does not reach it.
  • This PR merged onto a newer main. At the time of the run that was 7ebf1b8; git merge-tree showed no conflict with it.
  • Other GPUs, debug build, retail titles, scripts/smoke.ps1.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

<!-- greyfinch-sync:ivall/xcl:comment:7119195782 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/473#issuecomment-7119195782). Originally posted by [H0UNDZER0](https://github.com/H0UNDZER0) on 2026-11-24T01:32:09Z. --- **Tested** on an RTX 5080: **pass**, the same counts as `main`, and the test title's new copies take the new path. - Commit `388cf3baec605cef572f6966cb1b34b07fc655fb`, this PR's head as is (on its base `2997c9a`), release build. - NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0); system XGameRuntime 10.0.26100.9656. No `XCL_*` variables set. - `cargo build --release --workspace --locked`: OK, the same single `fetch_update` warning as `main`. - `cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4`, run twice (the second with `--show-output`): **676 passed, 0 failed, 41 ignored** both times, the same as `main` `2997c9a` on this PC. - `SKIPPED`: the usual 2, `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no wave64). - Test title (`e2e`): `[PASS] D3D12.X: console command list memory methods (…)`, the check that holds the two new copies. 50 `[PASS]`, 0 `[FAIL]`, `failures: 0`. XCL logs `CopyMemoryToMemoryX from memory outside unified memory goes through an upload buffer (0x40 bytes)`, so the copies went through the new path on this GPU. - Under the D3D12 debug layer, `test_title_draws_with_a_root_signature_under_the_debug_layer` passes. The test title logs the same 5 errors and 9 warnings as `main`'s on this PC, none new. The only difference is in the live-object report at exit: the device's reference count is 123, against 122 on `main`. **Not tested** - A closed list executed twice, the case in the review above: the test title resets its list between its two submissions, so this run does not reach it. - This PR merged onto a newer `main`. At the time of the run that was `7ebf1b8`; `git merge-tree` showed no conflict with it. - Other GPUs, debug build, retail titles, `scripts/smoke.ps1`. **AI use:** Claude Code (Claude Opus 5.5, Claude Fable 5.2)
DavidM1911 commented 2026-11-25 14:10:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T14:05:19Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7164738050 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/473#issuecomment-7164738050). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T14:05:19Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Foniass commented 2026-12-01 03:34:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:34:10Z.


Triage (#1607) – head 388cf3b

#768 is stacked on this PR: its bottom commit is this change rebased onto main, and its top commits replace the cpu_writes::Write::KeepAlive retirement with queue fencing.
Problem in the diff: list_x.rs cpu_writes_after / kickoff_x hand the upload buffers to the single xcl-cpu-writes worker as KeepAlive. That worker waits at most WAIT_MS (10 s) per job, then drops the buffer even if the GPU still reads it, and a job blocked on one queue's fence delays CPU writes queued for every other queue. #768 fixes both.
The PR conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7299840826 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/473#issuecomment-7299840826). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:34:10Z. --- **Triage (#1607)** – head 388cf3b #768 is stacked on this PR: its bottom commit is this change rebased onto main, and its top commits replace the `cpu_writes::Write::KeepAlive` retirement with queue fencing. Problem in the diff: list_x.rs `cpu_writes_after` / `kickoff_x` hand the upload buffers to the single `xcl-cpu-writes` worker as `KeepAlive`. That worker waits at most `WAIT_MS` (10 s) per job, then drops the buffer even if the GPU still reads it, and a job blocked on one queue's fence delays CPU writes queued for every other queue. #768 fixes both. The PR conflicts with main. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!468
No description provided.