D3D12.X: a pipeline a draw went without keeps its priority past its wait budget #3307

Open
grahamster2 wants to merge 2 commits from upstream-pr/3307 into main
grahamster2 commented 2026-11-29 06:54:44 +00:00 (Migrated from github.com)

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_waiting and ParkedWorker::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 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. 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).
  • At the gate (big_compile_turn_late, from huge_compile_turn and 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_spared sends 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 by run_build, run_reserved_rebuild and RunningBuild::drop; unwant keeps 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).
  • Tests: a_late_build_takes_a_freed_slot_before_other_unwanted_ones and a_late_build_keeps_its_preload_worker_raised fail without the change (checked by dropping the late_waiting check and the late guard in unwant); a_build_late_when_it_starts_runs_raised_and_its_worker_is_lowered_after (not late / late / wanted at the start, and the priority after RunningBuild::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

  • NVIDIA GeForce RTX 3080 10 GB, driver 610.88; AMD Ryzen 5 7600X; Windows 11 build 10.0.26200.9974; rustc 1.94.0 (4a4ef493e 2026-03-02); tests in the debug profile, smoke runs on a release build (cargo build --release -p xcl)
  • on 8d89ba9e36ae5a069c54791ce2fbd763e6b954ee: cargo build --workspace ok; cargo test --workspace -- --test-threads=4: 2616 passed, 0 failed, 49 ignored
  • 29 SKIPPED lines 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 wave64
    • SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
    • SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
    • SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
    • SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
    • SKIPPED 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 wave64
    • SKIPPED 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 wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
    • SKIPPED 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 wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: f64, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
    • SKIPPED gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu: mask_ff0_flbit, wave64: no wave64
    • SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
    • SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
    • SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
    • SKIPPED 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.dll
    • SKIPPED the title under the debug layer (dred: true): no d3d12SDKLayers.dll
    • SKIPPED 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 900 with XCL_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 sets XCL_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:

xcl-smoke v1
commit: fa204595a488c60c6c5f905244f0172072c9c2a9
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1680 (PresentX 1680)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 12321 MB

this PR's head:

xcl-smoke v1
commit: 8d89ba9e36ae5a069c54791ce2fbd763e6b954ee
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 12292 MB

Not tested

  • The benefit in game is not measured: no in-game run of this commit. The smoke run above is of this branch's head, which includes the commit it is stacked on, and stays on the title's first screens (no late huge build at the gate).
  • The immediate wake-up when a late build stops being counted has no test of its own (it only saves up to one 50 ms look).
  • XCL_PSO_IMAGE_SKIP=1, AMD GPUs (the medium lane), other titles.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code and tests, ran the tests and smoke runs, drafted this description. A separate Claude Code agent that did not write the change reviewed the diff adversarially and its findings were fixed before opening.
<!-- greyfinch-sync:ivall/xcl:issue:5548424701 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307). Originally posted by [grahamster2](https://github.com/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_waiting` and `ParkedWorker::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 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. 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`). - At the gate (`big_compile_turn_late`, from `huge_compile_turn` and 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_spared` sends 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 by `run_build`, `run_reserved_rebuild` and `RunningBuild::drop`; `unwant` keeps 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). - Tests: `a_late_build_takes_a_freed_slot_before_other_unwanted_ones` and `a_late_build_keeps_its_preload_worker_raised` fail without the change (checked by dropping the `late_waiting` check and the `late` guard in `unwant`); `a_build_late_when_it_starts_runs_raised_and_its_worker_is_lowered_after` (not late / late / wanted at the start, and the priority after `RunningBuild::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** - NVIDIA GeForce RTX 3080 10 GB, driver 610.88; AMD Ryzen 5 7600X; Windows 11 build 10.0.26200.9974; rustc 1.94.0 (4a4ef493e 2026-03-02); tests in the debug profile, smoke runs on a release build (`cargo build --release -p xcl`) - on `8d89ba9e36ae5a069c54791ce2fbd763e6b954ee`: `cargo build --workspace` ok; `cargo test --workspace -- --test-threads=4`: 2616 passed, 0 failed, 49 ignored - 29 `SKIPPED` lines 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 wave64` - `SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64` - `SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64` - `SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64` - `SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64` - `SKIPPED 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 wave64` - `SKIPPED 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 wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64` - `SKIPPED 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 wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: f64, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64` - `SKIPPED gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu: mask_ff0_flbit, wave64: no wave64` - `SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64` - `SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64` - `SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows` - `SKIPPED 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.dll` - `SKIPPED the title under the debug layer (dred: true): no d3d12SDKLayers.dll` - `SKIPPED 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 900` with `XCL_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 sets `XCL_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: ``` xcl-smoke v1 commit: fa204595a488c60c6c5f905244f0172072c9c2a9 gpu: NVIDIA GeForce RTX 3080 title: 5d6132ca seconds: 60 exit: 0x0 frames shown: 1680 (PresentX 1680) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 12321 MB ``` this PR's head: ``` xcl-smoke v1 commit: 8d89ba9e36ae5a069c54791ce2fbd763e6b954ee gpu: NVIDIA GeForce RTX 3080 title: 5d6132ca seconds: 60 exit: 0x0 frames shown: 1678 (PresentX 1678) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 12292 MB ``` **Not tested** - The benefit in game is not measured: no in-game run of this commit. The smoke run above is of this branch's head, which includes the commit it is stacked on, and stays on the title's first screens (no late huge build at the gate). - The immediate wake-up when a late build stops being counted has no test of its own (it only saves up to one 50 ms look). - `XCL_PSO_IMAGE_SKIP=1`, AMD GPUs (the medium lane), other titles. **AI use** - Claude Code with Claude Opus 5.5: wrote the code and tests, ran the tests and smoke runs, drafted this description. A separate Claude Code agent that did not write the change reviewed the diff adversarially and its findings were fixed before opening.
andrewDoing commented 2026-11-29 07:06:13 +00:00 (Migrated from github.com)

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 8d89ba9e 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 {
<!-- greyfinch-sync:ivall/xcl:comment:7252262443 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#issuecomment-7252262443). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T07:06:13Z. --- A waiter can briefly wait behind **its own old priority** when a bind times out. At 8d89ba9e 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: ```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 { ```
andrewDoing commented 2026-11-29 07:08:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T07:08:28Z.


On 8d89ba9e I 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 production run_build and the spared branch of resolve_wait_pending; the worker sampled its own priority using GetThreadPriority.

First demand for the image-only pipeline During job, after demand After job
Before the preload worker starts 0 (NORMAL) -2 (LOWEST)
After the preload worker starts -2 (LOWEST) -2 (LOWEST)

Both calls returned the stand-in and set build.late = true. In the second case, run_build has already recorded the preload thread ID and checked runs_raised(). resolve_spared sets the atomic late flag but never raises that registered thread. Production resolve_pending can already send a spared build before the dispatch goes through resolve_spared. Even when resolve_spared sends 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.

<!-- greyfinch-sync:ivall/xcl:comment:7252286606 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#issuecomment-7252286606). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T07:08:28Z. --- On `8d89ba9e` I 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 production `run_build` and the spared branch of `resolve_wait_pending`; the worker sampled its own priority using GetThreadPriority. | First demand for the image-only pipeline | During job, after demand | After job | |---|---:|---:| | Before the preload worker starts | 0 (NORMAL) | -2 (LOWEST) | | After the preload worker starts | -2 (LOWEST) | -2 (LOWEST) | Both calls returned the stand-in and set `build.late = true`. In the second case, `run_build` has already recorded the preload thread ID and checked `runs_raised()`. `resolve_spared` sets the atomic late flag but never raises that registered thread. Production `resolve_pending` can already send a spared build before the dispatch goes through `resolve_spared`. Even when `resolve_spared` sends 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.
andrewDoing commented 2026-11-29 07:22:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T07:22:21Z.


I verified a worker-priority correction against 8d89ba9e. Inside the 0 => arm of resolve_spared, replace the late store currently after send_spared with this block before the sent.swap / enqueue:

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 run_build and its removal in RunningBuild::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 Slots gate change.

AI disclosure: OpenAI Codex implemented and tested the local correction and drafted this follow-up.

<!-- greyfinch-sync:ivall/xcl:comment:7252431650 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#issuecomment-7252431650). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T07:22:21Z. --- I verified a worker-priority correction against `8d89ba9e`. Inside the `0 =>` arm of `resolve_spared`, replace the late store currently after `send_spared` with this block **before** the `sent.swap` / enqueue: ```rust 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 `run_build` and its removal in `RunningBuild::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 `Slots` gate change. AI disclosure: OpenAI Codex implemented and tested the local correction and drafted this follow-up.
Foniass commented 2026-11-29 14:58:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:58:02Z.


merge-check
base: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
head: 8d89ba9e36ae5a069c54791ce2fbd763e6b954ee
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2622 passed, 4 failed, 49 ignored; SKIPPED: 44; failing: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (driver E_OUTOFMEMORY, same on base on this machine)
review: stacked on #3306; this merge includes #3306's commit, so it tests both. No bug found in the gate logic. Minor: build.late is set after send_spared queues the build, so a preload worker can still start a late build at the lowest priority. It only takes effect with the XCL_*_PSO_WAIT_MS / XCL_PSO_IMAGE_SKIP switches.
performance: 60 s smoke: 1675 frames (100.2 %), peak commit 16992 MB (94.7 %); the smoke run reaches no late build
verdict: safe to merge (after #3306, whose CI needs a rerun past the pipeline_library flake)
hardware / tool and model: RTX 5070 Ti (driver 32.0.16.2114), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

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.ps1 run of a retail title against main on the same machine. The 4 fuzz_validate_and_gpu_* failures happen on main on this machine too.

<!-- greyfinch-sync:ivall/xcl:comment:7257714270 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#issuecomment-7257714270). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T14:58:02Z. --- ```text merge-check base: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 head: 8d89ba9e36ae5a069c54791ce2fbd763e6b954ee merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2622 passed, 4 failed, 49 ignored; SKIPPED: 44; failing: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (driver E_OUTOFMEMORY, same on base on this machine) review: stacked on #3306; this merge includes #3306's commit, so it tests both. No bug found in the gate logic. Minor: build.late is set after send_spared queues the build, so a preload worker can still start a late build at the lowest priority. It only takes effect with the XCL_*_PSO_WAIT_MS / XCL_PSO_IMAGE_SKIP switches. performance: 60 s smoke: 1675 frames (100.2 %), peak commit 16992 MB (94.7 %); the smoke run reaches no late build verdict: safe to merge (after #3306, whose CI needs a rerun past the pipeline_library flake) hardware / tool and model: RTX 5070 Ti (driver 32.0.16.2114), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 ``` 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.ps1` run of a retail title against main on the same machine. The 4 `fuzz_validate_and_gpu_*` failures happen on main on this machine too.
Foniass commented 2026-12-01 04:23:46 +00:00 (Migrated from github.com)

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.

  • The conflict is test code only: the two new tests sit above a_build_ahead_keeps_its_pieces_on_threads_of_its_own, whose doc comment main's 281f32ea rewrote. Not superseded: main only halves the commit headroom for a late build, and this PR keeps that.
  • It conflicts with open #3336 in five hunks of the same worker-priority code (RunningBuild::drop, run_build, unwant / set_priority, run_reserved_rebuild), and #3336 adds normal_thread, which the late check in unwant doesn't cover. Whichever lands second needs rework. #3318 doesn't conflict textually but sends recorded draws through resolve_within, so more builds become late.
  • resolve_spared queues the build (send_spared, pso_async.rs ~11386) before setting late (~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. Setting late before sending would fix it.
  • Unwanted builds that aren't late can wait indefinitely while late builds keep coming.
  • The ordering test sets the late_waiting count 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_MS variables or XCL_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, and late is set before unwant in resolve_within.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7300690954 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#issuecomment-7300690954). Originally posted by [Foniass](https://github.com/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. - **The conflict is test code only:** the two new tests sit above `a_build_ahead_keeps_its_pieces_on_threads_of_its_own`, whose doc comment main's 281f32ea rewrote. Not superseded: main only halves the commit headroom for a late build, and this PR keeps that. - **It conflicts with open #3336** in five hunks of the same worker-priority code (`RunningBuild::drop`, `run_build`, `unwant` / `set_priority`, `run_reserved_rebuild`), and #3336 adds `normal_thread`, which the late check in `unwant` doesn't cover. Whichever lands second needs rework. #3318 doesn't conflict textually but sends recorded draws through `resolve_within`, so more builds become late. - `resolve_spared` queues the build (`send_spared`, `pso_async.rs` ~11386) before setting `late` (~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. Setting `late` before sending would fix it. - Unwanted builds that aren't late can wait indefinitely while late builds keep coming. - The ordering test sets the `late_waiting` count 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_MS` variables or `XCL_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, and `late` is set before `unwant` in `resolve_within`. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-01 22:12:39 +00:00 (Migrated from github.com)

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_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.

<!-- greyfinch-sync:ivall/xcl:review:6141077621 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#pullrequestreview-6141077621). Originally posted by [bmjask](https://github.com/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_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._
bmjask commented 2026-12-01 22:12:40 +00:00 (Migrated from github.com)

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 4191

@@ -4117,7 +4188,7 @@ fn run_reserved_rebuild(build: Arc<Build>, recipe: Recipe) {
     if preload {
         let mut demand = build.demand.lock().unwrap();
         demand.preload_thread = unsafe { GetCurrentThreadId() };
-        if build.wanted.load(Ordering::Acquire) {
+        if build.runs_raised() {

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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4761752720 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3307#discussion_r4761752720). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-01T22:12:40Z. **Code review location:** `crates/xcl/src/hle/d3d12x/pso_async.rs`; line 4191 ~~~~diff @@ -4117,7 +4188,7 @@ fn run_reserved_rebuild(build: Arc<Build>, recipe: Recipe) { if preload { let mut demand = build.demand.lock().unwrap(); demand.preload_thread = unsafe { GetCurrentThreadId() }; - if build.wanted.load(Ordering::Acquire) { + if build.runs_raised() { ~~~~ --- `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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3307:upstream-pr/3307'
git switch 'upstream-pr/3307'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3307'
git switch 'upstream-pr/3307'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3307'
git switch 'upstream-pr/3307'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3307'
git switch 'main'
git merge --squash 'upstream-pr/3307'
git switch 'main'
git merge --ff-only 'upstream-pr/3307'
git switch 'main'
git merge 'upstream-pr/3307'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3307
No description provided.