Skip to content

D3D12.X: copy from the backing pages of GPU-only views - #768

Open
philip-roy-jones wants to merge 4 commits into
xcl-dev:mainfrom
philip-roy-jones:d3d12x-mirrored-copy-sources
Open

philip-roy-jones wants to merge 4 commits into
xcl-dev:mainfrom
philip-roy-jones:d3d12x-mirrored-copy-sources

Conversation

@philip-roy-jones

@philip-roy-jones philip-roy-jones commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #473 by 7ROBE. Part of #319. Includes upstream main at c160d86.

CopyMemoryToMemoryX dropped copies from a GPU-only reservation even when the paired CPU view held the data. The staged copy also put its upload buffer on a worker that gives up after ten seconds. A blocked copy could lose XCL's last reference while the GPU still needed it and delay a CPU write on another queue.

What is in it

Read backing spans at submission, prefer directly mapped pages and zero the holes. Fill each submitted segment, including split lists and KickoffX. The upload shares the submitting queue's fence with its copy scratch buffer. The bundled title checks late source writes on both submission paths. CuteBooty reported the timeout and cross-queue delay on an RTX 3070. The retirement code reuses zohaiblazuli's queue fencing. Review and measurements · Copy scratch fencing in #993

Tested

Windows 11, native D3D12, Radeon RX 580, driver 31.0.21925.1001, Rust 1.100.0 MSVC.

  • cargo test --locked -p xcl --lib staged_copy_waits_for_its_own_queue_without_blocking_cpu_writes -- --test-threads=1 --nocapture. On the unfixed merge 7cb9599 with only that test added, the independent write took 10.010 s and the held queue had lost XCL's reference. The test failed. On clean head f13de96 it took 1.595 ms (1.458 ms in the group run). Across the 10.25-second stall and subsequent fence completion, upload references went 1/1/1 before and 1/2/1 after. The test kept its own reference throughout. Readback after opening the gate was 0x1234abcd on both revisions, as expected. Head passed twice with zero skips.
  • cargo test --locked -p xcl --lib hle::d3d12x:: -- --test-threads=4 --nocapture. Clean main c160d86 reported 145 passed, 0 failed, 1 ignored. Clean head f13de96 reported 147 passed, 0 failed, 1 ignored. Both pass totals include one hardware skip, placed_title_textures_share_vram_and_preserve_pixels, because this adapter could not create a reserved cube with mips. cargo check --locked --workspace --all-targets passed on head.
  • cargo test --locked --workspace --lib --no-fail-fast -- --test-threads=4 --nocapture exited 0xc0000005 in the XCL test process on both revisions. Running the unreported tests in batches with the same library harness accounted for all 831 tests on main and 833 on head. Main reported 787 passed and head 789. Both had the same 21 assertion failures, 22 ignored tests and one process exit in gpu_wave64_ps_whole_wave_reductions. Each pass total includes the same 21 hardware skips (15 without wave32, four without mesh shaders, one without the requested wave32/wave64 combination and one reserved cube).

Regression run

Toons29 ran scripts/smoke.ps1 on clean main and this PR’s clean head with the same retail title, Radeon RX 9070 and 60-second duration. Both runs used XCL_NETWORK=0. Toons29’s RX 9070 results and setup

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: f13de96bcd3e505bac3684c2e24d9f7fc3a99b3d
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

The PR showed 1,631 frames versus 1,618 on main. Both runs exited cleanly with zero crashes and zero device removals. Coverage of the changed copy path in this retail run is unverified.

coolpersonnn also recorded 1,670 frames on c160d86 in a separate 60-second RTX 5090 control using warm shader caches and the default switch-window mode. The matching RTX 5090 head run is pending. RTX 5090 control · Head-run request

The previous local pair, 47efa2e and 6c0066b, presented frames and both exited with 0xc0000409 before 60 seconds. The RX 7900 XT report of 1,109 frames used the earlier 70dfae4. Request for current-head smoke blocks · Earlier RX 7900 XT results

