Skip to content

D3D12.X: a pipeline build that panics fails like a driver error instead of hanging its waiters - #3028

Closed
tiagonleal wants to merge 2 commits into
xcl-dev:mainfrom
tiagonleal:d3d12x/pipeline-build-panic
Closed

tiagonleal wants to merge 2 commits into
xcl-dev:mainfrom
tiagonleal:d3d12x/pipeline-build-panic

Conversation

@tiagonleal

Copy link
Copy Markdown
Contributor

A pipeline build that panics on a worker thread left its entry "building" forever. Waits without a budget (the submit-time waits) then never returned, the worker thread died so the pool shrank for the rest of the run, and in build_pieces the parent's recv blocked. This PR catches the panic at the three places a build job runs and records the result a failed driver build gives (0), so the existing failed-build path applies: binds get the stand-in pipeline and the run goes on.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: run(job) wraps the job in catch_unwind, logs a rate-limited warning (first 16, then powers of two) and returns 0. Used in build, in the bind-side build of resolve_wait_for and in build_pieces. Builds that do not panic are unchanged.
  • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs: the build_whole lock is taken with into_inner on poison. It guards () and the value is a OnceLock, so nothing can be half-updated; before, one panic made every later build of that chain fail.
  • THIRD_PARTY.md and the module header: provenance. The idea is adapted from victory-fork (https://github.com/fxceless/victory-fork, GPL-3.0-or-later), commit 46da5ee, crates/victory-gpu/src/pipeline/make.rs, Pending::make_with. No code was copied; XCL's version is its own three call sites. Credit for the mechanism goes to Filip Michalski, the author of that commit. Port tracked in [OFFICIAL] Swarm: ports from other GPL-3.0 projects into XCL #3011.
  • Test a_panicking_build_fails_and_the_workers_go_on: a panicking build releases its waiter with the stand-in; a second wait on the same pipeline returns at once; after compile_threads() + 1 more panicking builds a good build still completes on a worker thread (the job reports its thread name); no mutex is left poisoned.

Before this change the unwind crossed the title's call on the bind-side path. On a worker it was silent: the only trace was the panic hook's line, and the run looked like a GPU stall.

Tested

RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, on main 06f90c19.

  • cargo test -j 4 -p xcl --lib pso_async: 15 passed, 0 failed.
  • cargo test -j 4 -p xcl --lib dispatch_chain: 10 passed, 0 failed, 1 SKIPPED (no wave64 on this card).
  • With run changed to call the job directly, the new test fails on its 10 s wait and the log shows worker xcl-pso-0 dying. Restored afterwards.
  • cargo test -j 6 --workspace --no-fail-fast -- --test-threads=4: 1455 passed, 4 failed, 47 ignored, 25 SKIPPED lines. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState 0x8007000E); they fail the same way on main without this change.

Regression run

Both runs used XCL_PREPARE=0 and a filled XCL_DXIL_CACHE: with the default cache empty, the startup preparation of main does not finish inside the 120 s the script allows.

main 06f90c19:

xcl-smoke v1
commit: 06f90c1986f43698d0405eff3c2ab0af230e1ed9
gpu: NVIDIA GeForce RTX 5070 Ti
title: caf8267a
seconds: 60
exit: 0x0
frames shown: 1586 (PresentX 1586)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16546 MB

This PR 571aea4c:

xcl-smoke v1
commit: 571aea4c08ba62f0e453bd90d110283ace151f49
gpu: NVIDIA GeForce RTX 5070 Ti
title: caf8267a
seconds: 60
exit: 0x0
frames shown: 1689 (PresentX 1689)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14902 MB

Not tested

  • A real translator or driver panic in a title. I have not seen one in my runs; the test injects the panic.
  • AMD, Linux/Wine.

AI use

Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing with the supervision of @tiagonleal.

…waiters

A build closure that panicked on a pipeline worker unwound out of
`build` before `complete` ran: `done` stayed false, so a submit-time or
bind wait without a budget (`resolve_wait_for`) waited forever, and the
worker thread died with it, leaving one worker fewer for the rest of the
run. A panicking piece in `build_pieces` also left its parent waiting for
a result that never came.

