D3D12.X: split sparse readback spin and submission out of STATE lock #2749
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2749
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2749"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Decodere on GitHub · 2026-11-26 10:05 UTC · original
Decodere:ws8-part2-sparse-lock-split→nvidia-dev· +1193 −302 · 1 files · 1 commits · openTargets
nvidia-dev(af2cecc408), independent of #2729. Splits async sparse readback fence spinning and command recording out ofsparse::STATEso submitting threads and allocation/mapping callers no longer stall behinddrain_readbacks_spinGPU waits orreadback_after_executeD3D12 recording.Part of #2688
What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:rb_jobs,imm_jobs,rb_pool,rb_fence,rbq_done,job_seq,submitting,landing) intoArc<SharedReadbacks>(Mutex<ReadbackQueue>+Condvar, reachable withoutSTATEviastatic READBACKS) and per-queue fence/recording state (dev,rb_queue_fences) intoArc<Mutex<RbSubmit>>, establishing a strict 2-level DAG (STATE -> ReadbackQueueandRbSubmit -> ReadbackQueue) whereSTATEandRbSubmitnever nest andReadbackQueueis never held across GPU spins,Condvarwaits, D3D12 COM calls, orRbJobdrops.prepare_after_execute(whileSTATEis still held) untilsubmit_async_readbackpublishes or cancels viaReadbackQueue::submitting+ RAIISubmittingGuardpaired withRB_PENDINGandSharedReadbacks::published:wait_and_check_readywaits within the caller's existing budget (lock_ms/ unbounded) so concurrent fence observers never return early with stale CPU values when an unrelated unfinished readback is already queued, returnfalseif their budget expires before publication, and wake immediately if a plan is dropped/cancelled on error.Drain::TitleDonefence spinning (wait_and_check_ready) outside all locks with a single totalspin_usdeadline across pending title-done copies; skip lockingSTATEcompletely whensubmitting == 0, no job has finished, andlanding == 0. Tracklandingcount underSTATE -> ReadbackQueuewhile jobs are popped and landing so concurrentsettle_readbacks*callers synchronize onSTATEbefore reading CPU memory while preserving strict ascendingseqlanding order.RbJobs above the 32-job pool cap fromland_finished_readbacks,before_execute_on, andreadback_rangesso callers drop them outside all locks; decrement remaining unlanded jobs inReadbackQueue::dropsoRB_PENDINGstays balanced acrossinitre-initialization (withSubmittingGuardholdingArc<SharedReadbacks>soDropcannot run while a plan is in flight).start_readback_threadonRB_PENDING != 0and a leafREADBACKScheck (has_unpopped_finished_jobs) before tryingSTATE.readback_after_executeinto a briefSTATEsnapshot (prepare_after_execute, leaving the rarerbq.is_none()sync fallback intact) followed bysubmit_async_readbackunderRbSubmitoutsideSTATE, pushingImmJob/RbJobentries toReadbackQueueonly after both queue fences are signalled.sparse::tests:settle_readbacks_waits_for_copy_fence_without_holding_state,settle_readbacks_skips_state_lock_when_no_job_finished(using anmpsc::channel+recv_timeout(500 ms)and always droppingSTATEbeforeworker.join()so a blocking regression fails cleanly instead of deadlocking),concurrent_settle_lands_jobs_in_strict_seq_order,readback_after_execute_records_outside_state_lock_and_drops_excess_outside_locks,state_lock_latency_stays_unblocked_under_readback_spin_contention, andsettle_waits_for_in_flight_plan_publication_and_handles_cancellation.Tested
rustc 1.100.0, DXC1.9.2609.5, debug and release.cargo test -p xcl --lib -- --test-threads=1 --nocapture ...):XCL_ADAPTER=warp):6 passed, 0 failed, 0 ignored(0 skipped,1.94 s); contention bench (40spin calls):STATElock waitp50=1 us, p99=2 us, max=2 us.6 passed, 0 failed, 0 ignored(0 skipped,1.70 s); contention bench (38spin calls):STATElock waitp50=0 us, p99=0 us, max=0 us(vs holdingSTATEacross the2000 uscopy-fence spin before).cargo test --release -p xcl --lib hle::d3d12x::sparse::tests:: -- --test-threads=4 --nocapture:66 passed, 0 failed, 1 ignored(early_commit_timing, 0 skipped,3.44 s; contention bench39spin callsp50=0 us, p99=0 us, max=0 us).cargo test --release -p xcl --test sparse_reinit -- --test-threads=1 --nocapture:1 passed, 0 failed, 0 ignored(0.48 s).cargo clippy -p xcl --all-targets: 0 new warnings and 0 new errors across all added/changed lines incrates/xcl/src/hle/d3d12x/sparse.rs(pre-existing clippy errors in untouchedlower_valu.rs,lower_wide.rs,lower.rs, andsparse.rs:6597).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture(RTX 4060):1753 passed, 3 failed, 48 ignoredacross 39 test binaries + doc-tests (1626 passed, 0 failed, 28 ignoredinxcl --lib;30SKIPPEDlines: 21 wave64 on 32-lane RTX 4060, 3 per-lane form refused, 3 no D3D12 debug layer, 2XCL_HEAP_WINDOWSunset, 1 driver cache; plus sample-pack /xgameruntime.dllskips). All 3 failures (d3d12_mesh_stream::console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly,gpu_compute_e2e::async_compute_pso_registers_real_pso_and_not_standin,gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs) are pre-existing on unmodifiedorigin/nvidia-dev(af2cecc408), verified on detachedaf2cecc408.XCL_LOOK_STATS=2+ 8 GB flags (XCL_LOOK_STATS=2,XCL_HEAP_WINDOWS=1,XCL_UMA_WINDOWS=16,XCL_DIRECT_DXIL=1,XCL_TEXTURE_SAFE_READ=1,XCL_WATCH_HOT_MS=60000, 60 sscripts/smoke.ps1ontitle: 29640639):1476frames (PresentX 1476),60 60 60presents per 2 s,0device removals,0crashes,16272 MBpeak commit,exit: 0x0.Regression run
60 s
scripts/smoke.ps1runs on RTX 4060 with default flags (XCL_LOOK_STATSunset). Includesmain(b49be183, merge-base ofmainandnvidia-dev, same-day run on this hardware) forpr_check.py,nvidia-devbase (af2cecc408), and PRHEAD(9cfa7536):main(b49be183, merge-base):nvidia-dev(af2cecc408, target base):PR
HEAD(9cfa7536, default flags):Not tested
title: 29640639recorded0 KBof sparse readback copies and0FenceSettlecalls, so live retail readback-contention paths were not exercised in the automated smoke (those lock-contention and publication-window paths are verified by the 6 unit/concurrency tests and contention micro-bench above).XCL_SAMPLE_RPF/XCL_SAMPLE_TTPF/XCL_SAMPLE_AWCunset) and D3D12 debug-layer tests (d3d12SDKLayers.dllnot installed).AI use
ReadbackQueue/RbSubmitlock split andSharedReadbacks/SubmittingGuardpublication visibility, wrote the 6 concurrency/contention tests and this description, and ran clippy, unit/workspace tests, and the RTX 4060 retail smoke runs on the hardware above.@luckyteagirl on GitHub · 2026-11-26 10:09 UTC · original · reviewed
On
88c2045, the newsettle_readbacks_skips_state_lock_when_no_job_finishedfixture holdsiso.statewhile callingworker.join(), then drops the guard afterward. The currentSome(5000)path avoids blocking on that lock, but a future regression to a blockingSTATE.lock()—the behavior this fixture is meant to catch—would make the worker and join wait on each other indefinitely. The existingtook < 500 msassertion would never execute, so CI would hang instead of reporting the regression.Could the worker send its result over a channel, let the main thread use
recv_timeoutwhile it holdsSTATE, then always release the guard before joining and asserting the timed result? That preserves the timing check without detaching a worker that may still use the fixture. This is exact-head source review; I did not deliberately hang the test.@KDenKC on GitHub · 2026-11-26 10:20 UTC · original
Source review of
88c20454, no run. A question about one window this opens:readback_after_execute_withbuilds the plan under theSTATElock (prepare_after_execute) and drops the lock. Only after that doessubmit_async_readbackrecord the copies, signal, push the jobs andRB_PENDING.fetch_add(added). On the base,after_executedid the planning and theRB_PENDINGincrement under one lock. Between the two here, copies of GPU-written ranges are planned butRB_PENDINGis still 0. Sosettle_readbacks/settle_readbacks_withinreturn at theirRB_PENDING == 0fast path, andreadback_nowskips itswait_and_check_readyand goes straight to its own pass under the lock. It's a short window, but it's on every submit with readbacks.Is that intended (e.g.
readback_now's own pass is always enough there)? If not, counting the planned jobs inside the lock (incrementingRB_PENDINGinprepare_after_executeand settling it ifsubmit_async_readbackbails, as on its fence-creationreturnand thetake_or_alloc_rb_jobbreak) would keep the old ordering.Not tested: no build or run of this head on our side.
AI use: Gemini (Antigravity) flagged it in a review. Claude Code (Claude Opus 5.5) read the paths in the diff and wrote this.
@thehollowedone on GitHub · 2026-11-26 10:33 UTC · original
Follow-up to KDenKC's publication-gap comment on head
88c2045: incrementingRB_PENDINGwhen the plan is made would not, by itself, make a settling caller wait for that plan to be published.settle_readbacks_withcan still return success whenwait_and_check_readysees no finished queued job or active landing.A schedule that distinguishes this head from its base is: one unrelated, GPU-unfinished readback is already pending; a second submission completes its title fence for an immediate CPU write, then pauses after
prepare_after_executedropsSTATEand beforesubmit_async_readbackpublishes the immediate. A concurrent fence observer seesRB_PENDING > 0, finds only the unfinished old job, and can return the completed fence value while the immediate's CPU destination still holds its old value. On the base path, the submitter holdsSTATEthrough publication, so an observer that obtains it within its wait budget serializes with that write. The all-zeroRB_PENDINGfast path existed on base too; it alone does not prove a regression.Could an unpublished submission remain visible to settling callers until publication or cancellation, with those callers observing that transition within their existing wait budget? A deterministic regression can use barriers to pause publication after the second title fence completes, start the observer with a bounded test timeout, release publication, and assert the CPU value when the observer reports the fence complete. The current contention test starts settling after joining the submitter, so it does not cover this window.
This is a source trace, not a live reproduction. No build or GPU test of #2749 was run for this finding. AI use: Codex (GPT-6.2 Astra) traced the ordering; Codex (GPT-6.2 Sol) checked the current diff and drafted this comment.
@KDenKC on GitHub · 2026-11-26 10:43 UTC · original
Thanks @thehollowedone, that is the better framing. Counting the plan earlier only changes the zero fast path, which existed on the base too. Your schedule (an older unfinished job pending, an immediate write planned but not yet published, a fence observer settling in between) is the case that actually differs from the base. Keeping an unpublished submission visible to settling callers until it is published or cancelled is the right shape for a fix; my
RB_PENDINGsuggestion alone would not do it.AI use: Claude Code (Claude Opus 5.5) wrote this.
@MarcosMDev on GitHub · 2026-11-26 10:54 UTC · original
Test report:
88c2045against its baseaf2ceccon an RTX 4060 (Windows): full suite, no new failure. No title was run.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4, debug, each commit in its own worktree and target folder:af2cecc: 1745 passed, 6 failed, 48 ignoredsparse::testspass, the contention bench included.The suite does not cover the publication window @thehollowedone describes above: as they note, the contention test starts settling after the submitter has joined.
RTX 4060 8 GB (driver 621.01), Ryzen 7 5700X, 24 GB, Windows 11 26200, rustc 1.100.0, DXC 1.9.2609.5.
Not tested: any title or smoke run, the sparse path under a real workload, timings, AMD.
AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this; I read it before posting.
88c20454dfto9cfa7536e9@thehollowedone on GitHub · 2026-11-26 11:19 UTC · original
Follow-up to my source review: I reproduced the planned-but-unpublished immediate window on head
88c20454with a test-only change. The PR head andnvidia-devbase were unchanged when checked.The test leaves an older readback unfinished, prepares a second immediate write under
STATE, and pauses its submission on a channel. After a title-visible fence completes,settle_readbacks_with(..., Drain::TitleDone, ..., Some(0))reports success even though the immediate is neither published nor present in CPU memory. The test then releases submission, lands both jobs, verifies the destination value andRB_PENDING == 0, and fails only on the early-success assertion. The channels keep publication paused during the observation; there is no timing sleep.On Windows 11 build 26300, RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, rustc 1.99.1 MSVC:
cargo test --offline --locked -p xcl --lib a_planned_immediate_is_visible_to_a_concurrent_fence_observer -- --nocapture --test-threads=1: 0 passed, 1 failed, 0 ignored, 0 GPU skips, withobserver reported success before the planned immediate was published. Repeated in a separate process with the same result.cargo test --offline --locked -p xcl --lib readback_after_execute_records_outside_state_lock_and_drops_excess_outside_locks -- --nocapture --test-threads=1: 1 passed, 0 failed, 0 ignored, 0 GPU skips.A fix needs the planned submission to remain visible until it is published or cancelled, and the settling caller to observe that transition within its wait budget. Merely incrementing
RB_PENDINGat planning does not makewait_and_check_readysee an unpublished plan. The regression below is offered as a starting point; it does not validate a production fix or prove a retail-title failure.Test-only regression diff
AI use: Codex (GPT-6.2 Sol) wrote and ran the regression and drafted this report; Codex (GPT-6.2 Astra) reviewed the publication/cancellation design.
@Decodere on GitHub · 2026-11-26 11:29 UTC · original
Thanks
@luckyteagirl,@KDenKC, and@thehollowedone! Addressed all points in9cfa7536:settle_readbacks_skips_state_lock_when_no_job_finished(@luckyteagirl): The worker now reportsokover anmpsc::channel; the main thread waits withrx.recv_timeout(500 ms)while holdingSTATE, always drops theSTATEguard beforeworker.join().unwrap(), and then asserts the timed result so a blocking-lock regression fails cleanly instead of hanging CI.@KDenKC/@thehollowedone): WrappedMutex<ReadbackQueue>with aCondvar(SharedReadbacks) and addedReadbackQueue::submittingplus an RAIISubmittingGuardacquired inprepare_after_executewhileSTATEis still held (keepingRB_PENDINGelevated until publication or cancellation, and holdingArc<SharedReadbacks>soReadbackQueue::dropcannot run early).submit_async_readbackatomically publishes jobs, decrementssubmitting, adjustsRB_PENDING, and notifiespublished(andSubmittingGuard::dropcancels and notifies on any bail/error).wait_and_check_readywaits outsideSTATEonpublishedwhilesubmitting > 0within the caller's existing wait budget (lock_ms/ unbounded), returningfalsefromsettle_readbacks_withif the budget expires before publication (includingSome(0)whilesubmitting > 0).settle_waits_for_in_flight_plan_publication_and_handles_cancellationreproducing the exact schedule (unrelated unfinished readback pending, immediate plan paused afterSTATEdrops and GPU title fence completes, bounded timeout returningfalse, observer waiting for publication and asserting the landed CPU immediate immediately upon returningtrue, plus plan-drop cancellation wakeup).Re-verified all 6 lock-split/publication/contention tests on debug WARP (
6/6,p99=2 us) and release RTX 4060 (6/6,p50=p99=max=0 us), fullsparse::tests::(66/0/1),sparse_reinit(1/0/0), full release workspace (1753 passed, 3 pre-existing nvidia-dev failures), and 60 s RTX 4060 smokes (default+XCL_LOOK_STATS=2).@MarcosMDev on GitHub · 2026-11-26 11:51 UTC · original
Follow-up to my report, on the new head
9cfa753(same baseaf2cecc, same RTX 4060 and setup):sparse::testspass,settle_waits_for_in_flight_plan_publication_and_handles_cancellationincluded.cargo test -p xcl --lib hle::d3d12x::sparse::tests -- --test-threads=4, 20 times in a row: 66 passed, 0 failed every time, no hang.Not tested: any title or smoke run, timings, AMD.
AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this; I read it before posting.
@thehollowedone on GitHub · 2026-11-26 12:02 UTC · original
Independent RTX 3080 Ti recheck of #2749 head
9cfa7536against its exactnvidia-devbaseaf2cecc4. The PR head was unchanged when checked before posting. Windows 11 build 26300, RTX 3080 Ti 12 GiB / NVIDIA 621.35, rustc 1.99.1 MSVC, debug builds. Separate clean source archives and target directories, synthetic tests only.Both revisions passed
cargo build --offline --locked --workspace, then rancargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4:SKIPPEDnoticesaf2cecc49cfa7536The six distinct failing test names are identical on base and head;
two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsis counted twice. The others areconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk,pieces_hold_the_texels_of_their_levels,gpu_parts_of_a_texture_go_up_and_the_rest_stays,console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly, andasync_compute_pso_registers_real_pso_and_not_standin. The two texture-upload failures both panic on a debug multiplication overflow attexture_upload.rs:1002on both revisions. This paired run found no additional failure on the head; it is not a whole-suite pass. GPU skips are not coverage.On the head,
cargo test --offline --locked -p xcl --lib hle::d3d12x::sparse::tests:: -- --test-threads=4passed 66, failed 0, ignored 1, with 0 GPU skips. The newsettle_waits_for_in_flight_plan_publication_and_handles_cancellationregression also passed alone (1/0/0) usingcargo test --offline --locked -p xcl --lib settle_waits_for_in_flight_plan_publication_and_handles_cancellation -- --nocapture --test-threads=1. I reviewed the new reservation and publication path against my earlier reproducer and found that the original planned-but-unpublished window is closed.Not tested: a retail title, paired clean-commit smoke, sustained in-world readback traffic, AMD/Intel, or a performance improvement under real contention. The tests establish Ampere coverage for the fix, not a merge-readiness or runtime-speed claim.
AI use: Codex (GPT-6.2 Sol) ran the paired Windows tests and wrote this report; Codex (GPT-6.2 Astra) reviewed the low-level publication path.
@throny on GitHub · 2026-11-26 14:11 UTC · original
Test report: in the world on an RTX 4080 16 GB (the case under "Not tested"). Three back-to-back runs of the retail title of #505 into the world, two with this PR and one without, same warm caches.
Tested
nvidia-devaf2cecc4+ #684 (needed to pass world entry on this card) + #2697 (accounting line only). With: the same + this PR's diff at9cfa753(git apply, applies as it is tosparse.rs).XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GFX_PSO_WAIT_MS=200 XCL_NETWORK=0 XCL_ACTIVITY=1, Series X profile, scripted presses, limit 900 s. The world starts at about 172 s in all three.0x887a0005at 423 s0x887a0005at 269 snvlddmkmevent in the two runs with the PR; 2 × 250–750 s of world submits went through the new path.submit costlines in the world (run 15, at 494 s and 784 s): "refresh lock wait 0.00 ms", "sparse lock 0.01–0.02 ms" of 1.9–4.7 ms refresh per submit. The lines also show 177 and 208 ms "in all" perExecuteCommandListsof which the listed parts explain under 5 ms; that remainder is what #2729 is for, not this PR.Not tested
AI use: Claude Code (Claude Fable 5.2) ran this on the owner's machine and wrote the report.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.