From d3bba829acfb2eabce748220eff045ef0c6f7880 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 20 Oct 2018 14:16:56 -0700 Subject: Multiple improvements to shader resource binding in D3D11 and D3D12 --- Common/interface/RefCntAutoPtr.h | 43 +++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/RefCntAutoPtr.h b/Common/interface/RefCntAutoPtr.h index 6a826c27..b76fd048 100644 --- a/Common/interface/RefCntAutoPtr.h +++ b/Common/interface/RefCntAutoPtr.h @@ -85,6 +85,7 @@ public: pObj->QueryInterface( IID, reinterpret_cast(&m_pObject) ); } + // Copy constructor must not be template! RefCntAutoPtr(const RefCntAutoPtr& AutoPtr) : m_pObject(AutoPtr.m_pObject) { @@ -92,6 +93,13 @@ public: m_pObject->AddRef(); } + template::value>::type> + RefCntAutoPtr(const RefCntAutoPtr& AutoPtr) : + RefCntAutoPtr(AutoPtr.m_pObject) + { + } + + // Non-template move constructor RefCntAutoPtr(RefCntAutoPtr&& AutoPtr) : m_pObject(std::move(AutoPtr.m_pObject)) { @@ -99,6 +107,14 @@ public: AutoPtr.m_pObject = nullptr; } + template::value>::type> + RefCntAutoPtr(RefCntAutoPtr&& AutoPtr) : + m_pObject(std::move(AutoPtr.m_pObject)) + { + //Make sure original pointer has no references to the object + AutoPtr.m_pObject = nullptr; + } + ~RefCntAutoPtr() { Release(); @@ -149,16 +165,26 @@ public: return *this = AutoPtr.m_pObject; } + template::value>::type> + RefCntAutoPtr& operator = (const RefCntAutoPtr& AutoPtr) + { + return *this = static_cast(AutoPtr.m_pObject); + } + RefCntAutoPtr& operator = (RefCntAutoPtr&& AutoPtr) { if (m_pObject != AutoPtr.m_pObject) - { - if (m_pObject) - m_pObject->Release(); - m_pObject = std::move(AutoPtr.m_pObject); - //Make sure original pointer has no references to the object - AutoPtr.m_pObject = nullptr; - } + Attach(AutoPtr.Detach()); + + return *this; + } + + template::value>::type> + RefCntAutoPtr& operator = (RefCntAutoPtr&& AutoPtr) + { + if (m_pObject != AutoPtr.m_pObject) + Attach(AutoPtr.Detach()); + return *this; } @@ -245,6 +271,9 @@ public: const T** GetRawDblPtr()const{return &m_pObject;} private: + template + friend class RefCntAutoPtr; + T* m_pObject; }; -- cgit v1.2.3