Every build now goes through `run`, which turns a panic into the failed
result (0), so the existing failed-build path applies (the stand-in) and
the worker goes on. Builds that do not panic are unchanged. The idea is
adapted from victory-fork (xcl-dev#1353, GPL-3.0-or-later); see THIRD_PARTY.md.
The warning for a pipeline build that panicked now follows the file's
pattern (the first 16, then powers of two) and says that later builds may
fail too when the panic happened holding a lock. The one such lock a
build holds across translation and the driver call, a dispatch chain's
`build_whole`, guards no data (`whole` is a `OnceLock`), so it now takes
the lock back after a panic instead of failing every later build of that
chain.

The test now checks that a worker takes both the panicking build and the
next one, without the test's thread building them, and takes
WORKER_SATURATION_LOCK like the other worker tests. The provenance notes
name the victory-fork commit (46da5ee) instead of its PR number.
@JJAutoCompare

Copy link
Copy Markdown

Tested

CPU-only rerun on Windows 11 x64 build 26200.9974, AMD Ryzen 7 3800X, and Rust 1.100.0 MSVC. The pinned libtest executable was built from an archive of 571aea4c08ba62f0e453bd90d110283ace151f49 with a single 51-line #[cfg(test)] append to pso_async.rs. I verified the original module bytes, fixture append, and executable hash and reused the existing build.

Ran each filter in a separate process with --exact <filter> --test-threads=1 --nocapture and XCL_PSO_WAIT_MS=0:

  • hle::d3d12x::pso_async::local_bind_panic_tests::a_panicking_lazy_compute_bind_completes_and_the_next_bind_succeeds: the synthetic closure panicked on the binding thread through resolve_for_bind. The failed entry completed and subsequent binds of that entry returned the stand-in. The next lazy compute job on the same binding thread completed with its expected sentinel value. The fixture bounded completion with a five-second receive timeout.
  • hle::d3d12x::pso_async::used_tests::a_bind_of_a_shared_stand_in_gets_its_driver_pipeline: the unmodified checked-in control passed in the same overlay executable.

2 passed, 0 failed, 0 ignored, 0 skipped. Both processes exited 0.

Not tested

Real driver or translator panics, GPU execution, pre-fix behavior, full workspace suite, and retail smoke.

AI use

T3 Code / Codex (gpt-6.2-sol) wrote the synthetic fixture, verified the pinned artifacts, independently reran both tests, and wrote this report.

@tiagonleal
tiagonleal marked this pull request as ready for review November 27, 2026 14:58
@Anon64

Anon64 commented Nov 27, 2026

Copy link
Copy Markdown

RTX 3060 12 GB, retail title, 300 s: no regression. This PR's head 571aea4c against main 2c717a04, one run each, release, warm caches, XCL_ACTIVITY=1 XCL_NETWORK=0, 8 preparation threads, A pressed every 4 s from 20 s.

Both exit 0x0 with no device removals or crashes. Frames: 2 198 against 2 234 on main. Peak commit: 38 494 MB against 38 242 MB. Peak local video memory: 18 979 MB against 18 893 MB. Neither run gets past world load on this card in 300 s, and I didn't check whether a pipeline build panicked in either run. This is a regression check only.

Regression run

main:

xcl-smoke v1
commit: 2c717a043c8488938179fca81da4bb9e7913a358
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 2234 (PresentX 2234)
presents per 2 s (last 3): 6 6 5
device removals: 0
crashes: 0
peak commit: 38242 MB

this PR:

xcl-smoke v1
commit: 571aea4c08ba62f0e453bd90d110283ace151f49
gpu: NVIDIA GeForce RTX 3060
title: retail-1
seconds: 300
exit: 0x0
frames shown: 2198 (PresentX 2198)
presents per 2 s (last 3): 6 6 6
device removals: 0
crashes: 0
peak commit: 38494 MB

RTX 3060 12 GB (driver 581.80), i9-14900KF, 64 GB RAM, Windows 11 26200.

AI use: Claude Code (Claude Opus 5.5) built both commits, ran the title and wrote this report.

@thehollowedone

Copy link
Copy Markdown
Contributor

merge-check claim
head: 571aea4

1 similar comment
@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 571aea4

@thehollowedone

Copy link
Copy Markdown
Contributor

merge-check
base: 753e8b1a (main)
head: 571aea4c
merge: Clean trial merge into current main, no commit.
build: cargo build --workspace --locked passed.
tests: cargo test --workspace --locked --no-fail-fast -- --test-threads=4 on the unmodified merge: 1,512 passed, 1 failed, 47 ignored; 25 GPU skip notices. The new a_panicking_build_fails_and_the_workers_go_on test passed. The sole failure was console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet), which also fails with the same message on untouched base 753e8b1a in my filtered exact-base control (0 passed, 1 failed).
review: The helper returns the existing failed-build sentinel 0 after a panic. I checked its three current call sites: worker completion signals waiters, bind-side direct completion returns the stand-in, and split-piece construction receives one result per piece and releases successful pieces if any other piece fails. Chain::whole can retry after a poisoned build lock because its protected result is a OnceLock. The new checked-in regression covers the worker path, but the PR also says a panicking piece used to strand its parent. A focused test against production build_pieces verifies that distinct path: a panicking piece and a successful piece must return [0, 0x5C5C] within five seconds. On this PR's unmodified implementation plus that test-only addition it passed 1/0/0, no skip. Replacing only run(job) with the old job() at the piece call site made the same test fail 0/1/0 (a panicking piece held the parent wait: Disconnected). The collapsed diff below is this test-only addition; it was not pushed. It preserves the existing worker regression.
performance: No title build time or frame-rate comparison was run here. The normal build result is unchanged; the warning and failed-build sentinel occur only after an unwind.
verdict: not yet: include the direct build_pieces panic regression, then rerun the required checks on that head. The implementation passed the focused test and I found no source-level blocker in the changed paths.
hardware / tool and model: Windows 11 build 26300, RTX 3080 Ti 12 GiB / NVIDIA 621.35, rustc 1.99.1 MSVC, Windows SDK DXC 1.8.2502.11. OpenAI Codex (GPT-6.2 Sol) performed the merge, source review, native suite, focused positive and negative controls, and report.

