Placements: drop completed unmaps' references after releasing REGISTRY #3665

Open
Prime1997 wants to merge 1 commit from upstream-pr/3665 into main
Prime1997 commented 2026-12-02 05:54:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Prime1997 on 2026-12-02T05:54:06Z.


Requested by Prime

placements::unmap_if_superseded holds the placements REGISTRY mutex while it calls vram::unmap_superseded_target. That call also finishes the other held unmaps on the device whose fences have passed, and it dropped their resource references before returning, so still under REGISTRY. If one of those is the last reference to a target the title released while its unmap was held, the hooked Release runs res_release -> forget_for_recycle -> placements::released -> settle, which locks REGISTRY again on the same thread. The thread then waits for itself, and every later CreatePlacedResource, note_use and held unmap waits behind it: the title hangs. We found it in our fork, where another change makes this case common; on main it is latent but the path is the same. Now the completed references are returned to unmap_if_superseded, which drops them after it lets REGISTRY go. REGISTRY is also locked through a small lock() helper that fails a debug assertion when a thread locks it twice, so tests catch this kind of re-entry instead of hanging.

Related: #3577 (draft) changes how note_use takes REGISTRY; the two touch the same lock line in note_use, so whichever lands second needs a one-line rebase.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs: unmap_placed and unmap_superseded_target return the completed held unmaps' references (#[must_use]) instead of dropping them; unmap_superseded, whose callers hold no lock, drops them as before.
  • crates/xcl/src/hle/d3d12x/placements.rs: unmap_if_superseded drops the REGISTRY guard, then the returned references. lock() replaces REGISTRY.lock().unwrap() and keeps a thread-local "held" flag that a debug assertion checks.

Tested

  • RTX 3060 Ti 8 GB, Windows 11, release build: the change has been in our test builds since 30 Nov (no measured before/after on its own).
  • This branch (on main 1c8b5514): cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnu passes. The test suite was not run on this exact branch.

Regression run

  • Not run yet: testers welcome.

Not tested

  • The suite and scripts/smoke.ps1 on this branch; AMD.
  • No unit test for the re-entry itself: it needs a live device and a held unmap that completes after the title released its target. The debug assertion covers any test that reaches it.

