Repository navigation
D3D12.X: a pipeline a draw went without keeps its priority past its wait budget - #3307
grahamster2 wants to merge 2 commits 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)
…ait budget When a bind's wait budget runs out (resolve_within), the pipeline is late: its draws or dispatches are left out until it is built. Its build was then made unwanted like any other (Build::unwant): the preload worker building it went back to THREAD_PRIORITY_LOWEST, and at the huge-compile gate it stood among all other unwanted builds, in no order. With the gate's queue of 21 huge compiles seen on an RTX 3080 (each waiting 90 - 213 s), a pipeline the title was actively drawing with did not catch up. A late build is still needed, so it is not demoted: - unwant leaves a late build's preload worker at its normal priority, and a preload worker that starts a build already late (or wanted) raises itself to normal (run_build, run_reserved_rebuild); it is set back to the lowest when the build ends (RunningBuild::drop); - at the gate (big_compile_turn_late, from huge_compile_turn and the AMD medium compute lane) a late build with its commit free (Slots::late_waiting) takes a freed slot before other unwanted builds, after a wanted one. One short of commit holds nobody back, and the others are woken at once when it stops counting (or takes its slot) instead of on their next 50 ms look. A build ahead of its pipeline's first use is never late there. Its queue place stays Foreground (from want) as before. A build the title skips through resolve_spared (XCL_PSO_IMAGE_SKIP=1) is marked late too and gets the same treatment: a preload worker builds it at a normal priority, and at the gate it goes before the other unwanted builds. The slot limits, the wanted cap and the commit headroom (halved for a late huge build, full in the medium lane) are unchanged. Tests: a_late_build_takes_a_freed_slot_before_other_unwanted_ones, a_late_build_keeps_its_preload_worker_raised (both fail before this change), a_build_late_when_it_starts_runs_raised_and_its_worker_is_lowered_after. Assisted-by: Claude Code (Claude Opus 5.5)
|
A waiter can briefly wait behind its own old priority when a bind times out. At 8d89ba9 I exercised the production Slots, SlotGuard::drop, big_compile_turn_late and count_waiting with one occupied slot and one waiting build. The first wanted() poll returned true (the bind still waiting). On the first poll after releasing the slot, wanted() returned false and late() true, representing expiration of the bind's budget. Commit was sufficient throughout; no other waiter or wakeup was involved. Across five bounded Windows/Ryzen 7 5700X3D trials, staying wanted required two polls and admitted immediately after release. Wanted → late required three polls in 5/5: the waiter still contributed 1 to wanted_waiting when computing behind, removed that registration later in the loop, then slept with the slot empty. Observed release-to-receipt time was 61.7–63.3 ms here (the programmed LOOK is 50 ms). The symptom is one avoidable timed wait; these are synthetic gate times, not frame or driver timings. I tested a narrow predicate change: compare wanted_waiting against usize::from(wanted_queued), and late_waiting against usize::from(late_queued), instead of zero when checking behind. Thus only other waiting registrations count. Both cases then required two polls in all five paired controls and the slot, wanted and late counts returned to zero. This exercised the production gate with worker handoff stubbed; the pending-build registry and actual driver work weren't part of this test. #3284 handles admission of speculative work into the build-ahead backlog upstream of this gate. OpenAI Codex prepared and ran the focused test and drafted this comment. Follow-up: both roles registered behind an occupied one-slot gate. At release, I changed one waiter from wanted to late while the competitor remained wanted; then separately from late to ordinary while the competitor remained late. The genuine higher-priority waiter acquired first in all 5 trials of each case, on both stock and candidate. All four counters (occupancy, urgent, wanted, late) returned to zero. The single-waiter control again took three polls on stock and two with the candidate. The competitor test synchronizes the free-slot state change with demotion; the single-waiter control releases via the production SlotGuard destructor. No worker-priority changes are required for this admission fix. Apply-checked diff: --- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -5622,7 +5622,8 @@
let is_late = !is_wanted && !ahead && late();
let open = slots.ahead || !ahead;
let behind = !is_wanted
- && (slots.wanted_waiting.load(Ordering::Acquire) > 0 || (!is_late && slots.late_waiting.load(Ordering::Acquire) > 0));
+ && (slots.wanted_waiting.load(Ordering::Acquire) > usize::from(wanted_queued)
+ || (!is_late && slots.late_waiting.load(Ordering::Acquire) > usize::from(late_queued)));
// (a late build short of commit does not hold the others back)
let mut short = false;
if open && *n < cap && !behind { |
|
On
Both calls returned the stand-in and set A focused fix could publish late state before enqueue and raise an already registered preload worker under the demand lock on the first transition to late. The test synchronized the two orderings using a synthetic job with the build already marked sent. It measures Windows worker priority only; compile-gate ordering, driver compile time and game frame time are separate. AI disclosure: OpenAI Codex developed and ran the fixture and drafted this report. |
|
I verified a worker-priority correction against if !p.build.late.load(Ordering::Acquire) {
let demand = p.build.demand.lock().unwrap();
if !p.build.late.swap(true, Ordering::AcqRel) {
Build::set_priority(&demand, windows_sys::Win32::System::Threading::THREAD_PRIORITY_NORMAL);
}
}This shares the demand lock with registration of the preload thread in The same-thread control ran a second speculative build after the spared one. When demand came first, the sampled priorities were 0 → 0 → −2 (job start / after demand / next speculative job). When demand arrived during the job they were −2 → 0 → −2; the after-demand value on stock was −2. All 13 backlog tests passed with this change and the new regression. This checks Windows worker priority only and can be applied independently of the AI disclosure: OpenAI Codex implemented and tested the local correction and drafted this follow-up. |
Merge-check run and written with Claude Code (Claude Opus 5.5): a test merge onto the base above, the full suite, and a 60 s |
|
Review (head 8d89ba9, diff read, not a merge-check; it conflicts with main, so not built or run). Stacked on #3306; this covers the top commit.
Fine: nothing changes by default (builds are only marked late with the AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
bmjask
left a comment
There was a problem hiding this comment.
Review of 8d89ba9e: 3 finding(s). 1 are inline. These are on lines outside the diff:
crates/xcl/src/hle/d3d12x/pso_async.rs:11388: resolve_spared stores build.late = true only after send_spared has handed the build to the backlog, and it never calls set_priority. With XCL_PSO_IMAGE_SKIP=1, send_spared pushes and calls notify_one. An xcl-pso-ahead worker wakes, and run_build's runs_raised() reads late=false before this store, so it stays at THREAD_PRIORITY_LOWEST for the whole compile. The same happens if the build was already running ahead on a backlog worker: setting late raises nothing, since only want/add_waiter call set_priority. So the claim that a preload worker builds spared pipelines at normal priority isn't guaranteed. A Build::mark_late() that stores late and raises the worker under the demand lock would cover all these cases.
crates/xcl/src/hle/d3d12x/pso_async.rs:4354: Not certain about this one: build_is_backlog_only still treats a late build (preload_thread != 0, not wanted) as backlog-only. A late compute pipeline with a multi-piece dispatch chain therefore builds every piece serially on its one preload thread instead of spreading them over the normal workers, so it catches up much more slowly than the "a late build is still needed" treatment suggests.
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.
| let mut demand = build.demand.lock().unwrap(); | ||
| demand.preload_thread = unsafe { GetCurrentThreadId() }; | ||
| if build.wanted.load(Ordering::Acquire) { | ||
| if build.runs_raised() { |
There was a problem hiding this comment.
Build::late is never cleared, so once a pipeline has been late, later Priority::Speculative replacement rebuilds (request_rebuild_on/request_rehydrate_on) see runs_raised() true and run at NORMAL. At the gate, used is true and late() is true, so they're counted in late_waiting with halved headroom and block other unwanted builds, even though the title isn't drawing without them.
Stacked on #3306 (pr/huge-pso-handoff, "D3D12.X: a pipeline that must wait for a compile slot leaves its worker free"); only the top commit belongs here. It uses that PR's
Slots::wanted_waitingandParkedWorker::top_up.When a bind's wait budget runs out (
resolve_within), the pipeline is late: its draws or dispatches are left out until it is built. Its build was then made unwanted like any other (Build::unwant). The preload worker building it went back toTHREAD_PRIORITY_LOWEST, and at the huge-compile gate it stood among all other unwanted builds, in no order. With the gate's queue of 21 huge compiles seen on an RTX 3080 (each waiting 90–213 s), a pipeline the title was actively drawing with did not catch up.A late build is still needed, so it is not demoted:
unwantleaves a late build's preload worker at its normal priority. A preload worker that starts a build already late (or wanted) raises itself to normal (run_build,run_reserved_rebuild), and it is set back to the lowest when the build ends (RunningBuild::drop).big_compile_turn_late, fromhuge_compile_turnand from both callers of the AMD 128–256 KiB compute lane), a late build with its commit free (Slots::late_waiting) takes a freed slot before other unwanted builds, after a wanted one. A late build short of commit holds nobody back; when it stops being counted, or takes its slot, the others are woken at once instead of on their next 50 ms look. A build ahead of its pipeline's first use is never late there.Builds that
resolve_sparedsends off (pipelines binds do not wait for,XCL_PSO_IMAGE_SKIP=1) are marked late as well, so they get the same treatment: a preload worker builds them at a normal priority, and they go before other unwanted builds at the gate.The slot limits, the wanted cap and the commit headroom (halved for a late huge build, full in the medium lane, as before) are unchanged.
No issue.
What is in it
crates/xcl/src/hle/d3d12x/pso_async.rs:Build::runs_raised(wanted or late), used byrun_build,run_reserved_rebuildandRunningBuild::drop;unwantkeeps a late build's worker priority.crates/xcl/src/hle/d3d12x/real.rs:Slots::late_waiting,big_compile_turn_late(huge, giant and medium lanes),count_waiting(returns whether the count changed, for the wake-up).a_late_build_takes_a_freed_slot_before_other_unwanted_onesanda_late_build_keeps_its_preload_worker_raisedfail without the change (checked by dropping thelate_waitingcheck and thelateguard inunwant);a_build_late_when_it_starts_runs_raised_and_its_worker_is_lowered_after(not late / late / wanted at the start, and the priority afterRunningBuild::drop). The gate test polls against 10 s deadlines instead of sleeping a fixed 120 ms, and waits for each thread with a deadline before joining it.Tested
cargo build --release -p xcl)8d89ba9e36ae5a069c54791ce2fbd763e6b954ee:cargo build --workspaceok;cargo test --workspace -- --test-threads=4: 2616 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_PSO_IMAGE_SKIP=1, AMD GPUs (the medium lane), other titles.AI use