Skip to content

D3D12.X: replace busy copy scratch within budget - #1421

Open
hajduzsolt wants to merge 2 commits into
xcl-dev:mainfrom
hajduzsolt:fix/copy-scratch-busy-buffer
Open

hajduzsolt wants to merge 2 commits into
xcl-dev:mainfrom
hajduzsolt:fix/copy-scratch-busy-buffer

Conversation

@hajduzsolt

@hajduzsolt hajduzsolt commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Runtime fix verified with unit tests and RX 9070 XT smoke run.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: retain busy scratch until GPU completion and test replacement and accounting with synthetic D3D12 resources.

Tested

  • Windows 11 Pro x64 build 26300, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT 16 GB, driver 32.0.32029.2010; Rust 1.98.1 MSVC, debug.
  • cargo test -p xcl --lib copy_scratch -- --test-threads=4: 3 passed, 0 failed.
  • cargo test --workspace -- --test-threads=4 --nocapture: 752 passed, 0 failed, 41 ignored. The reported passes include tests that return early.
  • SKIPPED: test_title_draws_with_a_root_signature_under_the_debug_layer and uploads_start_from_each_subresources_state (D3D12 debug layer unavailable).

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 49 48 14
device removals: 0
crashes: 0
peak commit: 20195 MB

PR:

xcl-smoke v1
commit: 7124a95392e1a6b99db7b3fc5763d1269606c5f3
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1680)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14843 MB

Not tested

  • Retail title, debug-layer validation, and the end-to-end kickoff/copy path. The budget-exhausted fallback and its logging are unchanged.

AI use

  • Codex (GPT-6): wrote implementation and unit tests, ran validation, and drafted this description.

Retire a busy scratch buffer until its fence completes and allocate a replacement when the budget has room.

Co-Authored-By: Codex GPT-6 <noreply@openai.com>
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…#1395 in-place vtables

