From 30a65df99cfc678a431a89b0cff02a515416c78a Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 6 Mar 2021 14:06:26 -0800 Subject: Unified resource signature handling by pipeline state in D3D12, Vk and GL --- Common/interface/RefCntAutoPtr.hpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/RefCntAutoPtr.hpp b/Common/interface/RefCntAutoPtr.hpp index 0c261bd6..5b3f7de9 100644 --- a/Common/interface/RefCntAutoPtr.hpp +++ b/Common/interface/RefCntAutoPtr.hpp @@ -228,11 +228,12 @@ private: // Note that the DoublePtrHelper is a private class, and can be created only by RefCntWeakPtr // Thus if no special effort is made, the lifetime of the instances of this class cannot be // longer than the lifetime of the creating object + template class DoublePtrHelper { public: DoublePtrHelper(RefCntAutoPtr& AutoPtr) noexcept : - NewRawPtr{static_cast(AutoPtr)}, + NewRawPtr{static_cast(AutoPtr)}, m_pAutoPtr{std::addressof(AutoPtr)} { } @@ -247,22 +248,22 @@ private: ~DoublePtrHelper() { - if (m_pAutoPtr && static_cast(*m_pAutoPtr) != NewRawPtr) + if (m_pAutoPtr && *m_pAutoPtr != static_cast(NewRawPtr)) { - m_pAutoPtr->Attach(NewRawPtr); + m_pAutoPtr->Attach(static_cast(NewRawPtr)); } } - T*& operator*() noexcept { return NewRawPtr; } - const T* operator*() const noexcept { return NewRawPtr; } + DstType*& operator*() noexcept { return NewRawPtr; } + const DstType* operator*() const noexcept { return NewRawPtr; } // clang-format off - operator T**() noexcept { return &NewRawPtr; } - operator const T**() const noexcept { return &NewRawPtr; } + operator DstType**() noexcept { return &NewRawPtr; } + operator const DstType**() const noexcept { return &NewRawPtr; } // clang-format on private: - T* NewRawPtr; + DstType* NewRawPtr; RefCntAutoPtr* m_pAutoPtr; // clang-format off @@ -273,23 +274,28 @@ private: }; public: - DoublePtrHelper operator&() + template ::value>::type> + DoublePtrHelper DblPtr() noexcept { return DoublePtrHelper(*this); } + template ::value>::type> + DoublePtrHelper DblPtr() const noexcept { return DoublePtrHelper(*this); } + + DoublePtrHelper operator&() { - return DoublePtrHelper(*this); + return DblPtr(); } - const DoublePtrHelper operator&() const + const DoublePtrHelper operator&() const { - return DoublePtrHelper(*this); + return DblPtr(); } - T** GetRawDblPtr() noexcept { return &m_pObject; } - const T** GetRawDblPtr() const noexcept { return &m_pObject; } + T** RawDblPtr() noexcept { return &m_pObject; } + const T** RawDblPtr() const noexcept { return &m_pObject; } template ::value>::type> - DstType** GetRawDblPtr() noexcept { return reinterpret_cast(&m_pObject); } + DstType** RawDblPtr() noexcept { return reinterpret_cast(&m_pObject); } template ::value>::type> - DstType** GetRawDblPtr() const noexcept { return reinterpret_cast(&m_pObject); } + DstType** RawDblPtr() const noexcept { return reinterpret_cast(&m_pObject); } private: template -- cgit v1.2.3