D3D12.X: unregister resource from title_textures before final COM Release (#1359) #1394
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1404"
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 slopgobblercobbler on 2026-11-24T15:39:36Z.
Summary
Fixes #1359:
title_textures::TEXTURESstores raw, un-AddRef'dID3D12Resource*pointers and revives them into owned handles viaID3D12Resource::from_raw_borrowed(&p).map(|r| r.clone())(IUnknown::AddRef) inrefresh_onceandclone_resources.In
real::res_release:super::title_textures::forget(this as usize)previously ran only after the finalf(this)dropped the COM refcount to 0, destroying/freeing the resource, and aftersparseandvramteardown. Any concurrent upload thread could callr.clone()(AddRef) on a freed object or resurrect an object whose backing memory was being torn down.res_release, we now synchronizetitle_texturesunregistration with the final release:late_releaseis enabled andadd(this) == 2(refcount was 1, title's final release), callsuper::title_textures::forget(this as usize)beforef(this)or holding inlate_release.add(this) != 2, checkrem = f(this). Ifrem == 1, callsuper::title_textures::forget(this as usize)before the secondf(this)drops refcount to 0.late_releaseis disabled, probe refcount viaadd(this)and calltitle_textures::forget(this as usize)before the finalRelease().title_textures::forgetfirst in then == 0teardown block beforevram::forgetandUMA_BUFFERSteardown.Changes
crates/xcl/src/hle/d3d12x/real.rs:res_release: unregister fromtitle_texturesbefore finalReleasedrops COM refcount to 0.Tested
cargo test -p xcl -- real: 23 passed, 0 failed (100% pass rate).Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
Imported from ivall/xcl. Originally posted by Diskuss on 2026-11-24T15:51:55Z.
Tested on AMD Radeon RX 9070 XT (RDNA4) at
4a966038075702a657d3fdc472e987a735c3641aRyzen 7 5700X3D, 32 GB RAM, Windows 11 Pro 26300.9974, driver 32.0.32015.7029, Rust 1.100.0, DXC 1.9.2602.17, debug build.
Tested:
4a96603as-is (0 commits behind main930e8b4, no merge needed).cargo build --workspace: OK.cargo test --workspace --no-fail-fast -- --test-threads=4: 751 passed, 0 failed, 41 ignored.cargo test -p xcl --lib title_textures -- --test-threads=15 times: 13 passed, 0 failed each run (5/5).930e8b4alone gave 751 passed, 0 failed, 41 ignored, same as the PR.Not tested: retail title /
scripts/smoke.ps1(no game files), release build.Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T15:54:44Z.
Regression run for this PR: head
4a96603, based onmain930e8b4. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s.main
930e8b4:this PR:
No device removals or crashes; 98 % of main's frames, 98 % of its peak commit.
Both runs' peak commit is high because of this machine's pipeline preload list at the time (the same on
main), not this PR.Not tested: the whole suite; whether the title reaches the changed code in these 60 s.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T17:08:26Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.Thanks!
Imported from ivall/xcl. Originally posted by KainanP on 2026-11-24T19:35:28Z.
Thanks for working on #1359. I read the diff at
4a96603(not run).The refcount probes still miss the issue's first path. With the count at 2 (title +
upload_allclone) and two concurrentres_releasecalls: A add→3, B add→4, A Release→3, B Release→2, A Release→1, B Release→0. Neither thread seesadd == 2/c == 2orrem == 1, sotitle_textures::forgetfirst runs in then == 0block, after the object is freed, whilerefresh_once/clone_resourcescan still AddRef the stale pointer fromTEXTURES.A suggestion: make the decision under the lock that the revivers use. For example, do the real Release while holding the
TEXTURESlock and remove the entry in the same critical section when it returns 0, so no AddRef can land in between. Watch for re-entrancy: a clone dropped while that lock is held would deadlock.AI use: Claude Code (Claude Opus 5.5) read the diff; not run. Checked by the user before posting.
Imported from ivall/xcl. Originally posted by throny on 2026-11-24T19:38:10Z.
Two contributors checked independently and found that #1527 solves the same problem (for #1359) in a different way: #1607, group D4. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by throny on 2026-11-24T20:29:56Z.
Two contributors checked independently and found that #801 #1527 solves the same problem (for #1359) in a different way: #1607, group D38. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:38:54Z.
Triage (#1607) – head
4a96603#1527 and #801 fix the same issue (#1359) differently: #1527 decides under the TEXTURES lock with an AddRef probe and keeps the late_release hold; #801 (draft) runs the COM Release under the TEXTURES lock but is based on a main without late_release. This PR calls title_textures::forget before the final Release using refcount probes taken outside the TEXTURES lock.
In real.rs::res_release, a texture can be forgotten when the probe sees refcount 2 but another thread AddRefs before the Release, so it stops being tracked while alive; in the common path forget now runs up to three times per final release, and the non-late_release path gains an AddRef/Release probe on every release. No test was added for the fix.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.