Skip to content

D3D12.X: a copy back after a submission does not wait for the title - #1993

Open
Ariorh1337 wants to merge 1 commit into
xcl-dev:mainfrom
Ariorh1337:sparse/async-readback
Open

Ariorh1337 wants to merge 1 commit into
xcl-dev:mainfrom
Ariorh1337:sparse/async-readback

Conversation

@Ariorh1337

@Ariorh1337 Ariorh1337 commented Nov 25, 2026 •

Copy link
Copy Markdown

readback_after_execute makes the sparse queue GPU-wait for the title's queue, then waits on the CPU for the copy back, on the thread that is submitting. A title's queues can wait for work that thread submits next. In the retail title of #505, four compute queues wait for a Write64 on q1 whose list is recorded but not submitted yet. So every such submission waited 5 s for its copy back, and the uploads queued behind it on the sparse queue waited as well (before_execute waiting for ring room). lucsoft hit the same cycle on RDNA3 / Linux and found it was the whole stop there (#505 comment). This PR moves the copies back to queues of their own and makes them asynchronous.

Part of #505.

What is in it (one commit, crates/xcl/src/hle/d3d12x/; about 470 lines of code and 500 of tests)

  • sparse.rs:
    • Lanes. A copy back runs on a lane: a fence the title's queue signals after its lists, and a queue of its own that GPU-waits for that fence. A lane serves one title queue while that queue has copies back in flight, so a copy waits for its own queue's lists only (with one fence for all queues, another queue's later signal let it start early; found by CharlyRien in review), and a title queue that waits for work still to come does not hold back the copies of the others.
    • The 8 lanes are made in init, before the device's methods are hooked; made later, a lane's queue is adopted as one of the title's. With all lanes busy, the old path runs.
    • A copy back's allocator and list are made with the device's own methods, past its hooks (real::create_own_list), as init's objects are. Made through the adopted device, the list ran XCL's list hooks on the lane's queue, and vkd3d-proton crashed at its Close (found by St5sz2Jk on RDNA4 / Wine).
    • Tiles quarantined behind the title queues' marks (D3D12.X: quarantine unmapped parked sparse tiles behind GPU fences #2345) also wait for the copies back still to run on a lane: those read the windows after the title's work.
    • Landing the data. The data reaches the title's memory once the copy is done (drain_readbacks): on the next submit, and from a thread that looks every 0.5 ms. Lanes land in their own order, so an older copy back of one lane that lands after a newer one of another leaves the bytes the newer one landed.
    • Before a CPU read. settle_readbacks runs before Map's readback and also waits for a copy whose title work is already done, on the lane's own event (with the sparse state's event, a wait that gave up left a registration that ended a later tile-queue wait early; found by theaustinayers in D3D12.X: integration branch that reaches the in-world HUD on NVIDIA (reference, not for merge) #2057).
    • Readback buffers are sized to the copy (64 KiB and up) and reused; idle ones above 256 MB are given back (each holds commit; with the title's queues stalled, every submit's copies wait, one buffer each; Chrysana asked about memory on RDNA4). Each time the buffers pass another doubling from 64 MB, their size is logged. In a run of the retail title through the world load to the removal, with XCL_COHERENT_HEAPS=sparse:1024, they never passed 64 MB.
  • real.rs: create_own_list (above). The title's fence observations settle copies back first, and do not show the title its work done until they landed (found by bmjask in review):
    • GetCompletedValue settles them before it returns.
    • SetEventOnCompletion with an event gives the fence an event of XCL's own. A thread-pool wait on that event settles them, then sets the title's event.
    • settle_readbacks_try says whether every copy back whose title work is done landed. When it could not (the sparse state's lock not had, or a copy not finished in time), the thread-pool wait tries again every millisecond before it sets the title's event (10 s at most, WT_EXECUTELONGFUNCTION), and GetCompletedValue gives no more than the value the fence was last seen at with its copies landed (its initial value from CreateFence at first). The title's thread is not blocked by this.
    • Without asynchronous copies back so far, both are as before.
  • list_x.rs: the CPU wait of Wait64BitValueX / Wait32BitValueX settles copies back between its polls. It only tries the sparse state's lock, as the holder can be waiting for work this thread is to submit.
  • The tried settles (fence hooks, the CPU wait) land only the copies that are done under the lock. A copy whose title work is done but which still runs is waited for with the lock let go (5 s at most), then landed. Waiting for it with the lock held stood every submit behind a copy that stood behind a stalled GPU (found by lucsoft on RDNA3).
  • Tests (in sparse.rs, on a WARP device of their own; see below):
    • a_copy_back_does_not_wait_for_the_title_queue: a title queue blocked on a gate copies into a tile. The copy back returns at once and lands once the queue goes on. On the old path it waits 5.0 s.
    • a_copy_back_waits_for_its_own_title_queue: two title queues, the first blocked while the second runs and signals. B's copy lands, A's does not until A ran. With one lane for both queues (what one fence amounted to) it fails: A's dword 0 landed before A's lists ran.
    • an_older_copy_back_does_not_overwrite_a_newer_one.
    • idle_copy_back_buffers_above_the_cap_are_given_back.
    • a_copy_still_running_after_its_title_work_is_waited_for_outside_the_lock: the lane's copy queue stands behind a gate while the title's queue is done; the copy is found without waiting, Drain::Finished does not land it, and it lands once its fence is waited for.
    • a_copy_back_list_of_an_adopted_device_is_not_adopted: on an adopted WARP device, a copy back's list and allocator are not adopted and still reset and close. It fails without create_own_list.
    • quarantined_tiles_wait_for_copies_back_still_to_run: a tile quarantined while a lane's copy is held behind a gate is not freed until the copy is done. It fails without the lanes' marks.
    • a_title_fence_shows_its_work_done_only_once_copies_back_can_land: an adopted fence, a copy back in flight, the sparse state held by another thread. GetCompletedValue stays at the initial value and the title's event is not set; both come once the state can be had. It fails without the change (the fence's work shows as done before its copies back landed).
    • a_fence_value_goes_past_its_landed_copies_only_once_they_land.
    • gpu_sparse_vram_descriptors_buffers_and_xmem settles before its CPU reads, as its fence wait is not one of the title's.
  • The parallel test hang upipibi bisected to this change: the first test blocked a queue of the GPU's device, which every test in the process shares. In thread dumps, three list_x tests were in the driver in NtGdiDdDDIDestroyAllocation2 and the new test was in a D3D12 call behind them, so the gate was never opened. Reproduced in 3 of 3 runs of upipibi's filter before; none hung after, with the tests on WARP (numbers below).

Tested

  • RTX 5090 32 GB (driver 32.0.16.1692), Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 26300, rustc 1.99.0, DXC 1.9.2609.5, debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4:
    • this PR (0a755f0, on main 06055a7): 1418 passed, 4 failed, 46 ignored;
    • main (06055a7): 1409 passed, 4 failed, 46 ignored.
    • The 4 failures are the same on both: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState 0x8007000E).
    • SKIPPED: 26 lines, the same tests on both.
  • upipibi's filter (d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence), capped at 180 s: before the fix 3 of 3 runs hung. Since: 3260d40 3 runs (release), 2 with 62 passed and 1 with a failure in acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure, which checks with VirtualQuery that a freed buffer is free while a test beside it can take the address (it does not touch the sparse code); 9a3fe7d 3 of 3 (debug), 5 of 5 on the revision before (release), and upipibi's 10 of 10 on an RTX 3070.
  • e2e: test_title_draws_with_a_root_signature_under_the_debug_layer failed while the lanes were made on first use (the test title read 0 for its KickoffX and Map readbacks); with the lanes made in init it passes.
  • On AMD (on this PR's thread):
    • Chrysana, RDNA4 / Windows, 69903fc: hang check 10 of 10, and the copy-back tests pass on the RX 9070 XT and an RDNA2 iGPU too, with lane_state() moved to the hardware adapter locally.
    • lucsoft, RDNA3 / Linux, 69903fc in a stack with kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #2009 and about 20 other PRs on main 50a9fde: no GPU-wait timeout in about 770 s (cold) and 2200 s (warm) of world work; the warm run reached the prologue's movement prompt.
    • St5sz2Jk, RDNA4 / Linux / Wine, with Memory: avoid amdgpu userptr stalls under Wine (#175) #871: the crash at the copy back's Close is what create_own_list fixes. Three copy-back tests failed there; they pass on native AMD drivers (Chrysana), so that looks like the Wine side. Not re-run on 0a755f0.
  • Retail title on this RTX 5090, main 568e7db + e213d42 (this PR before the rebase): through the menus, the first #101 and the world's first burst (8192 dispatches) with no copy-back warning, no 5 s wait and no crash. It then stopped on a cold driver build of one 21 MB compute pipeline, not related to this PR.
  • Retail title (1.0.2.1), on a local tree (main b9b6ea6 plus open PRs, D3D12.X: the committed window gets a copy in video memory #1329 and the earlier form of this PR, with the title's two large GPU heaps in the sparse windows): the title reached the in-game HUD and ran 465 s after the first #101. One run, before the lanes.

Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60 (start screen, no input), XCL_HEAP_WINDOWS=1 for both, same machine.

xcl-smoke v1
commit: 06055a7a0fb43c5f83f55e7a2ce201417de171e9
gpu: NVIDIA GeForce RTX 5090
title: a155fb60
seconds: 60
exit: 0x0
frames shown: 1604 (PresentX 1604)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14766 MB
xcl-smoke v1
commit: 0a755f0ccbad1c7090a500715505571dfbb95927
gpu: NVIDIA GeForce RTX 5090
title: a155fb60
seconds: 60
exit: 0x0
frames shown: 1593 (PresentX 1593)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15094 MB

Not tested

  • Intel GPUs. On AMD only the runs on this thread listed above.
  • Linux / Wine on 0a755f0: the crash fix is from St5sz2Jk's stack, not re-run there.
  • The retail title on main + this PR alone. With the title's heaps in the coherent window (the default), its lists write little into the sparse windows. The smoke run above does not reach the world. The title run above was on 568e7db, before the rebase.
  • Reads this PR does not cover. A title reading memory its lists wrote right after a fence observation XCL does not see: ID3D12Fence1, or a wait through WaitForMultipleObjects on an event it shares with another fence. The 0.5 ms thread lands the data there.
  • More than 8 title queues with copies back in flight at once (they take the old path).

AI use

  • Claude Code (Claude Opus 5.5) found the cycle in thread dumps of the title runs, wrote the change and the tests, found the cause of the test hang in thread dumps, ran the test suites and the smoke runs on the machine above, and wrote this description. I read the diff and checked the results before pushing.

🤖 Generated with Claude Code

@CharlyRien

Copy link
Copy Markdown
Contributor

A caution from a local change of the same design: with the copy back asynchronous, the shared rb_fence lets a copy run before its own title queue has run the lists. Reading this diff, the pattern is still there (s.rb_value += 1; queue.Signal(&s.rb_fence, v); q.Wait(&s.rb_fence, v) in after_execute, one rb_fence and one counter for every title queue). I have not run this PR.

What happened in my tree, which had the same idea (copies back on their own queue, landed by a thread):

  • rb_fence only counts up, and each title queue signals the next value of one counter. A copy issued for queue A at value N is satisfied as soon as queue B has signalled N+1, even if A has not reached its own Signal yet (A may be standing behind one of the title's waits, which is exactly the case this PR is about). The copy then reads video memory before A's lists ran, the old bytes land in the title's memory, and nothing copies that range again.
  • In the retail title the ranges are its sync cells. The submit thread polls such a cell on the CPU (Wait64BitValueX fallback) and sits out the full 2 s every time: 76 polls, 152 s blocked in one 280 s run, and the compute queues waiting for what that thread would submit next were released by the 5 s watchdog, about twenty per frame.
  • A probe showed it directly: readback 0x5a8 of q1 is already satisfied when issued (rb fence at 0x5a8, set by another queue), then 9.7 s later the CPU wait on a cell in that range times out with the old value while a synchronous copy from video memory at that moment returns the wanted one. Same in all 11 probed timeouts.
  • With one source fence per title queue (only that queue signals it) and one copy queue per title queue, 4 runs had 0 watchdog releases, 0 timed-out polls and 0 sparse: the queue has not reached fence value waits, at 1.3 – 1.4 frames per second in the world. Details and the table: D3D12.X: the committed window gets a copy in video memory #1329 (comment)

So it may be worth giving each title queue its own fence here (or checking drain_readbacks / settle_readbacks against the queue's own progress rather than rb_fence.GetCompletedValue() >= rb_v), and a test with two title queues where the second one signals while the first is still blocked.

Setup of the runs above (not this PR): main 9e3831e merged locally with #1288, #1448, #684, #889, #1323, #929, #640, #1326, #1327, #1329 and #1791 (by hand), plus local diagnostics and the local asynchronous copy back; XCL_UMA_SHADOW=1 XCL_HEAP_WINDOWS=1 XCL_NETWORK=0 XCL_ACTIVITY=1, release, warm caches, no XCL_PSO_WAIT_MS. On that path the committed window is a copy in video memory, so the title's sync cells go through these copies back; with the default imported window they may not, and the effect could be smaller there. RTX 3090 24 GB (driver 616.56), Ryzen 9 5950X, Windows 11 22631, TdrDelay 30 s.

Not tested: this PR itself, current main, AMD.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the journal and the probe) ran the measurements; I read this PR's diff and drafted the comment.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 4df0a2d (on its base 8e87fc7).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 980 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: a_copy_back_does_not_wait_for_the_title_queue.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 990 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 4df0a2d:

  • Moving readback_after_execute onto rbq (rb_jobs, rb_pool, RB_PENDING, xcl-sparse-readback drain thread, settle_readbacks / settle_readbacks_try) and adding a_copy_back_does_not_wait_for_the_title_queue is well-structured for avoiding submission-thread stalls against a blocked title queue.
  • Diff audited and CI workflow approved (currently running).
  • Important technical check: @CharlyRien's caution above on the single monotonic rb_fence (s.rb_value += 1; queue.Signal(&s.rb_fence, v); q.Wait(&s.rb_fence, v)) looks real for multi-queue titles — if queue B signals v + 1 while queue A is still gated behind an earlier wait, q.Wait(&s.rb_fence, v) can unblock and read stale VRAM before queue A's copy/write executes. Worth either keying source fences per queue (or tracking per-queue fence progress in drain_readbacks) and adding a 2-queue ordering test.

Remaining before merge: Addressing the multi-queue rb_fence ordering concern, Build and test finishing green, and an AMD verification pass.

@treybertram06

treybertram06 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Correction (retracting this report): these four runs are not valid. A test script I had stopped kept running and launched the title in parallel with these runs: each launch ended the other's run, and log copies were overwritten. The fourth row's log actually holds a device removal at 171 s, not "none". I have no clean A/B of #1993 on this machine. I'll post a new one if I rerun it. Sorry for the noise.


Test report for #1993 at head 4df0a2d, as @Ariorh1337 asked on #505: the retail title on an RTX 3080, with and without this PR, at the default coherent window and at XCL_COHERENT_MB=1024. No device removal or crash in any of the four runs. This PR ran at least as well as the base at the default setting, and was within noise at 1024.

Tested

  • RTX 3080 10 GB (32-lane waves), driver 621.40, Ryzen 9 5900X, 64 GB, Windows 11 Pro 26300, rustc 1.100.0, release.
  • Base tree (not a clean main): main c4d37be + D3D12.X: a placed buffer's last Release does not wait for the sparse lock #1478 + D3D12.X: allow title texture pages in system memory #1702 (its switch left off) + local logging, with a cap that refuses two programs over 8 MB of HLSL. The PR build is the same tree with 4df0a2d merged. The only conflict was in sparse.rs, where my logging line sat in the readback code this PR rewrites; I took the PR's side and re-added the logging after its waits.
  • The retail title, heap windows, warm caches, A pressed every 5 s from 10 to 60 s, 300 s of title time per run, one run per row:
build XCL_COHERENT_MB frames in 300 s GPU waits released on the CPU device removal / crash
base default (4095) 1444 6 none
#1993 default (4095) 2175 4 none
base 1024 1240 1 none
#1993 1024 1095 1 none
  • At the D3D12.X: a copy back after a submission does not wait for the title #1993 run's watchdog releases, the only XCL-issued wait still unmet was a title queue on the sparse upload fence (q2, 6 times). There were no readback waits, as expected with the readback queue.
  • Frame counts include the world-load compile phase, and each row is a single run, so I would not read much into the 1444 / 2175 or 1240 / 1095 differences.

Not tested

AI use: Claude Code (Claude Opus 5.5) built both trees, ran the runs and wrote this report.

@JJAutoCompare

Copy link
Copy Markdown

PR #1993 verification on STOR-WINLAB

PR head 4df0a2d1d01c101d81d80d46fb9d865fddc4da25 was fetched from origin (xcl-dev/xcl) and tested in a clean detached checkout. The remote still advertised that head after the run. The assigned slot had no Git checkout, so the source checkout was created under L:\XclTooling\neon-slot-6\source.

origin/main was 86719eec1e9fc4c36c5fb568ec4951fd47a31b88. git merge-tree --write-tree origin/main HEAD exited 1 with a content conflict in crates/xcl/src/hle/d3d12x/sparse.rs.

Tested

  • STOR-WINLAB, Intel Arc A770 16 GiB with driver 32.0.101.9175, DoublePrecisionFloatShaderOps=0, wave range 8–32. AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974.
  • rustc 1.100.0 (0ef1bc386 2026-11-09), unoptimized dev and test profiles, debuginfo and incremental compilation disabled. DXC and DXIL 1.9.2609.5, XCL_ADAPTER=A770. The full-suite log identifies the A770 in the runtime backend.
  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the shared GPU lock.
  • cargo test -p xcl --lib a_copy_back_does_not_wait_for_the_title_queue -- --show-output and cargo test -p xcl --lib gpu_sparse_vram_descriptors_buffers_and_xmem -- --show-output each reported 1 passed, 0 failed, 0 ignored, and 0 skips under the shared GPU lock. Both passed again in the full suite. The copy-back test creates a default D3D12 device with a WARP fallback and emits no adapter name of its own.
Set-ExecutionPolicy -Scope Process Bypass -Force
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output }

One full workspace run exited 101. Libtest reported 965 passed, 26 failed, 45 ignored across 19 test binaries and one doc-test target. The log recorded 26 SKIPPED messages across 16 named tests. Libtest can report a pass when a test or subcase skips. Skipped work contributes no coverage.

Target Passed Failed Ignored
xcl library 917 25 25
xcl CLI 0 0 0
bcpack_parity.rs 1 0 0
console_dlls_e2e.rs 13 0 0
console_shaders.rs 3 0 4
disasm_e2e.rs 1 0 0
e2e.rs 2 1 0
gpu_compute_e2e.rs 4 0 0
gpu_pso_e2e.rs 7 0 0
heap_probe.rs 0 0 4
low_va.rs 1 0 0
pls_quota.rs 1 0 0
predication_e2e.rs 1 0 0
rpf_e2e.rs 2 0 0
shaders_e2e.rs 4 0 0
sparse_reinit.rs 1 0 0
texture_states.rs 1 0 0
xg_oracle.rs 6 0 12
xcl-testtitle 0 0 0
Doc-tests xcl 0 0 0

Failures

  • CreateComputePipelineState returned 0x80070057 in 21 library tests. The four DXIL fuzz failures were fuzz_validate_and_gpu_0 (seed 2), fuzz_validate_and_gpu_1 (506), fuzz_validate_and_gpu_2 (1003), and fuzz_validate_and_gpu_3 (1501).
  • The same pipeline creation error occurred in doubles_match_cpu, groupshared_barrier_and_atomics_run, gpu_direct_f32_round_modes_dynamic_and_denormals, gpu_direct_f32_round_preserved_denormal_times_inf_is_inf, gpu_direct_f32_round_modes_static, f64_programs_on_the_gpu, gpu_clamp_and_omod_per_instruction, gpu_f64_class_compare, gpu_f64_literal_high_word, gpu_f64_compares_with_nan, gpu_f64_rounding_and_conversions, gpu_f64_roots, gpu_f64_math_random, gpu_frexp_f64_exp_and_mant, gpu_ldexp_f64, gpu_float_compares_random, gpu_rndne_f64.
  • gpu_nonfused_mad_and_mac_prevent_fma_contraction failed its fused FMA overflow assertion. The output was 2139095040, expected 1946157055.
  • gpu_ps_image_sample_offset_implicit_lod_between_mips returned 25.609375 for pixel (0,0), expected 26.
  • gpu_valu_16_and_64_bit returned zero in the lane 0 v_add_f16 high-half preservation check, expected 3203351424.
  • gpu_wave64_ps_whole_wave_reductions returned [2, 217, 2] for pixel 0, expected [2, 216, 2].
  • test_title_runs_and_game_folder_is_untouched failed the test title's RSSetDepthBiasX(-1000.5) check (Split wave64: masks read only lane by lane stay in their half #94). The top-right pixel was blue [0, 0, 255, 255] and the check expected green.

Skips

SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)
SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
SKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))

Raw logs in L:\XclTooling\neon-slot-6\tmp include pr1993-build.log, pr1993-compile-tests.log, pr1993-targeted.log, and pr1993-suite.log.

Not tested

This run covered the PR head on STOR-WINLAB. No main test baseline, merged-tree run, retail-title smoke run, sample-backed coverage (XCL_SAMPLE_* inputs unset), or additional adapters were tested. The run does not establish which failures reproduce on main.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the build and tests and drafted this report. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr1993-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/hle/d3d12x/sparse.rs) — needs a rebase before it can be tested.

theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 25, 2026
… commits is looked at (local test)

From a review of the local changes:
- The fence cells the title reads (`fence_x`) are stored after the copies back a value covers have
  landed (a value the title waits for promises the memory behind it), read and stored one refresh
  at a time.
- A copy back (and a stored immediate) lands 64-byte chunk by chunk, never over a chunk the CPU
  wrote since it was last sent: those bytes are newer and go up with the next look.
- `settle_readbacks_within` waits for the state's lock up to a bound; GetCompletedValue no longer
  spins 2 ms per copy back.
- Memory the title commits, and the memory of a texture it places, is looked at for a while
  (`mark_hot`): a write made right after the commit was seen up to 20 ms late.
- A copy back that finds no readback buffer still signals its queue's fence; at most 32 finished
  readback buffers are kept; `pagelog::counts` takes no blocking lock in the exception filter.

Loading:
- The watched ranges are made of 16 MiB blocks of the textures' sources, not from all textures (tens
  of thousands of them, each submit while a title loads).
- A DirectStorage destination in a sparse window is written without a VirtualQuery (a query there
  walks the whole committed heap: 3-5 ms a request, with a 2 GB heap). A part the title gave back
  fails the write (`write_title`).

The unit test of xcl-dev#1993 waits for the per-queue fences now. `submit_cost` also counts ranges,
re-checks and texture uploads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dezmonius

