D3D12.X: fix HEAP_UMA lifetime issue for placed buffers (XCL-BT-001) #2076
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2086"
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 saurabhbhoir456 on 2026-11-25T03:34:50Z.
What changes and why
Fix XCL-BT-001: HEAP_UMA lifetime issue for placed buffers.
When a HEAP_UMA heap was released (refcount reached 0), its backing memory block was freed immediately even if placed buffers still referenced it. This caused memory corruption when the title's last
Releaseof a buffer raced with the heap'sRelease.The fix tracks
live_buffersper HEAP_UMA heap:live_bufferswhen a buffer is placed in a HEAP_UMA heap (2 insertion sites pass a non-zero heap:place_console_bufferandplace_at_title_addressfor heap-allocated buffers)res_release: decrementlive_buffers; if it reaches 0 and the heap was already released (block isSome), free the blockmem_heap_release: iflive_buffers == 0, free block immediately and remove entry; otherwise keep the entry and its block so the last buffer'sReleasecan free itThis defers the block free until all buffers in the heap are released.
Commits:
D3D12.X: fix HEAP_UMA lifetime issue for placed buffers (XCL-BT-001)(crates/xcl/src/hle/d3d12x/real.rs)live_buffers: usizefield toHeapUmastructUmaBuffertype from(usize, usize, bool)to(usize, usize, bool, usize)to store the heap referencelive_buffersres_releaseto decrementlive_buffersand defer block freemem_heap_releaseto defer block free when buffers are still aliveD3D12.X: keep HEAP_UMA block until all placed buffers are released(crates/xcl/src/hle/d3d12x/real.rs)mem_heap_releaseno longer discardse.blockwhen buffers are still alive, sores_releasecan free the block oncelive_buffersreaches zeroWhat is in it
D3D12.X: fix HEAP_UMA lifetime issue for placed buffers (XCL-BT-001)(crates/xcl/src/hle/d3d12x/real.rs)D3D12.X: keep HEAP_UMA block until all placed buffers are released(crates/xcl/src/hle/d3d12x/real.rs)Tested
cargo build --workspace; cargo test --workspace -- --test-threads=4Regression run
scripts/smoke.ps1 -Game <folder>on main and this branch head and paste both xcl-smoke blocks when a title is available.Not tested
AI use
🤖 Generated with Claude Code
upstream-sync referenced this pull request2026-11-25 05:07:03 +00:00
Imported from ivall/xcl. Originally posted by frenziedcoder on 2026-11-25T04:23:57Z.
NVIDIA test report for
697caca: no new test failures (the 4 that fail also fail oncbc296a), no own test to run, and a clean smoke pair on the retail title (1605 vs 1655 frames).Tested
stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (SDK 10.0.26100.0). Exact head697cacae7a8ad7e6897dc4d7d7c8a9f00e836014, no local changes.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4(debug): 1150 passed, 4 failed, 46 ignored; the PR adds no test of its own. SKIPPED:gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu(no wave64),gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu(no wave64),gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu(no wave64),gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu(no wave64),gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu(no wave64),gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu(const_mask, wave64: no wave64),gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu(f16 arithmetic, wave64: no wave64),gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu(f16 packed, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 arithmetic, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 compares, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 conversions, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 rounding, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 three-source, wave64: no wave64),gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu(f32 transcendentals, wave64: no wave64),gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu(f64, wave64: no wave64),gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu(integer arithmetic, wave64: no wave64),gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu(integer carries, wave64: no wave64),gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(mask_ff0_flbit, wave64: no wave64),gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).fuzz_validate_and_gpu_0,fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_2,fuzz_validate_and_gpu_3ingpu::dxil::fuzz_tests. They fail the same way on the basecbc296ahere (0x8007000EfromCreateComputePipelineStateon seeds 70, 545, 1019 and 1507, the NVIDIA refusal @PHeitor1 reported on #1679), so this PR adds no failure.test_title_draws_with_a_root_signature_under_the_debug_layerreports ok, but this machine has no D3D12 debug layer (debug layer requested but unavailable … (0x887A002D)), so it ran without the layer and is no evidence either way.Regression run (
scripts/smoke.ps1 -Seconds 60, release, the retail title of #505 at its start screen;XCL_PSO_PRELOAD=0for both builds, because this machine's preload list holds the program of #1307)base (
cbc296a, this PR's merge base withmain):this PR:
Not tested: the world load (the smoke runs stop at the start screen, so code that only runs later is not exercised there); AMD.
AI use: Claude Code (Claude Opus 5.5) built and ran the tests and smoke runs on my machine and wrote this report; I checked it.
Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-25T05:22:19Z.
A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with
main(1365 here; 1371 and 1356 on the twomainruns). Nothing in the log points to the placed-bufferHEAP_UMApath, so I cannot tell whether this run reached it; this is a regression run only.Tested
x86_64-pc-windows-gnu.697cacaas it is (based oncbc296a) andmainf5c5bdf, no uncommitted changes. Retail title 1.0.2.1,scripts/linux/smoke.sh(#257) for 60 s, no input. Runs in order: main, this PR (with other PRs in between), main.Regression run
main (first run):
this PR:
The second
mainrun: 1356 frames,exit: 0x0, no device removal, no crash. Under Wine,peak commitreads 0 MB, so these blocks do not check memory.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T05:26:59Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
upstream-sync referenced this pull request2026-11-25 10:09:30 +00:00
Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T09:38:19Z.
Regression run of
e11ce9b7on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon568e7db7, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 105 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T10:48:58Z.
Code review on
e11ce9b:runner.rs(already landed via #2022) anddstorage.rs/dstorage/parallel.rs(overlapping #2094 / #2159).HEAP_UMAblock lifetime (eal.rs):
res_releasefreese.blockas soon ase.live_buffers == 0without checking whether the heap itself was released (mem_heap_release hit== 0). If a title keeps a HEAP_UMA heap alive, places and releases a first buffer, and later places a second buffer on the same heap,
e.blockwill already have been freed (leaving e.block == None). Tracking an explicit heap_released: bool on HeapUma (removing the entry + freeing e.block only once both heap_released && live_buffers == 0) fixes this safely.upstream-sync referenced this pull request2026-11-25 12:04:57 +00:00
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-25T12:53:33Z.
The suite passes on NVIDIA, but nothing in it reaches the changed release order. I agree with @raylitebull's review above: the block is freed under a live heap, and the
heap_releasedflag fixes that. It would also fix the entry of a heap released before its buffers, which the last buffer frees but never removes. Three more points:HEAP_UMAones would cover both orders: release the heap before its buffer and check that the block is freed once and the entry is gone; and release a live heap's only buffer, place a new one at the same offset, and check that its data stays where it was.late_release::holdkeeps the block until the queues are past it). Worth agreeing with that claim before both land.Tested (RTX 3060 12 GB, driver 610.88, Windows 11 Pro 26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug; on
maincbc296a):cargo build --workspace+cargo test --workspace --no-fail-fast -- --test-threads=4: 1154 passed, 0 failed, 46 ignored, at bothfe97ba1and697caca. 24 SKIPPED (no wave64, the per-lane refusals, no heap windows; the same as onmain). TheHEAP_UMAcode is unchanged ate11ce9b.Not tested: a title, the two release orders at run time.
AI use: Claude Code (Claude Opus 5.5) ran the suite, read the diff and wrote this comment.
Imported from ivall/xcl. Originally posted by throny on 2026-11-25T17:24:11Z.
Two contributors checked independently and found that #1648 solves the same problem (for #1488) in a different way: #1607, group D88. 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 from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:42:15Z.
This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T07:28:41Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:19:25Z.
Triage (#1607) – head
e11ce9bThe HEAP_UMA fix does not take effect. In
real.rsplace_at_title_addressandplace_console_buffer,heapis the UMA window's heap (UMA_HEAPS[k]).HEAP_UMAis keyed by the title'sID3D12Heap(note_heap_uma), soh.get_mut(&heap)never finds an entry andlive_buffersstays 0. The title's heap is not passed down fromdev_create_placed_resource_x, and sparse placements record heap 0. As a resultmem_heap_releasestill frees the block while buffers placed in it are alive.If the count did work,
res_releasewould free the block as soon as the last buffer goes, even while the heap itself is still alive, because nothing records that the heap was released.#1648 was opened first. It records the title heap at
dev_create_placed_resource_x, keeps areleasedflag and has a test.This PR also bundles the commits of #2150 (debug layer in the test runner) and #2159 (DirectStorage counters), which are separate changes.
Recommendation: close (bad: placed-buffer count never matches a HEAP_UMA entry; see #1648).
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.