Repository navigation
test: d3d12test::Ref owns its pointer alone: move only, and ref = {} releases (TEST-REF-MOVE-ONLY) - #1758
test: d3d12test::Ref owns its pointer alone: move only, and ref = {} releases (TEST-REF-MOVE-ONLY)#1758adrianmjim wants to merge 3 commits into
ref = {} releases (TEST-REF-MOVE-ONLY)#1758Conversation
…` 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.
There was a problem hiding this comment.
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
noexceptmove 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
| void reset() { | ||
| if (p) p->Release(); |
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
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(test: texture tiles NOTE only for the measured CopyTiles offset rounding on AMD and Intel (D3D-TILES-AMD-BYTE-OFFSET) #964),pipeline_cache_seed(vk_pipeline_check: choose robustBufferAccess and VK_EXT_robustness2 as the runtime does (RT-PIPELINE-CHECK-ROBUSTNESS) #1833) andd3d12_clearfail onmainhere.dxgi_waitable_latencypasses when run alone.d3d12_set_descriptor_heapsfails the same way withmain's header (a 256 MiBvkAllocateMemoryin the BAR heap returns -2, then line 353).
|
Independent verification of head Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.
Note: the PR adds no test of its own. The same No game files used. AI-assisted (Claude Code). |
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).
|
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 |
One transfer expression in both move operations, as suggested in the ProjectLeonida#1758 review.


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, soRelease()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. UnderLEONIDA_VK_VALIDATION=1the result was a 63-objectvkDestroyDevicereport, which I first misread as a runtime leak.std::vector<Ref<...>>that grows copies every element and then destroys the originals.d3d12_bundle_testkeepsRefs in vectors (Rig::bundle_allocators,Rig::bundles). EachRigcallsbundle()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 itspmember,reset()andoperator->, and no test copies aRefor initialises one from a pointer, so every test builds unchanged.Tested
On
main2b567edcawith 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):ctest -j 6: 400 of 403 without failures (387 passed, 13 skipped). The three failures are the same as onmain42537e7b6without it:d3d12_texture_tiles(test: texture tiles NOTE only for the measured CopyTiles offset rounding on AMD and Intel (D3D-TILES-AMD-BYTE-OFFSET) #964),d3d12_clear, andd3d12_geometry_views(d3d12: geometry views fall back to system memory when the BAR window is full (RT-GEOMETRY-VIEWS-NO-REBAR) #1678, no Resizable BAR).placed.reset()(whatplaced = {}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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No translator change.)