Copy link
Copy Markdown

Independent native Windows test of #1993 (4df0a2d) adapted locally onto cbc296ab + #1931 + the same local #1464 and activity counters used in my #1931 report. I resolved two context conflicts in sparse.rs, preserving the base's lock helper and its synchronous fallback's internal-wait logging. RTX 5070 / 610.88, i7-7700K, 32 GiB RAM, Windows 10 19045, Rust 1.100.0 release. The pair used direct DXIL, offline Series X, the same scripted input, cache location, DRED and wait settings (1000 ms/pipeline and 500 ms/frame). The #1993 run was second.

Earlier control With #1993
PresentX calls in activity samples 821 819
GPU queue.Wait watchdog releases 10 10
Exit time and code 266.6 s, 0xc0000005 268.8 s, 0xc0000005

Both stopped at world loading. The later run logged no asynchronous-copy timeout. In both runs the queue watchdog eventually released waits for a submitted producer fence whose completion was one value behind. This pair did not reproduce a reduction in queue timeouts or prevent the title error. It does not isolate or disprove the readback cycle addressed in the PR.

On the adapted tree, a_copy_back_does_not_wait_for_the_title_queue and gpu_sparse_vram_descriptors_buffers_and_xmem both passed, with no skips reported. Full suite not run. No game assets or raw logs attached. AI-assisted (OpenAI Codex, GPT-6).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A parallel-test hang this PR's change brings in, found through #2057, which carries it as cbba2d9d (same title and diff as this PR's 4df0a2d). RTX 3070 (Ampere, driver 616.56, Windows 11, 32 logical CPUs). tiagonleal's filter on #2057, release, default test threads, each run capped at 180 s: cargo test --release -p xcl --lib -- d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence.

A first-parent bisect of #2057 named cbba2d9d. Checked against its parent, 3 runs each, every run holding the GPU alone:

tree runs hung (cap hit)
4de1452d (parent) 3 0 (54 passed each)
cbba2d9d (this change) 3 2
cbba2d9d, --skip ...a_copy_back_does_not_wait_for_the_title_queue 3 0 (54 passed each)
cbba2d9d, a_copy_back_does_not_wait_for_the_title_queue alone 3 0

In the hung runs, the new test and older list_x tests were still running after 60 s: cross_queue_cycle_and_same_queue_fifo_do_not_deadlock, mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares, write_buffer_immediate_on_open_existing_heap_visible_to_cpu, cross_queue_wait64_before_signal_does_not_deadlock_submit_thread. So neither the change without its new test nor the test alone hangs; it takes the new test running in parallel with the other queue tests in one process. That fits the earlier reports here, where the test passed alone (JJAutoCompare, Dezmonius) and in a debug suite (futurepro62). A possible cause is CharlyRien's caution about the shared rb_fence (7149051542); I haven't verified that.

On #2057 the same hang shows on all three heads (41303e4, f7e08e6, 4df1e6e, 3 of 3 runs each) and not on main 568e7db (0 of 3).

AI-assisted (Claude Code). Synthetic tests only.

@Ariorh1337

Copy link
Copy Markdown
Author

@CharlyRien thanks, you were right: rb_fence and its counter were shared by all title queues, so a later signal on another queue let a copy back start before its own queue's lists ran. Fixed in 9a3fe7d (rebased onto main 568e7db):

  • each title queue gets a lane of its own: a fence that queue signals after its lists, and a copy queue that waits for it, so one queue's copies never wait behind another queue's wait;
  • copies land per lane, against that lane's own fence; an older copy of one lane that lands after a newer one of another lane leaves the bytes the newer one landed;
  • new test a_copy_back_waits_for_its_own_title_queue: two title queues, the first blocked on a gate while the second runs and signals. With one lane for both (what the old code amounted to) it fails with A's dword 0 landed before A's lists ran; with the fix it passes. Plus an_older_copy_back_does_not_overwrite_a_newer_one for the landing order.

@upipibi thanks for the bisect and the numbers. I reproduced the hang (3 of 3 runs of your filter). Thread dumps showed three list_x tests in the driver in NtGdiDdDDIDestroyAllocation2, and the new test stuck in a D3D12 call behind them. Its title queue was blocked on purpose, on the GPU's device that every test in the process shares, and the thread that was to open it never got out of the driver. The copy-back tests now run on a WARP device of their own. Also, Wait64BitValueX's CPU wait now only tries the sparse state's lock between its polls, instead of waiting for it. With that, no run of your filter hung: 3 of 3 on 9a3fe7d and 5 of 5 on the revision before it, 61 passed each.

@treybertram06, @futurepro62, @JJAutoCompare, @Dezmonius: thanks for the runs.

@lucsoft could you give the new head a run on RDNA3 when you have time? An AMD pass is the last thing raylitebull asked for.

Tested on 9a3fe7d (RTX 5090, driver 32.0.16.1692, Windows 11 26300, DXC 1.9.2609.5, debug): cargo test --workspace --no-fail-fast -- --test-threads=4 1153 passed, 4 failed, 46 ignored; main 568e7db 1150 passed, 4 failed, 46 ignored. The 4 failures are the same fuzz_validate_and_gpu_0..3 on both, and both skip the same 25. New smoke blocks are in the description.

Two more changes came out of the full run and of #2057:

AI use: Claude Code (Claude Opus 5.5) wrote the fix and the tests, ran them and drafted this reply.

@raylitebull

Copy link
Copy Markdown
Member

Code review on 9a3fe7d (crates/xcl/src/hle/d3d12x/{sparse,real,list_x}.rs, crates/xcl/src/gpu/recomp/tests.rs):

  • Per-queue RbLane queues with monotonically increasing per-lane src/done fences cleanly prevent one blocked title queue from holding back copies for other queues, while rb_landed sequence tracking prevents an older lane's copy-back from overwriting bytes already landed by a newer lane.
  • Wiring settle_readbacks_try across Fence::GetCompletedValue, Fence::SetEventOnCompletion (via WT_EXECUTEONLYONCE wrapper event and UnregisterWaitEx(..., INVALID_HANDLE_VALUE) cleanup on failure), and PendingWait ensures title fence observations observe landed bytes without holding STATE across driver waits, and the WARP-isolated lane_state tests address the earlier shared-device parallel hang.
  • Diff audited and CI workflow approved (45598142803).

Remaining before merge: Build and test + PR description green, plus independent AMD and secondary NVIDIA verification on 9a3fe7d.

@Ariorh1337

Copy link
Copy Markdown
Author

@Kalmarv I should have found #433 before opening this: it is older and goes at the same cycle (a copy back after ExecuteCommandLists waiting for a title queue that a later submit releases), and it also drops the shared rb_fence. Sorry for the overlap. How the two differ, as far as I read #433 at c20dd22:

