Skip to content

D3D12.X: a bind that waits long on a pipeline's build makes a second copy - #754

Closed
abilliontokens wants to merge 3 commits into
xcl-dev:mainfrom
abilliontokens:pso-bind-helps-build
Closed

abilliontokens wants to merge 3 commits into
xcl-dev:mainfrom
abilliontokens:pso-bind-helps-build

Conversation

@abilliontokens

@abilliontokens abilliontokens commented Nov 24, 2026 •

Copy link
Copy Markdown

Please 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_background passed send = lazy to submit_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 cost lazy()'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 = !lazy restored, one fresh pair on main beaa245 (same input, same warm caches, the same background load in both, one run each):

main beaa245 this PR 614f2cc
title's watchdog crash at 109.2 s 98.4 s
presents 1562 1419
background pipelines (built, failed, lazy) 1168, 0, 57594 1284, 0, 57478

So 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 main against 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

  1. The second-copy mechanism itself (Pending.second, submit_second, resolve_wait's grace period).
  2. Review round: the copy moved off the title's thread onto an xcl-pso-help thread with a 64 MB stack, so the big-driver-compile slot and the 3 GB commit gate take it (they only take xcl-pso* threads), the waiter stays interruptible, and XCL_PSO_HELP_MS=0 really is off.
  3. This round: send = !lazy; the copy is dropped once a pipeline exists (it held an Arc to 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 at THREAD_PRIORITY_LOWEST holding 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 the xcl-pso-help thread; complete picks the first successful build, releases the other and drops the copy.
  • crates/xcl/src/hle/d3d12x/real.rs: go_background supplies the copy's build (!lazy); SharedDesc shares the descriptor read-only.
  • Tests: 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 pins submit_second's contract; it does not cover go_background's call site, which needs a device — that is how the inverted send got past me.

Tested

  • RTX 5060 Ti 16 GB (32-lane waves), driver 621.24; Ryzen 5 7600X; 32 GB RAM; Windows 11 26200; Rust 1.100.0; SDK DXC 1.8.2502.11. Tests in a debug build, title runs in a release build.
  • cargo test --workspace -- --test-threads=4 on 614f2cc: 716 passed, 0 failed, 41 ignored. SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • The world-loading pair above.

Regression run
Main beaa245:

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: NVIDIA GeForce RTX 5060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2514 (PresentX 2514)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15805 MB

This PR 614f2cc:

xcl-smoke v1
commit: 614f2cc48465da9e5204bb8cd20a246988374a0b
gpu: NVIDIA GeForce RTX 5060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2498 (PresentX 2498)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16212 MB

Not tested

  • Gameplay is not reached; the title still ends at its watchdog during world loading.
  • AMD, and wave64 hardware.
  • Repeated runs: the world-loading pair is one run each on a contended machine, which is why I draw no positive conclusion from it.

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.

@JoaoPauluu

JoaoPauluu commented Nov 24, 2026 •

Copy link
Copy Markdown

Test report: #754 under Wine (Linux, NVIDIA): GTA VI regression pair

A retail-title run of this PR's head 149850e against main 64b3f35 under Wine / vkd3d-proton. No device removals or crashes, and frames within what smoke.sh / pr_check.py ask for.

Setup

build frames shown first presents at draws in XCL's activity lines removals / crashes
64b3f35 958, 966 22 s, 22 s 12204, 12513 0 / 0
149850e 881, 1029 28 s, 22 s 6556, 12888 0 / 0
  • The first PR run started presenting about 6 s later than the others and showed fewer frames (881, 92 % of the first main run); 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.
xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 958 (PresentX 959)
presents per 2 s (last 3): 48 44 0
device removals: 0
crashes: 0
peak commit: 0 MB
xcl-smoke v1
commit: 149850ea4191667357bbfc0223d8ef67484505ca
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 881 (PresentX 881)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 0 MB

(The first pair. peak commit: 0 MB is XCL reading 0 MB committed under Wine, see #257.)

Not tested

  • The test suite on this branch; Windows, AMD; world loading (past 60 s); the picture

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.

@bstillbstill

Copy link
Copy Markdown

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_background inverts lazy creation. Before, a lazy pipeline was submitted with send = false (submit_lazy) and an eager one with send = true (submit). Now it is:

super::pso_async::submit_second(*ppv as usize, compute, job, lazy, if lazy { key } else { 0 }, second);

so with lazy creation on (the default) every pipeline goes to the workers when it is made, and with XCL_LAZY_PSO=0 none does until its first bind. send should be !lazy. This matches the PR's own table: 50 987 background pipelines built against 121 / 866 on main, 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 cost lazy()'s comment describes: ~51 000 pipelines, ~400 KB each in the driver) rather than from the second copy. A run with send = !lazy would separate the two.

2. second is kept for the life of the pipeline. Only resolve_wait takes it; complete doesn't clear it. So each pending entry keeps its unused second job, and with it an Arc to the OwnedDesc, until the title releases the stand-in. Before, the descriptor was dropped once the worker's job ran. Not measured here; clearing p.second in complete would 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

  • NVIDIA RTX 3090 Ti, Windows 11 Pro 10.0.26300, Rust 1.100.0, DXC 1.9.2609, debug.
  • cargo test --workspace -- --test-threads=4 on 149850e: 702 passed, 0 failed, 41 ignored. a_bind_waiting_on_a_slow_worker_builds_a_second_copy passes. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.

Not tested

  • No title run or smoke run on this hardware.
  • The memory effect in point 2 and the runtime effect of point 1 were not measured, only read from the code.

@CowboyBingus

Copy link
Copy Markdown

In go_background (crates/xcl/src/hle/d3d12x/real.rs, the submit_second call at 149850e), the third argument is send = lazy:

let lazy = super::pso_async::lazy();
super::pso_async::submit_second(*ppv as usize, compute, job, lazy, if lazy { key } else { 0 }, second);

On main the lazy branch calls submit_lazy, which does not send, and the other branch calls submit, which sends. In this PR's pso_async.rs, submit passes send = true and submit_lazy passes false, so send = lazy inverts both:

  • with lazy pipelines on (the default), every pipeline goes to the workers when it is created;
  • with 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 on lazy() 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

Copy link
Copy Markdown

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 main 64b3f35 (clean pick, local branch, so
the 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.

Build Frames stop Crash Peak commit
main 64b3f35 ~60 s +0x23cf683 write to 0 at 105.9 s 29.0 GB
#754 on main, warm ~60 s +0x23cf683 write to 0 at 108.9 s 30.8 GB
#754 on main, cold (first run of the new binary) – +0x53664a8 read of 0xffffffffffffffff at 130.5 s 31.3 GB

Free 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 on xcl-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_wait the PR writes
if let Some(job) = p.job.lock().unwrap().take() { … } else { … }. The crate is edition 2021,
where a temporary in the if let scrutinee lives until the end of the whole if … else, so the
job guard is still held in the else branch: during the 250 ms wait, the second-copy build and
the final wait. Main's let job = p.job.lock().unwrap().take(); drops it at once. In a
non-invasive cdb snapshot of the #754 build during loading, three of the title's render threads
were parked in Mutex::lock_contended inside resolve_wait on that Mutex<Option<Job>>.
Splitting it back into a let would keep the rest of your change as is.

Test suite and setup

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.

abilliontokens added a commit to abilliontokens/xcl that referenced this pull request Nov 24, 2026
…s own

Review of xcl-dev#754 found three faults in building the second copy on the
waiting title thread:

- the thread was inside the build when the worker finished, so a bind whose
  worker was computing returned at max(worker, 250 ms + copy) instead of the
  worker's own time: slower, not faster, in the common case;
- the one-big-driver-compile-at-a-time slot and the 3 GB commit gate take
  only threads named xcl-pso* (real::translated_compute_pso), so a copy on a
  title thread ran a ~1.5 GB driver compile outside both;
- translation recurses deeply and a title's thread may have a 1 MiB stack,
  while XCL's own build threads get 64 MB.

The copy now goes to an xcl-pso-help thread with a 64 MB stack: the gates
take it for one of theirs, and the waiting thread goes back to the condvar,
so the worker finishing first still wakes it at once.

Two more from the same review: XCL_PSO_HELP_MS=0 is documented as off and
now is (it used to help without waiting at all), and a copy that fails no
longer finalises the pipeline as failed - the worker's build still decides,
instead of every later dispatch of it being skipped. Its test is new.

Assisted-by: Claude Code (Claude Opus 5.5)
…copy

A compute pipeline's first bind waits for its build. When a worker is
already building it, the title's thread waited on that one build for as
long as it took: on a retail title's world loading (RTX 5060 Ti, main
f4ce27c) cdb showed 10 of 11 DXC threads and 10 of 11 pipeline workers
parked, one build in flight, and the render thread in resolve_wait's
condvar. Frames stopped, and the title's watchdog crashed it at +0x23cf683
at 93-101 s on four runs (xcl-dev#232, xcl-dev#581), with and without xcl-dev#690's preloading.

After a grace period (250 ms; XCL_PSO_HELP_MS, 0 = off) the waiting thread
builds a second copy itself, and the first of the two to finish is the
pipeline (complete: the later one is released). go_background supplies the
second copy's build; the descriptor is shared read-only (SharedDesc). A
pipeline no run used still waits for its worker as before.

Measured, same input and caches, 300 s runs that reach world loading:
crash at 152.6 s instead of 93.4 / 100.4 s; 2669 frames instead of 1324 /
1443; background pipelines built 50987 against 121 / 866 on main. It does
not reach gameplay: the next wait on the title's thread is the title-texture
write-watch refresh (xcl-dev#551) and XMemMapPhysicalPagesScatter (xcl-dev#156).

Assisted-by: Claude Code (Claude Opus 5.5)
…s own

Review of xcl-dev#754 found three faults in building the second copy on the
waiting title thread:

- the thread was inside the build when the worker finished, so a bind whose
  worker was computing returned at max(worker, 250 ms + copy) instead of the
  worker's own time: slower, not faster, in the common case;
- the one-big-driver-compile-at-a-time slot and the 3 GB commit gate take
  only threads named xcl-pso* (real::translated_compute_pso), so a copy on a
  title thread ran a ~1.5 GB driver compile outside both;
- translation recurses deeply and a title's thread may have a 1 MiB stack,
  while XCL's own build threads get 64 MB.

The copy now goes to an xcl-pso-help thread with a 64 MB stack: the gates
take it for one of theirs, and the waiting thread goes back to the condvar,
so the worker finishing first still wakes it at once.

Two more from the same review: XCL_PSO_HELP_MS=0 is documented as off and
now is (it used to help without waiting at all), and a copy that fails no
longer finalises the pipeline as failed - the worker's build still decides,
instead of every later dispatch of it being skipped. Its test is new.

Assisted-by: Claude Code (Claude Opus 5.5)
@Anon64

Anon64 commented Nov 24, 2026

Copy link
Copy Markdown

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_AT every 5 s, RTX 3060 12 GB (581.80, wave32), Windows 11 26200. The build was main f4ce27c plus #640, #628 and #708 merged locally; main alone stalls at the same point.

Who holds the pipeline the title waits for: one of #690's xcl-pso-pre-* threads, at THREAD_PRIORITY_LOWEST.

  • Two of the title's threads, in the dumps at 95, 100 and 105 s (frames stopped at ~90 s, watchdog at 116 s):
    bind::set_pipeline_state → real::bind_pipeline → pso_async::resolve_for_bind (pso_async.rs:403) → resolve_wait (pso_async.rs:392) → Condvar::wait
  • All 31 xcl-pso-* workers and all xcl-dxc-* threads idle; three of the four xcl-pso-pre-* idle.
  • xcl-pso-pre-0 inside nvwgf2umx.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 and resolve_wait finds its job already taken.

With XCL_PSO_PRELOAD=0 (same build) the stall comes anyway, later: the title's thread waits in bind::execute_indirect (bind.rs:271) → resolve_wait, and in each dump one xcl-pso-* thread at a time is in nvgpucomp64.dll while the rest idle, so the title takes its compute pipelines one after another.

On main beaa245 (with #795 / #797, no Wait64BitValueX timeouts 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.

Three faults found in review of xcl-dev#754:

- go_background passed `send = lazy` to submit_second, inverting lazy
  creation: with it on (the default) every pipeline a title made went to the
  workers at once, and with XCL_LAZY_PSO=0 none did until its first bind. A
  retail title makes ~51 000 pipelines in its first 30 s and uses few, which
  is what `lazy` exists to avoid, so the measurements in the description
  carried that cost rather than the second copy's effect. It is `!lazy` now.
- The copy was kept for the life of the pipeline, holding the descriptor its
  build reads; `complete` drops it once there is a pipeline.
- A build that failed could win over a success still being built. The first
  build that *succeeds* is the pipeline now; a failure no longer takes its
  place, and the later result is released.

The test pins submit_second's own contract: a pipeline with a second copy is
built on its first use, not before, and an eager one is built without a use.
It does not cover go_background's call (that needs a device).

Thanks to bstillbstill and CowboyBingus for the inverted `send`, and to
bstillbstill for the other two.

Assisted-by: Claude Code (Claude Opus 5.5)
@CowboyBingus

Copy link
Copy Markdown

Confirmed: at 614f2cc, go_background passes !lazy to submit_second, so the inversion I reported above is fixed, and a_lazy_pipeline_with_a_second_copy_waits_for_its_first_use covers it. Thanks.

AI use: checked with Claude Code (Claude Opus 5.5); I read the diff.

@raylitebull

Copy link
Copy Markdown
Member

Closing per the author's note withdrawing / marking this PR do-not-merge.

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.

7 participants