Skip to content

Shaders: stop startup shader preparation promptly when cancelled - #2830

Draft
Flamingo572 wants to merge 1 commit into
xcl-dev:mainfrom
Flamingo572:shaders/cancel-preparation
Draft

Flamingo572 wants to merge 1 commit into
xcl-dev:mainfrom
Flamingo572:shaders/cancel-preparation

Conversation

@Flamingo572

@Flamingo572 Flamingo572 commented Nov 26, 2026 •

Copy link
Copy Markdown

Follow-up to #2555. Closing the startup shader preparation window sets LaunchPreparation::cancel, which precompile() previously checked only at the outer record loop. While a split compute shader, a multi-variant record, or a driver slot wait inside Pipelines::make_one was running, cancellation had to wait until those inner loops or driver slot waits finished.

What is in it

  • crates/xcl/src/shaders.rs:
    • Add is_cancelled(Option<&AtomicBool>) and Pipelines::make_with_cache_path_cancel (preserving Pipelines::make and Pipelines::make_with_cache_path under #[cfg(test)]), checking cancellation before and during split compute piece builds.
    • Thread Option<&AtomicBool> into Pipelines::make_one, using a bounded 50 ms Condvar::wait_timeout while driver build slots are busy and exiting early before uncached CreateComputePipelineState builds.
    • Propagate startup.map(|p| &p.cancel) in precompile() across compute builds, the whole-form split fallback, completion counters, and inner fssm / programs / jobs loops.
    • Add two tests in pipeline_cap_tests (cancelled_split_compute_build_skips_pieces_and_writes_no_blobs and cancelled_pipeline_waiter_exits_while_driver_slots_are_busy), using recomp::runner::skip_test when DXC/D3D12 is unavailable.

Tested

  • Head d6cf64c19c6b38e31e3f2df31631481fcf6e56b0 (amended from 069292cadbe4fa31e19b2b282b25325ae6eaf0d8 to add #[cfg(test)] on make and make_with_cache_path, clearing the dead_code warning).
  • Hardware: NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.1742), AMD Ryzen AI 7 350 w/ Radeon 860M (AMD Radeon 860M driver 32.0.22042.8003), Windows NT 10.0.26300.0, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), Windows SDK DXC 1.9.2602.17 (10.0.26100.0), debug.
  • cargo build --workspace: exited 0 (0 warnings in crates/xcl/src/shaders.rs).
  • cargo test -p xcl --lib pipeline_cap_tests -- --nocapture: 5 passed, 0 failed, 0 ignored (0 skipped; both new cancelled_* tests ran on NVIDIA GeForce RTX 5060 Laptop GPU).
  • cargo test -p xcl --lib -- --skip fuzz_validate_and_gpu --test-threads=4: 1316 passed, 0 failed, 27 ignored (SKIPPED GPU tests: 21 no wave64, 3 refused per-lane f16/f32 forms, 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record cannot disable the driver cache (Windows Developer Mode is required)).
  • cargo test --workspace --test '*' --no-fail-fast -- --test-threads=4: 128 passed, 0 failed, 20 ignored (SKIPPED: 2 debug-layer e2e tests no d3d12SDKLayers.dll, 1 heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows, 1 uploads_start_from_each_subresources_state: no D3D12 debug layer).
  • Earlier .\scripts\test.ps1 on 069292ca stopped in xcl --lib because gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0,1,2,3} hit pre-existing RTX 5060 CreateComputePipelineState E_OUTOFMEMORY (0x8007000E) on seeds 70, 545, 1019, and 1507 (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905), including serially (--test-threads=1).

Regression run
Pending Windows 11 run of scripts/smoke.ps1 on main (8b957bec) and PR head d6cf64c19c6b (no retail GDK title available locally).

Not tested

AI use

  • Antigravity (Neon): investigated the post-xcl run: prepare shaders in the game window before title execution #2555 cancellation gap, implemented the cancellation checks and tests in crates/xcl/src/shaders.rs, and opened the initial draft PR.
  • Antigravity (Gemini 4 Neon (Medium)): ran Windows 11 GPU tests on RTX 5060 Laptop GPU, added #[cfg(test)] to clear the dead_code warning, re-verified tests, and updated this PR description.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / Wine release check of the cancellation primitives, paired with main.

Tested

  • Head 069292cadbe4fa31e19b2b282b25325ae6eaf0d8 against main 8b957bec6f82495aec940944c6bf47faa02db590.
  • RX 9070 16 GB (RADV GFX1201, PCI 1002:7550), Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, Mesa 26.3.1-arch3.5, GE-Proton11-12 Wine 11.0 Staging, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC/DXIL 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.
  • Explicit RX 9070 selection, XCL_NETWORK=0, one DXC worker, two pipeline slots, private enabled caches; inherited XCL_* flags cleared first.
  • Original tests unchanged. Both source copies receive a local synthetic probe and a cfg(test) atomic observer immediately before the real condition-variable wait. Test-only wrappers call the cancel-aware primitive on head and the existing primitive on main. Removing the additions reconstructs the pinned source hashes.

Original module

shaders::pipeline_cap_tests::, once with one test thread and once with four:

Source Passed / failed / ignored, each run
Main 3 / 0 / 0
Head 5 / 0 / 0

Both new cancellation tests ran without capability skips. The existing stale-cap regression also dispatched its synthetic control and verified gpu_word0=42 on each source/thread setting.

