D3D12.X: retain root signature COM ownership in device_x Base descriptor (#1488) #1624

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

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


Summary

Retains root signature COM pointer ownership in device_x::Base::desc in crates/xcl/src/hle/d3d12x/device_x.rs to prevent use-after-free (Issue #1488, finding XCL-BT-005):

  1. COM lifetime retention in pipeline descriptors:
    • In device_x::Base, added _root_sig: Option<ID3D12RootSignature> to retain strong ownership of the root signature COM object.
    • In note_base, extracted pRootSignature pointer at ROOT_SIGNATURE (offset 0) and retained via ID3D12RootSignature::from_raw_borrowed(&root_sig_ptr).cloned(), incrementing the COM reference count via AddRef.
    • Prevents use-after-free crashes when titles release the original root signature pointer after creating the base pipeline, while subsequent CreateDerivedPipelineStateX and RSSetDepthBiasX calls reuse the cached Base::desc to call CreateGraphicsPipelineState.
    • On descriptor drop (forget_base), dropping Base drops _root_sig, safely invoking COM Release.
  2. Unit tests:
    • Added root_signature_lifetime_retained_in_base_and_safely_released with synthetic COM mock object: validates initial refcount increment (AddRef) upon note_base, survival after caller releases its reference (preventing UAF), retention across derived pipelines, safe release on descriptor drop (forget_base) when refcount drops to 0, and safe handling of null root signature descriptors.

Changes

  • crates/xcl/src/hle/d3d12x/device_x.rs:
    • Retain root signature COM reference in Base struct.
    • Safe refcounting and cleanup on pipeline descriptor drop.
    • Unit test verifying COM lifecycle and UAF prevention.

Tested

  • Windows 11 x64, Rust MSVC stable.
  • cargo test -p xcl -- device_x: 9 passed, 0 failed.
  • cargo test -p xcl -- list_x: 27 passed, 0 failed.
  • Clean diff: zero trailing whitespace, clean rebase on latest upstream/main, GPL-2.0-only compliant, zero retail game data or keys.

Not Tested

  • Real-time derived pipeline state creation under hardware D3D12 device.

AI Use

Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity

<!-- greyfinch-sync:ivall/xcl:issue:5477977424 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-24T18:26:41Z. --- ## Summary Retains root signature COM pointer ownership in `device_x::Base::desc` in `crates/xcl/src/hle/d3d12x/device_x.rs` to prevent use-after-free (Issue #1488, finding `XCL-BT-005`): 1. **COM lifetime retention in pipeline descriptors**: - In `device_x::Base`, added `_root_sig: Option<ID3D12RootSignature>` to retain strong ownership of the root signature COM object. - In `note_base`, extracted `pRootSignature` pointer at `ROOT_SIGNATURE` (offset 0) and retained via `ID3D12RootSignature::from_raw_borrowed(&root_sig_ptr).cloned()`, incrementing the COM reference count via `AddRef`. - Prevents use-after-free crashes when titles release the original root signature pointer after creating the base pipeline, while subsequent `CreateDerivedPipelineStateX` and `RSSetDepthBiasX` calls reuse the cached `Base::desc` to call `CreateGraphicsPipelineState`. - On descriptor drop (`forget_base`), dropping `Base` drops `_root_sig`, safely invoking COM `Release`. 2. **Unit tests**: - Added `root_signature_lifetime_retained_in_base_and_safely_released` with synthetic COM mock object: validates initial refcount increment (`AddRef`) upon `note_base`, survival after caller releases its reference (preventing UAF), retention across derived pipelines, safe release on descriptor drop (`forget_base`) when refcount drops to 0, and safe handling of null root signature descriptors. ## Changes - `crates/xcl/src/hle/d3d12x/device_x.rs`: - Retain root signature COM reference in `Base` struct. - Safe refcounting and cleanup on pipeline descriptor drop. - Unit test verifying COM lifecycle and UAF prevention. ## Tested - Windows 11 x64, Rust MSVC stable. - `cargo test -p xcl -- device_x`: 9 passed, 0 failed. - `cargo test -p xcl -- list_x`: 27 passed, 0 failed. - Clean diff: zero trailing whitespace, clean rebase on latest `upstream/main`, GPL-2.0-only compliant, zero retail game data or keys. ## Not Tested - Real-time derived pipeline state creation under hardware D3D12 device. ## AI Use Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
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:21Z.


Regression run for this PR: head f4be21e, based on main 9e3831e. 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 9e3831e:

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

this PR:

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

No device removals or crashes; 101 % of main's frames, 100 % 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:7142265348 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634#issuecomment-7142265348). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-24T19:33:21Z. --- Regression run for this PR: head `f4be21e`, based on `main` `9e3831e`. 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 `9e3831e`: ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1536 (PresentX 1536) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 97380 MB ``` this PR: ``` xcl-smoke v1 commit: f4be21e776262d7809a31906200193308d01f8a3 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1552 (PresentX 1552) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 98303 MB ``` No device removals or crashes; 101 % of main's frames, 100 % 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:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T20:56:12Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7144254526 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634#issuecomment-7144254526). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T20:56:12Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. Thanks!
throny commented 2026-11-24 23:08:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-24T22:59:06Z.


Two contributors checked independently and found that this PR makes the same change as #1619 (for #1488): #1607, group D48. They suggest keeping #1619. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

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:7146875155 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634#issuecomment-7146875155). Originally posted by [throny](https://github.com/throny) on 2026-11-24T22:59:06Z. --- <!-- xcl-1607-hint:D48 --> Two contributors checked independently and found that this PR makes the same change as #1619 (for #1488): #1607, group D48. They suggest keeping #1619. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps. 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.
github-actions[bot] commented 2026-11-28 08:01:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:01:01Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7236306697 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634#issuecomment-7236306697). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T08:01:01Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 06:20:46 +00:00 (Migrated from github.com)

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


Triage (#1607) – head f4be21e

#1619 makes the same change in device_x.rs. It adds a ROOT_SIGNATURE offset, stores ID3D12RootSignature::from_raw_borrowed(..).cloned() in Base, and tests it with a mock COM refcount. #1619 was opened 9 minutes earlier and is already rebased onto main's shared shader-blob Base. It also releases the old entry outside the BASES lock in forget_base and on re-insert. This PR conflicts with main.
The only extra here is the readable() check on the pointer before cloning it. If that matters, it can be suggested on #1619.
Recommendation: close (duplicate of #1619).

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:7302766480 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1634#issuecomment-7302766480). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:20:46Z. --- **Triage (#1607)** – head f4be21e #1619 makes the same change in device_x.rs. It adds a `ROOT_SIGNATURE` offset, stores `ID3D12RootSignature::from_raw_borrowed(..).cloned()` in `Base`, and tests it with a mock COM refcount. #1619 was opened 9 minutes earlier and is already rebased onto main's shared shader-blob `Base`. It also releases the old entry outside the `BASES` lock in `forget_base` and on re-insert. This PR conflicts with main. The only extra here is the `readable()` check on the pointer before cloning it. If that matters, it can be suggested on #1619. Recommendation: close (duplicate of #1619). 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/1634:upstream-pr/1634'
git switch 'upstream-pr/1634'

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