D3D12.X: a bind that waits long on a pipeline's build makes a second copy #754
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!754
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/754/head"
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?
@abilliontokens on GitHub · 2026-11-24 04:43 UTC · original
abilliontokens:pso-bind-helps-build→main· +201 −29 · 2 files · 3 commits · closed without mergingPlease do not merge this as it stands: the measurement that motivated it does not survive review. Details below — I would rather withdraw the claim than have it taken on trust.
A compute pipeline's first bind waits for its build. When a worker already has it, the title's thread waits for that one build however long it takes. On a retail title's world loading cdb showed the DXC threads and pipeline workers parked, one build in flight, and the render thread in
resolve_wait's condvar. The idea here: when the worker is still not done after a grace period (250 ms;XCL_PSO_HELP_MS, 0 = off), build a second copy on a thread of its own and let the first build that succeeds be the pipeline.Why the original numbers were wrong
go_backgroundpassedsend = lazytosubmit_second, which inverted lazy pipeline creation: with it on (the default) every pipeline the title made went to the workers as soon as it was created. The "93 s → 152 s" and "50,987 background pipelines" in the first version of this description were produced by that, not by the second copy — the costlazy()'s own comment warns about (~51,000 pipelines, ~400 KB each in the driver). Found independently by @bstillbstill and @CowboyBingus; thank you both.With
send = !lazyrestored, one fresh pair onmainbeaa245(same input, same warm caches, the same background load in both, one run each):mainbeaa245614f2ccSo the second copy shows no benefit here, and this pair is slightly worse. That agrees with the two independent runs posted on this PR: @Celegans12 measured 105.9 s on
mainagainst 108.9 s with the PR, and @JoaoPauluu's six 60 s runs under Wine show no separation. One run each and a contended machine, so the difference itself is noise — but there is no longer evidence for the benefit the PR was opened on.What the three commits are now
Pending.second,submit_second,resolve_wait's grace period).xcl-pso-helpthread with a 64 MB stack, so the big-driver-compile slot and the 3 GB commit gate take it (they only takexcl-pso*threads), the waiter stays interruptible, andXCL_PSO_HELP_MS=0really is off.send = !lazy; the copy is dropped once a pipeline exists (it held anArcto the descriptor for the pipeline's life); and the first build that succeeds wins, so a failure no longer displaces a success still being built.Commits 2 and 3 are corrections to commit 1. If the maintainer wants the mechanism dropped, commit 1 goes with it and nothing is lost; if it is kept, it needs a case where a worker is blocked rather than compiling — @Anon64's dumps on this PR show one (a
xcl-pso-pre-*thread atTHREAD_PRIORITY_LOWESTholding a build for over 100 s while the title waits on it), which is the shape this would get past.What the stall actually is. Measured on an RTX 5060 Ti: single compute pipelines take 68 s, 95 s and 204 s in NVIDIA's driver for 0.7–1.0 MB of translated DXIL (
compute PSO with the translated console CS (997968 B DXIL, 94926 ms)). An audit of the title's whole shader pack translated 26,698 of 26,698 programs with 0 errors, so the recompiler is not the cost; of 1,815 compute programs compiled, 654 exceed 256 KB of DXIL, 515 exceed 512 KB and 169 exceed 1 MB, and the title has not yet built one over 1 MB. That is #156, and no scheduling change in this PR addresses it.What is in it
crates/xcl/src/hle/d3d12x/pso_async.rs:Pending.second;resolve_wait's grace period and thexcl-pso-helpthread;completepicks the first successful build, releases the other and drops the copy.crates/xcl/src/hle/d3d12x/real.rs:go_backgroundsupplies the copy's build (!lazy);SharedDescshares the descriptor read-only.a_bind_waiting_on_a_slow_worker_builds_a_second_copy,a_second_copy_that_fails_leaves_the_workers_build_to_decide,a_lazy_pipeline_with_a_second_copy_waits_for_its_first_use. The last pinssubmit_second's contract; it does not covergo_background's call site, which needs a device — that is how the invertedsendgot past me.Tested
cargo test --workspace -- --test-threads=4on614f2cc: 716 passed, 0 failed, 41 ignored. SKIPPED:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).Regression run
Main
beaa245:This PR
614f2cc:Not tested
AI use
Claude Code (Claude Opus 5.5) wrote the change and the tests, ran the tests and runs above on my machine, and drafted this description. The three faults corrected in commits 2 and 3 were found by reviewers on this PR, not by me.
@bstillbstill on GitHub · 2026-11-24 05:03 UTC · original
Review + test run on
149850e(this PR's head). Written with Claude Code (Claude Opus 5.5), which checked each point against the code; the test run is from my machine.1.
go_backgroundinverts lazy creation. Before, a lazy pipeline was submitted withsend = false(submit_lazy) and an eager one withsend = true(submit). Now it is:so with lazy creation on (the default) every pipeline goes to the workers when it is made, and with
XCL_LAZY_PSO=0none does until its first bind.sendshould be!lazy. This matches the PR's own table: 50 987 background pipelines built against 121 / 866 onmain, and peak commit 30.4 GB vs 29.0–29.5 GB (smoke: 16 675 vs 15 473 MB). It also means part of the 93 s → 152 s improvement may come from building every pipeline up front (the costlazy()'s comment describes: ~51 000 pipelines, ~400 KB each in the driver) rather than from the second copy. A run withsend = !lazywould separate the two.2.
secondis kept for the life of the pipeline. Onlyresolve_waittakes it;completedoesn't clear it. So each pending entry keeps its unused second job, and with it anArcto theOwnedDesc, until the title releases the stand-in. Before, the descriptor was dropped once the worker's job ran. Not measured here; clearingp.secondincompletewould avoid it.3. The first build to finish wins even if it failed. If one copy fails (
real == 0) first, it becomes the result, and a later successful copy is released. Probably rare, but "first successful build wins" seems like the intent.Question: why does a second copy of the same build finish sooner than the worker's? The unit test models a worker that is slow for its own reasons (a 3 s sleep). If the worker is slow inside the driver compile itself (#156), the title's thread now runs that same compile, which is what the draw path tried to keep off the title's thread. If the cdb dumps show the worker parked somewhere else (e.g. the DXC memory gate), saying so in the description would help.
Tested
cargo test --workspace -- --test-threads=4on149850e: 702 passed, 0 failed, 41 ignored.a_bind_waiting_on_a_slow_worker_builds_a_second_copypasses. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.Not tested
@JoaoPauluu on GitHub · 2026-11-24 05:03 UTC · original
Test report: #754 under Wine (Linux, NVIDIA): GTA VI regression pair
A retail-title run of this PR's head
149850eagainstmain64b3f35under Wine / vkd3d-proton. No device removals or crashes, and frames within whatsmoke.sh/pr_check.pyask for.Setup
experimental-11.0-20261112(wine-11.0), vkd3d-proton v3.1 (4522cc1a) + the patch from #257, DXVK from Proton, DXC 1.9.2609,DXVK_CONFIG="dxgi.hideNvidiaGpu = False"x86_64-pc-windows-gnu(mingw-w64-gcc 16.2.0), release buildsscripts/linux/smoke.shfrom #257,XCL_NETWORK=0. Order: main, #754, #757, #757, #754, main (the same twomainruns serve both reports)64b3f35149850emainrun); the second PR run showed the most frames of the six. This PR logs nothing when a second copy is built, so these runs don't show whether that happened. They are also only the first 60 s, not the world loading where the description saw the stall.(The first pair.
peak commit: 0 MBis XCL reading 0 MB committed under Wine, see #257.)Not tested
AI use: Claude Code (Claude Opus 5.5) built the commits, ran every run above on the machine above and wrote this report. The blocks and counts are pasted from those runs. The account owner asked for test reports to be posted while they were away and has not reviewed this one.
@CowboyBingus on GitHub · 2026-11-24 05:22 UTC · original
In
go_background(crates/xcl/src/hle/d3d12x/real.rs, thesubmit_secondcall at149850e), the third argument issend = lazy:On
mainthe lazy branch callssubmit_lazy, which does not send, and the other branch callssubmit, which sends. In this PR'spso_async.rs,submitpassessend = trueandsubmit_lazypassesfalse, sosend = lazyinverts both:XCL_LAZY_PSO=0, none does until its first bind.That matches the table in the description: 50,987 pipelines built in the background, against 121 on
main. So part of the watchdog moving from 93 s to 152 s may come from building everything up front rather than from the second copy. The comment onlazy()notes that building them all ran the process out of commit before.Suggested:
submit_second(*ppv as usize, compute, job, !lazy, if lazy { key } else { 0 }, second).Checked by reading the code (two independent reads against
main), not by a run.AI use: found by Claude Code (Claude Opus 5.5) while scouting PRs; I checked the call and both
submit*paths myself.@Celegans12 on GitHub · 2026-11-24 05:32 UTC · original
I ran #754 against the retail title on an NVIDIA laptop GPU to see whether it gets past the
world-loading watchdog. On this machine it doesn't: the run with the PR crashes at the same
point as main, and I think I can see why from a thread dump.
What I ran. Your commit cherry-picked onto
main64b3f35(clean pick, local branch, sothe only difference from main is this PR), release build. Same title, same save (setup and
terms already accepted), same scripted input (
XCL_PRESS_AT, A every 5–10 s),XCL_NETWORK=0,10-minute runs through
scripts/smoke.ps1.64b3f35+0x23cf683write to 0 at 105.9 s+0x23cf683write to 0 at 108.9 s+0x53664a8read of0xffffffffffffffffat 130.5 sFree physical RAM never dropped below 7.8 GB in any of these runs (sampled every 5 s), so on
this 32 GB machine it isn't the RAM exhaustion described in #646.
Why I think it doesn't help here. The second copy runs on the title's render thread, and it
skips
BIG_COMPILES(that slot is only taken onxcl-pso*threads). That's good for the slot,but the pipelines that block world loading are the big ones (100–316 KB of DXIL, seconds each in
the NVIDIA driver here), so after the 250 ms the render thread is compiling instead of waiting –
it still doesn't present, and the watchdog fires at the same time.
There's also a lock-scope detail worth a look. In
resolve_waitthe PR writesif let Some(job) = p.job.lock().unwrap().take() { … } else { … }. The crate is edition 2021,where a temporary in the
if letscrutinee lives until the end of the wholeif … else, so thejobguard is still held in theelsebranch: during the 250 ms wait, the second-copy build andthe final wait. Main's
let job = p.job.lock().unwrap().take();drops it at once. In anon-invasive cdb snapshot of the #754 build during loading, three of the title's render threads
were parked in
Mutex::lock_contendedinsideresolve_waiton thatMutex<Option<Job>>.Splitting it back into a
letwould keep the rest of your change as is.Test suite and setup
Rust 1.100 MSVC, DXC 1.9.2609.
cargo build --workspace && cargo test --workspace -- --test-threads=4on #754-on-main:702 passed, 0 failed, 41 ignored; SKIPPED:
gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).MiniDumpWriteDump(all other threads suspended, one held the heap lock) – the hang #742 is about.Not tested: AMD, other NVIDIA drivers, runs longer than 10 minutes, #754 on its own base
f4ce27c.AI use: Claude Code with Claude Opus 5.5 ran the builds and runs, read the dumps and drafted this;
I reviewed it before posting. Logs, report.json and the stack snapshot are available on request.
@Anon64 on GitHub · 2026-11-24 06:31 UTC · original
A data point for the case this PR's second copy covers, from thread dumps on a retail title's world loading (not a run of this PR). Release build with full symbols,
XCL_THREAD_DUMP_ATevery 5 s, RTX 3060 12 GB (581.80, wave32), Windows 11 26200. The build wasmainf4ce27cplus #640, #628 and #708 merged locally;mainalone stalls at the same point.Who holds the pipeline the title waits for: one of #690's
xcl-pso-pre-*threads, atTHREAD_PRIORITY_LOWEST.bind::set_pipeline_state→real::bind_pipeline→pso_async::resolve_for_bind(pso_async.rs:403) →resolve_wait(pso_async.rs:392) →Condvar::waitxcl-pso-*workers and allxcl-dxc-*threads idle; three of the fourxcl-pso-pre-*idle.xcl-pso-pre-0insidenvwgf2umx.dll's compiler in every dump from 50 s to 105 s; its last log line is at 7.8 s. One build held by a lowest-priority thread for over 100 s, while the title binds it at ~90 s andresolve_waitfinds itsjobalready taken.With
XCL_PSO_PRELOAD=0(same build) the stall comes anyway, later: the title's thread waits inbind::execute_indirect(bind.rs:271) →resolve_wait, and in each dump onexcl-pso-*thread at a time is innvgpucomp64.dllwhile the rest idle, so the title takes its compute pipelines one after another.On
mainbeaa245(with #795 / #797, noWait64BitValueXtimeouts left) single builds during the stall: 395 KB DXIL 14.6 s, 526 KB 20.7 s.So on this machine both shapes are there: a bind behind a starved build-ahead thread (what a second copy at normal priority gets past) and binds behind builds that are just long (#156, as you say). Whether the build-ahead one was slow because of its priority or because of the pipeline itself these dumps cannot tell.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
@CowboyBingus on GitHub · 2026-11-24 07:34 UTC · original
Confirmed: at
614f2cc,go_backgroundpasses!lazytosubmit_second, so the inversion I reported above is fixed, anda_lazy_pipeline_with_a_second_copy_waits_for_its_first_usecovers it. Thanks.AI use: checked with Claude Code (Claude Opus 5.5); I read the diff.
@raylitebull on GitHub · 2026-11-24 10:42 UTC · original
Closing per the author's note withdrawing / marking this PR do-not-merge.
Pull request closed