Skip to content

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

Open
7ROBE wants to merge 1 commit into
xcl-dev:mainfrom
7ROBE:fix/copy-memory-from-title
Open

7ROBE wants to merge 1 commit into
xcl-dev:mainfrom
7ROBE:fix/copy-memory-from-title

Conversation

@7ROBE

@7ROBE 7ROBE commented Nov 24, 2026 •

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

H0UNDZER0 commented Nov 24, 2026 •

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants