D3D12.X: hold BASES lock across DEPTH_BIAS_PSOS in depth_bias_pso and forget_base #1321

Open
b3IKK wants to merge 1 commit from upstream-pr/1331 into main
b3IKK commented 2026-11-24 14:50:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T14:50:24Z.


In depth_bias_pso, the temporary MutexGuard from BASES.lock() was dropped at the semicolon before acquiring DEPTH_BIAS_PSOS.lock(), and forget_base likewise dropped BASES before locking DEPTH_BIAS_PSOS. If forget_base ran between those two locks, it removed base from BASES and scanned an empty DEPTH_BIAS_PSOS, after which depth_bias_pso inserted the derived PSO under stale alive == trueÔÇöleaking the derived PSO permanently and risking stale cache hits if the base COM address is later reused.

This holds both locks in consistent BASES -> DEPTH_BIAS_PSOS order in cache_depth_bias_pso and forget_base_entries (still releasing PSOs outside the locks).

What is in it

  • crates/xcl/src/hle/d3d12x/device_x.rs: extract cache_depth_bias_pso and forget_base_entries holding BASES across DEPTH_BIAS_PSOS; add 200-iteration concurrent test concurrent_depth_bias_cache_and_forget_base_never_orphans_pso.

Since the last push: rebased onto main 06c9f55; the only conflict was uav_format_promotion_and_linearization, a test main had added at the same place, and both are kept.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 1266 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required))
  • cargo test -p xcl --lib concurrent_depth_bias_cache_and_forget_base_never_orphans_pso: 1 passed, 0 failed

Regression run

main (426a5a7, clean tree, no local changes):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1642 (PresentX 1642)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15158 MB

PR (e860e83, clean tree, no local changes):

xcl-smoke v1
commit: e860e83a11780a6d2ff5180f8bdc2adc28773190
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15858 MB

(The main block is 426a5a7, an ancestor of the current main, from the same machine and data folder.)

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Claude Fable 5.2: rebased onto main 06c9f55, resolved the conflicts, ran the suite and the scripts/smoke.ps1 pair at the head above.
<!-- greyfinch-sync:ivall/xcl:issue:5474477097 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1331). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T14:50:24Z. --- In `depth_bias_pso`, the temporary `MutexGuard` from `BASES.lock()` was dropped at the semicolon before acquiring `DEPTH_BIAS_PSOS.lock()`, and `forget_base` likewise dropped `BASES` before locking `DEPTH_BIAS_PSOS`. If `forget_base` ran between those two locks, it removed `base` from `BASES` and scanned an empty `DEPTH_BIAS_PSOS`, after which `depth_bias_pso` inserted the derived PSO under stale `alive == true`ÔÇöleaking the derived PSO permanently and risking stale cache hits if the base COM address is later reused. This holds both locks in consistent `BASES -> DEPTH_BIAS_PSOS` order in `cache_depth_bias_pso` and `forget_base_entries` (still releasing PSOs outside the locks). **What is in it** - `crates/xcl/src/hle/d3d12x/device_x.rs`: extract `cache_depth_bias_pso` and `forget_base_entries` holding `BASES` across `DEPTH_BIAS_PSOS`; add 200-iteration concurrent test `concurrent_depth_bias_cache_and_forget_base_never_orphans_pso`. **Since the last push**: rebased onto `main` `06c9f55`; the only conflict was `uav_format_promotion_and_linearization`, a test `main` had added at the same place, and both are kept. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): **1266 passed, 0 failed, 46 ignored** (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)`) - `cargo test -p xcl --lib concurrent_depth_bias_cache_and_forget_base_never_orphans_pso`: 1 passed, 0 failed **Regression run** main (`426a5a7`, clean tree, no local changes): ``` xcl-smoke v1 commit: 426a5a745db4d5e4b037449ede0b70cb342f5192 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1642 (PresentX 1642) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15158 MB ``` PR (`e860e83`, clean tree, no local changes): ``` xcl-smoke v1 commit: e860e83a11780a6d2ff5180f8bdc2adc28773190 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1645 (PresentX 1645) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15858 MB ``` (The main block is `426a5a7`, an ancestor of the current `main`, from the same machine and data folder.) **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Claude Fable 5.2: rebased onto `main` `06c9f55`, resolved the conflicts, ran the suite and the `scripts/smoke.ps1` pair at the head above.
futurepro62 commented 2026-11-24 15:06:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:55:17Z.


Full-suite run, since this PR has no test report yet. Tested exact head bf129cf (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: concurrent_depth_bias_cache_and_forget_base_never_orphans_pso.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

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:7135165223 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1331#issuecomment-7135165223). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T14:55:17Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `bf129cf` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `concurrent_depth_bias_cache_and_forget_base_never_orphans_pso`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**, no skips. **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.
DavidM1911 commented 2026-11-24 16:06:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:10:05Z.


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

  • cargo test -p xcl --lib: 707 passed, 1 failed (coherent_buffer_sanitizes_console_flags_and_state — the known flake from #913; passes standalone), 21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7135569689 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1331#issuecomment-7135569689). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:10:05Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: 707 passed, 1 failed (`coherent_buffer_sanitizes_console_flags_and_state` — the known flake from #913; passes standalone), 21 ignored. Thanks!
DavidM1911 commented 2026-11-24 16:07:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:58:38Z.


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

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7136922439 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1331#issuecomment-7136922439). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T15:58:38Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib -- --test-threads=1`: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified `main`.) Thanks!
DavidM1911 commented 2026-11-26 05:05:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:53:16Z.


Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7182989725 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7182989725). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T04:53:16Z. --- Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
github-actions[bot] commented 2026-12-01 02:31:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:31:47Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298714232 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7298714232). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:31:47Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 05:27:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:27:23Z.


Triage (#1607) – head e860e83

Main still has the race this fixes. In device_x.rs on main, depth_bias_pso checks the base in BASES, drops that lock, and only then inserts into DEPTH_BIAS_PSOS, and forget_base takes the two locks one after the other. No open PR makes the same change. The new BASES -> DEPTH_BIAS_PSOS order matches every other place that takes both locks, so it adds no deadlock.
The branch conflicts with main. When you rebase, the test's Base { .. } literal must gain the fields main has added since (e.g. shader_blobs).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301789032 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7301789032). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:27:23Z. --- **Triage (#1607)** – head e860e83 Main still has the race this fixes. In `device_x.rs` on main, `depth_bias_pso` checks the base in `BASES`, drops that lock, and only then inserts into `DEPTH_BIAS_PSOS`, and `forget_base` takes the two locks one after the other. No open PR makes the same change. The new `BASES -> DEPTH_BIAS_PSOS` order matches every other place that takes both locks, so it adds no deadlock. The branch conflicts with main. When you rebase, the test's `Base { .. }` literal must gain the fields main has added since (e.g. `shader_blobs`). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1331:upstream-pr/1331'
git switch 'upstream-pr/1331'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1331'
git switch 'upstream-pr/1331'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1331'
git switch 'upstream-pr/1331'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1331'
git switch 'main'
git merge --squash 'upstream-pr/1331'
git switch 'main'
git merge --ff-only 'upstream-pr/1331'
git switch 'main'
git merge 'upstream-pr/1331'
git push origin 'main'
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!1321
No description provided.