Repository navigation
D3D12.X: a pipeline that must wait for a compile slot leaves its worker free - #3306
grahamster2 wants to merge 1 commit into
Conversation
…er free On an RTX 3080 pipeline building stood still in game: the window said "driver 1 building (21 waiting for a slot), ... 1000+ pipelines queued", 0 - 2 fps and 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 (huge: >= 256 KB of DXIL, XCL_HUGE_PSO_CONCURRENCY default 1; also the giant lane and AMD's medium compute lane) on a normal worker parks it in big_compile_turn. A helper took the parked worker's place in the queue, but no more helpers than normal workers were started (compile_threads), and the helpers took huge builds too and parked behind the same slot. Once every worker and every helper stood at the gate, nothing served the queue. The driver call of a parked build is made of what its thread holds (the descriptors and DXIL on its stack, known only after translation and DXC), so the build stays on that thread, which waits for the slot and builds it; its result is delivered as before (complete, done/cv, cache publish). 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), so normal builds go on. Each helper builds 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 while it waits. On a development branch a bound of 64 drained the queue in game but ran the machine out of RAM. 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. That only matters in a lane where wanted_most == most (the giant lane, or the environment set so); elsewhere a wanted build has slots of its own. The wanted cap and its commit bypass are unchanged. The pipeline line counts "N workers handed off at the compile gate" (helpers actually started). README documents XCL_HUGE_PSO_HANDOFFS. Tests: helpers_parked_at_the_gate_are_replaced_too (2x the workers parked, a later build still runs; fails before this change), parked_workers_start_no_helper_without_commit_and_none_past_the_bound, a_helper_starts_only_under_the_bound_and_with_commit_free, an_unwanted_build_leaves_a_free_slot_to_a_waiting_wanted_one (fails before), the_handoff_bound_is_never_below_the_workers. The job of graphics_first_use_carries_the_exact_serialized_recipe_identity builds no pipeline now: that test releases its stand-in without waiting, and a build-ahead worker finishing the orphan released its fake 0x4332 as a COM object (the test binary aborted when the queue's normal workers were all parked). Assisted-by: Claude Code (Claude Opus 5.5)
|
Ran the compile-gate handoff tests at System
Results
What this adds Not tested 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. |
|
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. |
|
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
The stall without this PR. It happened in 8 of 11 runs: 1 of 4 plain runs, and 7 of 7 runs with
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 With this PR (3 runs)
Not tested: more runs (the stall comes and goes, so 3 runs say little either way), 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. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
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.
| pub(super) struct ParkedWorker(bool); | ||
| /// Whether one more helper may start: fewer than the parked workers and than `most`, and | ||
| /// commit free (asked last). | ||
| fn may_add_helper(helpers: usize, parked: usize, most: usize, commit_free: impl Fn() -> bool) -> bool { |
There was a problem hiding this comment.
Helpers 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 in big_compile_turn, unwanted builds also wait on commit_free, and top_up refuses 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.
|
|
||
| /// Commit a helper is started with at least: the floor a huge compile waits for at the gate | ||
| /// (`real::big_compile_headroom`). | ||
| const HELPER_COMMIT_HEADROOM: u64 = 3 << 30; |
There was a problem hiding this comment.
HELPER_COMMIT_HEADROOM is documented as the floor a huge compile waits for, but huge_compile_turn uses headroom_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, yet top_up refuses 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 same headroom_for source.
| let ahead = !is_wanted && ahead(); | ||
| let open = slots.ahead || !ahead; | ||
| if open && *n < cap && (is_wanted || commit_free()) && !(ahead && slots.urgent.load(Ordering::Acquire) > 0) { | ||
| let behind = !is_wanted && slots.wanted_waiting.load(Ordering::Acquire) > 0; |
There was a problem hiding this comment.
behind is computed before the build removes its own count from wanted_waiting, so a build that was wanted and just became unwanted (the title gave up after XCL_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 when wanted_waiting drops either, so unwanted builds blocked only by behind sit until their timeout.
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