Observed wait and native controls

Three fresh serial processes per source, alternating source order. The local probe compiles three owned HLSL inputs: two split pieces and a distinct whole fallback. It calls the inner pipeline helpers directly; it does not launch a preparation window or guest.

Local helper case Main Head
Cancellation already set: two pieces plus whole call 3 native PSOs, 3 blobs 0 native PSOs, 0 blobs
Flag cleared, fresh cache: same calls 3 additional PSOs, 3 blobs 3 PSOs, 3 blobs
Cancel after observed CV-wait entry, slots still busy stays blocked returns before manual slot release
Waiter PSOs after cleanup 1 0

For the wait case, both slots are marked busy. The test waits for the observer, sets the cancel flag and watches for return without releasing a slot or externally notifying the CV. Only after return or a two-second observation timeout does it release the slots, notify and join the thread. In every head run it observed return first; in every main run return followed cleanup. Slots were still 2/2 before cleanup and returned to zero afterwards.

The uncancelled positive control succeeds on both versions, with identical DXIL and positive-cache filenames/blob bytes across all six processes. No pipeline was refused. The local probe constructs 30 PSOs in total and verifies every 112-byte driver blob. It does not dispatch these three probe shaders; GPU execution above belongs to the separate existing gpu_word0=42 control.

Head probe: 1/0/0 in each process. Main probe: expected 0/1/0, at the final pre-cancelled-build assertion after both controls and blocked-waiter cleanup. All ten completed harness summaries, counters, cache files, source reconstruction and executable hashes were independently checked; no runtime skips or ignored tests.

One additional Wine launch failed before libtest with recvmsg: Connection reset by peer. The identical invocation was retried once and passed; the failed log is retained separately from the ten completed runs.

Build: cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. Under GE-Proton Wine, run the libtest executable with shaders::pipeline_cap_tests:: --nocapture --test-threads=1 / 4; local probe shaders::workflow_cancelled_pipeline_checks_native_controls --exact --nocapture --test-threads=1.

Not tested

Cancellation during an in-flight DXC or native driver call, restored-cache cancellation races, the actual preparation UI/guest launch, all multi-record startup loops, other GPUs, native Windows, full suite, retail inputs, scripts/smoke.ps1, performance or FPS. This report covers the inner cancellation primitives and their native positive controls, not a hard scheduling-latency guarantee.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the diff, added the local probe/observer, ran the original module and paired native checks, independently verified the evidence and drafted this report. Publication authorized by the account owner.

@CryingLaughing

Copy link
Copy Markdown

Independent Windows verification on exact head 069292cadbe4fa31e19b2b282b25325ae6eaf0d8 and parent 8b957bec6f82495aec940944c6bf47faa02db590. RTX 4080 driver 621.01, Core i5-13600K, Windows 11 25H2 build 26200.9974, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11, debug.

cargo test -p xcl --lib --locked -j 2 --no-run built successfully. The exact libtest binary ran both shaders::pipeline_cap_tests::cancelled_ cases serially and reported 2 passed, 0 failed, 0 ignored, with no capability skips. The cases covered leaving no driver blobs after an already-cancelled split build and returning from driver-slot admission while all slots were occupied. The separate hle::d3d12x::present::preparation::tests:: selection passed 3/3, including closing before READY preventing handoff.

The launcher preparation window and these checks share the cancellation flag. This covered the pipeline and preparation-screen state below the window. The busy-slot fixture uses its timed entry delay. A live window-close run and cancellation during an active native compiler or driver call remain outside this check.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Overlap with #2179 (open), from reading both diffs, no run. #2179 replaces this driver-slot wait in make_one with acquire_running(), a plain condvar wait, and adds an OfflineGate wait (a 50 ms wait_timeout loop). Neither checks a cancel flag.

Whichever of the two merges second needs to pass cancel into both waits. Otherwise a cancel while all slots, or the commit gate, are busy waits again for a driver compile to finish. cancelled_pipeline_waiter_exits_while_driver_slots_are_busy is the test that would catch it.

AI-assisted (Claude Code, Claude Opus 5.5).

Closing the startup shader preparation window (xcl-dev#2555) sets LaunchPreparation::cancel, which precompile() only checked at the outer record loop. Thread the cancellation flag into Pipelines::make_with_cache_path_cancel, Pipelines::make_one (bounded Condvar wait while driver slots are busy), the whole-form split fallback, and the inner FSSM/program/job loops.
@Flamingo572
Flamingo572 force-pushed the shaders/cancel-preparation branch from 069292c to d6cf64c Compare November 26, 2026 18:43
@Flamingo572

Copy link
Copy Markdown
Author

Thank you @SzczepanGrela and @CryingLaughing for testing 069292ca, and thank you @upipibi for flagging the overlap with #2179 (acquire_running() and OfflineGate).

I force-pushed an amended head d6cf64c19c6b38e31e3f2df31631481fcf6e56b0 (no runtime changes from 069292ca; only added #[cfg(test)] to Pipelines::make and Pipelines::make_with_cache_path in crates/xcl/src/shaders.rs to clear the dead_code warning) and updated the PR description with Windows 11 + RTX 5060 Laptop GPU test results.

If anyone with a retail GDK title can run a paired scripts/smoke.ps1 regression check against main (8b957bec) and d6cf64c19c6b (I don't have a title locally to generate the xcl-smoke blocks), I'd really appreciate it so we can get PR description green and take this out of draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants