Skip to content

D3D12.X: catch panics in async PSO builds so waiters and workers do not stall - #2053

Open
RandomGithub12309 wants to merge 1 commit into
xcl-dev:mainfrom
RandomGithub12309:d3d12x/pso-async-catch-panics
Open

RandomGithub12309 wants to merge 1 commit into
xcl-dev:mainfrom
RandomGithub12309:d3d12x/pso-async-catch-panics

Conversation

@RandomGithub12309

@RandomGithub12309 RandomGithub12309 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

dxc::pool() wraps HLSL compilation in std::panic::catch_unwind so a panicking compile cannot kill a DXC worker or hang its caller, but pso_async ran each pipeline's full shader translation and D3D12 PSO build closure without panic recovery or RAII cleanup:

  • A panic on an xcl-pso-* or xcl-pso-pre-* worker killed the worker thread permanently and skipped complete(p, 0), leaving *p.done == false forever so waiting resolve_wait calls deadlocked on p.cv.wait (with HELD elevated indefinitely) and BUILDING / p.demand.preload_thread remained stale.
  • A panic on an inline lazy build inside resolve_wait_for skipped complete(&p, 0) (deadlocking concurrent waiters) and unwound toward the extern "system" SetPipelineState / ClearState COM vtable hooks.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs:
    • Add run_job() wrapping each Job in std::panic::catch_unwind(AssertUnwindSafe(job)), logging the panic payload via xlog_error! and returning 0 so complete() increments FAILED, marks *p.done = true, and wakes waiting binds with the stand-in pipeline.
    • Add an RAII BuildGuard in build() that clears p.demand.preload_thread, restores THREAD_PRIORITY_LOWEST when boosted, and clears BUILDING before complete() notifies waiters.
    • Route both worker builds (build()) and inline bind builds (resolve_wait_for()) through run_job().
    • Add three regression unit tests in pso_async::used_tests (all three fail before the fix and pass after):
      • a_panicking_worker_build_wakes_waiters_and_keeps_workers_alive
      • a_panicking_preload_build_restores_state_and_keeps_preloaders_alive
      • a_panicking_inline_bind_build_does_not_unwind_or_hang_waiters

Tested

Hardware: Windows 11 (Build 26300), Intel Core Ultra 7 255HX, NVIDIA GeForce RTX 5050 Laptop GPU (wave32-only, driver 32.0.16.2114), rustc 1.100.0 (0ef1bc386 2026-11-09) stable-x86_64-pc-windows-msvc, Windows SDK DXC 1.8.2502.11.

  • Verified all three new tests fail before the fix:
    • cargo test -p xcl --lib hle::d3d12x::pso_async::used_tests::a_panicking -- --test-threads=1 → 0 passed; 3 failed (worker threads died and waiters timed out; inline builder unwound).
  • Verified with the fix (ea16145):
    • cargo test -p xcl --lib hle::d3d12x::pso_async -- --test-threads=4 and -- --test-threads=1 → 9 passed; 0 failed; 0 ignored.
    • cargo build --workspace → succeeded.
    • cargo test --workspace -- --test-threads=4 --skip fuzz_validate_and_gpu:
      • xcl lib: 1083 passed; 0 failed; 26 ignored; 4 filtered out (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0..3}, pre-existing RTX 50 0x8007000E failure tracked by DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905); 24 SKIPPED lines printed inside passing tests (20 wave64 / no-wave64 sub-cases, 3 wave32 per-lane refused sub-cases, 1 pso_measurement_compiles_an_exact_synthetic_record due to Developer Mode being off).
      • Integration tests (16 binaries): 49 passed; 0 failed; 20 ignored (1 SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows in gpu_compute_e2e).
      • Workspace total: 1132 passed; 0 failed; 46 ignored; 4 filtered out (25 SKIPPED notices).

Regression run

Baseline (upstream/main):

xcl-smoke v1
commit: 025c7861c7acabaa2d9f8f005de478ed4470cba4
gpu: NVIDIA GeForce RTX 5050 Laptop GPU
title: e61570a3
seconds: 60
exit: 0x0
frames shown: 1593 (PresentX 1593)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14323 MB

PR head (ea16145):

xcl-smoke v1
commit: ea16145a4694f0b05a3b00bd76e8ccd973d384bc
gpu: NVIDIA GeForce RTX 5050 Laptop GPU
title: e61570a3
seconds: 60
exit: 0x0
frames shown: 1601 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14332 MB

Not tested

  • Wave64-only GPU tests (RTX 5050 is wave32-only), gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_{0..3} (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905), and pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode not enabled on this host).
  • A live retail shader triggering a Rust translator panic during gameplay (exercised via unit tests instead).

AI use

Antigravity (Gemini 4 Neon) identified the missing panic recovery and RAII cleanup in pso_async.rs, wrote the fix and regression tests, ran the test suite and smoke runs, and drafted this PR description.

