Placements: drop completed unmaps' references after releasing REGISTRY #3665
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3665"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-12-02T05:54:06Z.
Requested by Prime
placements::unmap_if_supersededholds the placementsREGISTRYmutex while it callsvram::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 underREGISTRY. If one of those is the last reference to a target the title released while its unmap was held, the hooked Release runsres_release->forget_for_recycle->placements::released->settle, which locksREGISTRYagain on the same thread. The thread then waits for itself, and every laterCreatePlacedResource,note_useand 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 tounmap_if_superseded, which drops them after it letsREGISTRYgo.REGISTRYis also locked through a smalllock()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_usetakesREGISTRY; the two touch the same lock line innote_use, so whichever lands second needs a one-line rebase.What is in it
crates/xcl/src/hle/d3d12x/vram.rs:unmap_placedandunmap_superseded_targetreturn 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_supersededdrops theREGISTRYguard, then the returned references.lock()replacesREGISTRY.lock().unwrap()and keeps a thread-local "held" flag that a debug assertion checks.Tested
1c8b5514):cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnupasses. The test suite was not run on this exact branch.Regression run
Not tested
scripts/smoke.ps1on this branch; AMD.AI use
🤖 Generated with Claude Code
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 checksrefuses the PR because the runtime changes (placements.rs,vram.rs) and Regression run has noxcl-smokeblock from this head (15ae802667) or from main. Tested also has no suite run on this branch, onlycargo checkfor thex86_64-pc-windows-gnutarget. "In our test builds since 30 Nov" is about a fork with other changes, not this commit.CHAINS) and tests it without a device: a value whoseDropchecks withtry_lockthat the map's lock is free. A test like that would work here, for example aDroptype in the returnedVecthat checksREGISTRYwithtry_lock. At the least, a#[should_panic]test that callslock()twice should cover the new assertion. Right now nothing exercises the assertion.lock(). The tests inplacements.rs(~717, ~778) callRegistrymethods directly.placed,settle,note_useandunmap_if_supersededare only reached from the D3D12 hooks on a live device. So thedebug_assertinlock()(~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
Releasehook takes the last-reference path inreal.rs~2541 and callsvram::forget_for_recycle(~928), which callsplacements::released, thensettle, which locksREGISTRYagain. Before this change that ran insideunmap_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 returnedVeckeeps 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 titleRelease. It is the same order asunmap_superseded's callers,before_execute(vram.rs~2895-2930,completed_unmapsdropped afterPAGES) andmap_again/settle. Every early return ofunmap_placednow returns an emptyVec. EveryREGISTRYlock goes throughlock(). #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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:36:27Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
15ae802667merge: 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
1c8b5514vs 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.
Imported from ivall/xcl. Originally posted by Edgaras0404 on 2026-12-02T16:45:41Z.
Test report (not a merge-check:
PR descriptionis red — the description has no regression run;Build and testis green on this head)base:
5eaadb54c1head:
15ae802667merge: 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_blobsfails on base too (child at line 472, parent at line 584), andgpu_compute_e2eloses its process to a device removal 0x887a0020 on base too. Cause: open #3694 (#3655in main sinced71578f8; split-wave64 compute givesCreateComputePipelineState0x887A0005 and removes the device on RDNA2). Targeted on the merge:hle::d3d12x::vram::tests85 passed / 0 failed / 1 ignored,hle::d3d12x::placements::tests13 passed / 0 failed.review: whole diff read. Most serious: (1) no test for the fix. The PR says so;
placed,settle,note_useandunmap_if_supersededare reached only from the D3D12 hooks on a live device, the tests inplacements.rscallRegistrymethods directly, and nothing exercises the newlock()assertion, so a regression in this order still goes unnoticed. (2) Regression run is empty and Tested has onlycargo check --target x86_64-pc-windows-gnuon this branch, soPR descriptionis red and the PR is not mergeable yet. (3) The assertion isdebug_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 returnedVec<ID3D12Resource>keeps the completed unmaps alive, so no target address can be reused before their release cleanup runs; they are dropped afterREGISTRYis let go; everyREGISTRYlock now goes throughlock();remap_if_unmapped's cancel branch also drops a held unmap's resource underREGISTRY, 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
Vecreturn, aCell<bool>per lock, andREGISTRYheld for a shorter time (the release work moved out of it). Measured on AMD, 40 sscripts/smoke.ps1on1c8b5514(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 inamdxc64.dllat ~45 s on this GPU (open #3544). Current main5eaadb54cannot 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 descriptionred).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, mergeaec87505= this head merged onto it):xcl-smoke v1
commit:
1c8b551475gpu: 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.
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.crates/xcl/src/hle/d3d12x/vram.rs:2575: see below.On lines outside the diff:
crates/xcl/src/hle/d3d12x/vram.rs:2575: Not certain about this one, because it depends on a queue-lease holder reaching REGISTRY:unmap_placedcallsnative_queue_signal, which waits forqueue_submit's per-queue lease, whileplacements::unmap_if_supersededstill 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(), ornote_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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T14:40:28Z.
merge-check
base:
16c2fd082ahead:
15ae802667merge: 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 descriptionis redhardware / 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
Medium
Nit
Checked and fine
How this was tested
16c2fd08, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main16c2fd08and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.