#433 #1993
where the copy runs on the title's own queue, a list of that queue's type on a queue of XCL's own per title queue (8 lanes made at init), waiting for a fence that title queue signals
the submitting thread waits for the copy, as on main, unless the queue has a wait that has not completed or an earlier copy back has not landed; then a worker lands it never waits for it
when the bytes reach the CPU view when the call returns (or the worker lands them) at the title's next look: GetCompletedValue / SetEventOnCompletion hooks, Wait64BitValueX's CPU wait, Map, the next submit, a 0.5 ms thread
what it does not cover a held queue's copy lands on the worker, after the title's fence may already read done a read after a fence look XCL does not see (ID3D12Fence1, WaitForMultipleObjects on a shared event)

So #433 keeps main's guarantee in the common case and goes asynchronous only where main hangs; #1993 is asynchronous always and leans on the fence hooks. The case that made me write #1993 is the heavy one: with the title's big GPU heaps in the sparse windows (#2009), almost every submit of the retail title writes sparse memory, and every copy back waiting in the call was the stop.

I don't want two PRs for one problem in the review queue. Two ways I see:

@raylitebull which would you prefer?

AI use: Claude Code (Claude Opus 5.5) compared the two PRs and drafted this.

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for the comparison. One thing for the A/B: #433 conflicts with current main and I haven't rebased it, so c20dd22 only runs on its old base. If you want both on today's main, #1993 is the one that's ready. I have no objection to keeping whichever form holds up on the heavy-readback case. If it's #433's, I'll rebase it; tell me here.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@lucsoft

lucsoft commented Nov 25, 2026

Copy link
Copy Markdown

RDNA3 / Linux run of 9a3fe7d: no GPU wait was released in 700 s, with the watchdog at 5 s. The fence value going backwards that I saw before is still there, but it is at a coherent-window address, so the copies back can't be what writes it.

Setup:

The run:

  • First #101 at 370.8 s.
  • 262 144 dispatches and 70 341 draws by 613 s; 149 indirect dispatches folded by D3D12.X: dispatches of more than 65 535 groups in X are folded into Y #1428.
  • On screen: the game's opening credits.
  • 0 did not complete within lines in the whole run, with XCL_GPU_WAIT_TIMEOUT_MS=5000.
  • No sparse or copy-back timeout logged.
  • 4 CPU Wait64BitValueX timeouts (2 s each), all on the same cell 0x42437fe18:
time want memory holds queue fence (submitted, completed)
578.8 s 0x1245 0x123c 0x1246, 0x1245
584.6 s 0x1248 0x122d 0x1249, 0x1248
689.0 s 0x1289 0x1285 0x128a, 0x1289
695.2 s 0x128d 0x128b 0x128e, 0x128d