Integrates 16 upstream PRs (xcl-dev#1380, xcl-dev#1383, xcl-dev#1384, xcl-dev#1395, xcl-dev#1398, xcl-dev#1400,
xcl-dev#1404, xcl-dev#1405, xcl-dev#1419, xcl-dev#1420, xcl-dev#1421, xcl-dev#1423, xcl-dev#1424, xcl-dev#1427, xcl-dev#1428, xcl-dev#1429)
on top of the Linux/Proton fork, plus three Proton/vkd3d-proton fixes
caught during verification:
- Recompiler (xcl-dev#1428): flatten IO_GROUP_LIMIT early-return in compute
  shaders so vkd3d-proton v3.1 dxil-spirv accepts the emitted CFG.
- D3D12.X (xcl-dev#1395 + xcl-dev#867): skip UnadoptGuard on in-place-patched vtables
  and restore native vtables in runner::submit_list when a prior test
  adopted the singleton ID3D12Device.
- Tests: match Wine centered default in window_position_modes.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- gpu_sparse_vram_descriptors_buffers_and_xmem + gpu_valu_float_and_int
  + window_position_modes: 3 passed, 0 failed
- Broad sweep (present, real, sparse, clamp, dstorage, gpu_valu,
  gpu_typed_buffer): 82 passed, 0 failed, 1 ignored, 0 skipped
- 2.5 min retail title run (XCL_MEM_LIMIT=12G): 3,000+ frames at 30.0
  fps, 6.0-6.1 GB flat committed RAM, 6.4 GB local VRAM, 0 DS failures.
@pvfreis

pvfreis commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Test report for 7124a95 (this PR's head) merged onto main 1d027e5 (git auto-merged list_x.rs, no conflict). (Edited after a rerun. The first version covered 4c65020 onto b7aa9f3: 770 passed, 1 failed, 41 ignored; main 769/1/41, and noted the log line was missing; 7124a95 added it.) The new test passes on NVIDIA; no other test result changed. I opened #1408. Of its "Expected": a busy scratch moves to released, still charged to the budget, and a new one is made within it; the log line when the budget forces the fallback is now there.

Tested

  • RTX 3060 12 GB (driver 617.14), Ryzen 9 5900XT, Windows 11 26H2 (10.0.26300), Rust 1.100.0 stable MSVC, debug
  • cargo build --workspace --locked --offline, then cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4:
    • main 1d027e5: 958 passed, 1 failed, 43 ignored
    • this PR merged onto 1d027e5: 959 passed, 1 failed, 43 ignored. The difference is busy_copy_scratch_is_retired_when_budget_allows_a_replacement, which passes; the other two copy-scratch tests pass too, and the log has the new warning (emitted once per process) for a request of 67108864 bytes
  • SKIPPED, the same 22 lines on both: 18 no wave64 (16 in gpu::recomp::lower / lower_dxil, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), 3 refused wave32 per-lane cases in f16_programs_on_the_gpu / f32_programs_on_the_gpu, and heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • The 1 failure is the same on both and not from this PR: test_title_runs_and_game_folder_is_untouched (e2e, presents 0), because these runs are in an isolated non-interactive session where CreateSwapChainForHwnd returns 0x887A0022.

Not tested

  • main after 1d027e5 (689f2db now; the commits since touch only gpu/dxil and gpu/recomp)
  • the warning has no test asserting it
  • kickoff_x / copy_memory_x end to end, the debug layer on this path
  • AMD, Intel; a retail title (no smoke run here)

Run and written with Claude Code (Claude Opus 5.5); counts recomputed from the logs by a second agent (Claude Opus 5.5); text reviewed with Claude Fable 5.2. The runs are real, on the hardware above.

@srcamarda

Copy link
Copy Markdown
Contributor

Test report for 4c65020 merged onto main 2008399: AMD RDNA3, with the debug layer installed; the retail title does not reach the #1408 path in its first 150 s

Tested

  • AMD Radeon RX 7800 XT 16 GB (RDNA3), driver 32.0.32029.2010; Ryzen 5 5600G, 32 GB; Windows 11 Pro 26300 with Graphics Tools (D3D12 debug layer); rustc 1.100.0; debug for the tests, release for the title.
  • This PR merged onto main 2008399 locally (clean merge, not pushed).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 752 passed, 0 failed, 41 ignored. No SKIPPED lines. The two debug-layer tests your description lists as skipped ran and passed here: test_title_draws_with_a_root_signature_under_the_debug_layer (which asserts no "invalid for use as a source buffer" since D3D12.X: a copy within one memory window reads through a scratch buffer (#958) #993) and uploads_start_from_each_subresources_state. The three copy-scratch tests pass, including busy_copy_scratch_is_retired_when_budget_allows_a_replacement.

Retail title under the debug layer

  • Retail title 1.0.2.1, XCL_D3D12_DEBUG=1 XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_RUN_SECONDS=150, Enter (= A) at 30 / 40 / 50 s (title screens into the start of loading). Interleaved main, this PR, main, this PR.
  • XCL logs only the first 8 messages of each id, and id 538 fills that from 2.9 s with other state errors. So for these runs both builds carried the same local diagnostic, not part of this PR: messages that mention CopyBufferRegion are logged with no cap.
  • CopyBufferRegion state errors: 0 in all four runs, main and this PR alike. No device removal or crash; frames shown: main 2157 / 2008, this PR 1698 / 2009.
  • So in these 150 s the title does not reach a copy within one window after a resubmitted list, and this run does not show the effect of the change either way. It also shows no regression.

The id 538 errors the title does hit (same in both builds, and on main 47efa2e before #993; for whoever looks at them, not this PR's):

  • ClearRenderTargetView on a resource in UNORDERED_ACCESS (also once in COPY_SOURCE);
  • CopyResource with its source in RENDER_TARGET;
  • Draw with a render target in NON_PIXEL_SHADER_RESOURCE | PIXEL_SHADER_RESOURCE.

Not tested

Claude Code (Claude Opus 5.5), from runs on the hardware above.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@enderrr9

Copy link
Copy Markdown

Test report: NVIDIA, 32-lane waves, head 4c65020

Tested

  • NVIDIA GeForce RTX 3050 Laptop GPU (4 GB, driver 621.24), AMD Ryzen 5 4600H, Windows 11 build 26300, rustc 1.100.0 (MSVC), DXC 1.8.2502.11, debug build
  • cargo test -p xcl --lib copy_scratch -- --test-threads=4 --nocapture: 3 passed, 0 failed (a_new_list_takes_no_copy_scratch_of_an_earlier_one, busy_copy_scratch_is_retired_when_budget_allows_a_replacement, copy_scratch_budget_counts_resources_until_gpu_completion), none SKIPPED
  • cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64)

Not tested

  • a retail title (I have none), the D3D12 debug layer, whether the new test fails without the change

Report written and the tests run with Claude Code (Claude Opus 5.5).

@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 19:01
@hajduzsolt
hajduzsolt marked this pull request as draft November 24, 2026 19:23
@hajduzsolt

Copy link
Copy Markdown
Contributor Author

Thanks for noting the missing diagnostic. Budget-driven scratch refusals now emit a one-time warning before using the in-place fallback, including requests larger than the budget. The existing budget-exhaustion test and cargo test --workspace -- --test-threads=2 passed (708 library tests passed, 21 ignored).

@hajduzsolt
hajduzsolt marked this pull request as ready for review November 24, 2026 19:38
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@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

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 7124a95

No open or merged PR makes the same change; main's CopyScratchCache::acquire still returns None when the list's scratch is still in flight. #3111 also touches the copy scratch, but only moves the drop outside the lock.
No problems found in the diff: the busy scratch moves to released and stays charged until its fence passes, and the budget is checked before the replacement is made.
Recommendation: keep open.

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

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: b2b1f10
head: 7124a95
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2902 passed, 1 failed, 51 ignored (second run; base alone: 2902 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), same set as base; failing: not this PR. Run 2: hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime (left: 2, right: 1 at xaudio2.rs:1793) failed once; it passes 3 of 3 alone on both the merge and base, and hle::xaudio2:: 5 of 5 at 8 threads on both. Run 1: the lib binary was ended with exit code 0x7C10003 by uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment ("coherent window could not be restored"), the known problem #3187 addresses.
review: no correctness problem found after reading the whole diff (1 file, +61 -8). A list reset while its scratch is still in flight now moves that scratch to released (charged until its fence passes) and makes a new one when the budget allows, instead of returning None; budget refusals warn once.

  • The new busy_copy_scratch_is_retired_when_budget_allows_a_replacement and the two older copy-scratch tests pass 30 of 30 alone each on this GPU (it creates a real device and fence, not skipped).
  • Mutation: the busy path back to return None (main's behaviour) fails the new test. Good.
  • list_x::tests:: 60 runs at --test-threads=8: no copy-scratch test failed. bundle_generations_propagate_and_final_release_runs_outside_lists ("final COM Release ran under LISTS") failed 7 of 60 on the merge and 8 of 60 on base (2 of 30 on the merge with the new test skipped), so it is a pre-existing flake, not this PR. One E_OUTOFMEMORY in write_buffer_immediate_on_open_existing_heap_visible_to_cpu, a known parallel flake.
  • Minor, from reading only: a scratch whose submission could not be fenced (untracked_submission, when CreateFence/Signal fails in copy_scratch_submitted) never becomes idle. On main that list keeps its one stuck scratch and gets None. With this PR each reset moves it to released, where it stays charged for good, and a new one is made, so repeated resets can fill the 64 MB budget for every list. Only reached when fencing fails (e.g. a lost device). Keeping the old behaviour when untracked_submission is set would avoid it.
  • No retail title on this machine: the copy path in a real title was not run here (the PR's own smoke pair is on an RX 9070 XT).
    performance: not measured here. Up to one extra scratch per list in flight, inside the existing 64 MB budget; copies that used to take the in-place fallback while the scratch was busy now get a scratch.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 1, 2026
@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check claim
head: 7124a95

@vasanex

vasanex commented Dec 2, 2026

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: 7124a95
merge: clean (merged tree a0b9a608, git diff --check clean)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. The new test busy_copy_scratch_is_retired_when_budget_allows_a_replacement and the two existing copy-scratch tests pass.
review: whole diff read (one file, list_x.rs, +61/-8), in the merge result. No blocking finding. Before, a list whose scratch was still in flight on another queue got no scratch (None, the in-place fallback); now the busy buffer moves to released, stays counted in self.bytes until its fences are done (collect_released), and a new one is made if the 64 MiB budget has room for both, else None as before. The budget is checked before the move and again before the allocation, so the total cannot pass the cap. The idle and recorded cases are unchanged apart from the indentation. The warning is logged once per process. Small points: the test builds the busy state by hand (recorded = false plus a fence mark), so the real reset-while-executing path is covered by reasoning only; the once-only warning gives the first request's size, later ones are silent.
performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base 1c8b551: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit): 1539 frames shown, 60 60 60, 0 device removals, 0 crashes, peak commit 19677 MB. 96 % of the base's frames with the same rate at the end; I take the difference as start-up spread (one run each), not as an effect. The run logged no copy-scratch warning, so it did not reach the budget. By default the change can hold up to 64 MiB of scratch, the existing cap, where main fell back to the in-place path.
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.

@github-actions github-actions Bot added the ready-to-merge Has 2 independent safe merge-checks on current head (#3041) label Dec 2, 2026
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory goal:world-load Bears on the retail title getting past world loading gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants