d3d12_xs: shader_xlat mutex poison inconsistency causes crash on compilation thread panic #109

Closed
opened 2026-11-26 06:10:33 +00:00 by github-bot · 1 comment
Owner

@⁠Trwthh on GitHub · 2026-11-22 09:51 UTC · original

Bug

In crates/compat/d3d12_xs/src/shader_xlat.rs, mutex access is inconsistent:

  • Line ~28: uses unwrap_or_else(|e| e.into_inner()) to recover from a poisoned mutex (correct for resilience)
  • Line ~39: uses plain .unwrap() on the same kind of global mutex

If a shader compilation thread panics (e.g. from a malformed shader or an OOM), the mutex gets poisoned. The diagnostic/stats codepath then hits the .unwrap() and crashes the entire emulator with a panic, instead of recovering like the main path does.

The same inconsistency appears in gpu_va.rs line ~29 (recovers) vs other diagnostic paths.

Impact

A single bad shader that panics during translation takes down the whole emulator instead of just failing that one shader. This is especially problematic during first-use PSO creation where many shaders compile in rapid succession.

Expected behaviour

All mutex accesses on the same global should use the same poison-recovery pattern (unwrap_or_else(|e| e.into_inner())), so a panicked compilation thread doesn't cascade into a full crash.

**@⁠Trwthh** on GitHub · 2026-11-22 09:51 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/109) ## Bug In `crates/compat/d3d12_xs/src/shader_xlat.rs`, mutex access is inconsistent: - Line ~28: uses `unwrap_or_else(|e| e.into_inner())` to recover from a poisoned mutex (correct for resilience) - Line ~39: uses plain `.unwrap()` on the same kind of global mutex If a shader compilation thread panics (e.g. from a malformed shader or an OOM), the mutex gets poisoned. The diagnostic/stats codepath then hits the `.unwrap()` and crashes the entire emulator with a panic, instead of recovering like the main path does. The same inconsistency appears in `gpu_va.rs` line ~29 (recovers) vs other diagnostic paths. ## Impact A single bad shader that panics during translation takes down the whole emulator instead of just failing that one shader. This is especially problematic during first-use PSO creation where many shaders compile in rapid succession. ## Expected behaviour All mutex accesses on the same global should use the same poison-recovery pattern (`unwrap_or_else(|e| e.into_inner())`), so a panicked compilation thread doesn't cascade into a full crash.
github-bot 2026-11-26 06:10:33 +00:00
  • closed this issue
  • added the
    bug
    label
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:33 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 14:05 UTC · original

Fix details: published in aa14bfa (batch commit). Every Mutex lock in crates/compat/d3d12_xs/src/shader_xlat.rs (ORIGIN, CACHE, MESH_ROOT_CACHE, the prewarm queue) now recovers from poisoning with unwrap_or_else(|e| e.into_inner()), like ORIGIN_HASH and LINKS. The test poisoned_shader_globals_recover_instead_of_panicking poisons all three globals and checks that lookups still work. One correction: translation never runs while one of these locks is held (it runs inside OnceLock::get_or_init, under catch_unwind), so a translator panic could not poison them on its own path. The inconsistency was real, though. Thanks for the report.

**@⁠omonkeyz** on GitHub · 2026-11-22 14:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/109#issuecomment-7080282978) Fix details: published in aa14bfa (batch commit). Every Mutex lock in crates/compat/d3d12_xs/src/shader_xlat.rs (ORIGIN, CACHE, MESH_ROOT_CACHE, the prewarm queue) now recovers from poisoning with unwrap_or_else(|e| e.into_inner()), like ORIGIN_HASH and LINKS. The test poisoned_shader_globals_recover_instead_of_panicking poisons all three globals and checks that lookups still work. One correction: translation never runs while one of these locks is held (it runs inside OnceLock::get_or_init, under catch_unwind), so a translator panic could not poison them on its own path. The inconsistency was real, though. Thanks for the report.
This discussion has been locked. Commenting is limited to contributors.
No description provided.