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

Open
github-bot wants to merge 1 commit from github-bot/gh-1331 into main AGit
Owner

@⁠b3IKK on GitHub · 2026-11-24 14:50 UTC · original
b3IKK:d3d12x/depth-bias-pso-race → main · +87 −43 · 1 files · 1 commits · open

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.
**@⁠b3IKK** on GitHub · 2026-11-24 14:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1331) `b3IKK:d3d12x/depth-bias-pso-race` → `main` · +87 −43 · 1 files · 1 commits · open 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.
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 hits if the base address is
later reused.

Hold both locks in consistent BASES -> DEPTH_BIAS_PSOS order in
cache_depth_bias_pso and forget_base_entries (releasing PSOs outside
the locks as before), with a 200-iteration concurrent test.

Assisted-by: OpenCode (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:02 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 14:55 UTC · original · edited 2026-11-24 14:58 UTC

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.
**@⁠futurepro62** on GitHub · 2026-11-24 14:55 UTC · [original](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7135165223) · edited 2026-11-24 14:58 UTC 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 15:10 UTC · original

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** on GitHub · 2026-11-24 15:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7135569689) 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!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 15:58 UTC · original

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** on GitHub · 2026-11-24 15:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7136922439) 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!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 04:53 UTC · original

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.

**@⁠DavidM1911** on GitHub · 2026-11-26 04:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/1331#issuecomment-7182989725) 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.
This pull request has changes conflicting with the target branch.
  • crates/xcl/src/hle/d3d12x/device_x.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1331/head:github-bot/gh-1331'
git switch 'github-bot/gh-1331'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1331'
git switch 'github-bot/gh-1331'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1331'
git switch 'github-bot/gh-1331'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1331'
git switch 'main'
git merge --squash 'github-bot/gh-1331'
git switch 'main'
git merge --ff-only 'github-bot/gh-1331'
git switch 'main'
git merge 'github-bot/gh-1331'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.