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 425 lines of code and 265 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.
    • 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: the title's fence observations settle copies back first.
    • 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.
    • 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.
    • 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 (69903fc): 1155 passed, 4 failed, 46 ignored;
    • main (568e7db): 1150 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: 25, the same 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): lucsoft's RDNA3 / Linux runs (700 s, no GPU wait released; the submit thread no longer waits on the sparse lock), and Chrysana's RDNA4 / Windows run of 3260d40 (hang check 10 of 10; in the title no copy-back timeout).
  • 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: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 5090
title: a155fb60
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15127 MB
xcl-smoke v1
commit: 69903fce303d02209a2b9d7687108088a1cafe7c
gpu: NVIDIA GeForce RTX 5090
title: a155fb60
seconds: 60
exit: 0x0
frames shown: 1598 (PresentX 1598)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17005 MB

Not tested

  • AMD and Intel GPUs. lucsoft's RDNA3 run used a different change with the same aim.
  • 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 lanes have not been in a title run yet.
  • 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

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

@lucsoft thanks for the thread dump and for running 9a3fe7d on RDNA3. You were right: settle_readbacks_try only tried the lock, but once it had it, drain_readbacks(TitleDone) could wait up to 5 s per lane with STATE held, inside fence_wait_fired. With the GPU stalled, the submit thread then stood behind it.

Fixed in 3260d40. Under the lock, settle_readbacks_try now only lands the copies that are done and notes those whose title work is done but whose copy still runs. It lets the lock go, waits for those (5 s at most, on an event of the thread's own), then takes the lock briefly again to land them. Only Map's readback (readback_now) still waits with the lock held, as it copies with it held anyway. New test 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.

Tested on 3260d40 (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 1154 passed, 4 failed, 46 ignored (main 568e7db: 1150, the same 4 fuzz_validate_and_gpu_0..3 failures and the same 25 SKIPPED). upipibi's filter: 3 runs, 2 with 62 passed and 1 with a failure in acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure. That test checks with VirtualQuery that a freed buffer is free, and a test running beside it had taken the address already (MEM_COMMIT, 4096). It does not touch the sparse code. e2e: 3 passed.

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

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

Copy link
Copy Markdown

Test report: RTX 3060 / Windows. In 2 runs out of 2, the title keeps presenting about 30 s past the first #101 with this PR, against 2-4 s without it in 6 runs. The stall comes later and is not gone.

Setup: RTX 3060 12 GB (NVIDIA 621.14), i9-13900K, 64 GB RAM, Windows 11 (10.0.26200), release. Retail 1.0.2.1, XCL_NETWORK=0, XCL_DIRECT_DXIL=1 (except the two main runs marked HLSL), A pressed every 4 s from 12 to 120 s, 480 s per run, caches warm from earlier runs.

Trees:

tree run first #101 presents end gap did not complete within 5000 ms
without main HLSL 1 245.2 s 248.1 s 2.9 s 0
without main HLSL 2 222.6 s 226.1 s 3.5 s 0
without main direct 1 262.6 s 264.7 s 2.1 s 0
without + #2301 1 224.6 s 228.1 s 3.5 s 0
without + #2301 2 231.2 s 234.1 s 2.9 s 0
with 1 317.7 s 348.1 s 30.4 s 0
with 2 192.9 s 222.1 s 29.2 s 0

(A seventh run without the PR had its presents stop just before the first #101 call.)

  • Every run, with and without, ends at the 480 s limit with exit 0, no crash and no device removal.
  • Without the PR, presents stop within 4 s of #101, right after split command list (type 2) around mid-list Wait after Write64 (#1) and one Wait64BitValueX … bridged to GPU queue.Wait (waiter=q0/ty2, prod=qNone/…; wait-before-signal).
  • With the PR, the first bridged waits after #101 name their producer: seven waits at 345.08–345.13 s, waiter=q0/q2/q3/q4, prod=qSome(1), all >= 0x2656. The title presents about 60 frames per 2 s until the end. Then the same pattern as without the PR ends it: at 345.30 s, split command list … (#1), and at 345.72 s, Wait64BitValueX at 0x704180138 >= 0x2656 bridged to GPU queue.Wait (waiter=q2/ty2, prod=qNone/tySome(0); wait-before-signal). Presents stop at 348.1 s.
  • In a minidump taken 4 s into the stall of the first run (cdb), no title thread is inside XCL. The title's job threads all wait on their own events and semaphores.

Not tested: AMD; cold caches; more than two runs with the PR; XCL_COHERENT_MB or XCL_HEAP_WINDOWS other than the defaults.

AI use: Claude (claude-opus-5-5, through Hermes) ran the builds and title runs on the hardware above over SSH, read the logs and the minidump, and wrote this report.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@Ariorh1337 The same hang check at 3260d40, on the same RTX 3070 (616.56) with 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) failed
3260d40 10 0 0 (62 passed, 1 ignored each)

acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure passed in all 10. That fits your reading of the one failure you saw, a neighbouring test taking the freed address, as a rare race rather than something this change does. Ten passes here don't show it can't happen, though.

This covers only the synthetic filter, not the title stall Natakout describes above.

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

@tiagonleal

Copy link
Copy Markdown
Contributor

Hang check at 3260d40cf015966cf425dd42664e36f4c9aeba6f on NVIDIA RTX 5070 Ti (Blackwell, Windows 11): 10 runs, no hang

Tested

  • Head 3260d40cf015966cf425dd42664e36f4c9aeba6f (git rev-parse HEAD of a clean detached worktree, no local changes, built as is). The PR was open and the head unchanged when I started and again before writing this. Not merged with main.
  • Windows 11 Pro 10.0.26300 (Developer Mode on), NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42, 32.0.16.1742), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0.
  • upipibi's filter, release, default test threads, each run capped at 180 s, run one after another with the GPU otherwise idle (no other test binary or title running; GPU load 2-23% before each run): cargo test --release -p xcl --lib -- d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence.
  • 10 runs: 0 hung (cap hit), 0 failed. Every run: 62 passed, 0 failed, 1 ignored, finished in 0.42-0.50 s. The slowest run took 2 s including the cargo start. That is 10 of 10 on a Blackwell card, next to upipibi's 10 of 10 on an RTX 3070 at the same head.
  • I did not see the acphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure failure that was seen once on an RTX 5090 in any of the 10 runs.
  • No SKIPPED lines in the output.

Not tested

  • An AMD host.
  • cargo test --workspace, the debug profile, the e2e test, other test targets; the retail game and xcl-smoke.

Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5).

