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

Merged
Eterst merged 1 commit from upstream-pr/1981 into main 2026-11-25 01:14:50 +00:00
Eterst commented 2026-11-25 00:22:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Eterst on 2026-11-25T00:22:06Z.


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

<!-- greyfinch-sync:ivall/xcl:issue:6594218378 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1981). Originally posted by [Eterst](https://github.com/Eterst) on 2026-11-25T00:22:06Z. --- `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)
futurepro62 commented 2026-11-25 01:11:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T00:56:41Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7149049169 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7149049169). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-25T00:56:41Z. --- 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://github.com/xcl-dev/xcl/issues/1651#issuecomment-7146069648)) 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.
upstream-sync closed this pull request 2026-11-25 02:08:05 +00:00
raylitebull commented 2026-11-25 02:08:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:12:59Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7149322573 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7149322573). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T01:12:59Z. --- 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`.
DavidM1911 commented 2026-11-25 04:10:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T03:19:50Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7151812383 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1981#issuecomment-7151812383). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T03:19:50Z. --- 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!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1971
No description provided.