D3D12.X: a freed allocator's recordings leave before its address is reused #2919

Open
b3IKK wants to merge 15 commits from upstream-pr/2919 into main
b3IKK commented 2026-11-26 23:19:51 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-26T23:19:51Z.


Stacked on #2404 (5b9d4ff).

alloc_pool::title_reset puts a PC allocator aside and computes the free backings under STATE, then drops their dispatch_chain::RECORDINGS after unlocking. A backing reused in that window could have its new recording swept away, or keep the old recording's readbacks/COM releases alive; KDenKC's trace and the new test isolate the interleaving (#2404).

This takes each free backing's RECORDINGS entries out while STATE is held (dispatch_chain::take_recordings) and drops them after the unlock, so a backing reused in between keeps the recordings made after its reuse. The lock order stays STATE then RECORDINGS.

What is in it

  • crates/xcl/src/hle/d3d12x/alloc_pool.rs: title_reset_with/take_recordings; the free set is detached under the lock.
  • crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs: take_recordings.
  • test aside_sweep_keeps_recordings_made_after_backing_reuse (pauses the sweep after the unlock, reuses the backing and records on it, then finishes the sweep; fails on 5b9d4ff, passes here).

Measured on the retail title (RTX 5080, 2 GiB shader heap, heap windows, the stack of #2404 + #2519 + #684 + #2877):

without with
presentation 502.2 s 599.2 s
end device removed at 520.1 s exit 0x0, 0 removals

Two 600 s runs with it, both 0 removals and 0 crashes. Royalflamejlh reports 0/2 device losses with it against 2/2 without on Linux + NVIDIA.

Tested

  • hardware: 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): 1448 passed, 0 failed, 47 ignored
  • the new test alone: 1 passed; KDenKC reports it fails on 5b9d4ff (the earlier sweep erased the reused backing's new recording)
  • SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware, no heap windows, and cannot disable the driver cache (Windows Developer Mode is required)
  • the two 600 s runs above

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 (2b32e81, clean tree, no local changes):

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

(The main block is 426a5a7, an ancestor of current main, from the same machine and data folder. A fresh launch on 8b957be is blocked on this machine by #2555's startup preparation, reported on that PR.)

Not tested

  • AMD GPUs, other titles; Linux / Wine beyond Royalflamejlh's report.

AI use

  • OpenCode, Claude Fable 5.2: applied and submitted KDenKC's tested patch, ran the suite, the scripts/smoke.ps1 pair and the two 600 s title runs, and wrote this. Patch and test by KDenKC (#2404).
<!-- greyfinch-sync:ivall/xcl:issue:5518467986 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2919). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-26T23:19:51Z. --- Stacked on #2404 (`5b9d4ff`). `alloc_pool::title_reset` puts a PC allocator aside and computes the free backings under `STATE`, then drops their `dispatch_chain::RECORDINGS` after unlocking. A backing reused in that window could have its new recording swept away, or keep the old recording's readbacks/COM releases alive; KDenKC's trace and the new test isolate the interleaving (#2404). This takes each free backing's `RECORDINGS` entries out while `STATE` is held (`dispatch_chain::take_recordings`) and drops them after the unlock, so a backing reused in between keeps the recordings made after its reuse. The lock order stays `STATE` then `RECORDINGS`. **What is in it** - `crates/xcl/src/hle/d3d12x/alloc_pool.rs`: `title_reset_with`/`take_recordings`; the free set is detached under the lock. - `crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs`: `take_recordings`. - test `aside_sweep_keeps_recordings_made_after_backing_reuse` (pauses the sweep after the unlock, reuses the backing and records on it, then finishes the sweep; fails on `5b9d4ff`, passes here). **Measured on the retail title** (RTX 5080, 2 GiB shader heap, heap windows, the stack of #2404 + #2519 + #684 + #2877): | | without | with | |---|---:|---:| | presentation | 502.2 s | **599.2 s** | | end | device removed at 520.1 s | **exit 0x0, 0 removals** | Two 600 s runs with it, both 0 removals and 0 crashes. Royalflamejlh reports 0/2 device losses with it against 2/2 without on Linux + NVIDIA. **Tested** - hardware: 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`): **1448 passed, 0 failed, 47 ignored** - the new test alone: 1 passed; KDenKC reports it fails on `5b9d4ff` (the earlier sweep erased the reused backing's new recording) - SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware, `no heap windows`, and `cannot disable the driver cache (Windows Developer Mode is required)` - the two 600 s runs above **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 (`2b32e81`, clean tree, no local changes): ``` xcl-smoke v1 commit: 2b32e81824e82d21d3754b14804a3a797e3b1905 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1596 (PresentX 1596) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15595 MB ``` (The main block is `426a5a7`, an ancestor of current `main`, from the same machine and data folder. A fresh launch on `8b957be` is blocked on this machine by #2555's startup preparation, reported on that PR.) **Not tested** - AMD GPUs, other titles; Linux / Wine beyond Royalflamejlh's report. **AI use** - OpenCode, Claude Fable 5.2: applied and submitted KDenKC's tested patch, ran the suite, the `scripts/smoke.ps1` pair and the two 600 s title runs, and wrote this. Patch and test by KDenKC (#2404).
DarkPanda69 commented 2026-11-26 23:38:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-26T23:38:37Z.


AMD run (listed as untested), with an RTX 3060 in the same PC: the 13 new d3d12x tests pass on both, and nothing else changes from main.

Tested: pass, head 2b32e81 applied on main 8b957be, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17, card picked with XCL_ADAPTER; main and this PR one after the other on each card.

  • cargo test -p xcl --lib -- hle::d3d12x:: --test-threads=4 --nocapture:
    • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: main 260 passed, 0 failed; this PR 273 passed, 0 failed, 2 ignored, 0 SKIPPED.
    • NVIDIA RTX 3060, driver 32.0.16.1088: the same, 260 → 273 passed, 0 failed, 0 SKIPPED.
    • The only result changes on both cards are the 13 new tests, all ok (from aside_sweep_keeps_recordings_made_after_backing_reuse to a_title_thread_does_not_wait_behind_a_background_whole_build_waiting_for_its_turn).
  • cargo test -p xcl --lib -- gpu:: --test-threads=4 --nocapture (XCL_DIRECT_DXIL unset): RX 9070 XT 708 passed, 2 failed (the #2115 fuzz seeds, same on main), 6 SKIPPED, on both main and this PR; RTX 3060 710 passed, 0 failed, 24 SKIPPED on both. No result changes.

The diff adds test code that makes its device with D3D12CreateDevice(None, ..), so on the RTX 3060 run those still ran on the first adapter, the RX 9070 XT.

Not tested: the whole workspace suite, a title run, release, Intel, Linux / Wine.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7205721377 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2919#issuecomment-7205721377). Originally posted by [DarkPanda69](https://github.com/DarkPanda69) on 2026-11-26T23:38:37Z. --- AMD run (listed as untested), with an RTX 3060 in the same PC: the 13 new `d3d12x` tests pass on both, and nothing else changes from `main`. **Tested:** pass, head `2b32e81` applied on `main` `8b957be`, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17, card picked with `XCL_ADAPTER`; `main` and this PR one after the other on each card. - `cargo test -p xcl --lib -- hle::d3d12x:: --test-threads=4 --nocapture`: - AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: `main` 260 passed, 0 failed; this PR 273 passed, 0 failed, 2 ignored, 0 SKIPPED. - NVIDIA RTX 3060, driver 32.0.16.1088: the same, 260 → 273 passed, 0 failed, 0 SKIPPED. - The only result changes on both cards are the 13 new tests, all ok (from `aside_sweep_keeps_recordings_made_after_backing_reuse` to `a_title_thread_does_not_wait_behind_a_background_whole_build_waiting_for_its_turn`). - `cargo test -p xcl --lib -- gpu:: --test-threads=4 --nocapture` (`XCL_DIRECT_DXIL` unset): RX 9070 XT 708 passed, 2 failed (the #2115 fuzz seeds, same on `main`), 6 SKIPPED, on both `main` and this PR; RTX 3060 710 passed, 0 failed, 24 SKIPPED on both. No result changes. The diff adds test code that makes its device with `D3D12CreateDevice(None, ..)`, so on the RTX 3060 run those still ran on the first adapter, the RX 9070 XT. **Not tested:** the whole workspace suite, a title run, release, Intel, Linux / Wine. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
luckyteagirl commented 2026-11-27 06:21:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-27T06:21:37Z.

Review: COMMENTED


Could the new regression call a helper that bypasses the production environment gate, or explicitly assert that its reuse callback ran? With XCL_ALLOC_SWAP=0, title_reset_with returns None before calling after_unlock. The test already called note(spare), so holds(spare) still reports true for the old entry. Consequently both final assertions pass even though the sweep and reuse never ran. Checking callback execution would prevent this false pass. Moving the env gate to title_reset would also let the test exercise the same sweep regardless of shell settings.

Environment gate and sweep · Regression

AI-assisted review (GPT-6.2 Sol).

<!-- greyfinch-sync:ivall/xcl:review:6084319849 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2919#pullrequestreview-6084319849). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-27T06:21:37Z. **Review:** COMMENTED --- Could the new regression call a helper that bypasses the production environment gate, or explicitly assert that its reuse callback ran? With `XCL_ALLOC_SWAP=0`, `title_reset_with` returns `None` before calling `after_unlock`. The test already called `note(spare)`, so `holds(spare)` still reports true for the old entry. Consequently both final assertions pass even though the sweep and reuse never ran. Checking callback execution would prevent this false pass. Moving the env gate to `title_reset` would also let the test exercise the same sweep regardless of shell settings. [Environment gate and sweep](https://github.com/xcl-dev/xcl/blob/2b32e81824e82d21d3754b14804a3a797e3b1905/crates/xcl/src/hle/d3d12x/alloc_pool.rs#L312-L333) · [Regression](https://github.com/xcl-dev/xcl/blob/2b32e81824e82d21d3754b14804a3a797e3b1905/crates/xcl/src/hle/d3d12x/alloc_pool.rs#L405-L450) AI-assisted review (GPT-6.2 Sol).
LocranKing commented 2026-11-27 10:00:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by LocranKing on 2026-11-27T10:00:37Z.


Tested PR #2919 (2b32e818) against main (8b957bec) on Windows 11 (26300), Ryzen 5 5500 (6C/12T), RTX 3060 Ti 8 GiB (driver 621.40), rustc 1.100.0, DXC 1.9.2602.17.

Unit Test (cargo test --locked -p xcl)

  • hle::d3d12x::alloc_pool::tests::aside_sweep_keeps_recordings_made_after_backing_reuse: 1 passed, 0 failed.

Paired 180 s Retail Smoke (9cc6a39e, Series S lockhart, XCL_HEAP_WINDOWS=1, XCL_DIRECT_DXIL=all, XCL_DIRECT_SPLIT_INSTRUCTIONS=0, XCL_PSO_WAIT_MS=50)

Build Guest entry / World load Frames shown Peak commit Peak local / non-local VRAM Console stats (t ≈ 297 s) Crashes / Removals
main (8b957bec) 67.2 s / 188.4 s 1240 29,411 MB 14,281 / 2,241 MB 9,178 draws, 34,068 dispatches (100 blocks held for 58 allocators) 0 / 0 (exit: 0x0)
PR #2919 (2b32e818) 119.1 s / 256.8 s 1257 29,540 MB 14,237 / 2,153 MB 10,944 draws, 33,195 dispatches (78 blocks held for 50 allocators) 0 / 0 (exit: 0x0)

Clean 180 s retail run (exit: 0x0, 0 crashes, 0 device removals, 256 put-aside allocator resets handled cleanly). Note that PR #2919 is stacked on #2404 (5b9d4ff6), so the retail binary includes that prerequisite commit.

Not tested: Multi-minute stress soak past 180 s or full workspace test suite on 2b32e818.

<!-- greyfinch-sync:ivall/xcl:comment:7215365694 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2919#issuecomment-7215365694). Originally posted by [LocranKing](https://github.com/LocranKing) on 2026-11-27T10:00:37Z. --- Tested PR #2919 (`2b32e818`) against `main` (`8b957bec`) on Windows 11 (26300), Ryzen 5 5500 (6C/12T), RTX 3060 Ti 8 GiB (driver `621.40`), `rustc 1.100.0`, DXC `1.9.2602.17`. ### Unit Test (`cargo test --locked -p xcl`) - `hle::d3d12x::alloc_pool::tests::aside_sweep_keeps_recordings_made_after_backing_reuse`: **`1 passed, 0 failed`**. ### Paired 180 s Retail Smoke (`9cc6a39e`, Series S `lockhart`, `XCL_HEAP_WINDOWS=1`, `XCL_DIRECT_DXIL=all`, `XCL_DIRECT_SPLIT_INSTRUCTIONS=0`, `XCL_PSO_WAIT_MS=50`) | Build | Guest entry / World load | Frames shown | Peak commit | Peak local / non-local VRAM | Console stats (`t ≈ 297 s`) | Crashes / Removals | | --- | --- | --- | --- | --- | --- | --- | | `main` (`8b957bec`) | `67.2 s` / `188.4 s` | `1240` | `29,411 MB` | `14,281 / 2,241 MB` | `9,178` draws, `34,068` dispatches (`100` blocks held for `58` allocators) | `0 / 0` (`exit: 0x0`) | | PR #2919 (`2b32e818`) | `119.1 s` / `256.8 s` | `1257` | `29,540 MB` | `14,237 / 2,153 MB` | `10,944` draws, `33,195` dispatches (`78` blocks held for `50` allocators) | `0 / 0` (`exit: 0x0`) | Clean `180 s` retail run (`exit: 0x0`, `0` crashes, `0` device removals, `256` put-aside allocator resets handled cleanly). Note that PR #2919 is stacked on #2404 (`5b9d4ff6`), so the retail binary includes that prerequisite commit. **Not tested:** Multi-minute stress soak past 180 s or full workspace test suite on `2b32e818`.
Foniass commented 2026-12-01 09:11:03 +00:00 (Migrated from github.com)

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


Triage (#1607) – head 2b32e81

This PR is stacked on #2404 (5b9d4ff), and #2404 now carries the same fix as its own top commit 9620331 ("a free_aside sweep keeps recordings made after the allocator's reuse").
That commit detaches each free backing's dispatch_chain::RECORDINGS while STATE is held and drops them after the unlock (detach_recordings, title_reset_with_after_unlock). This PR does the same with take_recordings / title_reset_with.
#2404's test a_free_spare_reused_after_a_sweep_keeps_its_new_chain_recording reproduces the same interleaving as aside_sweep_keeps_recordings_made_after_backing_reuse.
The rest of this branch is #2404's stack.
#2404 itself looks superseded by main (#3499). I did not check whether main still has this free_aside race; if it does, the fix should be ported to main on its own.
Recommendation: close (duplicate of #2404).

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:7306333126 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2919#issuecomment-7306333126). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:11:03Z. --- **Triage (#1607)** – head 2b32e81 This PR is stacked on #2404 (5b9d4ff), and #2404 now carries the same fix as its own top commit 9620331 ("a free_aside sweep keeps recordings made after the allocator's reuse"). That commit detaches each free backing's `dispatch_chain::RECORDINGS` while `STATE` is held and drops them after the unlock (`detach_recordings`, `title_reset_with_after_unlock`). This PR does the same with `take_recordings` / `title_reset_with`. #2404's test `a_free_spare_reused_after_a_sweep_keeps_its_new_chain_recording` reproduces the same interleaving as `aside_sweep_keeps_recordings_made_after_backing_reuse`. The rest of this branch is #2404's stack. #2404 itself looks superseded by main (#3499). I did not check whether main still has this `free_aside` race; if it does, the fix should be ported to main on its own. Recommendation: close (duplicate of #2404). 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/2919:upstream-pr/2919'
git switch 'upstream-pr/2919'

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