Not tested

A full workspace run through the bundled title and controllable retail gameplay on this revision. The RX 9070 whole-suite report covered the previous head 6c0066b. Earlier RX 9070 results

AI use

Codex, GPT-6.2 Astra running on max reasoning effort, wrote the GPU-view change and regression tests, addressed the review, ran the native comparisons and prepared this description.

@philip-roy-jones
philip-roy-jones force-pushed the d3d12x-mirrored-copy-sources branch from 70dfae4 to 5ce1b4d Compare November 24, 2026 05:08
@crosettiremi

Copy link
Copy Markdown

RX 7900 XT, Windows 11 build 26100, native D3D12, offline Series S title profile.

  • Clean PR head 70dfae4, isolated empty application caches, 60-second retail smoke at the menu, no input. Exit 0, 1,109 frames shown, last three 2-second present counts 60 / 60 / 60, zero crashes or device removals, peak process commit 18,831 MB.
  • For coverage past the account picker I tested this change on my local integration build. Six prior world-loading runs had dropped a 16 KiB CopyMemoryToMemoryX. With the patch the call took the GPU-view upload path at 42.487 s. In a separate instrumented 60-second run the upload was filled at submission at 53.684 s. All 16,384 sampled bytes in that upload were zero. This cannot distinguish a valid zero source from an unmapped page. The retail destination was not read back. That run exited 0 with 1,370 presents and zero device removals.
  • In the longer integration run the title encountered E_OUTOFMEMORY on 64 MiB heap allocations close to the test job's 28 GiB limit and exited 0xc0000409. Gameplay remains unverified. The integration suite reported 738 passed, 0 failed, 41 ignored, including a counted pass that printed a missing xgameruntime.dll skip.

AI use: Codex (GPT-6) ran the checks and prepared this report.

@philip-roy-jones
philip-roy-jones force-pushed the d3d12x-mirrored-copy-sources branch from 5ce1b4d to 80c1790 Compare November 24, 2026 12:16
A graphics-only reservation outside unified memory can have its data in a paired CPU view. Resolve each source mapping when ExecuteCommandLists or KickoffX fills the upload, so CPU changes after recording reach the copy. On an RX 580 a 16 KiB readback from each submission path previously had 16,320 wrong bytes. Both now match in full.

Part of xcl-dev#319.

Assisted-by: Codex (GPT-6.2 Astra, max reasoning effort)
@philip-roy-jones

philip-roy-jones commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@crosettiremi, thanks for the 1,109-frame menu run on 70dfae4. Could you repeat that 60-second comparison on your RX 7900 XT using clean upstream main (c160d86 is the base of this revision) and the current #768 head f13de96?

On each clean checkout, build with cargo build --release --locked -p xcl and run .\scripts\smoke.ps1 -Game '<your local game folder>' -Seconds 60. Please use the same title, cache state, settings and menu inputs on both builds. Could you paste the two generated xcl-smoke blocks here? Those summaries are all we need.

Posted at Philip’s request via Codex (GPT-6.2 Astra, max reasoning effort).

@CuteBooty

Copy link
Copy Markdown

Two effects of keeping the upload buffers alive through cpu_writes (head 6c0066b), when the queue of such a copy is held by a long wait.

1. XCL's last reference to the buffer can go before the copy has run. The worker gives a job up after WAIT_MS (10 s from when it starts to wait for it) and drops the KeepAlive although the fence is not there. Until the list is reset, its state holds another reference. After KickoffX has returned (it takes pending_uploads out of the state) or after a Reset of the list, I found nothing else that does. The copy may then still be ahead on the GPU.

2. The copy can hold up other queues' CPU writes. The worker is one thread and takes jobs one after the other, so Immediate / ReadbackU64 jobs behind the copy's job wait with it, whichever queue they are for, up to 10 s for each such job. Lists with CPU writes already do that on main; this adds lists whose only job is the copy. (main skips these copies and queues nothing for them.)

