D3D12.X: retain backing UMA block while placed buffers survive (#1488) #1638

Open
slopgobblercobbler wants to merge 1 commit from upstream-pr/1648 into main
slopgobblercobbler commented 2026-11-24 18:40:49 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T18:40:49Z.


Resolves XCL-BT-001 in #1488.

What is in it

  • In crates/xcl/src/hle/d3d12x/real.rs:
    • Extended HeapUma with placed_buffers: usize refcount and released: bool state flag.
    • In dev_create_placed_resource_x, registers placed buffer resources via note_placed_buffer(heap, *ppv as usize) when placing buffers into a HEAP_UMA heap.
    • In mem_heap_release (ID3D12Heap::Release), sets released = true. If placed_buffers > 0, defers freeing the backing UMA block to prevent use-after-free while placed buffers remain mapped.
    • In res_release, calls forget_placed_buffer(this as usize). When placed_buffers decrements to 0 and released == true, removes the heap entry from HEAP_UMA and safely frees the backing physical sparse/UMA allocation.
    • Added unit tests placed_buffers_keep_heap_uma_allocation_alive_until_all_released and placed_buffers_released_before_heap_frees_block_on_heap_release.

Tested

  • cargo test -p xcl -- real (30 passed, 0 failed, including both new placed buffer lifetime tests)
  • git diff --check upstream/main..HEAD clean with zero trailing whitespace
  • python -I scripts/check_no_game_data.py crates/xcl/src/hle/d3d12x/real.rs confirmed clean

Not tested

  • Retail game package execution (retail smoke suite)

AI use

  • Architecture audit and patch implementation authored using Gemini 3.8 Flash (High).
<!-- greyfinch-sync:ivall/xcl:issue:5478178697 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-24T18:40:49Z. --- Resolves XCL-BT-001 in #1488. **What is in it** - In `crates/xcl/src/hle/d3d12x/real.rs`: - Extended `HeapUma` with `placed_buffers: usize` refcount and `released: bool` state flag. - In `dev_create_placed_resource_x`, registers placed buffer resources via `note_placed_buffer(heap, *ppv as usize)` when placing buffers into a `HEAP_UMA` heap. - In `mem_heap_release` (`ID3D12Heap::Release`), sets `released = true`. If `placed_buffers > 0`, defers freeing the backing UMA block to prevent use-after-free while placed buffers remain mapped. - In `res_release`, calls `forget_placed_buffer(this as usize)`. When `placed_buffers` decrements to 0 and `released == true`, removes the heap entry from `HEAP_UMA` and safely frees the backing physical sparse/UMA allocation. - Added unit tests `placed_buffers_keep_heap_uma_allocation_alive_until_all_released` and `placed_buffers_released_before_heap_frees_block_on_heap_release`. **Tested** - `cargo test -p xcl -- real` (30 passed, 0 failed, including both new placed buffer lifetime tests) - `git diff --check upstream/main..HEAD` clean with zero trailing whitespace - `python -I scripts/check_no_game_data.py crates/xcl/src/hle/d3d12x/real.rs` confirmed clean **Not tested** - Retail game package execution (retail smoke suite) **AI use** - Architecture audit and patch implementation authored using Gemini 3.8 Flash (High).
Anon64 commented 2026-11-24 21:08:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T19:33:24Z.


Regression run for this PR: head d5f9f9c, based on main c160d86. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main c160d86:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1531 (PresentX 1531)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 100443 MB

this PR:

xcl-smoke v1
commit: d5f9f9c3a88c1aace5f65b8ebc240e339847e72e
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1510 (PresentX 1510)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 103901 MB

No device removals or crashes; 98 % of main's frames, 103 % of its peak commit.

Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about 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.

<!-- greyfinch-sync:ivall/xcl:comment:7142266670 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#issuecomment-7142266670). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-24T19:33:24Z. --- Regression run for this PR: head `d5f9f9c`, based on `main` `c160d86`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s, in one batch with the `main` run. main `c160d86`: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1531 (PresentX 1531) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 100443 MB ``` this PR: ``` xcl-smoke v1 commit: d5f9f9c3a88c1aace5f65b8ebc240e339847e72e gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1510 (PresentX 1510) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 103901 MB ``` No device removals or crashes; 98 % of main's frames, 103 % of its peak commit. Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies from run to run, so it says little about 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.
DavidM1911 commented 2026-11-24 21:09:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:06:57Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7144495689 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#issuecomment-7144495689). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T21:06:57Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
throny commented 2026-11-25 18:04:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-25T17:24:10Z.


Two contributors checked independently and found that #2086 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.

<!-- greyfinch-sync:ivall/xcl:comment:7169451349 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#issuecomment-7169451349). Originally posted by [throny](https://github.com/throny) on 2026-11-25T17:24:10Z. --- <!-- xcl-1607-hint:D88 --> Two contributors checked independently and found that #2086 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.
upstream-sync closed this pull request 2026-11-25 23:07:32 +00:00
CalvyPZ commented 2026-11-25 23:09:14 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:42:11Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7176687098 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#issuecomment-7176687098). Originally posted by [CalvyPZ](https://github.com/CalvyPZ) on 2026-11-25T22:42:11Z. --- 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.
upstream-sync reopened this pull request 2026-11-26 00:04:31 +00:00
luckyteagirl commented 2026-11-26 09:49:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T09:49:45Z.

Review: COMMENTED


On d5f9f9c, the new last-placed-buffer cleanup can free the backing while the GPU still uses that buffer. With late release enabled, res_release sets logical n = 0 when it intentionally retains one native reference for late_release. If the heap was already released, forget_placed_buffer then drops the final pin and calls Uma::free before late_release::hold. For a coherent block, Uma::free immediately returns the range to XCL's free list; another allocation can reuse or zero it while the old submission remains behind a queue fence. Holding the COM resource alone does not retain that pool allocation. The later drain calls raw Release, so simply omitting the early cleanup when held is true would also need a deferred cleanup path.

Could the backing's lifetime follow the deferred resource release (or coordinate with the held-heap approach in open #1457 for #1394)? A fence-blocked test can release the heap and last placed buffer, verify an equal-sized coherent allocation cannot reuse the old range before the queue completes, then verify reuse is possible after the drain. This is exact-head source review; I did not run that GPU fixture or claim the same immediate recycling for sparse storage.

<!-- greyfinch-sync:ivall/xcl:review:6071851111 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#pullrequestreview-6071851111). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T09:49:45Z. **Review:** COMMENTED --- On `d5f9f9c`, the new last-placed-buffer cleanup can free the backing while the GPU still uses that buffer. With late release enabled, `res_release` sets logical `n = 0` when it intentionally retains one native reference for `late_release`. If the heap was already released, `forget_placed_buffer` then drops the final pin and calls `Uma::free` **before** `late_release::hold`. For a coherent block, `Uma::free` immediately returns the range to XCL's free list; another allocation can reuse or zero it while the old submission remains behind a queue fence. Holding the COM resource alone does not retain that pool allocation. The later drain calls raw `Release`, so simply omitting the early cleanup when `held` is true would also need a deferred cleanup path. Could the backing's lifetime follow the deferred resource release (or coordinate with the held-heap approach in open #1457 for #1394)? A fence-blocked test can release the heap and last placed buffer, verify an equal-sized coherent allocation cannot reuse the old range before the queue completes, then verify reuse is possible after the drain. This is exact-head source review; I did not run that GPU fixture or claim the same immediate recycling for sparse storage.
Foniass commented 2026-12-01 06:23:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:23:26Z.


Triage (#1607) – head d5f9f9c

#2086 targets the same problem (a heap_uma heap's block freed by ID3D12Heap::Release while buffers placed in it are alive), with a different implementation. In #2086 res_release frees the heap's block as soon as the last placed buffer goes, even while the heap is still alive, and that PR also carries unrelated DirectStorage counter and runner debug-layer changes. This PR frees the block only once both the heap and its last placed buffer are released (forget_placed_buffer / mem_heap_release), and has unit tests for both orders.
No problems found in the diff. It conflicts with main and needs a rebase.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302816523 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1648#issuecomment-7302816523). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:23:26Z. --- **Triage (#1607)** – head d5f9f9c #2086 targets the same problem (a heap_uma heap's block freed by ID3D12Heap::Release while buffers placed in it are alive), with a different implementation. In #2086 `res_release` frees the heap's block as soon as the last placed buffer goes, even while the heap is still alive, and that PR also carries unrelated DirectStorage counter and runner debug-layer changes. This PR frees the block only once both the heap and its last placed buffer are released (`forget_placed_buffer` / `mem_heap_release`), and has unit tests for both orders. No problems found in the diff. It conflicts with main and needs a rebase. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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/1648:upstream-pr/1648'
git switch 'upstream-pr/1648'

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