D3D12.X: a buffer's last release does not wait for the sparse state's lock #1981

Manually merged
github merged 1 commit from gh-pr/1981/head into gh-pr/1981/base 2026-11-26 05:12:41 +00:00
Owner

@⁠Eterst on GitHub · 2026-11-25 00:22 UTC · original
Eterst:fix/sparse-forget-buffer-deadlock → main · +74 −10 · 1 files · 1 commits · merged 2026-11-25 01:14 UTC

forget_buffer no longer waits for the sparse state's lock. before_execute holds STATE around D3D12 calls, and D3D12 can make a placed buffer's last Release inside a call of its own on another thread; that Release reaches forget_buffer, which took STATE. The D3D12 call under the lock then waits for D3D12's lock and the Release inside D3D12 for STATE. On a retail title this stopped presents after the third frame on every start (black screen), with both threads in those waits in a thread dump. #968 fixed the other half of the same cycle (queue()); this is the remaining half.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: forget_buffer queues the resource in FORGOTTEN and takes STATE only if it is free (try_lock); every other user of the state takes it through lock_state, which first lets the queued buffers go (forget_released → forget_in, the old body). Test a_buffer_released_while_the_state_is_held_does_not_wait_for_it.

Tested

  • NVIDIA GeForce RTX 4070 SUPER 12 GB (driver 616.92, 32-lane waves), Ryzen 7 5700X, 32 GB; Windows 10 22H2 (19045); Rust 1.100.0 MSVC; debug for the suite, release for the smoke run.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 on 892177b: 976 passed, 0 failed, 45 ignored. SKIPPED on this adapter (no wave64 / refused forms): the gpu::recomp::lower and lower_dxil GPU comparisons, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, heap_window_out_of_memory_falls_back_to_the_switch_form.
  • The new test fails on main 689f2db (forget_buffer waited for the sparse state's lock, after its 5 s timeout) and passes here.
  • On this machine hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory and three list_x GPU tests (0x887A0005) fail now and then in parallel runs, on main as well (3 of 8 parallel main runs); they passed in the run above.

Regression run

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1515 (PresentX 1515)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16570 MB

this PR:

xcl-smoke v1
commit: 892177b682542c574eafbda3b8ea5d57725c88c5
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1595 (PresentX 1596)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15939 MB

Not tested

  • AMD and Intel GPUs; Wine / vkd3d-proton.
  • With main the 60 s smoke run does not hit the deadlock (it needs a Release from inside D3D12 while STATE is held); the black screen was seen on an earlier base (930e8b4) before #968, so the smoke runs only check for regressions.

AI use

  • Claude Code (Claude Opus 5.5): found the cycle from thread dumps, wrote the fix, the test and this description, and ran the tests and smoke runs.

🤖 Generated with Claude Code

**@⁠Eterst** on GitHub · 2026-11-25 00:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/1981) `Eterst:fix/sparse-forget-buffer-deadlock` → `main` · +74 −10 · 1 files · 1 commits · merged 2026-11-25 01:14 UTC `forget_buffer` no longer waits for the sparse state's lock. `before_execute` holds `STATE` around D3D12 calls, and D3D12 can make a placed buffer's last `Release` inside a call of its own on another thread; that `Release` reaches `forget_buffer`, which took `STATE`. The D3D12 call under the lock then waits for D3D12's lock and the `Release` inside D3D12 for `STATE`. On a retail title this stopped presents after the third frame on every start (black screen), with both threads in those waits in a thread dump. #968 fixed the other half of the same cycle (`queue()`); this is the remaining half. **What is in it** - `crates/xcl/src/hle/d3d12x/sparse.rs`: `forget_buffer` queues the resource in `FORGOTTEN` and takes `STATE` only if it is free (`try_lock`); every other user of the state takes it through `lock_state`, which first lets the queued buffers go (`forget_released` → `forget_in`, the old body). Test `a_buffer_released_while_the_state_is_held_does_not_wait_for_it`. **Tested** - NVIDIA GeForce RTX 4070 SUPER 12 GB (driver 616.92, 32-lane waves), Ryzen 7 5700X, 32 GB; Windows 10 22H2 (19045); Rust 1.100.0 MSVC; debug for the suite, release for the smoke run. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4` on `892177b`: 976 passed, 0 failed, 45 ignored. SKIPPED on this adapter (no wave64 / refused forms): the `gpu::recomp::lower` and `lower_dxil` GPU comparisons, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `heap_window_out_of_memory_falls_back_to_the_switch_form`. - The new test fails on `main` `689f2db` (`forget_buffer waited for the sparse state's lock`, after its 5 s timeout) and passes here. - On this machine `hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory` and three `list_x` GPU tests (`0x887A0005`) fail now and then in parallel runs, on `main` as well (3 of 8 parallel `main` runs); they passed in the run above. **Regression run** main: ``` xcl-smoke v1 commit: 689f2db477c3c062cf162649781640ef8a977c18 gpu: NVIDIA GeForce RTX 4070 SUPER title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1515 (PresentX 1515) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16570 MB ``` this PR: ``` xcl-smoke v1 commit: 892177b682542c574eafbda3b8ea5d57725c88c5 gpu: NVIDIA GeForce RTX 4070 SUPER title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1595 (PresentX 1596) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15939 MB ``` **Not tested** - AMD and Intel GPUs; Wine / vkd3d-proton. - With `main` the 60 s smoke run does not hit the deadlock (it needs a `Release` from inside D3D12 while `STATE` is held); the black screen was seen on an earlier base (`930e8b4`) before #968, so the smoke runs only check for regressions. **AI use** - Claude Code (Claude Opus 5.5): found the cycle from thread dumps, wrote the fix, the test and this description, and ran the tests and smoke runs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`before_execute` holds the sparse state's lock (`STATE`) around D3D12 calls. D3D12 can make
a placed buffer's last Release inside one of its own calls on another thread; that Release
reaches `forget_buffer`, which took `STATE` too: the D3D12 call under the lock waited for
D3D12's lock, the Release inside D3D12 for `STATE`. A retail title's presents stopped after
its third frame on every start (black screen) with both threads in those waits.

`forget_buffer` now queues the resource in `FORGOTTEN` and only takes `STATE` if it is free
(`try_lock`); every other user of the state takes it through `lock_state`, which first lets
the queued buffers go. #968 fixed the other half of the same cycle (`queue()`).

Test: a_buffer_released_while_the_state_is_held_does_not_wait_for_it (fails on main after
its 5 s timeout: "forget_buffer waited for the sparse state's lock").

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:40 +00:00
github manually merged commit 892177b682 into gh-pr/1981/base 2026-11-26 05:12:41 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-25 00:56 UTC · original · edited 2026-11-25 01:07 UTC

Full-suite run, since this PR has no test report yet. Tested exact head 892177b (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 966 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: a_buffer_released_while_the_state_is_held_does_not_wait_for_it.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 975 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (#1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-25 00:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7149049169) · edited 2026-11-25 01:07 UTC Full-suite run, since this PR has no test report yet. Tested exact head `892177b` (on its base `689f2db`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests`: **966 passed, 0 failed, 43 ignored**. SKIPPED (no wave64): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - The new tests ran and passed: `a_buffer_released_while_the_state_is_held_does_not_wait_for_it`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`: **975 passed, 0 failed, 45 ignored**. SKIPPED: `f16_programs_on_the_gpu` (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f16_programs_on_the_gpu` (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `f32_programs_on_the_gpu` (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - `--skip` leaves out tests that fail on main `7994cd1` too, not because of this PR. On NVIDIA: `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651), the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests and `const_and_null_mask_operands_agree_with_hlsl_on_the_gpu` ([follow-up on #1651](https://git.gtahub.st/github/xcl-dev--xcl/issues/1651)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`, and `gpu::dxil::fuzz_tests` seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card (drivers 616.64 and 621.40). On AMD: `fuzz_validate_and_gpu_1` fails on seed 540 (`res[833]` 0x7 vs CPU 0x6). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:12 UTC · original

Code review on 892177b:

  • Avoiding taking sparse::STATE synchronously on forget_buffer prevents late_release::drain_known deadlocks when STATE is held across GPU resource/allocator work, and RTX 4070 SUPER + RTX 5070 Ti runs pass cleanly.
  • Diff audited and CI workflow approved (currently running).

Remaining before merge: Build and test (Windows, no GPU) finishing green plus an AMD verification pass on 892177b.

**@⁠raylitebull** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7149322573) Code review on `892177b`: - Avoiding taking `sparse::STATE` synchronously on `forget_buffer` prevents `late_release::drain_known` deadlocks when `STATE` is held across GPU resource/allocator work, and RTX 4070 SUPER + RTX 5070 Ti runs pass cleanly. - Diff audited and `CI` workflow approved (currently running). **Remaining before merge:** `Build and test (Windows, no GPU)` finishing green plus an **AMD** verification pass on `892177b`.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 03:19 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 03:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7151812383) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.