Skip to content

test: d3d12test::Ref owns its pointer alone: move only, and ref = {} releases (TEST-REF-MOVE-ONLY) - #1758

Open
adrianmjim wants to merge 3 commits into
ProjectLeonida:mainfrom
adrianmjim:test/ref-move-only
Open

adrianmjim wants to merge 3 commits into
ProjectLeonida:mainfrom
adrianmjim:test/ref-move-only

Conversation

@adrianmjim

Copy link
Copy Markdown

Claimed in the coordination issue as: TEST-REF-MOVE-ONLY (#1608 (comment))

What and why

d3d12test::Ref (runtime/test/d3d12_test_shaders.h, included directly by 40 test sources and 3 shared test headers) had a destructor but no copy or move members of its own. Two consequences:

  • ref = {} silently leaked. It builds an empty temporary and copies its null pointer over the held one, so Release() is never called. That is what happened in d3d12_xs: make a D16S8 depth texture without UAV when the depth provider refuses it (RT-D16S8-UAV-NVIDIA-FALLBACK) #1558's new test: its slot 133 resource stayed alive and kept the device proxy and the whole D3D12 device. Under LEONIDA_VK_VALIDATION=1 the result was a 63-object vkDestroyDevice report, which I first misread as a runtime leak.
  • A copy would release twice. With a user-declared destructor there is no implicit move. So a std::vector<Ref<...>> that grows copies every element and then destroys the originals. d3d12_bundle_test keeps Refs in vectors (Rig::bundle_allocators, Rig::bundles). Each Rig calls bundle() once, so neither grows past its first element, and the bug is latent.

The change: copying is deleted, moving transfers the pointer, and move assignment releases the old pointer. So ref = {} now does what it reads as, and a growing vector moves (noexcept). The struct keeps its p member, reset() and operator->, and no test copies a Ref or initialises one from a pointer, so every test builds unchanged.

Tested

On main 2b567edca with this change, Windows 11 build 26300, VS 2022 (MSVC 19.44) RelWithDebInfo, AMD Radeon RX 7900 XT, driver 32.0.32029.2010 (26.11.2):

GPUs tested: AMD Radeon RX 7900 XT (RDNA3), AMD 32.0.32029.2010, Windows 11 26300

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

…` releases (TEST-REF-MOVE-ONLY)

Ref had a destructor but no copy or move members of its own. So:
- `ref = {}` copied a null pointer over the held one and never called
  Release (the slot 133 resource in ProjectLeonida#1558's new test stayed alive and
  kept the whole device, 63 objects in the validation layer's
  vkDestroyDevice report);
- a copy, including the one std::vector makes when it grows (no
  implicit move with a user-declared destructor), would Release twice.

Copying is now deleted and moving transfers the pointer; move
assignment releases the old one, so `ref = {}` does what it reads as.
Every test that includes the header builds unchanged: none copies a Ref.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 11:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Makes d3d12test::Ref a unique-owner COM wrapper to prevent leaks on ref = {} and prevent double-Release() from accidental copying.

Changes:

  • Delete copy constructor/assignment to enforce single ownership.
  • Add noexcept move constructor/assignment that transfers the raw pointer.
  • Ensure move assignment releases any currently-held pointer before taking ownership.
File Description
runtime/​test/​d3d12_test_shaders.h Makes Ref<T> move-only with releasing move-assignment to prevent leaks/double-release in tests.

Review effort: Lite

Comment on lines 186 to 187
void reset() {
if (p) p->Release();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset() does clear it: if (p) p->Release(); p = nullptr; (the second line is just below the shown hunk), so calling it twice, or reset() then the destructor, releases once.

Comment thread runtime/test/d3d12_test_shaders.h Outdated
Comment on lines +176 to +184
Ref(Ref&& other) noexcept : p(other.p) { other.p = nullptr; }
Ref& operator=(Ref&& other) noexcept {
if (this != &other) {
reset();
p = other.p;
other.p = nullptr;
}
return *this;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 47e24615a: both move operations now transfer with std::exchange(other.p, nullptr), and the header includes <utility>. The branch also merges current main (cf1c34128).

Full build and ctest -j 6 on an RX 7900 XT (AMD 32.0.32029.2010, no Resizable BAR): 499 of 504 pass. The five failures:

@Tyrannys

Copy link
Copy Markdown
Contributor

Independent verification of head a8a56cb47ede0039988abab4a2e17e5be2a48c5c, with current main (a73a57e13) merged in, no conflicts.

Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.

  • Everything that includes d3d12_test_shaders.h builds with the move-only Ref (no test copies one).
  • Full suite with the PR: 475/477, the same as plain main on this machine; the two failures (xbox_present, d3d12_set_descriptor_heaps) fail on main too.

Note: the PR adds no test of its own. The same Ref change (deleted copies, releasing move assignment) is also in open #1716, which adds xbox_slot133_teardown to show the leak ref = {} caused, so one of the two should land and the other be closed.

No game files used. AI-assisted (Claude Code).

Tyrannys added a commit to Tyrannys/leonida that referenced this pull request Nov 26, 2026
ProjectLeonida#1758 makes the same d3d12test::Ref change (move-only, `ref = {}`
releases). Keep this pull request to the slot 133 teardown test, which
depends on that change.

AI-assisted (Claude Code).
@Tyrannys

Copy link
Copy Markdown
Contributor

Thanks @adrianmjim, this is the same Ref fix I had folded into #1716, so I dropped mine to avoid a double review. #1716 now only adds the xbox_slot133_teardown regression test (no game files) and depends on this PR. On top of this head (a8a56cb) it passes plain and with LEONIDA_VK_VALIDATION=1 with nothing left at vkDestroyDevice, and without this change it fails with VUID-05137. That matches my independent verification above. AI-assisted (Claude Code).

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.

3 participants