AI use

  • Claude Code wrote the change and this description.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5600746009 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665). Originally posted by [Prime1997](https://github.com/Prime1997) on 2026-12-02T05:54:06Z. --- <!-- claude-projects-attribution: {"github_login":"Prime1997"} --> _Requested by **Prime**_ `placements::unmap_if_superseded` holds the placements `REGISTRY` mutex while it calls `vram::unmap_superseded_target`. That call also finishes the other held unmaps on the device whose fences have passed, and it dropped their resource references before returning, so still under `REGISTRY`. If one of those is the last reference to a target the title released while its unmap was held, the hooked Release runs `res_release` -> `forget_for_recycle` -> `placements::released` -> `settle`, which locks `REGISTRY` again on the same thread. The thread then waits for itself, and every later `CreatePlacedResource`, `note_use` and held unmap waits behind it: the title hangs. We found it in our fork, where another change makes this case common; on main it is latent but the path is the same. Now the completed references are returned to `unmap_if_superseded`, which drops them after it lets `REGISTRY` go. `REGISTRY` is also locked through a small `lock()` helper that fails a debug assertion when a thread locks it twice, so tests catch this kind of re-entry instead of hanging. Related: #3577 (draft) changes how `note_use` takes `REGISTRY`; the two touch the same lock line in `note_use`, so whichever lands second needs a one-line rebase. **What is in it** - `crates/xcl/src/hle/d3d12x/vram.rs`: `unmap_placed` and `unmap_superseded_target` return the completed held unmaps' references (`#[must_use]`) instead of dropping them; `unmap_superseded`, whose callers hold no lock, drops them as before. - `crates/xcl/src/hle/d3d12x/placements.rs`: `unmap_if_superseded` drops the `REGISTRY` guard, then the returned references. `lock()` replaces `REGISTRY.lock().unwrap()` and keeps a thread-local "held" flag that a debug assertion checks. **Tested** - RTX 3060 Ti 8 GB, Windows 11, release build: the change has been in our test builds since 30 Nov (no measured before/after on its own). - This branch (on main 1c8b5514): `cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnu` passes. The test suite was not run on this exact branch. **Regression run** - Not run yet: testers welcome. **Not tested** - The suite and `scripts/smoke.ps1` on this branch; AMD. - No unit test for the re-entry itself: it needs a live device and a held unmap that completes after the title released its target. The debug assertion covers any test that reaches it. **AI use** - Claude Code wrote the change and this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Foniass commented 2026-12-02 09:20:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:20:53Z.


Review (head 15ae8026, diff read, not a merge-check; checks red):

  • PR description check is red: no regression run. PR checks refuses the PR because the runtime changes (placements.rs, vram.rs) and Regression run has no xcl-smoke block from this head (15ae802667) or from main. Tested also has no suite run on this branch, only cargo check for the x86_64-pc-windows-gnu target. "In our test builds since 30 Nov" is about a fork with other changes, not this commit.
  • No test for the fix. A bug fix needs a test that fails without it. #3648 fixes the same kind of bug (a replaced value dropped under CHAINS) and tests it without a device: a value whose Drop checks with try_lock that the map's lock is free. A test like that would work here, for example a Drop type in the returned Vec that checks REGISTRY with try_lock. At the least, a #[should_panic] test that calls lock() twice should cover the new assertion. Right now nothing exercises the assertion.
  • "So tests catch this kind of re-entry" does not hold yet. No test goes through lock(). The tests in placements.rs (~717, ~778) call Registry methods directly. placed, settle, note_use and unmap_if_superseded are only reached from the D3D12 hooks on a live device. So the debug_assert in lock() (~388) fires only in a debug build that runs a title. In release builds a re-entry still hangs, as before.

Fine: by reading, the hang described is real on main. The Release hook takes the last-reference path in real.rs ~2541 and calls vram::forget_for_recycle (~928), which calls placements::released, then settle, which locks REGISTRY again. Before this change that ran inside unmap_if_superseded's lock whenever a completed held unmap held the last reference to a target the title had already released. Dropping the references after the guard leaves no window for address reuse: the returned Vec keeps those objects alive, so their addresses (the registry keys) cannot be reused before the release cleanup runs. That cleanup then runs with no lock held, like any title Release. It is the same order as unmap_superseded's callers, before_execute (vram.rs ~2895-2930, completed_unmaps dropped after PAGES) and map_again/settle. Every early return of unmap_placed now returns an empty Vec. Every REGISTRY lock goes through lock(). #3648 uses the same pattern in another file, and #3651 and #3653 merge cleanly with this PR without overlapping it.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7340749636 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7340749636). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T09:20:53Z. --- Review (head 15ae8026, diff read, not a merge-check; checks red): - **PR description check is red: no regression run.** `PR checks` refuses the PR because the runtime changes (`placements.rs`, `vram.rs`) and **Regression run** has no `xcl-smoke` block from this head (15ae802667b1) or from main. **Tested** also has no suite run on this branch, only `cargo check` for the `x86_64-pc-windows-gnu` target. "In our test builds since 30 Nov" is about a fork with other changes, not this commit. - **No test for the fix.** A bug fix needs a test that fails without it. #3648 fixes the same kind of bug (a replaced value dropped under `CHAINS`) and tests it without a device: a value whose `Drop` checks with `try_lock` that the map's lock is free. A test like that would work here, for example a `Drop` type in the returned `Vec` that checks `REGISTRY` with `try_lock`. At the least, a `#[should_panic]` test that calls `lock()` twice should cover the new assertion. Right now nothing exercises the assertion. - **"So tests catch this kind of re-entry" does not hold yet.** No test goes through `lock()`. The tests in `placements.rs` (~717, ~778) call `Registry` methods directly. `placed`, `settle`, `note_use` and `unmap_if_superseded` are only reached from the D3D12 hooks on a live device. So the `debug_assert` in `lock()` (~388) fires only in a debug build that runs a title. In release builds a re-entry still hangs, as before. Fine: by reading, the hang described is real on main. The `Release` hook takes the last-reference path in `real.rs` ~2541 and calls `vram::forget_for_recycle` (~928), which calls `placements::released`, then `settle`, which locks `REGISTRY` again. Before this change that ran inside `unmap_if_superseded`'s lock whenever a completed held unmap held the last reference to a target the title had already released. Dropping the references after the guard leaves no window for address reuse: the returned `Vec` keeps those objects alive, so their addresses (the registry keys) cannot be reused before the release cleanup runs. That cleanup then runs with no lock held, like any title `Release`. It is the same order as `unmap_superseded`'s callers, `before_execute` (`vram.rs` ~2895-2930, `completed_unmaps` dropped after `PAGES`) and `map_again`/`settle`. Every early return of `unmap_placed` now returns an empty `Vec`. Every `REGISTRY` lock goes through `lock()`. #3648 uses the same pattern in another file, and #3651 and #3653 merge cleanly with this PR without overlapping it. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 09:36:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:36:27Z.


Test report (not a merge-check: PR description red)
base: 1c8b551475
head: 15ae802667
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7340749636 and its findings stand. Most serious: no test for the fix (the code is correct by reading).
performance: 60 s smoke of a retail title, main 1c8b5514 vs this merge (15ae8026): 1652 -> 1678 frames shown (101 %; last presents per 2 s: 61 60 60), peak commit 18228 -> 17254 MB, 0 device removals, 0 crashes.
assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: no test for the fix (the code is correct by reading)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7341192977 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7341192977). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T09:36:27Z. --- Test report (not a merge-check: `PR description` red) base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: 15ae802667b179f0b4fd5e5cb978733a799316f1 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2909 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7340749636 and its findings stand. Most serious: no test for the fix (the code is correct by reading). performance: 60 s smoke of a retail title, main 1c8b5514 vs this merge (15ae8026): 1652 -> 1678 frames shown (101 %; last presents per 2 s: 61 60 60), peak commit 18228 -> 17254 MB, 0 device removals, 0 crashes. assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: no test for the fix (the code is correct by reading) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 AI-written and posted by Foniass without a human check of each point.
Edgaras0404 commented 2026-12-02 16:45:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Edgaras0404 on 2026-12-02T16:45:41Z.