…ot stall

`dxc::pool()` already wraps HLSL compilation in `catch_unwind`, but the
async pipeline jobs in `pso_async` ran the shader translator and D3D12
PSO creation without panic recovery or RAII cleanup:

- On an `xcl-pso-*` or `xcl-pso-pre-*` worker, a panic terminated the
  worker thread permanently and skipped `complete(p, 0)`, leaving
  `*p.done` false forever so waiting `resolve_wait` callers deadlocked
  and `p.demand.preload_thread` / `BUILDING` were left stale.
- On an inline lazy bind in `resolve_wait_for`, a panic skipped
  `complete(&p, 0)` (deadlocking concurrent waiters) and unwound toward
  the `extern "system"` `SetPipelineState` / `ClearState` COM hooks.

Catch panics in a shared `run_job` helper (logging the payload and
falling back to `0` so `complete` increments `FAILED` and wakes waiters
with the stand-in), and restore `BUILDING`, `preload_thread`, and
preload worker thread priority via a `BuildGuard` before calling
`complete`.

Assisted-by: Antigravity (Gemini 4 Neon)
@raylitebull

Copy link
Copy Markdown
Member

Code review on ea16145:

  • Wrapping pipeline build invocations in run_job (catch_unwind) and moving preload_thread / thread-priority / BUILDING TLS cleanup into RAII BuildGuard::drop in crates/xcl/src/hle/d3d12x/pso_async.rs guarantees panicked worker, preload, and inline builds still call complete(p, 0), wake all waiters with the stand-in, and keep pool threads alive.
  • All three new tests cover worker-pool survival past compile_threads() + 2, preload priority/TLS restoration, and concurrent inline waiters cleanly.
  • Build and test is running; once PR description passes, verified on both vendors, and marked ready for review, this looks very solid.

@RandomGithub12309
RandomGithub12309 marked this pull request as ready for review November 25, 2026 02:15
@JJAutoCompare

Copy link
Copy Markdown

PR #2053 compatibility verification

Tested ea16145a4694f0b05a3b00bd76e8ccd973d384bc on STOR-WINLAB with a clean detached checkout. All three async PSO panic tests passed. The workspace suite finished with 28 failures.

Environment

  • Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB, driver 32.0.101.9175. DoublePrecisionFloatShaderOps=0, wave range 8–32, and d3d12SDKLayers.dll absent.
  • rustc 1.100.0 (0ef1bc386 2026-11-09). Unoptimized Cargo profiles with debug info and incremental compilation disabled. Build and temporary files were under L:\XclTooling\neon-slot-6.
  • DXC/DXIL 1.9.2609.5 was on PATH via $env:LOCALAPPDATA\XclTooling\dxc-1.9.2609\bin\x64. XCL's DLL loader selected the Windows SDK's DXC/DXIL 1.9.2602.17, as recorded in the suite log. The results reflect that DLL selection.

Tested

  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the Arc lock.
  • cargo test -p xcl --lib pso_async::used_tests::a_panicking -- --nocapture reported 3 passed, 0 failed, 0 ignored, and 0 SKIPPED lines. All three also passed in the workspace suite.
    • a_panicking_worker_build_wakes_waiters_and_keeps_workers_alive verified stand-in fallback, waiter wakeup, failed-job accounting, and a successful follow-up job.
    • a_panicking_preload_build_restores_state_and_keeps_preloaders_alive verified stand-in fallback, cleared preload thread state, and a successful low-priority follow-up build.
    • a_panicking_inline_bind_build_does_not_unwind_or_hang_waiters verified that the inline caller and concurrent waiter both returned the stand-in.
  • One cargo test --workspace --no-fail-fast -- --test-threads=4 run under Invoke-ArcTest.ps1 exited 101. RUST_TEST_NOCAPTURE=1 exposed skip notices from the test harness. The combined output is in pr2053-suite.log.
Test target Passed Failed Ignored
xcl src/lib.rs 1060 27 26
xcl src/main.rs 0 0 0
tests/bcpack_parity.rs 1 0 0
tests/console_dlls_e2e.rs 13 0 0
tests/console_shaders.rs 3 0 4
tests/disasm_e2e.rs 1 0 0
tests/e2e.rs 2 1 0
tests/gpu_compute_e2e.rs 4 0 0
tests/gpu_pso_e2e.rs 7 0 0
tests/heap_probe.rs 0 0 4
tests/low_va.rs 1 0 0
tests/pls_quota.rs 1 0 0
tests/predication_e2e.rs 1 0 0
tests/rpf_e2e.rs 2 0 0
tests/shaders_e2e.rs 4 0 0
tests/sparse_reinit.rs 1 0 0
tests/texture_states.rs 1 0 0
tests/xg_oracle.rs 6 0 12
xcl-testtitle src/main.rs 0 0 0
xcl doctests 0 0 0
Total 1108 28 46