@Chrysana

Copy link
Copy Markdown

RDNA4 / Windows run of 3260d40, for "AMD and Intel GPUs" under Not tested. The hang check is clean on an AMD host (10 of 10). In the title, where the world load stops doesn't change here: with and without this PR, presents stop 2–5 s after the first #101, and the four-queue wait on q1 from the description shows up on main too and still holds with the PR. I don't see the ~30 s Natakout measured on the RTX 3060; their runs used XCL_DIRECT_DXIL=1, mine the default path.

Setup: AMD Radeon RX 9070 XT 16 GB (RDNA4), driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 26200.9974, rustc 1.100.0 MSVC, release. Retail title 1.0.2.1 with first-run setup done, XCL_NETWORK=0 XCL_ACTIVITY=1, A pressed every 4 s from 12 to 120 s, no XCL_DIRECT_DXIL. Title runs: main 06c9f55 against main 06c9f55 + this head (local merge, no conflicts).

Hang check (upipibi's filter, on this head as pushed): cargo test --release -p xcl --lib -- d3d12x::list_x d3d12x::fence_x d3d12x::sparse hle::acphal gpu::fence, default threads, 180 s cap, GPU otherwise idle: 10 runs, 0 hung, 0 failed. Each: 62 passed, 0 failed, 1 ignored, no SKIPPED, 0.37–0.66 s.

Title, 300 s runs:

run caches first #101 last presents (2 s window ending) after that end
main cold 119.0 s 124.1 s 174 s without a present 300 s limit, exit 0
+ this PR warm from the run before 108.3 s 110.1 s 188 s 300 s limit, exit 0
main warm 106.4 s 108.1 s 190 s 300 s limit, exit 0
+ this PR warm 108.1 s 110.1 s 72 s fail-fast 0xc0000409 at ~183 s (see below)
  • No device removal, no did not complete within and no frame-event wait timeout in any run. With this PR, sparse: a copy back has not finished 5 s after the title's work it follows is never logged.
  • After #101, submits and DirectStorage requests drop to 0 in every run; a few draws and dispatches are still recorded, not submitted.
  • The wait on q1: in the warm runs, both main and this PR log Wait64BitValueX at 0x8416ff68 >= 0x7a0 bridged to GPU queue.Wait (waiter=q0/ty2, prod=qSome(1)/tySome(0); wait-before-signal), and the same for q2, q3 and q4 (8 lines, cells 0x8416ff68–0x8416ffd8), within 2 s of #101. Nothing releases them before the end of the run.
  • Thread dumps (XCL_THREAD_DUMP_AT=125,135, a 150 s run of this PR): the title's main thread is in +0x23cf735 in both dumps (the routine next to The retail title 1.0.2.1 (RTX 5070): reaches the end of the first-run setup, then deterministic 0xC0000005 write at 0x0 in game_scarlett_master.exe+0x23cf683 #846's +0x23cf683); about twenty title workers are idle at +0x221c3c2; no title thread is inside an XCL D3D12 call (one is in XCL's Sleep). That fits a wait for GPU work rather than a bind or a copy back.
  • The cold main run is held by compiles instead: huge compute pipelines take 5–26 s each in the driver, and binds wait 159–198 s at the huge-compile gate. That run never reaches the q1 wait. The run after it had those pipelines cached, so I reran both builds warm; rows 3 and 4 are the fair pair.

Memory, one run: the second run with this PR committed 45 GB by 180 s and then ended with 0xc0000409 at ~183 s (a fail-fast; XCL logged no exception); dwm.exe crashed 3 s later on this 31 GB machine. The warm main run reached 40.5 GB at 160 s and dropped back to 30 GB. One run each, so I can't tell whether this PR adds to it; it reads like #1566. A third run with this PR (the thread-dump run) was stopped by my own memory guard at ~143 s, with the title at 35.7 GB and the whole system at 71 of its 79 GB commit ceiling.

Not tested

  • XCL_DIRECT_DXIL=1, as in Natakout's runs.
  • More than one warm run per side.
  • This head on its own base in the title (the title runs used the merge onto main; the hang check used the head).

AI use

  • Claude Code (Claude Opus 5.5) built the trees, ran the hang check and the title runs, read the logs and thread dumps, and drafted this comment. I checked it before posting.

@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.

`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 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).
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`.
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>
@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.

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.