diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-25 08:39:16 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-25 08:39:16 +0000 |
| commit | 90c56caa809cccccdec4cde3d1705fc4bb94de15 (patch) | |
| tree | 28c006bd7b74fd792577607dc020ae60a7a9bbcd | |
| parent | Removed unnecessary conversion from m_pPipelineState to target implementation... (diff) | |
| download | DiligentCore-90c56caa809cccccdec4cde3d1705fc4bb94de15.tar.gz DiligentCore-90c56caa809cccccdec4cde3d1705fc4bb94de15.zip | |
Few improvements to RefCntAutoPtr & DeviceContextBase::SetPipelineState
7 files changed, 52 insertions, 54 deletions
diff --git a/Common/interface/RefCntAutoPtr.h b/Common/interface/RefCntAutoPtr.h index 8be859f3..5ef3bfe6 100644 --- a/Common/interface/RefCntAutoPtr.h +++ b/Common/interface/RefCntAutoPtr.h @@ -72,28 +72,28 @@ template <typename T> class RefCntAutoPtr { public: - explicit RefCntAutoPtr(T *pObj = nullptr) : + explicit RefCntAutoPtr(T* pObj = nullptr) : m_pObject(pObj) { if( m_pObject ) m_pObject->AddRef(); } - RefCntAutoPtr(IObject *pObj, const INTERFACE_ID &IID) : + RefCntAutoPtr(IObject* pObj, const INTERFACE_ID& IID) : m_pObject(nullptr) { if(pObj) pObj->QueryInterface( IID, reinterpret_cast<IObject**>(&m_pObject) ); } - RefCntAutoPtr(const RefCntAutoPtr &AutoPtr) : + RefCntAutoPtr(const RefCntAutoPtr& AutoPtr) : m_pObject(AutoPtr.m_pObject) { if(m_pObject) m_pObject->AddRef(); } - RefCntAutoPtr(RefCntAutoPtr &&AutoPtr) : + RefCntAutoPtr(RefCntAutoPtr&& AutoPtr) : m_pObject(std::move(AutoPtr.m_pObject)) { //Make sure original pointer has no references to the object @@ -105,12 +105,12 @@ public: Release(); } - void swap(RefCntAutoPtr &AutoPtr) + void swap(RefCntAutoPtr& AutoPtr) { std::swap(m_pObject, AutoPtr.m_pObject); } - void Attach(T *pObj) + void Attach(T* pObj) { Release(); m_pObject = pObj; @@ -132,44 +132,42 @@ public: } } - RefCntAutoPtr& operator = (T *pObj) + RefCntAutoPtr& operator = (T* pObj) { - if( static_cast<T*>(*this) == pObj ) - return *this; - - return operator= (RefCntAutoPtr(pObj)); + if (m_pObject != pObj) + { + if (m_pObject) + m_pObject->Release(); + m_pObject = pObj; + if (m_pObject) + m_pObject->AddRef(); + } + return *this; } - RefCntAutoPtr& operator = (const RefCntAutoPtr &AutoPtr) + RefCntAutoPtr& operator = (const RefCntAutoPtr& AutoPtr) { - if( *this == AutoPtr ) - return *this; - - Release(); - m_pObject = AutoPtr.m_pObject; - if(m_pObject) - m_pObject->AddRef(); - - return *this; + return *this = AutoPtr.m_pObject; } - RefCntAutoPtr& operator = (RefCntAutoPtr &&AutoPtr) + RefCntAutoPtr& operator = (RefCntAutoPtr&& AutoPtr) { - if( *this == AutoPtr ) - return *this; - - Release(); - m_pObject = std::move( AutoPtr.m_pObject ); - //Make sure original pointer has no references to the object - AutoPtr.m_pObject = nullptr; + 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; + } return *this; } // All the access functions do not require locking reference counters pointer because if it is valid, // the smart pointer holds strong reference to the object and it thus cannot be released by // ohter thread - bool operator ! () const{return m_pObject == nullptr;} - operator bool () const{return m_pObject != nullptr;} + bool operator ! () const{return m_pObject == nullptr;} + operator bool () const{return m_pObject != nullptr;} bool operator == (const RefCntAutoPtr& Ptr)const{return m_pObject == Ptr.m_pObject;} bool operator != (const RefCntAutoPtr& Ptr)const{return m_pObject != Ptr.m_pObject;} bool operator < (const RefCntAutoPtr& Ptr)const{return static_cast<const T*>(*this) < static_cast<const T*>(Ptr);} @@ -198,7 +196,7 @@ private: class DoublePtrHelper { public: - DoublePtrHelper(RefCntAutoPtr &AutoPtr) : + DoublePtrHelper(RefCntAutoPtr& AutoPtr) : NewRawPtr( static_cast<T*>(AutoPtr) ), m_pAutoPtr( std::addressof(AutoPtr) ) { @@ -226,8 +224,8 @@ private: operator T**(){return &NewRawPtr;} operator const T**()const{return &NewRawPtr;} private: - T *NewRawPtr; - RefCntAutoPtr *m_pAutoPtr; + T* NewRawPtr; + RefCntAutoPtr* m_pAutoPtr; DoublePtrHelper(const DoublePtrHelper&); DoublePtrHelper& operator = (const DoublePtrHelper&); DoublePtrHelper& operator = (DoublePtrHelper&&); @@ -248,7 +246,7 @@ public: const T** GetRawDblPtr()const{return &m_pObject;} private: - T *m_pObject; + T* m_pObject; }; /// Implementation of weak pointers @@ -256,7 +254,7 @@ template <typename T> class RefCntWeakPtr { public: - explicit RefCntWeakPtr(T *pObj = nullptr) : + explicit RefCntWeakPtr(T* pObj = nullptr) : m_pRefCounters(nullptr), m_pObject(pObj) { @@ -309,7 +307,7 @@ public: return *this; } - RefCntWeakPtr& operator = (T *pObj) + RefCntWeakPtr& operator = (T* pObj) { return operator= (RefCntWeakPtr(pObj)); } @@ -385,12 +383,12 @@ public: bool operator != (const RefCntWeakPtr& Ptr)const{return m_pRefCounters != Ptr.m_pRefCounters;} protected: - RefCountersImpl *m_pRefCounters; + RefCountersImpl* m_pRefCounters; // We need to store raw pointer to object itself, // because if the object is owned by another object, // m_pRefCounters->GetObject( &pObj ) will return // pointer to owner, which is not what we need. - T *m_pObject; + T* m_pObject; }; } diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 037e6ba4..4a78a2e8 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -90,9 +90,6 @@ public: inline virtual void InvalidateState()override = 0; - /// Base implementation of IDeviceContext::SetPipelineState(); caches references to the pipeline state object. - inline virtual void SetPipelineState(IPipelineState* pPipelineState)override = 0; - /// Base implementation of IDeviceContext::CommitShaderResources(); validates parameters. inline bool CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags, int); @@ -139,6 +136,8 @@ protected: inline bool SetStencilRef(Uint32 StencilRef, int Dummy); + inline void SetPipelineState(PipelineStateImplType* pPipelineState, int /*Dummy*/); + /// Clears all cached resources inline void ClearStateCache(); @@ -257,9 +256,9 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType } template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> -inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: SetPipelineState(IPipelineState* pPipelineState) +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: SetPipelineState(PipelineStateImplType* pPipelineState, int /*Dummy*/) { - m_pPipelineState = ValidatedCast<PipelineStateImplType>(pPipelineState); + m_pPipelineState = pPipelineState; } template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index a0038e46..b7874487 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -85,7 +85,7 @@ public: { // Render device owns allocators for all types of device objects, // so it must be destroyed after all device objects are released. - // Consider the following scenario: an object A ownes last strong + // Consider the following scenario: an object A owns the last strong // reference to the device: // // 1. A::~A() completes diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index bc0222c8..a36260ef 100644 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -79,9 +79,9 @@ namespace Diligent void DeviceContextD3D11Impl::SetPipelineState(IPipelineState* pPipelineState) { - TDeviceContextBase::SetPipelineState( pPipelineState ); auto* pPipelineStateD3D11 = ValidatedCast<PipelineStateD3D11Impl>(pPipelineState); - auto &Desc = pPipelineStateD3D11->GetDesc(); + TDeviceContextBase::SetPipelineState( pPipelineStateD3D11, 0 /*Dummy*/ ); + auto& Desc = pPipelineStateD3D11->GetDesc(); if (Desc.IsComputePipeline) { auto* pd3d11CS = pPipelineStateD3D11->GetD3D11ComputeShader(); diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index c4c4f11b..d5210e40 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -102,7 +102,7 @@ namespace Diligent Flush(true); } - auto *pPipelineStateD3D12 = ValidatedCast<PipelineStateD3D12Impl>(pPipelineState); + auto* pPipelineStateD3D12 = ValidatedCast<PipelineStateD3D12Impl>(pPipelineState); const auto &PSODesc = pPipelineStateD3D12->GetDesc(); bool CommitStates = false; @@ -126,7 +126,7 @@ namespace Diligent CommitScissor = OldPSODesc.GraphicsPipeline.RasterizerDesc.ScissorEnable != PSODesc.GraphicsPipeline.RasterizerDesc.ScissorEnable; } - TDeviceContextBase::SetPipelineState( pPipelineState ); + TDeviceContextBase::SetPipelineState( pPipelineStateD3D12, 0 /*Dummy*/ ); auto *pCmdCtx = RequestCmdContext(); diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index b83b07e7..394542aa 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -65,9 +65,10 @@ namespace Diligent void DeviceContextGLImpl::SetPipelineState(IPipelineState *pPipelineState) { - TDeviceContextBase::SetPipelineState(pPipelineState); + auto* pPipelineStateGLImpl = ValidatedCast<PipelineStateGLImpl>(pPipelineState); + TDeviceContextBase::SetPipelineState(pPipelineStateGLImpl, 0 /*Dummy*/); - const auto &Desc = pPipelineState->GetDesc(); + const auto& Desc = pPipelineStateGLImpl->GetDesc(); if (Desc.IsComputePipeline) { } diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 4b0af79e..ba888614 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -200,8 +200,8 @@ namespace Diligent Flush(); } - auto *pPipelineStateVk = ValidatedCast<PipelineStateVkImpl>(pPipelineState); - const auto &PSODesc = pPipelineStateVk->GetDesc(); + auto* pPipelineStateVk = ValidatedCast<PipelineStateVkImpl>(pPipelineState); + const auto& PSODesc = pPipelineStateVk->GetDesc(); bool CommitStates = false; bool CommitScissor = false; @@ -224,7 +224,7 @@ namespace Diligent CommitScissor = !OldPSODesc.GraphicsPipeline.RasterizerDesc.ScissorEnable; } - TDeviceContextBase::SetPipelineState( pPipelineState ); + TDeviceContextBase::SetPipelineState( pPipelineStateVk, 0 /*Dummy*/ ); EnsureVkCmdBuffer(); if (PSODesc.IsComputePipeline) |