Seen with a scratch test in cpu_writes.rs: queue B waits for a fence and executes a list with a CopyBufferRegion from an upload buffer, then after(B, [KeepAlive(buf)]) and after(A, [Immediate(..)]); on the base without the first after. Times are from after the after(A, ..) call until the test sees the value.

base 47efa2e 6c0066b
A's write, B not yet used 0.001 s 0.001 s
A's write while B is held under 1 ms 10.0 s
references to the buffer: before / job queued / after A's write (B's copy not done) 1 / 1 / 1 1 / 2 / 1

The test holds one reference itself, so nothing was freed early in it. That no other reference is left after KickoffX or Reset is from reading the code.

Possible fix: keep an upload buffer until its fence is reached, without a time limit and outside the worker's queue (for example a list of (fence, value, buffer) looked at on each submit). #562 (a worker per queue) would end the second effect, not the first.

Tested: cargo test -p xcl --lib with that one test on both commits; RTX 3070, NVIDIA 621.24, Windows 11 Pro 26200, rustc 1.100.0 MSVC, debug.

Not tested: copy_memory_x / KickoffX end to end, an actual use after free, the whole suite, a retail title, whether a title's queue is held that long with such a copy in it.

AI use: Claude Code (Claude Opus 5.5) found this, ran the test and wrote the comment; Codex (GPT-6.2 Astra) checked the claims and the draft by reading the code, without running anything.

The CPU-write watchdog can abandon a pending upload after ten seconds and makes an unrelated queue wait behind it. Carry upload references across native submission and share the per-queue completion mark with copy scratch. The regression keeps a queue behind a fence, verifies an independent write, and checks the upload lifetime and readback after the list state is gone.

Assisted-by: Codex (GPT-6.2 Astra, max reasoning effort)
@CuteBooty

Copy link
Copy Markdown

Both points are fixed in f13de96 as far as my test shows. Same setup as before (queue B held by a fence, a copy from an upload buffer on it), now through copy_buffers_submitted(B, [list], [buf]):

6c0066b f13de96
A's CPU write while B is held 10.0 s under 1 ms
references to the buffer: before / submitted / B still held after that 1 / 2 / 1 (after 10 s) 1 / 2 / 2 (after 15 s)
gate open: the copy is done, the reference is let go – yes, after about 10 ms

Tested: that one scratch test and cargo test -p xcl --lib list_x on f13de96 (28 passed, 0 failed, staged_copy_waits_for_its_own_queue_without_blocking_cpu_writes among them); RTX 3070, NVIDIA 621.24, Windows 11 Pro 26200, rustc 1.100.0 MSVC, debug.

Not tested: copy_memory_x / KickoffX end to end, the whole suite, a retail title.

AI use: Claude Code (Claude Opus 5.5) read the change, ran the tests and wrote this.

@philip-roy-jones

Copy link
Copy Markdown
Contributor Author

@coolpersonnn, could you run one 60-second retail smoke test on your RTX 5090 using clean #768 head f13de96bcd3e505bac3684c2e24d9f7fc3a99b3d? Your clean main run on c160d86 recorded 1,670 frames in 60 seconds and gives us the comparison. Your baseline in #1439

Please use the same title, warm shader caches, default switch-window mode, settings and inputs as that run. On the clean head, build with cargo build --release --locked -p xcl and run .\scripts\smoke.ps1 -Game '<your local game folder>' -Seconds 60. Could you paste just the generated xcl-smoke block here? We can pair it with the main block you already posted.

Posted at Philip's request via Codex (GPT-6.2 Astra, max reasoning effort).

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of f13de96b on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: f13de96bcd3e505bac3684c2e24d9f7fc3a99b3d
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14814 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

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.

7 participants