Test report (not a merge-check: PR description is red — the description has no regression run; Build and test is green on this head)
base: 5eaadb54c1
head: 15ae802667
merge: clean (merge commit e473ffc2d7157c978d8dfec09628a6e05b0c5290)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> lib: 1158 ok, 278 failed, 26 ignored (no test result: line; the binary aborts at exit 0x80004005 after 40 watchdog thread dumps); the other binaries: 138 passed, 2 failed, 20 ignored; SKIPPED: 1 (hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap: no heap windows (opt-in: XCL_HEAP_WINDOWS=1)); failing: the same 278 lib tests fail on base (base: 1153 ok, 278 failed, 26 ignored, same abort; a lib-only rerun of each tree fails the identical 278 names, and across the two full-suite runs only the two tests in flight when the device went away differ), gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs fails on base too (child at line 472, parent at line 584), and gpu_compute_e2e loses its process to a device removal 0x887a0020 on base too. Cause: open #3694 (#3655 in main since d71578f8; split-wave64 compute gives CreateComputePipelineState 0x887A0005 and removes the device on RDNA2). Targeted on the merge: hle::d3d12x::vram::tests 85 passed / 0 failed / 1 ignored, hle::d3d12x::placements::tests 13 passed / 0 failed.
review: whole diff read. Most serious: (1) no test for the fix. The PR says so; placed, settle, note_use and unmap_if_superseded are reached only from the D3D12 hooks on a live device, the tests in placements.rs call Registry methods directly, and nothing exercises the new lock() assertion, so a regression in this order still goes unnoticed. (2) Regression run is empty and Tested has only cargo check --target x86_64-pc-windows-gnu on this branch, so PR description is red and the PR is not mergeable yet. (3) The assertion is debug_assert!: in release builds a re-entry still deadlocks, so it is a diagnostic, not a fix for an unknown path. (4) By reading the fix is correct: the returned Vec<ID3D12Resource> keeps the completed unmaps alive, so no target address can be reused before their release cleanup runs; they are dropped after REGISTRY is let go; every REGISTRY lock now goes through lock(); remap_if_unmapped's cancel branch also drops a held unmap's resource under REGISTRY, but it returns early once the target was forgotten, so it cannot be the last reference there. Scope: one logical change, +79/−20 in 2 files.
performance: no cost expected — a Vec return, a Cell<bool> per lock, and REGISTRY held for a shorter time (the release work moved out of it). Measured on AMD, 40 s scripts/smoke.ps1 on 1c8b5514 (the last main before #3655, because current main cannot start the title): base 1023 frames / 17,904 MB, this PR 1030 frames / 17,925 MB (101 % frames, 100 % peak commit), 0 device removals, 0 crashes, presents per 2 s 61 57 60 vs 61 59 60. 40 s and not 60 s because this title dies in amdxc64.dll at ~45 s on this GPU (open #3544). Current main 5eaadb54 cannot be compared: it exits 0x887a0020 at 4.2 s on a 62 KB split-wave64 compute PSO (#3694).
assessment: nothing in this PR regresses the base — the 278 suite failures, the two integration failures and the title crash are identical on base 5eaadb54, and all come from open #3694. What blocks the PR is its own description and test: no test for the fix, and Regression run empty (PR description red).
hardware / tool and model: AMD Radeon RX 6700 XT 12 GB (RDNA2), driver 32.0.21045.29003; AMD Ryzen 5 5600X; Windows 10 build 19045 / OpenCode with DeepSeek V4.1 Flash 1017

Smoke blocks, if the author wants them for a regression run (base 1c8b5514, merge aec87505 = this head merged onto it):

xcl-smoke v1
commit: 1c8b551475
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 40
exit: 0x0
frames shown: 1023 (PresentX 1023)
presents per 2 s (last 3): 61 57 60
device removals: 0
crashes: 0
peak commit: 17904 MB

xcl-smoke v1
commit: aec87505f96097f4d88351ca53663175289a0e5b
gpu: AMD Radeon RX 6700 XT
title: 1778c2d9
seconds: 40
exit: 0x0
frames shown: 1030 (PresentX 1030)
presents per 2 s (last 3): 61 59 60
device removals: 0
crashes: 0
peak commit: 17925 MB

AI-written from a real run (OpenCode, DeepSeek V4.1 Flash 1017); posted only after the human checks each point.

<!-- greyfinch-sync:ivall/xcl:comment:7352415760 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7352415760). Originally posted by [Edgaras0404](https://github.com/Edgaras0404) on 2026-12-02T16:45:41Z. --- Test report (not a merge-check: `PR description` is red — the description has no regression run; `Build and test` is green on this head) base: 5eaadb54c14e0fc29597b2a1689d7dbd83491303 head: 15ae802667b179f0b4fd5e5cb978733a799316f1 merge: clean (merge commit e473ffc2d7157c978d8dfec09628a6e05b0c5290) build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> lib: 1158 ok, 278 failed, 26 ignored (no `test result:` line; the binary aborts at exit 0x80004005 after 40 watchdog thread dumps); the other binaries: 138 passed, 2 failed, 20 ignored; SKIPPED: 1 (`hle::d3d12x::bind::tests::two_pass_binds_set_the_shared_view_heap: no heap windows (opt-in: XCL_HEAP_WINDOWS=1)`); failing: the same 278 lib tests fail on base (base: 1153 ok, 278 failed, 26 ignored, same abort; a lib-only rerun of each tree fails the identical 278 names, and across the two full-suite runs only the two tests in flight when the device went away differ), `gpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` fails on base too (child at line 472, parent at line 584), and `gpu_compute_e2e` loses its process to a device removal 0x887a0020 on base too. Cause: open #3694 (`#3655` in main since d71578f8; split-wave64 compute gives `CreateComputePipelineState` 0x887A0005 and removes the device on RDNA2). Targeted on the merge: `hle::d3d12x::vram::tests` 85 passed / 0 failed / 1 ignored, `hle::d3d12x::placements::tests` 13 passed / 0 failed. review: whole diff read. Most serious: (1) no test for the fix. The PR says so; `placed`, `settle`, `note_use` and `unmap_if_superseded` are reached only from the D3D12 hooks on a live device, the tests in `placements.rs` call `Registry` methods directly, and nothing exercises the new `lock()` assertion, so a regression in this order still goes unnoticed. (2) **Regression run** is empty and **Tested** has only `cargo check --target x86_64-pc-windows-gnu` on this branch, so `PR description` is red and the PR is not mergeable yet. (3) The assertion is `debug_assert!`: in release builds a re-entry still deadlocks, so it is a diagnostic, not a fix for an unknown path. (4) By reading the fix is correct: the returned `Vec<ID3D12Resource>` keeps the completed unmaps alive, so no target address can be reused before their release cleanup runs; they are dropped after `REGISTRY` is let go; every `REGISTRY` lock now goes through `lock()`; `remap_if_unmapped`'s cancel branch also drops a held unmap's resource under `REGISTRY`, but it returns early once the target was forgotten, so it cannot be the last reference there. Scope: one logical change, +79/−20 in 2 files. performance: no cost expected — a `Vec` return, a `Cell<bool>` per lock, and `REGISTRY` held for a shorter time (the release work moved out of it). Measured on AMD, 40 s `scripts/smoke.ps1` on `1c8b5514` (the last main before #3655, because current main cannot start the title): base 1023 frames / 17,904 MB, this PR 1030 frames / 17,925 MB (101 % frames, 100 % peak commit), 0 device removals, 0 crashes, presents per 2 s 61 57 60 vs 61 59 60. 40 s and not 60 s because this title dies in `amdxc64.dll` at ~45 s on this GPU (open #3544). Current main `5eaadb54` cannot be compared: it exits 0x887a0020 at 4.2 s on a 62 KB split-wave64 compute PSO (#3694). assessment: nothing in this PR regresses the base — the 278 suite failures, the two integration failures and the title crash are identical on base `5eaadb54`, and all come from open #3694. What blocks the PR is its own description and test: no test for the fix, and **Regression run** empty (`PR description` red). hardware / tool and model: AMD Radeon RX 6700 XT 12 GB (RDNA2), driver 32.0.21045.29003; AMD Ryzen 5 5600X; Windows 10 build 19045 / OpenCode with DeepSeek V4.1 Flash 1017 Smoke blocks, if the author wants them for a regression run (base `1c8b5514`, merge `aec87505` = this head merged onto it): xcl-smoke v1 commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f gpu: AMD Radeon RX 6700 XT title: 1778c2d9 seconds: 40 exit: 0x0 frames shown: 1023 (PresentX 1023) presents per 2 s (last 3): 61 57 60 device removals: 0 crashes: 0 peak commit: 17904 MB xcl-smoke v1 commit: aec87505f96097f4d88351ca53663175289a0e5b gpu: AMD Radeon RX 6700 XT title: 1778c2d9 seconds: 40 exit: 0x0 frames shown: 1030 (PresentX 1030) presents per 2 s (last 3): 61 59 60 device removals: 0 crashes: 0 peak commit: 17925 MB AI-written from a real run (OpenCode, DeepSeek V4.1 Flash 1017); posted only after the human checks each point.
bmjask commented 2026-12-02 20:16:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:16:47Z.

Review: COMMENTED


Review of 15ae8026: 1 finding(s) (1 medium), most severe first.

  1. Medium crates/xcl/src/hle/d3d12x/vram.rs:2575: see below.

On lines outside the diff:

  1. Medium crates/xcl/src/hle/d3d12x/vram.rs:2575: Not certain about this one, because it depends on a queue-lease holder reaching REGISTRY: unmap_placed calls native_queue_signal, which waits for queue_submit's per-queue lease, while placements::unmap_if_superseded still holds REGISTRY, so here REGISTRY is taken before the queue lease. If thread B (drain_known -> unmap_if_superseded) holds REGISTRY and waits for queue Q's lease, while thread A holds Q's lease (inside ExecuteCommandLists or XCL setup work) and reaches REGISTRY (a last Release -> res_release -> forget_for_recycle -> placements::released -> settle -> lock(), or note_use), each waits on the other and the title hangs, the same class of hang this PR fixes. Returning the signals and issuing them after REGISTRY is dropped, as the PR now does for the references, would close it.

These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6158209395 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665#pullrequestreview-6158209395). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T20:16:47Z. **Review:** COMMENTED --- Review of `15ae8026`: 1 finding(s) (1 medium), most severe first. 1. **Medium** `crates/xcl/src/hle/d3d12x/vram.rs:2575`: see below. **On lines outside the diff:** 1. **Medium** `crates/xcl/src/hle/d3d12x/vram.rs:2575`: Not certain about this one, because it depends on a queue-lease holder reaching REGISTRY: `unmap_placed` calls `native_queue_signal`, which waits for `queue_submit`'s per-queue lease, while `placements::unmap_if_superseded` still holds REGISTRY, so here REGISTRY is taken before the queue lease. If thread B (`drain_known` -> `unmap_if_superseded`) holds REGISTRY and waits for queue Q's lease, while thread A holds Q's lease (inside ExecuteCommandLists or XCL setup work) and reaches REGISTRY (a last Release -> `res_release` -> `forget_for_recycle` -> `placements::released` -> `settle` -> `lock()`, or `note_use`), each waits on the other and the title hangs, the same class of hang this PR fixes. Returning the signals and issuing them after REGISTRY is dropped, as the PR now does for the references, would close it. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
Foniass commented 2026-12-03 14:40:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:40:28Z.


merge-check
base: 16c2fd082a
head: 15ae802667
merge: clean
build: ok
tests: 3012 passed, 0 failed, 56 ignored; 28 skipped, the same as on main
review: 1 high, 2 medium, 1 nit (below)
performance: 60 s smoke run: 1683 → 1664 frames (98 % of main), peak commit 18505 → 18661 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 240 s there, 0 device removals, 0 crashes, 2.9 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: 1 blocking finding (critical or high, below); also PR description is red
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: vram::unmap_superseded_target now returns the completed held unmaps' references, and placements::unmap_if_superseded drops them after it lets REGISTRY go. This fixes a hang where a thread locked REGISTRY again while holding it. It also adds a debug-only check for that. The head has not changed since my earlier review: the code is correct by reading (another tester's AMD report agrees), but the fix has no test and nothing exercises the new check, which blocks it.

