Skip to content

[upstream #1070] D3D12.X: a held resource keeps its memory until its Release goes - #84

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1070
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1070

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Late release (e7da8a1) holds a resource whose last Release comes while a queue may still have work on it. But res_release still gave back, at the title's Release, what XCL had placed under the resource. The unified-memory block went back on the free list, so the next resource XCL placed could get it while the GPU still used it. A sparse block was decommitted and its address range returned, and the buffer's tiles were unpinned (sparse::forget_buffer → release_if_unused). The held resource's in-flight work could then read another resource's data or unmapped tiles. e7da8a1 measured 356 held releases on the retail title.

XCL's bookkeeping for the resource still goes at the title's Release, as before (a held object keeps its address). A held resource's block and its tile pins go to late_release with it: drain_known unpins the tiles before the final Release (while the resource is alive, its address is no other resource's) and frees the block after it. A release that is not held frees at once, as before. vram::forget (arena release, which has its own delay) and title_textures::forget (bookkeeping) are unchanged. Fixes xcl-dev#1040.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: res_release passes the block to late_release::hold when it holds the resource, and skips sparse::forget_buffer then; free_backing (the UMA / sparse free, as before).
  • crates/xcl/src/hle/d3d12x/late_release.rs: held entries carry their block; drain_known unpins, releases, then frees. The two existing tests now carry the pair.
  • crates/xcl/src/gpu/uma.rs: Uma::is_allocated, test-only (#[cfg(test)]).
  • Test held_release_tests::a_held_resource_keeps_its_unified_memory_until_it_goes. A known queue stands still on a fence; an adopted buffer gets a unified-memory block recorded as place_console_buffer does; its last Release goes through res_release. The block must stay allocated while the queue has work, and go once it has passed. On main it fails at the first check ("the block under a held resource went back while a queue still had work").

Tested

  • AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Ryzen 5 5600X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug; DXC 1.9.2602.17 (SDK 10.0.26100.0).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 at 9aa0e9a (on main 47efa2e): 742 passed, 0 failed, 41 ignored, 0 SKIPPED.
  • cargo test -p xcl --lib held_release_tests: fails on main, passes with the change; 5 of 5 runs passed alone.
  • late_release::tests (2) pass.

Regression run

Not run yet: there's no runnable title on this machine. A tester with any unpacked Xbox Series title can supply the pair (the title need not reach this code): in clean checkouts of main and of this PR's head, cargo build --release -p xcl then .\scripts\smoke.ps1 -Game '<folder>' -Seconds 60, same title and machine, and post both xcl-smoke blocks here. I'll put them in this section.

Not tested

  • A retail title: the corruption itself (what a reused block looks like on screen) is not observed, only the early free.
  • The sparse path end to end: the test uses a block in the coherent window. The sparse branch goes through the same free_backing / forget_buffer calls.
  • XCL_LATE_RELEASE=0 (nothing is held, so the change does nothing there).

AI use

  • Claude Code (Claude Opus 5.5): found the bug, wrote the test, the fix and this description. I read the diff and ran the tests above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1070 (auto-synced, do not edit).

Late release (e7da8a1) holds a resource whose last Release comes while a
queue may still use it, but res_release still gave back what XCL placed
under it at the title's Release: the unified-memory block went back on
the free list (the next resource could get it while the GPU still used
it), and a sparse block was decommitted and its tiles unpinned.

The bookkeeping still goes at the title's Release. A held resource's
block and its sparse tile pins go to late_release, which unpins the
tiles before the resource's final Release (its address is no other
resource's yet) and frees the block after it. A release that is not
held frees at once, as before.

Fixes xcl-dev#1040

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1070 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1070 branch November 25, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: a held last Release gives the resource's unified memory / sparse tiles back while the queues still use it

2 participants