The log contains 27 lines beginning with SKIPPED . The library emitted 24 (19 unavailable wave64 cases, three refused wave32 per-lane lowering cases, one tiled-resource tier below 2, and one inability to disable the driver cache). The integration binaries emitted three (two missing D3D12 debug-layer checks and one unavailable heap-window case). These lines include subcases. Cargo's pass totals also include early returns for unset XCL_SAMPLE_* variables. Those skipped paths provide no coverage.

Failures

All 27 library failures are unrelated to the changed async PSO path by code inspection. The GPU shader tests use the test runner's direct D3D12 calls. No baseline run was performed.

22 tests received 0x80070057 from native CreateComputePipelineState. The Arc reports no FP64 shader support, which is relevant to the double-precision cases. The HRESULT alone cannot establish the cause of every rejection.

  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3
  • gpu::dxil::ops_tests::doubles_match_cpu
  • gpu::dxil::ops_tests::groupshared_barrier_and_atomics_run
  • gpu::dxil::round_tests::gpu_direct_f32_round_modes_dynamic_and_denormals
  • gpu::dxil::round_tests::gpu_direct_f32_round_modes_static
  • gpu::dxil::round_tests::gpu_direct_f32_round_preserved_denormal_times_inf_is_inf
  • gpu::dxil::round_tests::gpu_frexp_exp_f32_denorm_with_directed_rounding
  • gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu
  • gpu::recomp::tests::gpu_clamp_and_omod_per_instruction
  • gpu::recomp::tests::gpu_f64_class_compare
  • gpu::recomp::tests::gpu_f64_compares_with_nan
  • gpu::recomp::tests::gpu_f64_literal_high_word
  • gpu::recomp::tests::gpu_f64_math_random
  • gpu::recomp::tests::gpu_f64_roots
  • gpu::recomp::tests::gpu_f64_rounding_and_conversions
  • gpu::recomp::tests::gpu_float_compares_random
  • gpu::recomp::tests::gpu_frexp_f64_exp_and_mant
  • gpu::recomp::tests::gpu_ldexp_f64
  • gpu::recomp::tests::gpu_rndne_f64

Five shader output mismatches

  • gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction (fused FMA overflow control).
  • gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mips (pixel value 25.609375, expected 26).
  • gpu::recomp::tests::gpu_split_wave64_reduction_tails (split-wave minimum).
  • gpu::recomp::tests::gpu_valu_16_and_64_bit (v_add_f16 high half).
  • gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductions (pixel-wave min/sum and waterfall read).

One integration failure

  • test_title_runs_and_game_folder_is_untouched reached the end of the bundled test title with one failed check. RSSetDepthBiasX(-1000.5) left the top-right pixel blue instead of green. This appears unrelated to the panic fix because the failing check uses PC shader bytecode and native dynamic depth bias. A baseline run would be needed to establish whether the failure predates the PR.

Not tested

No retail Xbox title or retail shader-pack input, no D3D12 debug-layer validation, no main regression smoke run, and no GPU other than this Arc A770. XCL's loading and use of the standalone DXC/DXIL 1.9.2609.5 DLLs were outside the observed run.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr2053-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/pso_async.rs
@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of ea16145 merged on main aaa0936 with #684: its 9 pso_async tests pass under Wine, the three new panic tests among them. In 3 runs of the title no pipeline build panicked, so the change's recovery path was not exercised there. The threads that died in these runs, with the change and without it, died of stack overflows, which are not panics and which catch_unwind does not catch.

Setup: Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, RTX 4070 12 GB (driver 615.71.09). Release, cross-compiled to x86_64-pc-windows-gnu. Title runs: XCL_DIRECT_DXIL=1, XCL_PSO_PRELOAD=0, XCL_SKIP_BINK=1, XCL's driver blobs absent and NVIDIA's disk cache off, WINEDEBUG=err+all,fixme-all, 100 s; retail title 1.0.2.1, the first-run screens completed once and no story progress. The runs without it were made 3 hours earlier, so their DXIL cache held fewer translated shaders.

Tested

100 s, direct backend without: aaa0936 + #684 (2 runs) with ea16145 (3 runs)
Rust panics logged (panicked at; with the change also panic while building pipeline) 0, 0 0, 0, 0
virtual_setup_exception stack overflow on a 2 MB thread 1, 2 1, 1, 1
compute pipelines built 23, 24 24, 24, 23
crashes / device removals 0 / 0 0 / 0

Not tested: a build that panics in a title run; Windows; AMD and Intel.

AI use: Claude Code read the diff, built the trees, ran the title and the tests, and wrote this comment: Claude Fable 5.2 for the earlier part (the tests and the two runs without the change at least), Claude Opus 5.5 for the writing; the session changed model during the work.

Posted without review by a person: the account owner was away and reads replies later.

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