D3D12.X: a pipeline a draw went without keeps its priority past its wait budget #3307
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3307"
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:44Z.
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
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T07:06:13Z.
A waiter can briefly wait behind its own old priority when a bind times out. At
8d89ba9eI 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:
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T07:08:28Z.
On
8d89ba9eI found an ordering where the spared image-only build is marked late but its active preload worker stays at THREAD_PRIORITY_LOWEST. A channel-synchronized Windows fixture ran productionrun_buildand the spared branch ofresolve_wait_pending; the worker sampled its own priority using GetThreadPriority.Both calls returned the stand-in and set
build.late = true. In the second case,run_buildhas already recorded the preload thread ID and checkedruns_raised().resolve_sparedsets the atomic late flag but never raises that registered thread. Productionresolve_pendingcan already send a spared build before the dispatch goes throughresolve_spared. Even whenresolve_sparedsends it itself, the enqueue and wake precede the late store.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.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T07:22:21Z.
I verified a worker-priority correction against
8d89ba9e. Inside the0 =>arm ofresolve_spared, replace the late store currently aftersend_sparedwith this block before thesent.swap/ enqueue:This shares the demand lock with registration of the preload thread in
run_buildand its removal inRunningBuild::drop. If demand arrives first, the worker sees late at startup. If the worker registered first, the setter raises that worker before the demand call returns. Subsequent binds already marked late take the atomic fast path.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
Slotsgate change.AI disclosure: OpenAI Codex implemented and tested the local correction and drafted this follow-up.
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:58:02Z.
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
scripts/smoke.ps1run of a retail title against main on the same machine. The 4fuzz_validate_and_gpu_*failures happen on main on this machine too.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:23:46Z.
Review (head
8d89ba9e, diff read, not a merge-check; it conflicts with main, so not built or run). Stacked on #3306; this covers the top commit.a_build_ahead_keeps_its_pieces_on_threads_of_its_own, whose doc comment main's281f32earewrote. Not superseded: main only halves the commit headroom for a late build, and this PR keeps that.RunningBuild::drop,run_build,unwant/set_priority,run_reserved_rebuild), and #3336 addsnormal_thread, which the late check inunwantdoesn't cover. Whichever lands second needs rework. #3318 doesn't conflict textually but sends recorded draws throughresolve_within, so more builds become late.resolve_sparedqueues the build (send_spared,pso_async.rs~11386) before settinglate(~11388), and nothing raises a worker that already started it, so such builds can run at the lowest priority for their whole build, while the description says late builds run at normal priority. Settinglatebefore sending would fix it.late_waitingcount directly instead of racing a real late build against a real unwanted one.Fine: nothing changes by default (builds are only marked late with the
XCL_*PSO_WAIT_MSvariables orXCL_PSO_IMAGE_SKIP=1, and with none late the rewritten gate decides as before), a late build short of commit can't block the others, the priority tests are right, andlateis set beforeunwantinresolve_within.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:39Z.
Review: COMMENTED
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_sparedstoresbuild.late = trueonly aftersend_sparedhas handed the build to the backlog, and it never callsset_priority. With XCL_PSO_IMAGE_SKIP=1,send_sparedpushes and calls notify_one. An xcl-pso-ahead worker wakes, andrun_build'sruns_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: settinglateraises nothing, since onlywant/add_waitercallset_priority. So the claim that a preload worker builds spared pipelines at normal priority isn't guaranteed. ABuild::mark_late()that stores late and raises the worker under thedemandlock would cover all these cases.crates/xcl/src/hle/d3d12x/pso_async.rs:4354: Not certain about this one:build_is_backlog_onlystill 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T22:12:40Z.
Code review location:
crates/xcl/src/hle/d3d12x/pso_async.rs; line 4191Build::lateis never cleared, so once a pipeline has been late, later Priority::Speculative replacement rebuilds (request_rebuild_on/request_rehydrate_on) seeruns_raised()true and run at NORMAL. At the gate,usedis true andlate()is true, so they're counted inlate_waitingwith halved headroom and block other unwanted builds, even though the title isn't drawing without them.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.