Skip to content

Tests: d3d12x test locks recover from a poisoned mutex - #1263

Closed
Rj45n wants to merge 1 commit into
xcl-dev:mainfrom
Rj45n:tests/d3d12x-test-locks-recover-from-poisoning
Closed

Rj45n wants to merge 1 commit into
xcl-dev:mainfrom
Rj45n:tests/d3d12x-test-locks-recover-from-poisoning

Conversation

@Rj45n

@Rj45n Rj45n commented Nov 24, 2026

Copy link
Copy Markdown

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)

What is in it

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release:
  • cargo test --workspace -- --test-threads=4: N passed, N failed, N ignored (SKIPPED GPU tests: …)

Regression run

main:

PR:

Not tested

AI use

  • none / tool and model, and what it did

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`
(xcl-dev#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 (xcl-dev#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 xcl-dev#673, which came first; this one is rebased
on current main, where xcl-dev#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 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl lib vram: 10 passed, 1 failed (gpu_sparse_vram_descriptors_buffers_and_xmem - flaky, passes standalone on PR and on main), 0 failed.

Thanks!

@DavidM1911

Copy link
Copy Markdown
Contributor

Related observation while verifying: cargo test -p xcl --lib d3d12x (default parallelism) intermittently aborts the whole test binary with STATUS_ACCESS_VIOLATION (0xc0000005) on unmodified main — reproduced twice in a row on this machine (RTX 3060 Ti, Windows 11). With -- --test-threads=1 the same filter passes cleanly: 87 passed, 0 failed, 1 ignored. Looks like a test-parallelism issue in this area, possibly adjacent to what this PR hardens. Not caused by this change.

@Rj45n

Rj45n commented Nov 24, 2026

Copy link
Copy Markdown
Author

On the vram filter run. That matches what I see. cargo test -p xcl --lib vram -- --list selects 11 tests, and gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem is one of them, so 10 passed / 1 failed is the expected shape. It is not one of the tests this PR touches — it takes neither TEST_LOCK nor VRAM_TEST_LOCK — and it is the subject of #343. I have eight runs of gpu::recomp on an RTX 5070 Ti where it is the first failure in every failing run: 6 of 8 at --test-threads=4, and in half of those the device is then lost (DXGI_ERROR_DEVICE_REMOVED, 0x887A0005) and three to five further GPU tests fail with it. So one root cause can be reported as up to seven failures. The numbers are in #343 rather than here.

On the access violation — reproduced, on a different card, with a sharp thread boundary. cargo test -p xcl --lib d3d12x on unmodified main (930e8b4), RTX 5070 Ti 16 GB (driver 621.01), Windows 11 Pro 10.0.26300, Rust 1.98.1 stable-x86_64-pc-windows-msvc, debug profile, 24 logical CPUs:

--test-threads | runs | result -- | -- | -- 1 | 2 | 131 passed, 0 failed, 1 ignored 2 | 2 | 131 passed, 0 failed, 1 ignored 4 | 2 | 131 passed, 0 failed, 1 ignored 5 | 3 | 131 passed, 0 failed, 1 ignored 6 | 3 | 131 passed, 0 failed, 1 ignored 7 | 9 | 131 passed, 0 failed, 1 ignored — 0 faults 8 | 8 | exit code: 0xc0000005, STATUS_ACCESS_VIOLATION — 8 of 8 16 | 2 | 0xc0000005 default (24) | 3 | 0xc0000005

The whole test binary dies; it is not a test reporting a failure. So it is not specific to your RTX 3060 Ti, and not specific to this branch — it is on bare main, and that is why the project's prescribed --test-threads=4 does not show it.

The threshold is sharp rather than load-flaky: 0 faults in 9 runs at 7 threads, 8 faults in 8 runs at 8. That should make it reproducible on the first attempt rather than after a dozen. I looked for a structure sized 8 indexed per thread in hle/d3d12x/ and did not find one — the [u32; 8] occurrences are the D3D12_RESOURCE_BARRIER word layout, and CALL_STACK_ARGS = 8 in guard.rs is a calling convention. So "sharp at 8" is a measurement, not a diagnosis.

Where it dies varies, so it is not one test faulting deterministically: counting completed tests before the fault at 8 threads gives 90, 90 and 118 of 131 over three runs. In all three default-parallelism runs the last line printed before the fault is the same family,

xcl: D3D12.X: Wait64BitValueX at 0x… >= 0x677 bridged to GPU queue.Wait
  (waiter=q0/ty0, prod=qNone/tySome(2); wait-before-signal, after_write64=false)

but output is buffered, so the last line printed is not the faulting site. I have no stack: I tried to identify the in-flight tests from --nocapture output and that method does not work, because libtest does not put a test's completion at the start of a line when output interleaves, so "started but never finished" cannot be read off it. Anyone with a debugger attached will get further in a minute than I did in twenty.

Why it is not what this PR hardens. A 0xc0000005 takes the process down, so no mutex is left poisoned and there is nothing for a recovering guard to recover. The two are independent: this PR removes the cascade after a Rust panic under the d3d12x test locks, which is what turns the #718 flake into three reported failures. The access violation needs its own fix and its own issue — it is a runtime bug on main, not a test-lock question. You saw it first, so I would rather you filed it; say the word and I will open it with the table above instead.

Not tested: AMD, Linux / Wine, release profile, any retail title (no Xbox GDK files here, so no scripts/smoke.ps1), and I have not caught a stack for the fault.

AI use: Claude Code with Claude Opus 5 ran the thread-count matrix and drafted this comment; I checked each figure against the logs before posting.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Closing this as a duplicate: #673 makes the same change and was opened first (the test locks recover from a poisoned mutex). It stays open and is the one that will be reviewed and merged.

This says nothing about the quality of the code here. I compared the two diffs; the pair was also found by independent checks in #1607. If this PR covers a case #673 does not, or #673 is closed without being merged, say so and I'll reopen it. A test that is only here is welcome on #673.

Thank you for the work.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this comment; the decision is the maintainer's.

@ivall ivall closed this Nov 24, 2026
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.

3 participants