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

Open
github-bot wants to merge 1 commit from github-bot/gh-1758 into main AGit
Owner

@⁠adrianmjim on GitHub · 2026-11-25 11:24 UTC · original
adrianmjim:test/ref-move-only → main · +13 −0 · 1 files · 1 commits · open

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

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 #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):

  • Build: the whole runtime and every test build with no errors, and no warning points at the changed header.
  • ctest -j 6: 400 of 403 without failures (387 passed, 13 skipped). The three failures are the same as on main 42537e7b6 without it: d3d12_texture_tiles (#964), d3d12_clear, and d3d12_geometry_views (#1678, no Resizable BAR).
  • #1558's leak: in a local probe through #1558's slot 133 path, placed.reset() (what placed = {} does after this change) left no leaked objects under validation.

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.)
**@⁠adrianmjim** on GitHub · 2026-11-25 11:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758) `adrianmjim:test/ref-move-only` → `main` · +13 −0 · 1 files · 1 commits · open Claimed in the coordination issue as: TEST-REF-MOVE-ONLY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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 #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 `Ref`s 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): - **Build:** the whole runtime and every test build with no errors, and no warning points at the changed header. - **`ctest -j 6`:** 400 of 403 without failures (387 passed, 13 skipped). The three failures are the same as on `main` `42537e7b6` without it: `d3d12_texture_tiles` (#964), `d3d12_clear`, and `d3d12_geometry_views` (#1678, no Resizable BAR). - **#1558's leak:** in a local probe through #1558's slot 133 path, `placed.reset()` (what `placed = {}` does after this change) left no leaked objects under validation. GPUs tested: AMD Radeon RX 7900 XT (RDNA3), AMD 32.0.32029.2010, Windows 11 26300 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator change.)
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 #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:03:53 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 11:40 UTC · original · reviewed

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

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758#pullrequestreview-6056939659) · **reviewed** > [!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](https://gh.io/AA11tgch) for more details. <!-- ccr-overview-v2 --> ## Copilot review overview <details open> <summary><strong>2 open issues</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [`reset()` calls `Release()` but (in the shown code) does not clear `p`. If `p` is not set to…](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1758) · New - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [The move operations manually copy-and-null the pointer in multiple places. Consider using a single…](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1758) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> 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. | </details> <sub>Review effort: Lite</sub>
@ -172,3 +184,4 @@
}
~Ref() { reset(); }
void reset() {
if (p) p->Release();
Author
Owner

@⁠Copilot on GitHub · 2026-11-25 11:40 UTC · original

reset() calls Release() but (in the shown code) does not clear p. If p is not set to nullptr later in this function, repeated calls to reset() (or calling reset() followed by destruction) can double-Release() the same pointer. Make reset() idempotent by setting p = nullptr after releasing.

**@⁠Copilot** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758#discussion_r4694340122) `reset()` calls `Release()` but (in the shown code) does not clear `p`. If `p` is not set to `nullptr` later in this function, repeated calls to `reset()` (or calling `reset()` followed by destruction) can double-`Release()` the same pointer. Make `reset()` idempotent by setting `p = nullptr` after releasing.
@ -172,0 +181,4 @@
other.p = nullptr;
}
return *this;
}
Author
Owner

@⁠Copilot on GitHub · 2026-11-25 11:40 UTC · original

The move operations manually copy-and-null the pointer in multiple places. Consider using a single transfer expression (e.g., via std::exchange or a small private helper) to reduce duplication and the chance of future changes forgetting to clear the moved-from pointer.

**@⁠Copilot** on GitHub · 2026-11-25 11:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758#discussion_r4694340176) The move operations manually copy-and-null the pointer in multiple places. Consider using a single transfer expression (e.g., via `std::exchange` or a small private helper) to reduce duplication and the chance of future changes forgetting to clear the moved-from pointer.
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-26 05:44 UTC · original

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** on GitHub · 2026-11-26 05:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758#issuecomment-7183756846) **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).
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-26 11:25 UTC · original

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 (a8a56cb47) 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).

**@⁠Tyrannys** on GitHub · 2026-11-26 11:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1758#issuecomment-7190712433) 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 (a8a56cb47) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1758/head:github-bot/gh-1758'
git switch 'github-bot/gh-1758'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1758'
git switch 'github-bot/gh-1758'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1758'
git switch 'github-bot/gh-1758'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1758'
git switch 'main'
git merge --squash 'github-bot/gh-1758'
git switch 'main'
git merge --ff-only 'github-bot/gh-1758'
git switch 'main'
git merge 'github-bot/gh-1758'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.