From 6ea3f98dd3775d6443a84f7749824db119c3188d Mon Sep 17 00:00:00 2001 From: Rj45n Date: Tue, 24 Nov 2026 07:22:00 +0100 Subject: [PATCH] Tests: d3d12x test locks recover from a poisoned mutex The six call sites of TEST_LOCK and VRAM_TEST_LOCK took the lock with `.lock().unwrap()`, so one panic while a guard was held poisoned the mutex for the rest of the process and every later test that serialises on it died with `PoisonError` instead of running. The known flake in `placed_title_textures_share_vram_and_preserve_pixels` (#718) therefore reports three failures rather than one: it holds both locks, and `transitions_apply_when_their_list_is_submitted` and `d32s8_targets_take_their_own_size_of_video_memory` then fail for a reason of their own making. Both pass on their own. Contributors read the trio off a `cargo test` run and look for two bugs that are not there. The cascade is not specific to that flake: any panic under either guard produces it. These statics only serialise tests that share one D3D12 device; they guard no invariant that a panic can leave half-applied, so recovering the guard is right. It is also the form the crate already uses everywhere else for its test locks: ASYNC_TEST_LOCK, ACCESSIBILITY_TEST_LOCK and READING_CB_TEST_LOCK take `.lock().unwrap_or_else(|e| e.into_inner())` at all 41 of their call sites, and so does `vram.rs` itself since 38ea451 (#940), whose `reservable_agrees_with_the_driver` takes VRAM_TEST_LOCK that way two tests above a `d32s8_...` that still panics on it. After this change the crate has 48 recovering call sites and no bare `.unwrap()` on a test lock. Measured on an RTX 5070 Ti (driver 621.01), Windows 11, DXC 1.9.2602.17, with a temporary `panic!()` after the two locks in the placed-textures test to stand in for the flake: on main 47efa2e both `--test-threads=1` and `=4` report 3 failed, 0 passed; with this change both report 1 failed, 2 passed. Only the test that really panics fails, and no `PoisonError` is printed. Note this is the same change as #673, which came first; this one is rebased on current main, where #673's base is 78 commits behind. No test is added: the property is that no call site panics on a poisoned lock, and the only way to show it is to poison a shared static, which would leave the suite in that state for every other test. Assisted-by: Claude Code (Claude Opus 5) Co-Authored-By: Claude Opus 5 --- crates/xcl/src/hle/d3d12x/title_textures.rs | 10 +++++----- crates/xcl/src/hle/d3d12x/vram.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index ada439cbaa..48e95c416a 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -1227,8 +1227,8 @@ mod tests { use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT_R8_UNORM, DXGI_SAMPLE_DESC}; use windows_sys::Win32::System::Memory as mem; - let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap(); - let _guard = TEST_LOCK.lock().unwrap(); + let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); if super::super::backend() != super::super::Backend::Real { crate::gpu::recomp::runner::skip_test("no GPU"); return; @@ -1468,7 +1468,7 @@ mod tests { /// submission order, each time it is; a Reset forgets them; other resources are not noted. #[test] fn transitions_apply_when_their_list_is_submitted() { - let _guard = TEST_LOCK.lock().unwrap(); + let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); // RGBA8 64×64, 3 mips, 2 slices (6 subresources), 4KB_S let mut d = [0u8; 0x38]; d[0..4].copy_from_slice(&3u32.to_le_bytes()); @@ -1655,8 +1655,8 @@ mod tests { /// chains (including packed mips), cubemap arrays (`extra_pages`) and 3D volumes upload intact. #[test] fn placed_title_textures_share_vram_and_preserve_pixels() { - let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap(); - let _guard = TEST_LOCK.lock().unwrap(); + let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; use windows::Win32::Graphics::Dxgi::*; diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 040d78a0ce..0420ed420d 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -932,7 +932,7 @@ mod tests { /// arenas no target uses go. Needs a hardware adapter (skips on WARP). #[test] fn d32s8_targets_take_their_own_size_of_video_memory() { - let _vram_guard = VRAM_TEST_LOCK.lock().unwrap(); + let _vram_guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); use windows::core::Interface; use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0; use windows::Win32::Graphics::Dxgi::Common::*;