diff --git a/runtime/test/d3d12_test_shaders.h b/runtime/test/d3d12_test_shaders.h index a43c141240..0e812f3f33 100644 --- a/runtime/test/d3d12_test_shaders.h +++ b/runtime/test/d3d12_test_shaders.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "../shims/d3d12_xs_rootsig.h" @@ -169,6 +170,18 @@ inline D3D12_RESOURCE_BARRIER transition(ID3D12Resource* resource, D3D12_RESOURC template struct Ref { T* p = nullptr; + Ref() = default; + // One owner: a copy would Release twice, and `ref = {}` must Release what it held. + Ref(const Ref&) = delete; + Ref& operator=(const Ref&) = delete; + Ref(Ref&& other) noexcept : p(std::exchange(other.p, nullptr)) {} + Ref& operator=(Ref&& other) noexcept { + if (this != &other) { + reset(); + p = std::exchange(other.p, nullptr); + } + return *this; + } ~Ref() { reset(); } void reset() { if (p) p->Release();