The value going backwards:

  • Between the first two timeouts the memory went from 0x123c to 0x122d, 15 steps back, while the queue fence moved forward.
  • In an earlier run (old head 4df0a2d, reached through kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #2009) the same thing happened on another cell: 0x42437f998 went 0x16ac → 0x16ab.
  • I first suspected an older copy back landing over a newer one, which this head now prevents. But both cells are inside the coherent window (0x400000000, 1024 MB), not in a sparse window, so no copy back writes them.
  • My stack also has D3D12.X: give each command queue its own cpu_writes worker #562 (one cpu_writes worker per queue). Two workers writing the same cell out of order is my next suspect. I haven't checked that yet.

How the run ended: at ~700 s a compute dispatch on a vkd3d queue never finished.

  • amdgpu: ring comp_1.2.1 timeout, a queue reset, the same job timed out again, then MES failed and a mode1 reset followed.
  • No GPU wait was waiting on that queue, so the watchdog never released one, and D3D12.X: XCL_GPU_CULPRIT_ARGS keeps the root arguments of named dispatches #2205's culprit lines (logged only on a release) did not come.
  • I'm adding a time-based report to it locally to get the dispatch named next time. That is separate from this PR.

Not tested:

  • this PR's unit tests (I only build the Windows exe here);
  • the PR on its own, without my stack;
  • more than one run.

AI use: Claude Code (Claude Opus 5.5) built the tree, read the logs and drafted this comment. The run was real, on the hardware above.

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

@Ariorh1337 Re-run of the hang check at 9a3fe7d, same RTX 3070 and the same filter as before (cargo test --release -p xcl --lib -- d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence, default threads, 180 s cap, each run holding the GPU alone):

tree runs hung (cap hit)
cbba2d9d (this change as carried in #2057, before the fix) 3 2
9a3fe7d 10 0 (61 passed, 0 failed each)

Counted by script: if the hangs were spread at random over the 13 runs, the chance of all of them landing on the old commit is about 4%. So on this card 9a3fe7d as a whole removes the parallel-test hang. I haven't separated its parts (the per-queue rb_fence lanes, the WARP device and the lock changes), so this doesn't say which one does it (edited: I first credited the rb_fence lanes alone).

AI-assisted (Claude Code). Synthetic tests only.

@Ariorh1337

Copy link
Copy Markdown
Author

Thanks for the runs on 3260d40: @Natakout (RTX 3060, presenting ~30 s past the first #101 against 2–4 s without it), @upipibi (RTX 3070, 10 of 10) and @tiagonleal (RTX 5070 Ti, 10 of 10). @Chrysana, thanks for the AMD pass, the hang check (10 of 10) and the title runs (no copy-back timeout with it, the stop after #101 the same as on main on the default path).

On the memory in your second run: this PR can add to it there. Each copy back holds a readback buffer (64 KiB to 16 MiB, in system memory, so it counts toward commit) until it lands. After the first #101 the title's queues stand still, so the copies of each submit stay in flight, one buffer each. Once they land the buffers go back to a pool, and the pool never shrinks. On the start screen that is about 1.9 GB of peak commit in my smoke runs (17.0 against 15.1 GB on main); with stalled queues it can be more. I'll cap the pool and give buffers back above the cap, measure the commit with the queues stalled after #101, and push it here.

AI use: Claude Code (Claude Opus 5.5) read the code and drafted this.

@Royalflamejlh

Royalflamejlh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA, the title, 4 runs with #1993 and 4 without: no change in where presents stop, and no 5 s wait ran out (no sparse: the queue has not reached fence value, sparse: a copy back has not finished or did not complete within line). Shorter waits are not logged. All 8 stopped presenting by 85 s and ran to XCL's 120 s limit without a crash or device removal.

Setup: main 06c9f55 + #684 e56dbc3 + #1993 3260d40 (local merge 8944100), against main 06c9f55 + #684 (local merge 99355ee), in turn. RTX 4070 12 GB (615.71.09), Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, release, Series X, default shader path, first-run screens completed once and no story progress, A pressed at 16.0 to 16.5 s, XCL_ACTIVITY=1 XCL_PSO_PRELOAD=0.

main + #684 (4 runs, in run order) #1993 (4 runs, in run order)
first #101 74.4, 63.8, 75.9, 80.4 s 80.2, 76.0, 59.7, 81.4 s
last 2 s with a present 76.0, 84.3, 78.3, 84.0 s 82.0, 78.1, 78.1, 84.2 s
from the first #101 to the last present 1.6, 20.5, 2.4, 3.6 s 1.8, 2.1, 18.4, 2.8 s
frames 1,350, 1,385, 1,345, 1,397 1,385, 1,332, 1,340, 1,362
queue.Wait releases, faults 0, 0 0, 0
  • Presents went on about 20 s past the first #101 in 1 run of each tree, and at most 4 s in the other 3. So Natakout's gap of about 30 s (RTX 3060, 9a3fe7d, XCL_DIRECT_DXIL=1) did not come here, as in Chrysana's RDNA4 runs on the default path.
  • Every bridged wait was prod=qNone: the four-queue wait on q1 from the description did not appear. As in Natakout's runs, the first split … (#1) and … bridged … wait-before-signal came within about 3 s of the last present, in both trees.
  • In all 8, a 2.4 MB DXIL compute pipeline went to the driver within 1.5 s of the last present and was still compiling at 120 s. Whether presents waited on it is not shown.
  • Tests (list_x, fence_x, sparse, acphal, gpu::fence, Wine, 4 threads, 1 run each): 67 passed, 1 ignored with D3D12.X: a copy back after a submission does not wait for the title #1993, the four new ones included; 63 and 1 without; no hang.

Not tested: the cycle the description is about; XCL_DIRECT_DXIL=1; the rest of the suite; Windows; AMD and Intel.

AI use: Claude Code (Claude Opus 5.5) ran the title and the tests and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

Edited: the line above had been added 13 times by a posting script that retried while GitHub was refusing writes; 12 copies removed, nothing else changed.

@Ariorh1337
Ariorh1337 force-pushed the sparse/async-readback branch from 3260d40 to 69903fc Compare November 25, 2026 16:26
@Ariorh1337

Copy link
Copy Markdown
Author

@Chrysana the follow-up I promised, in 69903fc: idle copy-back buffers above 256 MB are now given back (largest first; test idle_copy_back_buffers_above_the_cap_are_given_back), and each time the buffers pass another doubling from 64 MB their size is logged.

What that log shows: in a run of the retail title on main 06c9f55 + this PR + #2009 (XCL_COHERENT_HEAPS=sparse:1024, RTX 5090), through the menus, the world load and the burst after the first #101 up to the removal, the copy-back buffers (idle and in flight together) never passed 64 MB. The process's peak commit in that run was 37.8 GB. So they are not where your extra ~4.5 GB came from. After #101 your runs submit nothing, and without submits no new copies are made. The start-screen smoke commit is the same with the cap as before (17.0 GB, against 15.1–16.6 GB in today's main runs here).

@Royalflamejlh thanks for the Linux / vkd3d-proton pairs: no change in where presents stop, no 5 s wait run out and no hang in the tests, which is what this PR should do where the cycle doesn't come up.

Tested on 69903fc (RTX 5090, debug): cargo test --workspace --no-fail-fast -- --test-threads=4 1155 passed, 4 failed, 46 ignored (the same 4 fuzz_validate_and_gpu_0..3 and 25 SKIPPED as on main). New smoke blocks are in the description.

AI use: Claude Code (Claude Opus 5.5) wrote the change and the test, ran them and drafted this.

@St5sz2Jk

St5sz2Jk commented Nov 25, 2026 •

Copy link
Copy Markdown

Update: the crash below is a missing UnadoptGuard, fixed with one line. With it, this PR takes the title on AMD / Wine through the world load and into the opening cutscene, with no copy-back waits.

  • readback_async submits the copy-back list straight to the lane queue: own_work(|| q.ExecuteCommandLists(&[Some(l)])). That is still the same in 0a755f0.
  • The list was made through the hooked device, so its vtable is XCL's. Under Wine, vkd3d-proton checks the vtable of the lists it is given, and its release build crashes in d3d12_command_queue_ExecuteCommandLists.cold (d3d12core.dll+0x597fbd, read of 0x2b28) instead of failing the check.
  • With Memory: avoid amdgpu userptr stalls under Wine (#175) #871 (which AMD under Wine needs), real::q_execute_command_lists wraps each list in Memory: avoid amdgpu userptr stalls under Wine (#175) #871's UnadoptGuard for exactly this reason. The copy-back submit does not:
super::title_textures::own_work(|| { let _g = super::real::UnadoptGuard::new(l.as_raw()); q.ExecuteCommandLists(&[Some(l)]) });
  • UnadoptGuard is Memory: avoid amdgpu userptr stalls under Wine (#175) #871's, not main's, so this line belongs to whichever of the two PRs lands second (@Ariorh1337 / @gustavsi). UnadoptGuard::new does nothing outside Wine, so Windows behaviour does not change.
  • Title run with that line (69903fc + the line, same tree as below, XCL_TARGET_PAGES_MB=6144; one run):
    • no crash at 7–8 s;
    • menus at 60 fps;
    • no sparse: the queue has not reached fence value, a copy back has not finished or did not complete within lines at all;
    • into the cutscene at about 280 s, with 1,000–2,000 draws every 2 s.
    • The run ended at 419 s with a ucrtbase memcpy crash in title_textures (a read of a title page that is unmapped by then). That crash happens without this PR too.
  • Without this PR, the same tree stops presenting from about 150 s, with a 5 s wait logged every ~5 s.

AMD / Linux / Wine with #871: the title crashes in vkd3d-proton 7–8 s after start with this PR (2 of 2). Without this PR the same tree runs past the menus and into the world load.

#871 is needed to start the title on AMD under Wine at all (see my comment there), so this PR can't be tested alone on this machine. The result comes from the combination.

Setup:

1. The title: 0xc0000005 in d3d12core.dll+0x597fbd, reading 0x2b28, at 7–8 s

  • The registers point at three objects with the same vkd3d-proton vtable (d3d12core.dll+0x8b9b0).
  • XCL's stack scan, symbolized with the PDB:
    • list_x::reset_copy_scratch
    • real::cl_close
    • sparse::State::readback_async (the q.ExecuteCommandLists / job.list.Close() part, sparse.rs:1270)
    • State::after_execute
    • readback_after_execute
  • So it seems to happen while a copy-back list is closed and submitted. real::cl_close is in the stack, so the list made by rb_job goes through XCL's list hooks.
    • The description says the lanes are made in init, before the device's methods are hooked. rb_job, though, makes its allocator and list later, through self.dev.
    • That is a guess from the stack. I haven't confirmed it.
  • What I ruled out: creating the lanes' src / done fences with real::create_raw_fence (as Memory: avoid amdgpu userptr stalls under Wine (#175) #871 does for fence / rb_fence) gives the same crash, at the same address.
  • Without this PR (same tree, run before): no crash in the first 279 s, but from about 150 s the sparse queue logged the queue has not reached fence value … after 5 s about every 5 s. Presents fell to about 1 every 10 s, which is the stall this PR is for.

2. Tests (edited: withdrawn). My first version listed three failing sparse tests. Those runs did not set WINEDLLOVERRIDES, so they used Wine's built-in vkd3d and not vkd3d-proton. I have withdrawn them until I rerun them properly.

Where the crash is (added): with the build's DWARF, d3d12core.dll+0x597fbd is d3d12_command_queue_ExecuteCommandLists.cold. vkd3d-proton was given a command list it does not recognise, and its release build has the vtable check compiled out.

Not tested:

AI use: Claude Code (Claude Opus 5.5) merged the tree, ran the title and the tests, read the stack and wrote this comment. My human API watched the runs.

@Chrysana

Copy link
Copy Markdown

@Ariorh1337 I've updated / edited my comment with some further tests

@lucsoft

lucsoft commented Nov 25, 2026

Copy link
Copy Markdown

Test report: Linux / RADV, RX 7800 XT (RDNA3). Head 69903fc, in a stack with #2009. Two runs with no GPU-wait timeout, the warm one into gameplay. This follows up my earlier report on 9a3fe7d and the lock report that led to 3260d40.

AI use: Claude Code (Claude Opus 5.5) ran the analysis and drafted this. The runs were real, on the hardware above.

@Ariorh1337

Copy link
Copy Markdown
Author

@St5sz2Jk thanks, your reading of the stack was right. Fixed in e8d597b, which is now rebased onto main 06055a7.

rb_job made each copy back's allocator and list through self.dev after the device had been adopted. So the list was adopted too, and its Reset, CopyBufferRegion and Close went through XCL's list hooks (cl_close, …). Those hooks are meant for the title's lists, and here the list was submitted on the lane's own queue, which isn't adopted. On main this couldn't happen, because its one readback list is made in init, before the hooks. Now real::create_own_list makes the allocator and the list with the device's own methods, past the hooks, the same way init's objects are made. Test: a_copy_back_list_of_an_adopted_device_is_not_adopted. It fails without the fix.

The rebase brought #2345's quarantine in. Its tiles now also wait for copies back still to run on a lane, since those read the windows after the title's work. Test: quarantined_tiles_wait_for_copies_back_still_to_run.

@Chrysana thanks for running the copy-back tests on the RX 9070 XT and the iGPU. Since they pass on native AMD drivers, St5sz2Jk's three test failures look like the Wine side or #871, as you say. @St5sz2Jk, if you can run cargo test -p xcl --lib sparse::tests on this PR without #871, that would tell which one. What does EnumWarpAdapter give under Wine there?

Tested on e8d597b (RTX 5090, Windows 11 26300, debug): cargo test --workspace --no-fail-fast -- --test-threads=4 gives 1416 passed, 4 failed, 46 ignored, against 1409 passed, 4 failed, 46 ignored on main 06055a7. The 4 failures (fuzz_validate_and_gpu_0..3) and the SKIPPED tests are the same on both. New smoke blocks are in the description. Not tested: Linux / Wine / AMD (I have no such machine).

AI use: Claude Code (Claude Opus 5.5) found the cause from the stack, wrote the fix, the rebase and the tests, ran them and drafted this.

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: fence_wait_fired calls settle_readbacks_try() then unconditionally signals the title event. settle_readbacks_try silently returns when it cannot acquire STATE within 2 ms (or cannot reacquire it after its bounded wait), so no copyback may land but a title waking from SetEventOnCompletion can read stale sparse-window memory. GetCompletedValue has the same try-only visibility gap. Defer/retry title completion until the relevant copyback is confirmed landed, and add an adopted-fence lock-contention regression; State-only tests do not cover this hook contract.

`readback_after_execute` made the sparse queue GPU-wait for the title's
queue and then waited on the CPU for the copy, on the thread that was
submitting. The title's queues can wait for work that same thread submits
next (four compute queues waiting for a Write64 on q1 whose list is
recorded but not submitted yet). So the copy waited its 5 s on every such
submission, and the uploads queued behind it on the sparse queue waited
too (`before_execute` waiting for ring room). In thread dumps of a retail
title on an RTX 5090, the submitting thread is in `readback_ranges` ->
`wait_for` while another title thread waits for the sparse state's lock in
`commit_range`. lucsoft found the same cycle on RDNA3 / Linux (xcl-dev#505).

The copies now run on a lane per title queue: a fence the title's queue
signals after its lists, and a queue of its own that GPU-waits for that
fence. The submitting thread returns. With one fence for all title
queues, a later signal on another queue let a copy start before its own
queue's lists ran (CharlyRien); with one queue for all, a title queue
waiting for work still to come held back the copies of the others.
The lanes (8) are made in `init`, before the device's methods are hooked:
made later, a lane's queue was adopted as one of the title's, and the e2e
title under the debug layer read 0 for what its lists wrote.
A copy back's allocator and list are made with the device's own methods,
past its hooks (`real::create_own_list`), as `init`'s objects are: made
through the adopted device, the list took XCL's list hooks on the lane's
queue, and vkd3d-proton crashed at its Close (St5sz2Jk, RDNA4 / Wine).
Tiles quarantined behind the title queues' marks (xcl-dev#2345) also wait for
the copies back still to run on a lane: they read the windows after the
title's work. A lane serves
a title queue while that queue has copies back in flight; with all lanes
busy (or none made), the old path runs. Readback buffers are sized to the
copy (64 KiB and up) and reused; idle ones above 256 MB are given back
(each holds commit, and with the title's queues stalled every submit's
copies wait, one buffer each; found by Chrysana's RDNA4 run). Each time the
buffers pass another doubling from 64 MB, their size is logged.

The data lands in the title's memory once the copy is done, before the
title can see the work it follows is done:
- on the next submit, and from a thread that looks every 0.5 ms;
- before Map's readback (waiting for the copy once the title's lists it
  follows are done), and in the CPU memory waits of Wait64BitValueX, which
  only try the sparse state's lock: its holder can be waiting for work the
  waiting thread is to submit;
- in the title's fence observations: `GetCompletedValue` settles the copies
  first. `SetEventOnCompletion` hands the fence an event of XCL's own, and a
  thread-pool wait on it settles them, then sets the title's event.
  These only try the lock; a copy whose title work is done but which still
  runs is waited for with the lock let go, then landed. Waiting for it with
  the lock held stood every submit behind a copy that stood behind a stalled
  GPU (lucsoft, RDNA3).
  Until they landed, the title is not told its work is done: the thread-pool
  wait tries again every millisecond before it sets the title's event (10 s
  at most), and `GetCompletedValue` gives no more than the value the fence
  was last seen at with its copies landed (its initial value at first).
  Before, a lock that could not be had let the title read stale memory
  (bmjask).
Lanes land in their own order, so an older copy back of one lane can land
after a newer one of another: it leaves the bytes the newer one landed.
A CPU wait for a copy uses its lane's event, not the sparse state's: a wait
that gave up leaves its registration behind, which set the shared event
later and ended a tile-queue wait early (theaustinayers, in xcl-dev#2057).

Tests:
- `a_copy_back_does_not_wait_for_the_title_queue` waits 5.0 s on the old
  path and under 1 s with this change;
- `a_copy_back_waits_for_its_own_title_queue`: two title queues, the first
  blocked; with one lane for both, the first one's copy lands before its
  list ran;
- `an_older_copy_back_does_not_overwrite_a_newer_one`.
- `a_copy_still_running_after_its_title_work_is_waited_for_outside_the_lock`.
- `idle_copy_back_buffers_above_the_cap_are_given_back`.
- `a_copy_back_list_of_an_adopted_device_is_not_adopted`.
- `quarantined_tiles_wait_for_copies_back_still_to_run`.
- `a_title_fence_shows_its_work_done_only_once_copies_back_can_land`: an
  adopted fence, the sparse state held by another thread.
- `a_fence_value_goes_past_its_landed_copies_only_once_they_land`.
They run on a WARP device of their own: they block a queue on purpose, and
on the GPU's device, which the tests in the process share, other queue
tests then hung in the driver releasing resources (upipibi; reproduced in 3
of 3 runs of the d3d12x queue tests). Without the fence hooks, the e2e test
title read 0 for its Write32BitValueBottomOfPipeX after its fence wait.
With them, both e2e tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Chrysana

Copy link
Copy Markdown

@Ariorh1337 Added more to my original comment again for you

@Ariorh1337
Ariorh1337 force-pushed the sparse/async-readback branch from e8d597b to 0a755f0 Compare November 25, 2026 21:12
@Ariorh1337

Copy link
Copy Markdown
Author

@bmjask thanks, that was a real gap. Fixed in 0a755f0.

settle_readbacks_try now says whether every copy back whose title work is done has landed. It returns false when the sparse state's lock couldn't be had, or when such a copy didn't finish in time. The fence hooks only show completion after it returns true:

  • SetEventOnCompletion: the thread-pool wait tries again every millisecond and sets the title's event only once the copies landed (settle_readbacks_until_landed, 10 s at most, registered with WT_EXECUTELONGFUNCTION). That runs on a pool thread, which can wait. The blocking form (null event) does the same after its wait.
  • GetCompletedValue: while the copies can't land, it returns the value the fence was last seen at with its copies landed. That starts at its initial value from CreateFence, and is never above the fence itself. The title's thread isn't blocked: it looks again, so a holder of the state that waits for this thread's next submit can go on, which was the reason the lock is only tried.

Tests:

  • a_title_fence_shows_its_work_done_only_once_copies_back_can_land uses an adopted WARP device and fence, with a copy back in flight and the sparse state held by another thread. GetCompletedValue stays at the initial value and the title's event isn't set within 300 ms. Both come once the state can be had. Without the fix it fails at the fence's work shows as done before its copies back landed.
  • a_fence_value_goes_past_its_landed_copies_only_once_they_land covers the value rule.

Tested on 0a755f0 (RTX 5090, Windows 11 26300, debug): cargo test --workspace --no-fail-fast -- --test-threads=4 1418 passed, 4 failed, 46 ignored, against 1409 passed, 4 failed, 46 ignored on main 06055a7; the same 4 failures (fuzz_validate_and_gpu_0..3) and SKIPPED tests on both. New smoke blocks are in the description.

@Chrysana thanks for the e8d597b runs. About the fail-fast at your 33 GB limit: the copy-back buffers are made through the driver, and a refused one is logged as no readback buffer and left out, not fatal. Beyond that, at a hard commit limit any Rust allocation anywhere in XCL ends the process the same way, main's code included. So one hit doesn't tell us much, and I'd be glad of a few more runs at the limit, ideally on 0a755f0: if the PR's side ends there and main's doesn't, that's worth finding.

AI use: Claude Code (Claude Opus 5.5) wrote the fix and the tests, ran them and drafted this.

@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

@ClosetPie107

ClosetPie107 commented Nov 26, 2026 •

Copy link
Copy Markdown

Tested head 0a755f0c on AMD RDNA4 / Linux (Proton Experimental), merged cleanly onto main (b49be183) alongside #871 (8f08d7cd) and #684 (e56dbc3f) — specifically verifying 0a755f0c's new real::create_own_list Wine fix (from @St5sz2Jk's report on 69903fc):

Hardware & environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton master ec207194 (3.2.0) + dxil-spirv b540c8a2 + relaxed-vtable patch (-Db_ndebug=true), DXVK v3.1.1-209, DXC 1.9.2609.5, Rust x86_64-pc-windows-gnu

Targeted unit tests (debug, --test-threads=1):

  • xcl.exe hle::d3d12x::sparse:: -- --test-threads=1: 25 passed, 0 failed, 1 ignored (early_commit_timing).
    • 8 skipped (no WARP device, expected under Wine where EnumWarpAdapter is a stub): a_copy_back_does_not_wait_for_the_title_queue, a_copy_back_waits_for_its_own_title_queue, a_copy_back_list_of_an_adopted_device_is_not_adopted, a_copy_still_running_after_its_title_work_is_waited_for_outside_the_lock, an_older_copy_back_does_not_overwrite_a_newer_one, quarantined_tiles_wait_for_copies_back_still_to_run, idle_copy_back_buffers_above_the_cap_are_given_back, a_title_fence_shows_its_work_done_only_once_copies_back_can_land.

Retail title A/B (1.0.2.1, pressing A past menus, 300 s, release)
Flags: XCL_DIRECT_DXIL=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PSO_WAIT_MS=50, XCL_SPLIT_MIDLIST_WAIT=0, XCL_COHERENT_MB=1024, VKD3D_CONFIG=ignore_shared_fence, XCL_PSO_PRELOAD=0, XCL_NETWORK=0.

  • Without D3D12.X: a copy back after a submission does not wait for the title #1993 (main b49be183 + #871 8f08d7cd + #684 e56dbc3f): exit=0, 0 crashes, but hit 44 sparse: the queue has not reached fence value 42916..42959 after 5 s (at 42915) warnings starting at 81.609 s (5.0 s after 76.609 s Wait64BitValueX at 0x42437fae8 bridged to q0.Wait on q1), stalling at 14,256 draws / 2,748 dispatches (4,096 skipped) / 0 chained split dispatches.
  • With D3D12.X: a copy back after a submission does not wait for the title #1993 (0a755f0c, no manual Wine patch needed): full 300 s (exit=0), 0 crashes (confirming create_own_list fixes the 7 s vkd3d-proton crash without needing an extra UnadoptGuard), 0 device removals, and 0 sparse: the queue has not reached fence value warnings. All 8 Wait64BitValueX at 0x42437f... bridges in 75.5–76.4 s completed with 0 stalls; reached 16,384 translated draws (48 skipped), 22,268 dispatches (73 skipped), 195 chained split-compute dispatches (207 split programs / 2,320 pieces), 1,620 PresentX frames, 63,477 Opus packets (0 errors), 15,140 MiB peak VRAM / 12,543 MiB peak RSS (swap=0).

Not tested

AI use

  • T3 Code / Antigravity (Gemini 4 Neon) merged the stack onto main, ran the Proton tests and A/B retail runs on this machine, and drafted this report.

@upipibi

upipibi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

NVIDIA test report for 0a755f0: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. One intermittent failure in a test this PR adds.

  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 (the hle::xaudio2 tests hang on this machine, on main too): 1288 passed, 0 failed, 26 ignored; 25 SKIPPED lines (21 no wave64, 3 per-lane forms refused under gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426, 1 driver cache needs Developer Mode).
  • Hang filter (d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence), 180 s cap: 5 of 5 finished in 6-7 s, so no hang. 4 had 77 passed, 0 failed; 1 had 76 passed, 1 failed.
  • The failing test is the new hle::d3d12x::sparse::tests::quarantined_tiles_wait_for_copies_back_still_to_run (sparse.rs:2442, "freed once the copy back is done"). It fails only with other tests running beside it:
    • hang filter, parallel: 14 of 25 runs failed;
    • d3d12x::sparse alone: 2 of 8; the test with only the non-sparse filters beside it: 1 of 8;
    • --test-threads=1: 0 of 5; the test alone: 0 of 10; the 4-thread full run above: passed;
    • the same filter on the base 06055a7, parallel: 0 of 5 failed (the test isn't there).
      It runs on the shared WARP device (lane_state()), so this is not NVIDIA-specific. Edit: cause checked with a local diagnostic build (the guess first written here, the new GetCompletedValue hook, is ruled out): quarantine_tiles also signals a mark on every known queue on the same device (sparse.rs:1869-1883, via sync_known_queues and the process-wide present::known_queues(), present.rs:293). Every test shares one WARP device, so queues of other tests running at the same time get a mark too. The test then waits only for its lane fences (sparse.rs:2437-2441), so drain_quarantined() (sparse.rs:1896) can still see one of those other queues' marks at 0; it reaches 1 a few ms later. In 13 failures exactly one mark was short, in 12 of 12 with owner info it was another test's queue, and the hooked and raw values were always equal; with the hook bypassed the test still failed 4 of 20 runs of the hang filter (8 of 20 with it).
  • a_title_fence_shows_its_work_done_only_once_copies_back_can_land, --exact --test-threads=1 --nocapture, 3 runs: 3 of 3 passed, 0 SKIPPED.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).

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.