D3D12.X: batch used-pipelines.txt writes off the bind lock #2635
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!2635
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2635"
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 03:37 UTC · original
Decodere:fix-pso-async-batch-used-writes→main· +480 −26 · 3 files · 1 commits · openWhat is in it
Part of #2508
Part of #1833
pso_async::used::note()(crates/xcl/src/hle/d3d12x/pso_async.rs) previously ran synchronouscreate_dir_all,OpenOptions::open, and unbufferedwriteln!(f, "{key:016x}")syscalls while holding the globalused::nowmutex on the title's command-recording / bind thread (Pending::note_use, called fromresolveandresolve_wait_for). During world-load pipeline bursts, every newly used pipeline serialized bind threads behind disk I/O.Changes (3 files:
crates/xcl/src/hle/d3d12x/pso_async.rs,crates/xcl/src/host.rs,crates/xcl/src/eh.rs):used::Journalbacked by a single lightweight writer thread (xcl-pso-used),Mutex<JournalState>,wake_cv, andflushed_cv.Journal::note(key)performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts intoseen, appends topending(continuing to queue keys whilefallback_pathis set even if writer spawn failed), and notifieswake_cvonly on empty-to-nonempty (1) and burst-threshold (64) transitions.writer_loopcoalesces bursts up to25 ms(draining immediately at64unique keys), drainspendingviastd::mem::take, drops the mutex before I/O, lazily creates parent directories and opensused-pipelines.txt, performs a single batchedwrite_all+flush, and updatescompleted_seq = completed_seq.max(batch_seq)so a slow batch never regressescompleted_seqbelow a timed-outflush_bounded()drain. I/O failures clear the cached handle and never panic or break in-memory deduplication.if cfg!(test)isolated from the user's cache file (Journal::in_memory, with a test-onlyXCL_TEST_USED_STATIC_PATHenv hook for subprocess exit verification) and leftcounts()un-flushed (present.rscalls it onPresentX).static U: OnceLock<Used>(addressing@luckyteagirl's exit-flush review and@KDenKC's follow-up review):Journal::writerinMutex<Option<JoinHandle<()>>>soJournal::shutdown(&self)flushes pending keys and joinsxcl-pso-usedthrough a shared&'staticreference (Dropdelegates toshutdown()), draining any remainingpendingkeys tofallback_pathif no writer thread was spawned; addedJournal::flush_bounded(&self, timeout)with a direct-append fallback tofallback_pathifxcl-pso-usedtimes out (e.g., blocked on the Windows loader lock during a fastExitProcess) or failed to spawn.atexit(on_process_exit)->used::shutdown()whenused::init_from_pathinitializes the file-backed static journal (covering ordinarymain()return).pso_async::shutdown_used()intocrates/xcl/src/host.rson both normal shutdown boundaries (XCL_RUN_SECONDSbeforereal::end_title(0)and normal return fromloader::run_main).pso_async::flush_used_bounded(100 ms)intocrates/xcl/src/eh.rs::hk_nt_terminate_processalongsidecrate::log::flush()so titles exiting directly via Win32ExitProcessflush pending keys beforeNtTerminateProcessends worker threads.pso_async::used_tests:used_note_does_not_block_on_slow_writerused_burst_coalesces_writes_and_deduplicates_keysused_flush_drop_lazy_file_and_io_error_are_gracefulused_static_once_lock_flushes_on_process_exit(subprocess test coveringnormalreturn viaatexit, Win32ExitProcessviaeh::install_crash_handler+std::process::exit(0), explicitshutdown_used(), andflush_used_bounded()without dropping a localJournal, using a 60 s coalesce window)used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound(verifyingcompleted_seqstays monotonic across a timed-outflush_bounded()so a subsequentflush()never hangs, and verifyingnote()+flush_bounded()/shutdown()persist keys directly tofallback_pathwhen writer thread spawn fails).Tested
rustc 1.100.0, DXC1.9.2609.5 (01b62ad4), release builds.bd9b4008:used_static_once_lock_flushes_on_process_exitfailed immediately (0 passed; 1 failed:static OnceLock journal lost keys on process exit: NotFound) becausestatic U: OnceLock<Used>did not runDropon process exit before the coalesce window elapsed.XCL_ADAPTER=warp,XCL_WARP=1):cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture->19 passed; 0 failed; 0 ignored(0skipped,0.82 s).cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture->19 passed; 0 failed; 0 ignored(0skipped,0.81 s).cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture:37test binaries,1440passed,0failed,47ignored (0new warnings),29pre-existing host-gatedSKIPPEDlines (none inpso_async):21wave64-only GPU tests (no wave64on RTX 4060 32-lane waves)3per-lane wave32 shader tests (refused)3D3D12 debug layer tests (no d3d12SDKLayers.dll/ debug layer unavailable)1heap-window OOM fallback test (no heap windows)1PSO driver-cache measurement test (cannot disable the driver cache)Regression run
Paired 60 s retail smoke (
scripts/smoke.ps1, RTX 4060): both base (889ef3e8, ancestor ofb49be183and24e584ca) and HEAD sustained60 60 60presents per 2 s with0device removals and0crashes (1582vs1550total frames,102.1%;13982 MBvs13981 MBpeak commit).Base (
origin/mainancestor):HEAD (
fix-pso-async-batch-used-writes):Not tested
TerminateProcessfrom outside the process (which bypasses user-mode hooks andatexit).#[ignore]tests.AI use
Google Antigravity (Gemini 4 Neon) authored the batched
used::Journalwriter, process-exit flush/shutdown wiring (atexit,host::host_main,eh::hk_nt_terminate_process), monotonic-sequence and spawn-failure fallback handling, subprocess and unit regression tests, and verification runs; verified via failing-first subprocess reproduction, WARP and RTX 4060 unit tests, full RTX 4060 release workspace tests, and paired 60 s retail smoke runs.bd9b400884toad798f3b5c@sage-sage on GitHub · 2026-11-26 05:18 UTC · original
Test report: passes on NVIDIA. Exact head
bd9b4008(its base is currentmainb49be18, so head = merged).Tested
cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three newused_testspassmainon this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dllnot installed), 1no heap windows, 1pso_measurement_compiles_an_exact_synthetic_record(Developer Mode off)Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@Decodere on GitHub · 2026-11-26 05:18 UTC · original
@luckyteagirl Great catch — pushed
ad798f3baddressing staticOnceLock<Used>exit persistence across all Windows exit paths:Journal::writerinMutex<Option<JoinHandle<()>>>soJournal::shutdown(&self)flushes pending keys and joinsxcl-pso-usedthrough the static reference (Dropdelegates toshutdown()), and registered CRTatexit(on_process_exit)whenused::init_from_pathinitializes the file-backed journal.pso_async::shutdown_used()intohost::host_mainon normal return andXCL_RUN_SECONDS(right beforereal::end_title(0)suspends threads / terminates), and wiredpso_async::flush_used_bounded(100 ms)intoeh::hk_nt_terminate_processalongsidelog::flush()with a direct-append fallback toused-pipelines.txtifxcl-pso-usedis blocked on the Windows loader lock during a fastExitProcess.used_static_once_lock_flushes_on_process_exit(subprocess test with a 60 s coalesce window, no localJournaldrop) covering normal process return (atexit), Win32ExitProcess(eh::install_crash_handler+std::process::exit(0)), explicitshutdown_used(), andflush_used_bounded()(reproduced failing-first onbd9b4008, now 18/18 passing on WARP and RTX 4060). Thanks for the review!@KDenKC on GitHub · 2026-11-26 05:53 UTC · original
Source review of head
ad798f3b, no run. Two small things in the journal, both low impact today:completed_seqcan go backwards (pso_async.rs,writer_loop:completed_seq = batch_seq). The writer takes batch 1 (batch_seq = 1) and is slow inwrite_batch. Meanwhile a new key arrives (enqueued_seq = 2), andflush_boundedtimes out, appends it itself and setscompleted_seq = 2. The writer then finishes and stores1. Withpendingempty andcompleted_seq < enqueued_seq, a laterflush()waits forever. Todayflush()is only called from tests, and the exit path isflush_bounded(with a timeout) followed byshutdown, which still joins. So this is a latent hang, not a live one.g.completed_seq = g.completed_seq.max(batch_seq);closes it.with_sinksetswriter_stopped = truewhen the thread fails to spawn, andnote()returns early onwriter_stopped. Nothing reachespending, so the "or failed to spawn" branch inflush_boundedwrites nothing and the run's keys are silently not recorded. If keys should survive that case,note()could still push whilefallback_pathis set.Not tested: no build or run of this head on our side.
AI use: Gemini (Antigravity) did a first-pass review; Claude Code (Claude Opus 5.5) checked both points against the source at
ad798f3band wrote this.@luckyteagirl on GitHub · 2026-11-26 04:14 UTC · original · reviewed
Usedis held in astatic OnceLock, so itsJournal::Drop(which joins and drains the worker) does not run on ordinary process exit. Afternote()returns, the writer can wait up toCOALESCE_WINDOW(25 ms) before opening/writingused-pipelines.txt; if the title exits during that window, those last-used keys are lost. The old synchronous path appended them before returning. Could the normal shutdown path explicitly flush/join this journal, and could a subprocess test record a key then exit without dropping a localJournal? The current drop test only covers a stack-owned journal.ad798f3b5cto24e584cab1@Decodere on GitHub · 2026-11-26 06:56 UTC · original
@KDenKC Good catches on both points — pushed
24e584caaddressing both:completed_seq:writer_loopnow storesg.completed_seq = g.completed_seq.max(batch_seq), so a slow batch completing after a timed-outflush_bounded()fallback drain can never regresscompleted_seqbelowenqueued_seq.Journal::note()now continues queuing keys whilefallback_path.is_some()even ifwriter_stoppedis set, andJournal::shutdown()also drains any remainingpendingkeys tofallback_pathso bothflush_bounded()andshutdown()persist keys ifxcl-pso-usedfails to spawn.used_flush_bounded_timeout_and_spawn_failure_fallback_are_soundcovering both cases; re-verified release WARP & RTX 4060pso_async::(19/0/0), full release workspace (1440/0/47), and paired 60 s RTX 4060 smoke (1582frames,60 60 60,0removals/crashes).@KDenKC on GitHub · 2026-11-26 07:14 UTC · original
Checked at
24e584ca:writer_loopstorescompleted_seq.max(batch_seq), andnote()keeps queuing while afallback_pathexists. Both points are addressed, thanks @Decodere.AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.
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.