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

Closed
leonida/mandy
adrianmjim wants to merge 0 commits from test/ref-move-only into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

adrianmjim commented 2026-11-25 11:24:24 +00:00

Claimed in the coordination issue as: TEST-REF-MOVE-ONLY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161001857)

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.)
Claimed in the coordination issue as: TEST-REF-MOVE-ONLY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161001857) ### 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.)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 11:40:32 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
> [!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://github.com/ubiquitarianism/leonida/pull/1758#discussion_r4694340122) · 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://github.com/ubiquitarianism/leonida/pull/1758#discussion_r4694340176) · 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> **`runtime/test/d3d12_test_shaders.h` line 187:** > `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. **`runtime/test/d3d12_test_shaders.h` line 184:** > 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.
Tyrannys commented 2026-11-26 05:44:06 +00:00

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

**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 commented 2026-11-26 11:25:40 +00:00

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

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).
adrianmjim reviewed 2026-11-27 21:13:24 +00:00
adrianmjim left a comment
No description provided.
**`runtime/test/d3d12_test_shaders.h` line 187:** > `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.
adrianmjim reviewed 2026-11-27 21:13:26 +00:00
adrianmjim left a comment
No description provided.
**`runtime/test/d3d12_test_shaders.h` line 184:** > 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: > - `d3d12_texture_tiles` (#964), `pipeline_cache_seed` (#1833) and `d3d12_clear` fail on `main` here. > - `dxgi_waitable_latency` passes when run alone. > - `d3d12_set_descriptor_heaps` fails the same way with `main`'s header (a 256 MiB `vkAllocateMemory` in the BAR heap returns -2, then line 353).
adrianmjim commented 2026-11-28 09:47:45 +00:00

Closing to make room: this account can only have two pull requests open here, and the 13 leak fixes claimed in #1608 now go into one pull request. This change still applies to current main and merges cleanly; the branch stays at 52d3060d3. @Tyrannys, #1716 depends on it: if it suits you, fold the Ref change back into #1716 as you first had it, or I'll reopen this when a slot frees.

Closing to make room: this account can only have two pull requests open here, and the 13 leak fixes claimed in #1608 now go into one pull request. This change still applies to current `main` and merges cleanly; the branch stays at `52d3060d3`. @Tyrannys, #1716 depends on it: if it suits you, fold the `Ref` change back into #1716 as you first had it, or I'll reopen this when a slot frees.
adrianmjim commented 2026-11-28 09:48:12 +00:00

Reopening: the combined pull request could not be opened after all, so this stays open for review.

Reopening: the combined pull request could not be opened after all, so this stays open for review.
Sign in to join this conversation.
No description provided.