Skip to content

D3D12.X: amd-dev readback waits: no stale wake-up, no buffer freed under a queued copy - #2842

Open
GreemSC wants to merge 2 commits into
xcl-dev:amd-devfrom
GreemSC:amd-dev-readback-inflight
Open

GreemSC wants to merge 2 commits into
xcl-dev:amd-devfrom
GreemSC:amd-dev-readback-inflight

Conversation

@GreemSC

@GreemSC GreemSC commented Nov 26, 2026 •

Copy link
Copy Markdown

Two fixes to amd-dev's sparse readback waits, found while running amd-dev c32c91a3 under Wine on an RX 7900 XT: a timed-out readback_now freed its readback buffer under a queued GPU copy (a GPU page fault on RADV), and the waits could end early on a stale signal of their reused event. Neither is Wine-specific in the code. Related: #2619, #2626 (amd-dev page faults entering the world on Windows; theirs are shader reads, ours a command-processor write, so maybe not the same bug).

What is in it

Why

  • Run entering the world (RX 7900 XT, RADV): a few seconds after the first readback_now queue has not reached fence value … after 5 s, the kernel logs [gfxhub] page fault … Faulty UTCL2 client ID: CPG, PERMISSION_FAULTS 0x5, RW 0x1; the GPU stalls and the title's GPU watchdog ends it (game_scarlett_master.exe+0x23cf683). GPU page faults in every run until the second commit, none after (6 runs).
  • Of 201 such "after 5 s" lines in one run, 193 came under 4.9 s after the previous one on the same thread, mostly 1 ms apart with the fence advancing normally: the stale event signal of the first commit. With both commits, a run that still had real readback stalls logged 6, each 5 s apart.