Focused test-only diff
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@
         let _ = (released(bad), released(good));
     }

+    #[test]
+    fn a_panicking_piece_does_not_hold_the_parent_wait() {
+        let (tx, rx) = std::sync::mpsc::channel();
+        std::thread::spawn(move || {
+            let result = build_pieces(vec![
+                Box::new(|| -> usize { panic!("synthetic piece build panic") }) as Job,
+                Box::new(|| 0x5C5Cusize) as Job,
+            ]);
+            let _ = tx.send(result);
+        });
+        let result = rx.recv_timeout(std::time::Duration::from_secs(5))
+            .expect("a panicking piece held the parent wait");
+        assert_eq!(result, vec![0, 0x5C5C]);
+    }

@throny

throny commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: 753e8b1
head: 571aea4
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1512 passed, 1 failed, 47 ignored; failing: gpu::recomp::dxc::cache_tests::concurrent_cache_misses_compile_once. That test is in the shader-compile cache, which this PR does not touch, and it failed once yesterday in an unrelated tree on nvidia-dev as well while passing in all others: I read it as a flaky test of the tree, not this PR's (26 SKIPPED lines); base alone: 1512 passed, 0 failed, 47 ignored
review: no blocking finding. Provenance: the commit named in the module header exists in another project and that project is GPL-3.0-or-later; the header note and the THIRD_PARTY.md row have the required form. catch_unwind is used soundly: a job is taken out of its slot before it runs and no XCL lock is held around it, so completion and the building flag are now always settled; before, a panic killed the worker and left waiters hanging, or unwound into the title's thread. Remaining risk, which the PR's own warning names: a mutex inside the job that a panic poisons turns every later build into a stand-in, and each such panic is logged without a rate limit. For whoever merges: #2547 makes the same change in build() (textual conflict and duplicate: one of the two), and #2424 and #1665 conflict textually in the same function.
performance: none unless a panic happens.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K (no SSE4a), Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@tiagonleal

Copy link
Copy Markdown
Contributor Author

Closing this because main already has the fix. 4755740 ("D3D12.X: complete failed pipeline worker jobs", by bmjask, merged with the #2959 stack) added run_job in pso_async.rs. It catches a panicking build, logs it and returns 0. On main e429936 the worker build (run_build), the split pieces (build_pieces) and the rehydrate rebuild all go through it, and I found no production call site that still runs a job bare. The Chain::build_whole lock this PR also handled went away with the split-PSO rework.

@thehollowedone the piece regression you asked for exists on main too. The used_tests case around pso_async.rs:8429 calls build_pieces with a panicking middle piece and expects [0x11, 0, 0x33]. Unlike your version it has no timeout.

The two things this PR still had on top are a rate limit on the panic log and a test that the workers survive. I don't think they justify a PR of their own.

Thanks to throny, thehollowedone and Anon64 for the merge checks and the 3060 run.

AI use: Claude Code wrote this comment (Claude Fable 5.2). Claude Opus 5.5 compared the branch with main, and the call sites were checked a second time against e429936 before closing.

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.

5 participants