diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-25 15:09:57 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-25 15:09:57 +0000 |
| commit | 404459e2cb9a17e94ee7d26c22fbe2485828b496 (patch) | |
| tree | 7b81d6ed6fa0612a35443b91e7b7948c51d824c5 /Graphics/GraphicsEngine | |
| parent | Few improvements to RefCntAutoPtr & DeviceContextBase::SetPipelineState (diff) | |
| download | DiligentCore-404459e2cb9a17e94ee7d26c22fbe2485828b496.tar.gz DiligentCore-404459e2cb9a17e94ee7d26c22fbe2485828b496.zip | |
Improved performance of DeviceObjectBase::Release()
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/BufferBase.h | 43 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/BufferViewBase.h | 11 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/CommandListBase.h | 13 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceObjectBase.h | 41 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/FenceBase.h | 9 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/PipelineStateBase.h | 15 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/RenderDeviceBase.h | 9 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/SamplerBase.h | 17 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/ShaderBase.h | 14 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/TextureBase.h | 35 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/TextureViewBase.h | 11 |
11 files changed, 118 insertions, 100 deletions
diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h index d3eaf2d4..b841d0b1 100644 --- a/Graphics/GraphicsEngine/include/BufferBase.h +++ b/Graphics/GraphicsEngine/include/BufferBase.h @@ -40,15 +40,18 @@ namespace Diligent /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::IBufferD3D11, Diligent::IBufferD3D12, /// Diligent::IBufferGL or Diligent::IBufferVk). +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) /// \tparam BufferViewImplType - type of the buffer view implementation /// (Diligent::BufferViewD3D11Impl, Diligent::BufferViewD3D12Impl, /// Diligent::BufferViewGLImpl or Diligent::BufferViewVkImpl) /// \tparam TBuffViewObjAllocator - type of the allocator that is used to allocate memory for the buffer view object instances -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -class BufferBase : public DeviceObjectBase < BaseInterface, BufferDesc> +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +class BufferBase : public DeviceObjectBase <BaseInterface, RenderDeviceImplType, BufferDesc> { public: - typedef DeviceObjectBase<BaseInterface, BufferDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, BufferDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this buffer. /// \param BuffViewObjAllocator - allocator that is used to allocate memory for the buffer view instances. @@ -59,7 +62,7 @@ public: /// must not keep a strong reference to the device. BufferBase( IReferenceCounters* pRefCounters, TBuffViewObjAllocator& BuffViewObjAllocator, - IRenderDevice* pDevice, + RenderDeviceImplType* pDevice, const BufferDesc& BuffDesc, bool bIsDeviceInternal) : TDeviceObjectBase( pRefCounters, pDevice, BuffDesc, bIsDeviceInternal), @@ -156,24 +159,24 @@ protected: std::unique_ptr<BufferViewImplType, STDDeleter<BufferViewImplType, TBuffViewObjAllocator> > m_pDefaultSRV; }; -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) { VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DEFAULT, "Only default usage buffers can be updated with UpdateData()" ); VERIFY_BUFFER( Offset < this->m_Desc.uiSizeInBytes, "Offset (", Offset, ") exceeds the buffer size (", this->m_Desc.uiSizeInBytes, ")" ); VERIFY_BUFFER( Size + Offset <= this->m_Desc.uiSizeInBytes, "Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) { VERIFY_BUFFER( DstOffset + Size <= this->m_Desc.uiSizeInBytes, "Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); VERIFY_BUFFER( SrcOffset + Size <= pSrcBuffer->GetDesc().uiSizeInBytes, "Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) { pMappedData = nullptr; switch( MapType ) @@ -212,22 +215,22 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map } } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags ) { } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView ) { CreateViewInternal( ViewDesc, ppView, false ); } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ) { if( ViewDesc.ByteWidth == 0 ) ViewDesc.ByteWidth = this->m_Desc.uiSizeInBytes; @@ -244,8 +247,8 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Cor } } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -IBufferView* BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> ::GetDefaultView( BUFFER_VIEW_TYPE ViewType ) +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +IBufferView* BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> ::GetDefaultView( BUFFER_VIEW_TYPE ViewType ) { switch( ViewType ) { @@ -255,8 +258,8 @@ IBufferView* BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator } } -template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: CreateDefaultViews() +template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> +void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: CreateDefaultViews() { if( this->m_Desc.BindFlags & BIND_UNORDERED_ACCESS ) { diff --git a/Graphics/GraphicsEngine/include/BufferViewBase.h b/Graphics/GraphicsEngine/include/BufferViewBase.h index b09b479e..c672fa43 100644 --- a/Graphics/GraphicsEngine/include/BufferViewBase.h +++ b/Graphics/GraphicsEngine/include/BufferViewBase.h @@ -42,11 +42,14 @@ class IBuffer; /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::IBufferViewD3D11, Diligent::IBufferViewD3D12, /// Diligent::IBufferViewGL or Diligent::IBufferViewVk). -template<class BaseInterface> -class BufferViewBase : public DeviceObjectBase<BaseInterface, BufferViewDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class BufferViewBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, BufferViewDesc> { public: - typedef DeviceObjectBase<BaseInterface, BufferViewDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, BufferViewDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this buffer view. /// \param pDevice - pointer to the render device. @@ -56,7 +59,7 @@ public: /// part of the buffer object. In this case the view will attach /// to the buffer's reference counters. BufferViewBase( IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, + RenderDeviceImplType* pDevice, const BufferViewDesc& ViewDesc, IBuffer* pBuffer, bool bIsDefaultView ) : diff --git a/Graphics/GraphicsEngine/include/CommandListBase.h b/Graphics/GraphicsEngine/include/CommandListBase.h index 77c85d86..8075f70c 100644 --- a/Graphics/GraphicsEngine/include/CommandListBase.h +++ b/Graphics/GraphicsEngine/include/CommandListBase.h @@ -40,18 +40,21 @@ struct CommandListDesc : public DeviceObjectAttribs /// Template class implementing base functionality for a command list object. /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ICommandListD3D11 or Diligent::ICommandListD3D12). -template<class BaseInterface> -class CommandListBase : public DeviceObjectBase<BaseInterface, CommandListDesc> +/// (Diligent::ICommandListD3D11, Diligent::ICommandListD3D12 or Diligent::ICommandListVk). +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class CommandListBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, CommandListDesc> { public: - typedef DeviceObjectBase<BaseInterface, CommandListDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, CommandListDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this command list. /// \param pDevice - pointer to the device. /// \param bIsDeviceInternal - flag indicating if the CommandList is an internal device object and /// must not keep a strong reference to the device. - CommandListBase( IReferenceCounters* pRefCounters, IRenderDevice* pDevice, bool bIsDeviceInternal = false ) : + CommandListBase( IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, CommandListDesc(), bIsDeviceInternal ) {} diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index b7874487..3d98b426 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -35,13 +35,8 @@ namespace Diligent { -template<typename BaseInterface> -class RenderDeviceBase; - -class IRenderDevice; - /// Template class implementing base functionality for a device object -template<class BaseInterface, typename ObjectDescType> +template<class BaseInterface, typename RenderDeviceImplType, typename ObjectDescType> class DeviceObjectBase : public ObjectBase<BaseInterface> { public: @@ -53,15 +48,15 @@ public: /// \param bIsDeviceInternal - flag indicating if the object is an internal device object /// and must not keep a strong reference to the device. DeviceObjectBase( IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, + RenderDeviceImplType* pDevice, const ObjectDescType& ObjDesc, bool bIsDeviceInternal = false) : TBase(pRefCounters), // Do not keep strong reference to the device if the object is an internal device object - m_spDevice( bIsDeviceInternal ? nullptr : pDevice ), - m_pDevice( pDevice ), + m_spDevice (bIsDeviceInternal ? nullptr : pDevice), + m_pDevice (pDevice), m_ObjectNameCopy(ObjDesc.Name ? ObjDesc.Name : ThisToString()), - m_Desc( ObjDesc ) + m_Desc (ObjDesc) { m_Desc.Name = m_ObjectNameCopy.c_str(); @@ -95,10 +90,16 @@ public: // 4. RefCountersImpl::ObjectWrapperBase::DestroyObject() calls // m_pAllocator->Free(m_pObject) - crash! - // We must keep the device alive while the object is being destroyed - RefCntAutoPtr<IRenderDevice> pDevice(m_spDevice); - // Note that internal device object do not keep strong reference to the device - return TBase::Release(); + RefCntAutoPtr<RenderDeviceImplType> pDevice; + return ValidatedCast<RefCountersImpl>(this->GetReferenceCounters())-> + ReleaseStrongRef( + [&]() + { + // We must keep the device alive while the object is being destroyed + // Note that internal device objects do not keep strong reference to the device + pDevice = m_spDevice; + } + ); } IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_DeviceObject, TBase ) @@ -119,20 +120,16 @@ public: return m_UniqueID.GetID(); } - IRenderDevice* GetDevice()const{return m_pDevice;} + RenderDeviceImplType* GetDevice()const{return m_pDevice;} - template<typename Type> - Type* GetDevice()const{return ValidatedCast<Type>(m_pDevice);} - private: /// Strong reference to the device - RefCntAutoPtr<IRenderDevice> m_spDevice; + RefCntAutoPtr<RenderDeviceImplType> m_spDevice; +protected: /// Pointer to the device - IRenderDevice* m_pDevice; + RenderDeviceImplType* const m_pDevice; -protected: - /// Copy of a device object name. /// When new object is created, its description structure is copied diff --git a/Graphics/GraphicsEngine/include/FenceBase.h b/Graphics/GraphicsEngine/include/FenceBase.h index f743d157..494960d5 100644 --- a/Graphics/GraphicsEngine/include/FenceBase.h +++ b/Graphics/GraphicsEngine/include/FenceBase.h @@ -41,18 +41,19 @@ class IFence; /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::IFenceD3D11, Diligent::IFenceD3D12, /// Diligent::IFenceGL or Diligent::IFenceVk). -template<class BaseInterface> -class FenceBase : public DeviceObjectBase<BaseInterface, FenceDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +template<class BaseInterface, class RenderDeviceImplType> +class FenceBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, FenceDesc> { public: - typedef DeviceObjectBase<BaseInterface, FenceDesc> TDeviceObjectBase; + typedef DeviceObjectBase<BaseInterface, RenderDeviceImplType, FenceDesc> TDeviceObjectBase; /// \param pRefCounters - reference counters object that controls the lifetime of this command list. /// \param Desc - fence description /// \param pDevice - pointer to the device. /// \param bIsDeviceInternal - flag indicating if the Fence is an internal device object and /// must not keep a strong reference to the device. - FenceBase( IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const FenceDesc& Desc, bool bIsDeviceInternal = false ) : + FenceBase( IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, const FenceDesc& Desc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, Desc, bIsDeviceInternal ) {} diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h index 62e8bf91..5a8f6a65 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.h +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h @@ -41,15 +41,14 @@ namespace Diligent /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::IPipelineStateD3D11, Diligent::IPipelineStateD3D12, /// Diligent::IPipelineStateGL or Diligent::IPipelineStateVk). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, -/// Diligent::IRenderDeviceGL, Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). -template<class BaseInterface, class RenderDeviceBaseInterface> -class PipelineStateBase : public DeviceObjectBase<BaseInterface, PipelineStateDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class PipelineStateBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, PipelineStateDesc> { public: - typedef DeviceObjectBase<BaseInterface, PipelineStateDesc> TDeviceObjectBase; - typedef RenderDeviceBase < RenderDeviceBaseInterface > TRenderDeviceBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, PipelineStateDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this PSO /// \param pDevice - pointer to the device. @@ -57,7 +56,7 @@ public: /// \param bIsDeviceInternal - flag indicating if the blend state is an internal device object and /// must not keep a strong reference to the device. PipelineStateBase( IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, + RenderDeviceImplType* pDevice, const PipelineStateDesc& PSODesc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, PSODesc, bIsDeviceInternal ), diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.h b/Graphics/GraphicsEngine/include/RenderDeviceBase.h index 70cf4707..db7234e4 100644 --- a/Graphics/GraphicsEngine/include/RenderDeviceBase.h +++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.h @@ -182,7 +182,7 @@ class RenderDeviceBase : public ObjectBase<BaseInterface> { public: - typedef ObjectBase<BaseInterface> TObjectBase; + using TObjectBase = ObjectBase<BaseInterface>; /// \param pRefCounters - reference counters object that controls the lifetime of this render device /// \param RawMemAllocator - allocator that will be used to allocate memory for all device objects (including render device itself) @@ -282,6 +282,13 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_RenderDevice, ObjectBase<BaseInterface> ) + // It is important to have final implementation of Release() method to avoid + // virtual calls + inline virtual IReferenceCounters::CounterValueType Release()override final + { + return TObjectBase::Release(); + } + /// Implementation of IRenderDevice::CreateResourceMapping(). virtual void CreateResourceMapping( const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping )override final; diff --git a/Graphics/GraphicsEngine/include/SamplerBase.h b/Graphics/GraphicsEngine/include/SamplerBase.h index c6e69c7e..49772c5d 100644 --- a/Graphics/GraphicsEngine/include/SamplerBase.h +++ b/Graphics/GraphicsEngine/include/SamplerBase.h @@ -38,22 +38,21 @@ namespace Diligent /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::ISamplerD3D11, Diligent::ISamplerD3D12, /// Diligent::ISamplerGL or Diligent::ISamplerVk). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, Diligent::IRenderDeviceGL, -/// Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). -template<class BaseInterface, class RenderDeviceBaseInterface> -class SamplerBase : public DeviceObjectBase<BaseInterface, SamplerDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class SamplerBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, SamplerDesc> { public: - typedef DeviceObjectBase<BaseInterface, SamplerDesc> TDeviceObjectBase; - typedef RenderDeviceBase<RenderDeviceBaseInterface> TRenderDeviceBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, SamplerDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this sampler. /// \param pDevice - pointer to the device. /// \param SamDesc - sampler description. /// \param bIsDeviceInternal - flag indicating if the sampler is an internal device object and /// must not keep a strong reference to the device. - SamplerBase( IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const SamplerDesc& SamDesc, bool bIsDeviceInternal = false ) : + SamplerBase( IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, const SamplerDesc& SamDesc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, SamDesc, bIsDeviceInternal ) {} @@ -61,7 +60,7 @@ public: { /// \note Destructor cannot directly remove the object from the registry as this may cause a /// deadlock. - auto &SamplerRegistry = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetSamplerRegistry(); + auto &SamplerRegistry = this->GetDevice()->GetSamplerRegistry(); SamplerRegistry.ReportDeletedObject(); } diff --git a/Graphics/GraphicsEngine/include/ShaderBase.h b/Graphics/GraphicsEngine/include/ShaderBase.h index 7db44cfe..c62dc0bb 100644 --- a/Graphics/GraphicsEngine/include/ShaderBase.h +++ b/Graphics/GraphicsEngine/include/ShaderBase.h @@ -187,21 +187,21 @@ struct DummyShaderVariable : ShaderVariableBase /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::IShaderD3D11, Diligent::IShaderD3D12, /// Diligent::IShaderGL or Diligent::IShaderVk). -/// \tparam RenderDeviceBaseInterface - base interface for the render device -/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, -/// Diligent::IRenderDeviceGL, Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). -template<class BaseInterface, class RenderDeviceBaseInterface> -class ShaderBase : public DeviceObjectBase<BaseInterface, ShaderDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class ShaderBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, ShaderDesc> { public: - typedef DeviceObjectBase<BaseInterface, ShaderDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, ShaderDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this shader. /// \param pDevice - pointer to the device. /// \param ShdrDesc - shader description. /// \param bIsDeviceInternal - flag indicating if the shader is an internal device object and /// must not keep a strong reference to the device. - ShaderBase( IReferenceCounters* pRefCounters, IRenderDevice* pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false ) : + ShaderBase( IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, ShdrDesc, bIsDeviceInternal ), m_DummyShaderVar(*this), m_VariablesDesc (ShdrDesc.NumVariables, ShaderVariableDesc(), STD_ALLOCATOR_RAW_MEM(ShaderVariableDesc, GetRawAllocator(), "Allocator for vector<ShaderVariableDesc>") ), diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h index c9abf042..a4b19b21 100644 --- a/Graphics/GraphicsEngine/include/TextureBase.h +++ b/Graphics/GraphicsEngine/include/TextureBase.h @@ -46,15 +46,18 @@ void VliadateCopyTextureDataParams( const TextureDesc& SrcTexDesc, Uint32 SrcMip /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::ITextureD3D11, Diligent::ITextureD3D12, /// Diligent::ITextureGL or Diligent::ITextureVk). +/// \tparam TRenderDeviceImpl - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) /// \tparam TTextureViewImpl - type of the texture view implementation /// (Diligent::TextureViewD3D11Impl, Diligent::TextureViewD3D12Impl, /// Diligent::TextureViewGLImpl or Diligent::TextureViewVkImpl). /// \tparam TTexViewObjAllocator - type of the allocator that is used to allocate memory for the texture view object instances -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -class TextureBase : public DeviceObjectBase<BaseInterface, TextureDesc> +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +class TextureBase : public DeviceObjectBase<BaseInterface, TRenderDeviceImpl, TextureDesc> { public: - typedef DeviceObjectBase<BaseInterface, TextureDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, TRenderDeviceImpl, TextureDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this texture. /// \param TexViewObjAllocator - allocator that is used to allocate memory for the instances of the texture view object. @@ -65,7 +68,7 @@ public: /// must not keep a strong reference to the device TextureBase( IReferenceCounters* pRefCounters, TTexViewObjAllocator& TexViewObjAllocator, - IRenderDevice* pDevice, + TRenderDeviceImpl* pDevice, const TextureDesc& Desc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, Desc, bIsDeviceInternal ), @@ -182,8 +185,8 @@ protected: }; -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CorrectTextureViewDesc(struct TextureViewDesc& ViewDesc) +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: CorrectTextureViewDesc(struct TextureViewDesc& ViewDesc) { #define TEX_VIEW_VALIDATION_ERROR(...) LOG_ERROR_AND_THROW( "Texture view \"", ViewDesc.Name ? ViewDesc.Name : "", "\": ", ##__VA_ARGS__ ) @@ -389,8 +392,8 @@ void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: Corre } } -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CreateDefaultViews() +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: CreateDefaultViews() { const auto& TexFmtAttribs = GetTextureFormatAttribs(this->m_Desc.Format); if (TexFmtAttribs.ComponentType == COMPONENT_TYPE_UNDEFINED) @@ -442,14 +445,14 @@ void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: Creat } -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: UpdateData( IDeviceContext* pContext, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData ) +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: UpdateData( IDeviceContext* pContext, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData ) { ValidateUpdateDataParams( this->m_Desc, MipLevel, Slice, DstBox, SubresData ); } -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CopyData( +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: CopyData( IDeviceContext* pContext, ITexture* pSrcTexture, Uint32 SrcMipLevel, @@ -467,13 +470,13 @@ void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CopyD this->GetDesc(), DstMipLevel, DstSlice, DstX, DstY, DstZ ); } -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData ) +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData ) { } -template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags ) +template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator> +void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags ) { } diff --git a/Graphics/GraphicsEngine/include/TextureViewBase.h b/Graphics/GraphicsEngine/include/TextureViewBase.h index 0837b962..722c544e 100644 --- a/Graphics/GraphicsEngine/include/TextureViewBase.h +++ b/Graphics/GraphicsEngine/include/TextureViewBase.h @@ -39,11 +39,14 @@ namespace Diligent /// \tparam BaseInterface - base interface that this class will inheret /// (Diligent::ITextureViewD3D11, Diligent::ITextureViewD3D12, /// Diligent::ITextureViewGL or Diligent::ITextureViewVk). -template<class BaseInterface> -class TextureViewBase : public DeviceObjectBase<BaseInterface, TextureViewDesc> +/// \tparam RenderDeviceImplType - type of the render device implementation +/// (Diligent::RenderDeviceD3D11Impl, Diligent::RenderDeviceD3D12Impl, +/// Diligent::RenderDeviceGLImpl, or Diligent::RenderDeviceVkImpl) +template<class BaseInterface, class RenderDeviceImplType> +class TextureViewBase : public DeviceObjectBase<BaseInterface, RenderDeviceImplType, TextureViewDesc> { public: - typedef DeviceObjectBase<BaseInterface, TextureViewDesc> TDeviceObjectBase; + using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, TextureViewDesc>; /// \param pRefCounters - reference counters object that controls the lifetime of this texture view. @@ -54,7 +57,7 @@ public: /// part of the texture object. In this case the view will attach /// to the texture's reference counters. TextureViewBase( IReferenceCounters* pRefCounters, - IRenderDevice* pDevice, + RenderDeviceImplType* pDevice, const TextureViewDesc& ViewDesc, class ITexture* pTexture, bool bIsDefaultView ) : |