Tested

  • RX 7900 XT 20 GB, Mesa 26.2.5 RADV, i7-12700K, 24 GB RAM, Linux 7.2, Proton-CachyOS Wine 11, vkd3d-proton (dxil-spirv 53aac41); release, cross-built for x86_64-pc-windows-msvc; lib tests run under Wine (tools-xcl/wine-tests.sh, which skips the few tests that call DXGI functions Wine lacks).
  • hle::d3d12x::sparse:: on this head: 34 passed, 0 failed, 1 ignored, no SKIPPED.
  • wait_fence_until_ignores_stale_event_signal fails with the old single wait (returned too early), passes with the fix.
  • Whole lib suite (cargo test -p xcl --lib binary under Wine): the run aborts at the same test on the base and on this head (after gpu::recomp::tests::scalar_relative_move_cluster, the process ends; pre-existing, as in amd-dev 6a0bb5b: 13 tests fail on an RX 9070 XT, and the lib test binary aborts after 1,024 of 1,564 tests #2632). Before the abort: amd-dev c32c91a3 974 passed / 72 failed, this head 976 passed / 69 failed, 6 SKIPPED lines each; no test fails only on this head (the three fewer are GPU tests that pass or fail from run to run here).
  • Retail title: the two commits are part of a larger Linux tree (amd-dev + the Wine stack + Wine-only changes discussed on Memory: lazily map sparse VRAM tiles for Wine graphics heaps (#175) #877 / D3D12.X: run sparse::readback_after_execute asynchronously per queue #1732), 600 s runs, 0 crashes, 0 device removals, 0 kernel GPU faults, reaching the playable part.

Regression run (by @vibryxcx on Windows, comment: RX 6800, retail title, 60 s, after a warm-up run). The base is this PR's base on amd-dev, not a commit of main.

xcl-smoke v1
commit: c32c91a30904fdf72071a8fa77db713cfea92b4c
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1386 (PresentX 1386)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15177 MB
xcl-smoke v1
commit: 344ce7b5b9a0301c1f76e3c3b0b2f9cbb3471762
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1389 (PresentX 1389)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15066 MB

On Windows no sparse or readback wait reached its 5 s timeout (300 s runs too), so these runs show the normal path does not regress, not that the two fixes work there; the whole suite there: the same failures on base and head. Under Wine (@SlopTart, two machines): the lib run stops at the same test on base and head.

Not tested

AI use

  • Claude Code (Claude Opus 5.5) found both bugs from the runs, wrote the code, the tests and this description; an independent Claude Code review pass (Claude Fable 5.2) found the stale-event cascade. I checked the runs and the diff.

🤖 Generated with Claude Code

Greem and others added 2 commits November 26, 2026 18:40
`wait_for`, `wait_for_rb` and `readback_now` arm `SetEventOnCompletion` on a
reused auto-reset event and wait once. When an earlier wait timed out, its
fence completing later sets the event, and the next wait on it returns at once:
a "not reached after 5 s" logged a millisecond after the previous one, and
`readback_ranges` copying the staging bytes before the GPU copy had run.

The waits now go through `wait_fence_until` (the helper of xcl-dev#1419 / xcl-dev#2821 for
`main`, same signature, so they merge as one): reset the event, then wait in a
loop until the fence reaches the target or the deadline passes.
`readback_ranges` copies nothing back after a failed wait.

Seen on an RX 7900 XT under Wine/RADV (amd-dev c32c91a + the Wine stack): of
201 "readback_now queue has not reached fence value ... after 5 s" in one run,
193 came under 4.9 s after the previous one on the same thread, mostly 1 ms
apart, with the fence advancing normally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s run

When `readback_now` gives up waiting for its readback (5 s), it dropped the
pooled `ReadbackJob` with the copy still queued on `rb_queue`: the readback
buffer, allocator and list were released under a pending GPU copy. Drivers
that free at `Release` (RADV) unmap the buffer at once; the copy then runs and
the command processor writes into freed memory.

Seen on an RX 7900 XT under Wine/RADV (amd-dev c32c91a + the Wine stack),
entering the world: kernel `[gfxhub] page fault ... Faulty UTCL2 client ID:
CPG, PERMISSION_FAULTS 0x5, RW 0x1` a few seconds after the first "readback_now
queue has not reached fence value ... after 5 s", the GPU stalls and the
title's GPU watchdog ends it (`game_scarlett_master.exe+0x23cf683`). GPU page
faults in every run until this change, none after.

The job now waits in `IN_FLIGHT_RB_JOBS` with its fence and value, and goes
back to the pool once the copy has run (`take_readback_job` reclaims first).

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

GreemSC commented Nov 26, 2026

Copy link
Copy Markdown
Author

A Windows pair is what this needs to leave draft: scripts/smoke.ps1 on amd-dev c32c91a3 and on this head (344ce7b5), same title, same time. If someone on Windows (ideally AMD, given #2619 / #2626) can run it, thank you.

One addition to Tested: the whole-suite abort under Wine is hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit, which @SlopTart isolated on two machines in #2764 (it fails the same way on bare amd-dev).

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

@SlopTart

Copy link
Copy Markdown

Wine dual-lane run at head 344ce7b5 - your two readback fixes land clean on Wine, and they neither cause nor cure the branch-level failure that makes our lanes unable to finish the suite. (No Windows machine here, so the smoke.ps1 pair above is out of our reach; this is the Linux/Wine half of the picture.)

  • Rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT (Mesa 26.2.5 RADV), Arch, wine-11.0 Proton build + vkd3d-proton
  • Boxb: i5-10600K, 16 GB DDR4, GTX 1070 (550.163.01), Debian 13, stock wine-10.0 + vkd3d-proton, xvfb

Suite: cargo test --release --locked -p xcl --lib --target x86_64-pc-windows-gnu -- --test-threads=2 --skip gpu::. Base for comparison: c32c91a3 (this PR's exact base), measured on both lanes earlier today.

At this head, both lanes die at the identical spot as base: 283 tests run, then hle::d3d12x::list_x::tests::a_dispatch_with_a_pipeline_still_building_waits_at_the_submit FAILED and the process dies (rig exit 5; boxb takes an execute page fault into winedbg). Nothing completed before the death differs from base - your changes break nothing that we can see in the 283 tests Wine does finish.

Solo repro of the killer test at this head, identical panic on both:

panicked at crates/xcl/src/hle/d3d12x/list_x.rs:8277:17:
dispatch 17 waited for the build (9.9722524s)   # rig
dispatch 17 waited for the build (9.922322s)    # boxb

Base numbers were 9.957s / 9.927s - same signature, same stand-in pipeline for console shader 0x7e57d001 never completing its background build, retries doubling to #16. So the stand-in-build deadlock survives your two fixes untouched on both Wine stacks. It stays branch-blocking for our lanes until someone finds why that build never lands under Wine (it completes fine on main and nvidia-dev, same test, measured today).

Practical note for Wine testers: on the NVIDIA lane the crash can hang winedbg --auto and wedge the whole run silently - kill the winedbg pid to let cargo report and move on.

AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@vibryxcx

Copy link
Copy Markdown

The Windows AMD pair asked for above: scripts/smoke.ps1 on amd-dev c32c91a3 and on this head 344ce7b5, same title, same time. There is no device removal or crash on either, and nothing in the suite fails only on this head. On Windows / RDNA2 the readback timeouts this PR handles did not occur, so these runs do not exercise the two fixed paths (see the end of this comment).

Tested

  • AMD Radeon RX 6800 (RDNA2, driver 32.0.21045.5002), Intel Core i5-10600KF, Windows 11 Pro 26200, rustc 1.100.0 (0ef1bc386 2026-11-09), release for xcl.exe, debug for the tests. Base and head each in their own worktree with no uncommitted changes. I read the full diff before building.
  • cargo test -p xcl --lib -- --test-threads=1 on head (the 4-thread run aborts on amd-dev, as reported on other PRs):
  • Each failure and both skipped tests run alone (--exact) on base and on head give the same result on both. The same 10 fail on both (fuzz_validate_and_gpu_1, dispatch_chain_native_wave64_builds_whole, a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, f32_programs_on_the_gpu, a_dispatch_with_a_pipeline_still_building_waits_at_the_submit, a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget, bitset_runs_emit_exact_contiguous_page_ranges, giant_driver_compiles_have_their_own_lane, title_bytes_are_used_in_place_when_all_are_readable, physical_home_without_sparse_windows_uses_coherent_window). two_pass_binds_set_the_shared_view_heap, d32s8_targets_take_their_own_size_of_video_memory and placed_title_textures_share_vram_and_preserve_pixels pass alone on both and fail, abort or hang only inside the full run.
  • title_textures::tests::gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released failed once in the first full run, then passed in the rerun and 3 times out of 3 alone on base and on head. It looks flaky rather than caused by this PR.
  • New tests wait_fence_until_ignores_stale_event_signal and a_timed_out_readback_job_is_kept_until_its_copy_ran: both pass on real hardware (not WARP).
  • SKIPPED: 4 to 5 lines, all f16_programs_on_the_gpu (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426).

Regression run (retail title, 60 s, after one 60 s warm-up run on base that is not counted)

xcl-smoke v1
commit: c32c91a30904fdf72071a8fa77db713cfea92b4c
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1386 (PresentX 1386)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15177 MB
xcl-smoke v1
commit: 344ce7b5b9a0301c1f76e3c3b0b2f9cbb3471762
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1389 (PresentX 1389)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15066 MB

The base is c32c91a3 on amd-dev (this PR's base), not a commit of main.

Longer runs, 300 s, XCL_PRESS_A_AT=40,60,…,180

tree frames peak commit device removals … after 5 s lines (sparse / readback)
c32c91a3 2677 29167 MB 0 0
344ce7b5 2456 27681 MB 0 0
  • Sparse windows are busy in both runs (8192 submits, about 1.98 GB of CPU writes uploaded, about 20.3k tiles mapped), but no wait_for, wait_for_rb or readback_now wait reached its 5 s timeout.
  • So the stale-event loop and the in-flight job keeping are not exercised on this title on Windows. These runs show that the PR's normal path does not regress; they do not show that the fixes work.
  • Both trees stop presenting at the same point, at about 155-185 s, after graphics pipeline wait window (12000 ms) spent (the same loading stall as on b5c0275f in D3D12.X: default XCL_INLINE_GUARD_BATCH off to avoid dead 64 KiB scratch allocations and AMD page faults #2757). It is not caused by this PR.

Not tested: a Windows run where a readback actually times out (I did not force one); NVIDIA / Intel; the world past the loading stall; #2619 / #2626.

AI use: Claude Code (Claude Opus 5.5) read the diff, ran the builds, tests and game runs, read the logs and wrote this comment. The numbers come from those runs on the hardware above.

@GreemSC

GreemSC commented Nov 26, 2026

Copy link
Copy Markdown
Author

@vibryxcx thank you for the Windows pair and the whole-suite run, and for saying plainly that the two fixed paths were not exercised there (no 5 s timeout on Windows / RDNA2); that matches what I expected: they only matter where a readback times out, which here is under Wine. I copied your two xcl-smoke blocks into Regression run with credit. @SlopTart thanks too for the two-lane rerun at this head.

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

@SlopTart

Copy link
Copy Markdown

Dual Wine re-check after the amd-dev rewind (heads re-verified at post time: this PR 344ce7b5, branch tip now b5c0275f, an ancestor of your old base c32c91a3).

We re-ran the current tip on both our Wine lanes: the stand-in-build deadlock still fires in isolation (solo panic 9.967s on the rig, identical signature at c32c91a3, at this PR head, and at b5c0275f), so rebasing this PR onto the new tip will not dodge it. Full branch-state data (including the 22-red NVIDIA-lane picture where wine-10 survives to finish the suite) in our follow-up here: #2764 (comment)

AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants