D3D12.X: a pipeline that must wait for a compile slot leaves its worker free #3306
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3306"
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?
Imported from ivall/xcl. Originally posted by grahamster2 on 2026-11-29T06:54:40Z.
On an RTX 3080 in a retail title, pipeline building stood still in game. All
xcl-psoworkers and helpers were parked at the huge-compile gate, the window said "driver 1 building (21 waiting for a slot)" with 1000+ pipelines queued, and the game ran at 0–2 fps with a black screen (draws without a built pipeline are left out). In the log, 21 huge compiles (667 KB – 1.08 MB of DXIL) each waited 90–213 s at the gate for 4–21 s of driver work.Root cause: a gated compile on a normal worker (huge: ≥ 256 KB of DXIL,
XCL_HUGE_PSO_CONCURRENCYdefault 1; also the 4 MiB giant lane and AMD's 128–256 KiB compute lane) parks it inbig_compile_turn. A helper took the parked worker's place in the queue, but no more helpers than normal workers were started (compile_threads). The helpers took huge builds too and parked behind the same slot. Once every worker and helper stood at the gate, nothing served the queue.The parked build stays on its thread: its driver call is made of what that thread holds (descriptors and DXIL on its stack, known only after translation and DXC). That thread waits for the slot and builds it, and the result is delivered as before. What changes is the seat in the queue: every parked normal worker or helper now gets a replacement, up to
XCL_HUGE_PSO_HANDOFFS(default twice the normal workers, never fewer than them, at most 512). Each helper builds pipelines too and takes memory, so one is started only while 3 GB of commit is free (the floor the huge gate itself waits for); a parked build that found no headroom tries again on each 50 ms look while it waits (the counts are checked first, so commit is only asked while a helper is missing; like before, a helper is started with the gate's lock held). The slot limits and the commit gate are unchanged.With many unwanted builds waiting at once, a wanted one (a title thread waits for it) must not lose a freed slot to them: while one waits (
Slots::wanted_waiting), no unwanted build takes a slot. This only changes anything in a lane where the wanted cap equals the unwanted one (wanted_most == most): the giant lane (1 / 1), orXCL_HUGE_PSO_WANTED_CONCURRENCY/XCL_MEDIUM_PSO_WANTED_CONCURRENCYset equal to their unwanted counterparts. With the defaults of the huge (1 / 2) and AMD medium lanes, a wanted build has slots of its own above the unwanted cap that no unwanted build takes, so there it changes nothing.No issue.
What is in it
crates/xcl/src/hle/d3d12x/pso_async.rs:handoff_most(XCL_HUGE_PSO_HANDOFFS, default 2× the normal workers);park_for_big_compile/ParkedWorker::top_up/may_add_helperstart a helper only under the bound and with 3 GB of commit free (real::big_compile_commit_free);HANDED_OFFcounts helpers actually started, shown as "N workers handed off at the compile gate" on the pipeline line.crates/xcl/src/hle/d3d12x/real.rs:big_compile_turnretries a helper while it waits;Slots::wanted_waiting; an unwanted build does not take a slot while a wanted one waits.README.md:XCL_HUGE_PSO_HANDOFFSnext to the huge / medium compile knobs.helpers_parked_at_the_gate_are_replaced_tooandan_unwanted_build_leaves_a_free_slot_to_a_waiting_wanted_onefail without the change (checked by putting back thecompile_threadsbound and dropping thewanted_waitingcheck);parked_workers_start_no_helper_without_commit_and_none_past_the_bound(no commit headroom: no helper; 2 parked with a bound of 1: one helper, the queue still served);a_helper_starts_only_under_the_bound_and_with_commit_free;the_handoff_bound_is_never_below_the_workers. The wanted-slot test polls against a 10 s deadline instead of sleeping a fixed 120 ms. The queue tests that park workers take the commit as free and get their bound passed, so they depend neither on the machine's commit nor onXCL_HUGE_PSO_HANDOFFS. The job of the existing testgraphics_first_use_carries_the_exact_serialized_recipe_identitynow builds no pipeline: it releases its stand-in without waiting for the build, and a build-ahead worker finishing that orphan released the fake0x4332as a COM object. With an earlier version of the new test that parked every normal worker, thexcllib test binary aborted that way (misaligned pointer dereference inxcl-pso-ahead-N) in 3 of 6used_tests::runs; main had 0 of 5. After both changes: 5 of 5 passed.In game (development build, not this head)
Two 300 s+ runs of the same retail title on this machine, on a development branch (main plus a page-alias port and other changes, with
XCL_HUGE_PSO_CONCURRENCY=2 XCL_HUGE_PSO_WANTED_CONCURRENCY=3, 11 compile threads), with the previous version of this change. They differ only inXCL_HUGE_PSO_HANDOFFS. The counter there still counted parked builds, not started helpers.xcl.log:a pipeline worker waits for a huge compile slot – a helper serves its queue meanwhile (64 helpers so far)at 166.8 s, and at 295.6 s… 181 with 256 KB of DXIL or more), 87 huge builds handed off, …. Free RAM from the run's monitor:XCL_HUGE_PSO_HANDOFFS=8:… (8 helpers so far)at 105.7 s, and at 348.8 s… 206 with 256 KB of DXIL or more), 49 huge builds handed off, …. Free RAM went down to 2.5 GB once and then stayed between 4.1 and 6.4 GB:Tested
cargo build --release -p xcl)3db78f6f96f102714a2e232552e44cfecf4e8147:cargo build --workspaceok;cargo test --workspace -- --test-threads=4: 2613 passed, 0 failed, 49 ignoredSKIPPEDlines on this adapter (no wave64 on NVIDIA, no heap windows, no D3D12 debug layer):SKIPPED gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: f64, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64SKIPPED gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu: mask_ff0_flbit, wave64: no wave64SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windowsSKIPPED hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap: no heap windows (opt-in: XCL_HEAP_WINDOWS=1)SKIPPED the title under the debug layer (dred: false): no d3d12SDKLayers.dllSKIPPED the title under the debug layer (dred: true): no d3d12SDKLayers.dllSKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))Regression run
scripts/smoke.ps1 -Game <title folder> -Seconds 60 -StartupTimeoutSeconds 900withXCL_DEVICE_TYPE=lockhart XCL_PREPARE=0(Series S mode as in the contributor's runs; no startup shader preparation, so pipelines are built in game) (smoke.ps1 setsXCL_NETWORK=0); same retail title, same settings for both runs. Both stay on the title's first screens (about 660 draws per 2 s) for the 60 s.main:
this PR's head:
Not tested
xcl.log:D3D12.X: lazy pipelines: 60744 made (58002 graphics), 4305 built (4305 before their first use, 3 with 256 KB of DXIL or more), 0 workers handed off at the compile gate, 54864 translated ahead, 56431 in the build-ahead backlog; binds waited 0 ms for pipelines being built (0 waits in 2 s).AI use
Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T08:22:31Z.
Ran the compile-gate handoff tests at
3db78f6fon an NVIDIA Blackwell desktop part.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib helpers_parked_at_the_gate_are_replaced_too -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib an_unwanted_build_leaves_a_free_slot_to_a_waiting_wanted_one -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib parked_workers_start_no_helper_without_commit_and_none_past_the_bound -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib a_helper_starts_only_under_the_bound_and_with_commit_free -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib the_handoff_bound_is_never_below_the_workers -- --test-threads=1: 1 passed, 0 failed, 0 ignored.What this adds
All five new tests pass: parked workers and helpers get replacements at the huge-compile gate, helpers respect the commit floor and the bound, a wanted build keeps a free slot, and the bound never drops below the worker count. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti on driver 32.0.16.2140. These are scheduler tests; I did not reproduce the 0-2 fps title freeze from the description.
Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T14:50:16Z.
Current-main audit (2026-11-29): real starvation bug, but not mergeable with this handoff bound.
The queue-progress fix is cache-key safe and the tests exercise the reported all-workers-parked condition. The critical risk is memory amplification: a parked worker spawns a replacement; that replacement can translate another huge job, park, and spawn another, up to twice the normal worker count (potentially hundreds). The 3 GiB headroom check is only a snapshot and reserves nothing, so many helpers can pass it concurrently and then retain large DXIL/descriptors while waiting at the same gate. This can convert a queue stall into commit exhaustion—the failure the gate is meant to prevent.
Prefer a bounded continuation/waiting queue, or at minimum a much smaller reserved handoff budget with explicit per-helper commit reservations and a stress test proving peak commit stays bounded. The required Windows check is also currently red and needs a current-main rerun.
Cache impact: safe; scheduling only. Disposition: revise design, then re-review.
Review assisted by Codex; exact model name was not exposed in this session. No game/sweep was run.
Imported from ivall/xcl. Originally posted by minimalhipster990 on 2026-11-29T21:57:14Z.
A retail repro of this starvation on an RTX 4090, with thread stacks. During the stalls system commit had only 0.9–1.9 GB free, below the 3 GB this PR needs to start a helper. With this PR, 2 of 3 runs reached 600 s; the third stalled the same way and then the GPU hung.
Setup
main7a649b0e+ #3318f5496479+ #33440f0cc342, release (local merge966f035b).3db78f6f, a clean merge (local2bdf7abe).cargo test --release --locked -p xcl --lib -- helpers_parked_at_the_gate_are_replaced_too an_unwanted_build_leaves_a_free_slot_to_a_waiting_wanted_one parked_workers_start_no_helper_without_commit_and_none_past_the_bound --test-threads=1: 3 passed, 0 failed.XCL_GFX_PSO_WAIT_MS=50 XCL_CS_PSO_WAIT_MS=200 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_COHERENT_HEAPS=sparse XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=3990 XCL_TWO_PASS_MB=3072. Thread stacks come fromXCL_THREAD_DUMP_AT, named with the build's PDB.The stall without this PR. It happened in 8 of 11 runs: 1 of 4 plain runs, and 7 of 7 runs with
XCL_LOOK_STATS=2. Each time, presents, submits, draws and I/O stopped at 189–495 s and stayed at 0 until 600 s, with no device removal. The only warning is the 1 s pipeline wait below. In the run with dumps every 30 s, 181 of 185 threads had the same stack from 210 s to 570 s:The title's submitting thread was waiting with no budget for a compute pipeline:
All 15
xcl-pso-N, all 15xcl-pso-hN(thecompile_threadsbound) andxcl-pso-wholewere inreal::huge_compile_turn, 28 of them underfinish_two_pass. No thread was in a driver or DXC compile, and the DXC pool and preload workers were idle.In 6 of the 8 stalls the log shows "thread N has waited 1000 ms for a compute pipeline still being built" within a second of the last present. In all 8, "a pipeline worker waits for a huge compile slot – a helper serves its queue meanwhile (16 helpers so far)" comes earlier, at 160–230 s.
System commit during the stalls: 0.9–1.9 GB free. That is below the 3 GB headroom (1.5 GB for a late build), so no parked build could start. Nothing in the process asked for more commit, so the page file did not grow either.
As far as I can tell the build the title waited for was still in the queue: a wanted build skips the commit wait, and with no slot taken it would have started. This matches your description. On plain
mainresolve_for_indirectalso waits with no budget unlessXCL_PSO_WAIT_MSis set, so this is not from #3318.With this PR (3 runs)
resolve_for_indirect→until_done, and 14xcl-pso-N, the one helper left, the 3xcl-pso-pre-Nandxcl-pso-wholeinhuge_compile_turn. With commit under 3 GB, no new helper could start.0x887a0006(DEVICE_HUNG), DRED state 3, and twonvlddmkmevent 153 entries in the System log at that time, with 619 MB of system commit left. I don't know whether the hang comes from this PR. None of my runs without it ended in0x887a0006: they ran on, stalled, or (with the 512 MB heap) were removed with0x887a0005.Not tested: more runs (the stall comes and goes, so 3 runs say little either way),
XCL_HUGE_PSO_HANDOFFSother than the default, this PR onmainalone, and a larger page file.AI use: Claude Code (Claude Opus 5.5) built the trees, ran the tests and replays, named the stacks and wrote this report. The person running these tests asked for it.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:08:44Z.
merge-check
base:
d0832e614fhead:
3db78f6f96merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2895 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (pso_async.rs +224/-22, real.rs +63/-6, README). By default at most 2x the normal workers run as helpers (main: as many as the workers), only while 3 GB of commit is free, and an unwanted build no longer takes a compile slot while a wanted one waits. Findings: (1)
may_add_helper(~4100) now needs 3 GB free to start a helper, where main started one regardless. With less than 3 GB free and every normal worker parked on an unwanted huge build (each also waiting for 3 GB), nothing serves the queue, including a pipeline a bind waits for with no budget, which a helper would build on main. (2) The default limit 2x(cores-1) follows the CPU, not the RAM: on a 32-thread CPU it's 62, about the 64 that ran the author's machine out of RAM, and the default wasn't run in game. (3) It raises the limit rather than removing it: once more huge builds are queued than workers plushandoff_most, every thread parks again. (4) Main'sc110ed8d(huge-compile slots scale with free commit) landed after this PR's base, so the "1 / 2" defaults and in-game runs in the description predate it. (5) The wanted-first slot rule (real.rs ~5610) is a separate change. The PR's CI run failed 4 pipeline_library / warm_library tests outside this diff (3 entries instead of 2, then a poisoned lock); #3307 carries this same commit and passed, so it looks intermittent; they all pass in the run above. Fine: no wakeup can be lost (50 ms re-check plusnotify_allwhen a slot frees), thewanted_waitingcount is balanced on every exit, helpers retire as before, and the new test fails with main's one-helper-per-worker limit.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (60b1c015): 1516 -> 1666 frames shown (109 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17766 MB, 0 device removals, 0 crashes.verdict: not yet: with less than 3 GB of free commit no helper starts, so a queue whose normal workers are all parked on unwanted huge builds stops serving even a pipeline a bind waits for (finding 1), and the default limit follows the CPU rather than the RAM
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:37Z.
Code review location:
crates/xcl/src/hle/d3d12x/pso_async.rs; line 4100Helpers now start only with 3 GB of commit free (
may_add_helper && commit_free()), which removes the old guarantee that every parked normal worker gets a replacement. With less than 3 GB of commit left (e.g. 16 GB RAM, small pagefile), every normal worker takes a huge/medium build and parks inbig_compile_turn, unwanted builds also wait oncommit_free, andtop_uprefuses a helper on every look. Nothing serves the Foreground/BoundSoon queue, so small pipelines that need no gate or headroom stand still until commit frees up. That's the freeze this PR describes. The PR also notes the commit check didn't prevent the RAM exhaustion it saw, so this check protects little and disables the fix exactly where commit is tight.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:37Z.
Code review location:
crates/xcl/src/hle/d3d12x/pso_async.rs; line 4051HELPER_COMMIT_HEADROOMis documented as the floor a huge compile waits for, buthuge_compile_turnusesheadroom_for(bytes, late), which halves it to 1.5 GB for late builds. With 1.5-3 GB of commit left, late builds pass the gate and wanted builds bypass commit, yettop_uprefuses every helper. Workers parked on slot contention get no replacement, so the queue stalls while the gate itself would let builds proceed. Both should come from the sameheadroom_forsource.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:37Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 5610behindis computed before the build removes its own count fromwanted_waiting, so a build that was wanted and just became unwanted (the title gave up afterXCL_GFX_PSO_WAIT_MS) is blocked by its own stale count. It refuses a free slot, decrements afterwards and sleeps a full LOOK (50 ms), and another build may take the slot. No notify is sent whenwanted_waitingdrops either, so unwanted builds blocked only bybehindsit until their timeout.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:37Z.
Review: COMMENTED
Review of
3db78f6f: 3 finding(s). 3 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.