D3D12.X: drop the replaced two-pass PSO outside the TWO_PASS lock #2882

Open
crazymanjared wants to merge 1 commit from upstream-pr/2882 into main
crazymanjared commented 2026-11-26 21:11:04 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by crazymanjared on 2026-11-26T21:11:04Z.


Fixes the deterministic 0xc0000005 write 0x0 at game_scarlett_master.exe+0x23cf683 world-load stop (the title's GPU watchdog) on AMD + Wine — root cause below. Discussion + thread dumps: #846 (comment 7202650249).

finish_two_pass registers a finished mesh pipeline with

TWO_PASS.lock().unwrap().get_or_insert_with(HashMap::new).insert(mesh_pso, Arc::new(..));

insert returns the replaced entry, which until now dropped as a statement temporary while the lock was still held. During the boot registration storm, freed mesh-PSO addresses are reused, so the replaced entry's last reference dies inside the lock: TwoPassPso::drop -> pso_async::release (compute) -> Release -> pso_release takes TWO_PASS again -> std locks are not reentrant -> the worker blocks on its own lock. Every draw queues behind it and the title's watchdog fires ~100 s in. Thread dump at 105 s (RX 6950 XT, Wine): both pso-pre workers stuck acquiring TWO_PASS (finish_two_pass, pso_release) while the main thread queues on the two_pass_of read behind them.

The fix binds the replaced entry and drops it after the guard releases — two lines.

Verified: on RX 6950 XT + GE-Proton Wine the stop is gone: 2,700+ frames presented (past the old hard wall at ~2,400–2,730 / ~100 s) and the run survives 40+ minutes of world load, the deepest AMD + Wine run reported on #846. Happy to share the thread dumps and full logs.

<!-- greyfinch-sync:ivall/xcl:issue:5517192158 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2882). Originally posted by [crazymanjared](https://github.com/crazymanjared) on 2026-11-26T21:11:04Z. --- Fixes the deterministic `0xc0000005 write 0x0 at game_scarlett_master.exe+0x23cf683` world-load stop (the title's GPU watchdog) on AMD + Wine — root cause below. Discussion + thread dumps: #846 (comment 7202650249). `finish_two_pass` registers a finished mesh pipeline with ```rust TWO_PASS.lock().unwrap().get_or_insert_with(HashMap::new).insert(mesh_pso, Arc::new(..)); ``` `insert` returns the replaced entry, which until now dropped as a statement temporary **while the lock was still held**. During the boot registration storm, freed mesh-PSO addresses are reused, so the replaced entry's last reference dies inside the lock: `TwoPassPso::drop` -> `pso_async::release` (compute) -> `Release` -> `pso_release` takes `TWO_PASS` again -> std locks are not reentrant -> the worker blocks on its own lock. Every draw queues behind it and the title's watchdog fires ~100 s in. Thread dump at 105 s (RX 6950 XT, Wine): both pso-pre workers stuck acquiring `TWO_PASS` (`finish_two_pass`, `pso_release`) while the main thread queues on the `two_pass_of` read behind them. The fix binds the replaced entry and drops it after the guard releases — two lines. **Verified:** on RX 6950 XT + GE-Proton Wine the stop is gone: 2,700+ frames presented (past the old hard wall at ~2,400–2,730 / ~100 s) and the run survives 40+ minutes of world load, the deepest AMD + Wine run reported on #846. Happy to share the thread dumps and full logs.
github-actions[bot] commented 2026-12-01 02:35:44 +00:00 (Migrated from github.com)

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


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:7298785252 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2882#issuecomment-7298785252). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:35:44Z. --- 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 09:07:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:07:34Z.


Triage (#1607) – head 3e8e2c4

No open or merged PR makes the same change (#3132, the nvidia-dev port, is closed).
The fix is correct: in the one-statement form, the Option<Arc<TwoPassPso>> that insert returns is a temporary. It is dropped before the TWO_PASS guard. A replaced entry's Drop (late_release::hold_pipeline, which with XCL_LATE_RELEASE=0 goes to pso_async::release -> pso_release -> forget_pso) then takes TWO_PASS again while the lock is still held. forget_pso already uses the same let gone = ...; drop(gone) pattern.
The PR has no test, and the deadlock can only happen with XCL_LATE_RELEASE=0 (by default the drop only queues the pipeline). The description should say so.
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:7306252560 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2882#issuecomment-7306252560). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:07:34Z. --- **Triage (#1607)** – head 3e8e2c4 No open or merged PR makes the same change (#3132, the nvidia-dev port, is closed). The fix is correct: in the one-statement form, the `Option<Arc<TwoPassPso>>` that `insert` returns is a temporary. It is dropped before the `TWO_PASS` guard. A replaced entry's `Drop` (`late_release::hold_pipeline`, which with `XCL_LATE_RELEASE=0` goes to `pso_async::release` -> `pso_release` -> `forget_pso`) then takes `TWO_PASS` again while the lock is still held. `forget_pso` already uses the same `let gone = ...; drop(gone)` pattern. The PR has no test, and the deadlock can only happen with `XCL_LATE_RELEASE=0` (by default the drop only queues the pipeline). The description should say so. 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/2882:upstream-pr/2882'
git switch 'upstream-pr/2882'

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