Repository navigation
D3D12.X: a copy back after a submission does not wait for the title - #1993
Ariorh1337 wants to merge 1 commit into
Conversation
|
A caution from a local change of the same design: with the copy back asynchronous, the shared What happened in my tree, which had the same idea (copies back on their own queue, landed by a thread):
So it may be worth giving each title queue its own fence here (or checking Setup of the runs above (not this PR): Not tested: this PR itself, current 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. |
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
|
Code review on
Remaining before merge: Addressing the multi-queue |
|
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 Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) built both trees, ran the runs and wrote this report. |
PR #1993 verification on STOR-WINLABPR head
Tested
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
Failures
SkipsRaw logs in Not testedThis run covered the PR head on STOR-WINLAB. No AI useT3 Code / Codex (gpt-6.2-sol) ran the build and tests and drafted this report. Coordinator #2 (T3 Code / Antigravity, |
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
… 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>
|
Independent native Windows test of #1993 (
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 parallel-test hang this PR's change brings in, found through #2057, which carries it as A first-parent bisect of #2057 named
In the hung runs, the new test and older On #2057 the same hang shows on all three heads ( AI-assisted (Claude Code). Synthetic tests only. |
4df0a2d to
9a3fe7d
Compare
|
@CharlyRien thanks, you were right:
@upipibi thanks for the bisect and the numbers. I reproduced the hang (3 of 3 runs of your filter). Thread dumps showed three @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 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. |
|
Code review on
Remaining before merge: |
|
@Kalmarv I should have found #433 before opening this: it is older and goes at the same cycle (a copy back after
So #433 keeps 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. |
|
Thanks for the comparison. One thing for the A/B: #433 conflicts with current AI use: Claude Code (Claude Opus 5.5) wrote this reply. |
|
RDNA3 / Linux run of Setup:
The run:
The value going backwards:
How the run ended: at ~700 s a compute dispatch on a vkd3d queue never finished.
Not tested:
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. |
|
@Ariorh1337 Re-run of the hang check at
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 AI-assisted (Claude Code). Synthetic tests only. |
|
Thanks for the runs on 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 AI use: Claude Code (Claude Opus 5.5) read the code and drafted this. |
|
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 Setup:
Not tested: the cycle the description is about; 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. |
3260d40 to
69903fc
Compare
|
@Chrysana the follow-up I promised, in What that log shows: in a run of the retail title on @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 AI use: Claude Code (Claude Opus 5.5) wrote the change and the test, ran them and drafted this. |
|
Update: the crash below is a missing
super::title_textures::own_work(|| { let _g = super::real::UnadoptGuard::new(l.as_raw()); q.ExecuteCommandLists(&[Some(l)]) });
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:
2. Tests (edited: withdrawn). My first version listed three failing sparse tests. Those runs did not set Where the crash is (added): with the build's DWARF,
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. |
|
@Ariorh1337 I've updated / edited my comment with some further tests |
|
Test report: Linux / RADV, RX 7800 XT (RDNA3). Head
AI use: Claude Code (Claude Opus 5.5) ran the analysis and drafted this. The runs were real, on the hardware above. |
69903fc to
e8d597b
Compare
|
@St5sz2Jk thanks, your reading of the stack was right. Fixed in
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: @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 Tested on 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
left a comment
There was a problem hiding this comment.
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>
|
@Ariorh1337 Added more to my original comment again for you |
e8d597b to
0a755f0
Compare
|
@bmjask thanks, that was a real gap. Fixed in
Tests:
Tested on @Chrysana thanks for the AI use: Claude Code (Claude Opus 5.5) wrote the fix and the tests, ran them and drafted this. |
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
|
Tested head Hardware & environment
Targeted unit tests (debug,
Retail title A/B (1.0.2.1, pressing
Not tested
AI use
|
|
NVIDIA test report for
|
readback_after_executemakes 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 aWrite64on 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_executewaiting 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: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.real::create_own_list), asinit'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 itsClose(found by St5sz2Jk on RDNA4 / Wine).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.settle_readbacksruns beforeMap'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).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):GetCompletedValuesettles them before it returns.SetEventOnCompletionwith 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_trysays 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), andGetCompletedValuegives no more than the value the fence was last seen at with its copies landed (its initial value fromCreateFenceat first). The title's thread is not blocked by this.list_x.rs: the CPU wait ofWait64BitValueX/Wait32BitValueXsettles 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.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::Finisheddoes 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 withoutcreate_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.GetCompletedValuestays 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_xmemsettles before its CPU reads, as its fence wait is not one of the title's.list_xtests were in the driver inNtGdiDdDDIDestroyAllocation2and 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
cargo test --workspace --no-fail-fast -- --test-threads=4:0a755f0, onmain06055a7): 1418 passed, 4 failed, 46 ignored;main(06055a7): 1409 passed, 4 failed, 46 ignored.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineState0x8007000E).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:3260d403 runs (release), 2 with 62 passed and 1 with a failure inacphal::tests::xapu_connect_returns_oom_and_cleans_up_on_failure, which checks withVirtualQuerythat a freed buffer is free while a test beside it can take the address (it does not touch the sparse code);9a3fe7d3 of 3 (debug), 5 of 5 on the revision before (release), and upipibi's 10 of 10 on an RTX 3070.test_title_draws_with_a_root_signature_under_the_debug_layerfailed while the lanes were made on first use (the test title read 0 for itsKickoffXandMapreadbacks); with the lanes made ininitit passes.69903fc: hang check 10 of 10, and the copy-back tests pass on the RX 9070 XT and an RDNA2 iGPU too, withlane_state()moved to the hardware adapter locally.69903fcin a stack with kernelx: XCL_COHERENT_HEAPS=sparse:N puts big GPU heaps in video memory #2009 and about 20 other PRs onmain50a9fde: 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.Closeis whatcreate_own_listfixes. Three copy-back tests failed there; they pass on native AMD drivers (Chrysana), so that looks like the Wine side. Not re-run on0a755f0.main568e7db+e213d42(this PR before the rebase): through the menus, the first#101and 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.mainb9b6ea6plus 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=1for both, same machine.Not tested
0a755f0: the crash fix is from St5sz2Jk's stack, not re-run there.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 on568e7db, before the rebase.ID3D12Fence1, or a wait throughWaitForMultipleObjectson an event it shares with another fence. The 0.5 ms thread lands the data there.AI use
🤖 Generated with Claude Code