High

  1. No test for the fix. Still open from my earlier review. A bug fix needs a test that fails without it. #3648 tests the same kind of bug without a device: a value whose Drop checks with try_lock that the lock is free. Here, a Drop type in the returned Vec that checks REGISTRY with try_lock would do it. At the least, a #[should_panic] test that calls lock() twice should cover the new check.

Medium

  1. "So tests catch this kind of re-entry" does not hold. Still open. No test goes through lock(). The tests in placements.rs (~717, ~778) call Registry methods directly, and placed, settle, note_use and unmap_if_superseded are reached only from the D3D12 hooks on a live device. The debug_assert in lock() (~388) fires only in a debug build that runs a title, and a re-entry in a release build still hangs.
  2. Description gaps. Still open. Tested has only cargo check for the gnu target, with no suite counts. Regression run has no xcl-smoke blocks. Another tester posted AMD blocks on the PR, but their PR block names merge aec87505, not this head, so it does not meet the rule. AI use does not name the model.

Nit

  1. Queue signals still go out under REGISTRY. unmap_placed (vram.rs ~2575) calls native_queue_signal, which takes the queue's submit lease, while unmap_if_superseded holds REGISTRY. A later review on the PR suggests this lock order could invert against a lease holder that reaches REGISTRY. That order is on main already and not changed here, and by reading I found no lease holder that takes REGISTRY. Returning the signals with the references would settle the question.
Checked and fine
  • The hang is real on main: Release hook last reference (real.rs ~2541) -> forget_for_recycle (~928) -> placements::released -> settle locks REGISTRY again under unmap_if_superseded
  • The returned Vec keeps those objects alive, so their addresses (the registry keys) cannot be reused before their release cleanup runs
  • Every early return of unmap_placed returns an empty Vec, every REGISTRY lock goes through lock(), and unmap_superseded's callers drop the references as before
  • Overlaps only textually with #3577 (one lock line in note_use)
How this was tested
  • Merged onto main 16c2fd08, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 16c2fd08 and on this merge; presents per 2 s at the end: 60 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7381840067 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3665#issuecomment-7381840067). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T14:40:28Z. --- merge-check base: 16c2fd082ae2e96967a2ab553bc2e1032e491f70 head: 15ae802667b179f0b4fd5e5cb978733a799316f1 merge: clean build: ok tests: 3012 passed, 0 failed, 56 ignored; 28 skipped, the same as on main review: 1 high, 2 medium, 1 nit (below) performance: 60 s smoke run: 1683 → 1664 frames (98 % of main), peak commit 18505 → 18661 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 240 s there, 0 device removals, 0 crashes, 2.9 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: not yet: 1 blocking finding (critical or high, below); also `PR description` is red hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** vram::unmap_superseded_target now returns the completed held unmaps' references, and placements::unmap_if_superseded drops them after it lets REGISTRY go. This fixes a hang where a thread locked REGISTRY again while holding it. It also adds a debug-only check for that. The head has not changed since my earlier review: the code is correct by reading (another tester's AMD report agrees), but the fix has no test and nothing exercises the new check, which blocks it. #### High 1. **No test for the fix.** Still open from my earlier review. A bug fix needs a test that fails without it. #3648 tests the same kind of bug without a device: a value whose Drop checks with try_lock that the lock is free. Here, a Drop type in the returned Vec that checks REGISTRY with try_lock would do it. At the least, a #[should_panic] test that calls lock() twice should cover the new check. #### Medium 2. **"So tests catch this kind of re-entry" does not hold.** Still open. No test goes through lock(). The tests in placements.rs (~717, ~778) call Registry methods directly, and placed, settle, note_use and unmap_if_superseded are reached only from the D3D12 hooks on a live device. The debug_assert in lock() (~388) fires only in a debug build that runs a title, and a re-entry in a release build still hangs. 3. **Description gaps.** Still open. Tested has only cargo check for the gnu target, with no suite counts. Regression run has no xcl-smoke blocks. Another tester posted AMD blocks on the PR, but their PR block names merge aec87505, not this head, so it does not meet the rule. AI use does not name the model. #### Nit 4. **Queue signals still go out under REGISTRY.** unmap_placed (vram.rs ~2575) calls native_queue_signal, which takes the queue's submit lease, while unmap_if_superseded holds REGISTRY. A later review on the PR suggests this lock order could invert against a lease holder that reaches REGISTRY. That order is on main already and not changed here, and by reading I found no lease holder that takes REGISTRY. Returning the signals with the references would settle the question. <details><summary>Checked and fine</summary> - The hang is real on main: Release hook last reference (real.rs ~2541) -> forget_for_recycle (~928) -> placements::released -> settle locks REGISTRY again under unmap_if_superseded - The returned Vec keeps those objects alive, so their addresses (the registry keys) cannot be reused before their release cleanup runs - Every early return of unmap_placed returns an empty Vec, every REGISTRY lock goes through lock(), and unmap_superseded's callers drop the references as before - Overlaps only textually with #3577 (one lock line in note_use) </details> <details><summary>How this was tested</summary> - Merged onto main `16c2fd08`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `16c2fd08` and on this merge; presents per 2 s at the end: 60 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
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/3665:upstream-pr/3665'
git switch 'upstream-pr/3665'

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