diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-20 05:41:05 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-20 05:41:05 +0000 |
| commit | 908672f5b447e1e96e0dcbb3ec1eaabbd1d503f4 (patch) | |
| tree | d0ae2d5956d803b7f4ce11195bebed8deecb124a /Graphics | |
| parent | Added comment about shader reflection data (diff) | |
| download | DiligentCore-908672f5b447e1e96e0dcbb3ec1eaabbd1d503f4.tar.gz DiligentCore-908672f5b447e1e96e0dcbb3ec1eaabbd1d503f4.zip | |
Added fence object stubs + code formatting
Diffstat (limited to 'Graphics')
43 files changed, 1134 insertions, 229 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt index c226701e..31bdc256 100644 --- a/Graphics/GraphicsEngine/CMakeLists.txt +++ b/Graphics/GraphicsEngine/CMakeLists.txt @@ -10,6 +10,7 @@ set(INCLUDE include/DeviceContextBase.h include/DeviceObjectBase.h include/EngineMemory.h + include/FenceBase.h include/pch.h include/PipelineStateBase.h include/RenderDeviceBase.h @@ -33,6 +34,7 @@ set(INTERFACE interface/DeviceCaps.h interface/DeviceContext.h interface/DeviceObject.h + interface/Fence.h interface/GraphicsTypes.h interface/InputLayout.h interface/MapHelper.h diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h index 9acd562c..66096e3c 100644 --- a/Graphics/GraphicsEngine/include/BufferBase.h +++ b/Graphics/GraphicsEngine/include/BufferBase.h @@ -37,10 +37,12 @@ namespace Diligent /// Template class implementing base functionality for a buffer object -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBufferD3D11, Diligent::IBufferD3D12 or Diligent::IBufferGL). +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::IBufferD3D11, Diligent::IBufferD3D12, +/// Diligent::IBufferGL or Diligent::IBufferVk). /// \tparam BufferViewImplType - type of the buffer view implementation -/// (Diligent::BufferViewD3D11Impl, Diligent::BufferViewD3D12Impl or Diligent::BufferViewGLImpl) +/// (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> @@ -55,11 +57,11 @@ public: /// \param BuffDesc - buffer description. /// \param bIsDeviceInternal - flag indicating if the buffer is an internal device object and /// must not keep a strong reference to the device. - BufferBase( IReferenceCounters *pRefCounters, - TBuffViewObjAllocator &BuffViewObjAllocator, - IRenderDevice *pDevice, - const BufferDesc& BuffDesc, - bool bIsDeviceInternal) : + BufferBase( IReferenceCounters* pRefCounters, + TBuffViewObjAllocator& BuffViewObjAllocator, + IRenderDevice* pDevice, + const BufferDesc& BuffDesc, + bool bIsDeviceInternal) : TDeviceObjectBase( pRefCounters, pDevice, BuffDesc, bIsDeviceInternal), #ifdef _DEBUG m_dbgBuffViewAllocator(BuffViewObjAllocator), @@ -108,20 +110,20 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Buffer, TDeviceObjectBase ) /// Base implementation of IBuffer::UpdateData(); validates input parameters. - virtual void UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override = 0; + virtual void UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override = 0; /// Base implementation of IBuffer::CopyData(); validates input parameters. - virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override = 0; + virtual void CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override = 0; /// Base implementation of IBuffer::Map(); validates input parameters. - virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override; + virtual void Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData )override; /// Base implementation of IBuffer::Unmap() - virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags )override = 0; + virtual void Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags )override = 0; /// Implementation of IBuffer::CreateView(); calls CreateViewInternal() virtual function /// that creates buffer view for the specific engine implementation. - virtual void CreateView( const struct BufferViewDesc &ViewDesc, IBufferView **ppView )override; + virtual void CreateView( const struct BufferViewDesc& ViewDesc, IBufferView** ppView )override; /// Implementation of IBuffer::GetDefaultView(). virtual IBufferView* GetDefaultView( BUFFER_VIEW_TYPE ViewType )override; @@ -138,13 +140,13 @@ public: protected: /// Pure virtual function that creates buffer view for the specific engine implementation. - virtual void CreateViewInternal( const struct BufferViewDesc &ViewDesc, IBufferView **ppView, bool bIsDefaultView ) = 0; + virtual void CreateViewInternal( const struct BufferViewDesc& ViewDesc, IBufferView **ppView, bool bIsDefaultView ) = 0; /// Corrects buffer view description and validates view parameters. - void CorrectBufferViewDesc( struct BufferViewDesc &ViewDesc ); + void CorrectBufferViewDesc( struct BufferViewDesc& ViewDesc ); #ifdef _DEBUG - TBuffViewObjAllocator &m_dbgBuffViewAllocator; + TBuffViewObjAllocator& m_dbgBuffViewAllocator; #endif /// Default UAV addressing the entire buffer @@ -155,7 +157,7 @@ protected: }; template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) +void BufferBase<BaseInterface, 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, ")" ); @@ -163,7 +165,7 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Upd } template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) +void BufferBase<BaseInterface, 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,")" ); @@ -171,7 +173,7 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Cop template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) +void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) { switch( MapType ) { @@ -209,7 +211,7 @@ 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 ) +void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags ) { } @@ -258,7 +260,7 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Cre { BufferViewDesc ViewDesc; ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS; - IBufferView *pUAV = nullptr; + IBufferView* pUAV = nullptr; CreateViewInternal( ViewDesc, &pUAV, true ); m_pDefaultUAV.reset( static_cast<BufferViewImplType*>(pUAV) ); VERIFY( m_pDefaultUAV->GetDesc().ViewType == BUFFER_VIEW_UNORDERED_ACCESS, "Unexpected view type" ); diff --git a/Graphics/GraphicsEngine/include/BufferViewBase.h b/Graphics/GraphicsEngine/include/BufferViewBase.h index de97f64c..b09b479e 100644 --- a/Graphics/GraphicsEngine/include/BufferViewBase.h +++ b/Graphics/GraphicsEngine/include/BufferViewBase.h @@ -39,9 +39,9 @@ class IBuffer; /// Template class implementing base functionality for a buffer view object -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IBufferViewD3D11, Diligent::IBufferViewD3D12 or Diligent::IBufferViewGL). -/// \tparam BuffViewObjAllocator - type of the allocator that is used to allocate memory for the buffer view object instances +/// \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> { @@ -55,11 +55,11 @@ public: /// \param bIsDefaultView - flag indicating if the view is default view, and is thus /// part of the buffer object. In this case the view will attach /// to the buffer's reference counters. - BufferViewBase( IReferenceCounters *pRefCounters, - IRenderDevice *pDevice, + BufferViewBase( IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, const BufferViewDesc& ViewDesc, - IBuffer *pBuffer, - bool bIsDefaultView ) : + IBuffer* pBuffer, + bool bIsDefaultView ) : // Default views are created as part of the buffer, so we cannot not keep strong // reference to the buffer to avoid cyclic links. Instead, we will attach to the // reference counters of the buffer. diff --git a/Graphics/GraphicsEngine/include/CommandListBase.h b/Graphics/GraphicsEngine/include/CommandListBase.h index 74725d31..77c85d86 100644 --- a/Graphics/GraphicsEngine/include/CommandListBase.h +++ b/Graphics/GraphicsEngine/include/CommandListBase.h @@ -51,7 +51,7 @@ public: /// \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, IRenderDevice* pDevice, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, CommandListDesc(), bIsDeviceInternal ) {} diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 86b213ad..d84956b1 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -65,7 +65,7 @@ public: /// \param pRefCounters - reference counters object that controls the lifetime of this device context. /// \param pRenderDevice - render device. /// \param bIsDeferred - flag indicating if this instance is a deferred context - DeviceContextBase(IReferenceCounters *pRefCounters, IRenderDevice *pRenderDevice, bool bIsDeferred) : + DeviceContextBase(IReferenceCounters* pRefCounters, IRenderDevice* pRenderDevice, bool bIsDeferred) : TObjectBase(pRefCounters), m_pDevice(pRenderDevice), m_bIsDeferred(bIsDeferred) @@ -80,32 +80,32 @@ public: /// Base implementation of IDeviceContext::SetVertexBuffers(); validates parameters and /// caches references to the buffers. - inline virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pOffsets, Uint32 Flags )override = 0; + inline virtual void SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, Uint32 Flags )override = 0; 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; + inline virtual void SetPipelineState(IPipelineState* pPipelineState)override = 0; /// Base implementation of IDeviceContext::CommitShaderResources(); validates parameters. template<typename PSOImplType> - inline bool CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int); + inline bool CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags, int); /// Base implementation of IDeviceContext::SetIndexBuffer(); caches the strong reference to the index buffer - inline virtual void SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset )override = 0; + inline virtual void SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset )override = 0; /// Caches the viewports - inline void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ); + inline void SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32& RTWidth, Uint32& RTHeight ); /// Caches the scissor rects - inline void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ); + inline void SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32& RTWidth, Uint32& RTHeight ); /// Caches the render target and depth stencil views. Returns true if any view is different /// from the cached value and false otherwise. - inline bool SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy = 0 ); + inline bool SetRenderTargets( Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil, Uint32 Dummy = 0 ); /// Sets the strong pointer to the swap chain - virtual void SetSwapChain( ISwapChain *pSwapChain )override final { m_pSwapChain = pSwapChain; } + virtual void SetSwapChain( ISwapChain* pSwapChain )override final { m_pSwapChain = pSwapChain; } /// Returns the swap chain ISwapChain *GetSwapChain() { return m_pSwapChain; } @@ -114,13 +114,13 @@ public: inline bool IsDefaultFBBound(){ return m_IsDefaultFramebufferBound; } /// Returns currently bound pipeline state and blend factors - inline void GetPipelineState(IPipelineState **ppPSO, float* BlendFactors, Uint32 &StencilRef); + inline void GetPipelineState(IPipelineState** ppPSO, float* BlendFactors, Uint32& StencilRef); /// Returns currently bound render targets - inline void GetRenderTargets(Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV); + inline void GetRenderTargets(Uint32& NumRenderTargets, ITextureView** ppRTVs, ITextureView** ppDSV); /// Returns currently set viewports - inline void GetViewports( Uint32 &NumViewports, Viewport *pViewports ); + inline void GetViewports( Uint32& NumViewports, Viewport* pViewports ); /// Returns the render device IRenderDevice *GetDevice(){return m_pDevice;} @@ -130,7 +130,7 @@ public: bool IsDeferred()const{return m_bIsDeferred;} protected: - inline bool SetBlendFactors(const float *BlendFactors, int Dummy); + inline bool SetBlendFactors(const float* BlendFactors, int Dummy); inline bool SetStencilRef(Uint32 StencilRef, int Dummy); @@ -197,7 +197,7 @@ protected: template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer **ppBuffers, Uint32 *pOffsets, Uint32 Flags ) +inline void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, Uint32 Flags ) { #ifdef DEVELOPMENT if ( StartSlot >= MaxBufferSlots ) @@ -243,14 +243,14 @@ inline void DeviceContextBase<BaseInterface> :: SetVertexBuffers( Uint32 StartSl } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: SetPipelineState(IPipelineState *pPipelineState) +inline void DeviceContextBase<BaseInterface> :: SetPipelineState(IPipelineState* pPipelineState) { m_pPipelineState = pPipelineState; } template<typename BaseInterface> template<typename PSOImplType> -inline bool DeviceContextBase<BaseInterface> :: CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, Uint32 Flags, int) +inline bool DeviceContextBase<BaseInterface> :: CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, Uint32 Flags, int) { #ifdef DEVELOPMENT if (!m_pPipelineState) @@ -261,7 +261,7 @@ inline bool DeviceContextBase<BaseInterface> :: CommitShaderResources(IShaderRes if (pShaderResourceBinding) { - auto *pPSOImpl = m_pPipelineState.RawPtr<PSOImplType>(); + auto* pPSOImpl = m_pPipelineState.RawPtr<PSOImplType>(); if (pPSOImpl->IsIncompatibleWith(pShaderResourceBinding->GetPipelineState())) { LOG_ERROR_MESSAGE("Shader resource binding object is not compatible with the currently bound pipeline state"); @@ -280,7 +280,7 @@ inline void DeviceContextBase<BaseInterface> :: InvalidateState() } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer *pIndexBuffer, Uint32 ByteOffset ) +inline void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset ) { m_pIndexBuffer = pIndexBuffer; m_IndexDataStartOffset = ByteOffset; @@ -295,17 +295,17 @@ inline void DeviceContextBase<BaseInterface> :: SetIndexBuffer( IBuffer *pIndexB template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: GetPipelineState(IPipelineState **ppPSO, float* BlendFactors, Uint32 &StencilRef) +inline void DeviceContextBase<BaseInterface> :: GetPipelineState(IPipelineState** ppPSO, float* BlendFactors, Uint32& StencilRef) { VERIFY( ppPSO != nullptr, "Null pointer provided null" ); - VERIFY( *ppPSO == nullptr, "Memory address contains a pointer to a non-null blend state" ); + VERIFY(* ppPSO == nullptr, "Memory address contains a pointer to a non-null blend state" ); if (m_pPipelineState) { m_pPipelineState->QueryInterface( IID_PipelineState, reinterpret_cast<IObject**>( ppPSO ) ); } else { - *ppPSO = nullptr; + * ppPSO = nullptr; } for( Uint32 f = 0; f < 4; ++f ) @@ -314,7 +314,7 @@ inline void DeviceContextBase<BaseInterface> :: GetPipelineState(IPipelineState }; template<typename BaseInterface> -inline bool DeviceContextBase<BaseInterface> ::SetBlendFactors(const float *BlendFactors, int) +inline bool DeviceContextBase<BaseInterface> ::SetBlendFactors(const float* BlendFactors, int) { bool FactorsDiffer = false; for( Uint32 f = 0; f < 4; ++f ) @@ -338,7 +338,7 @@ inline bool DeviceContextBase<BaseInterface> :: SetStencilRef(Uint32 StencilRef, } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 &RTWidth, Uint32 &RTHeight ) +inline void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32& RTWidth, Uint32& RTHeight ) { if ( RTWidth == 0 || RTHeight == 0 ) { @@ -366,7 +366,7 @@ inline void DeviceContextBase<BaseInterface> :: SetViewports( Uint32 NumViewport } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: GetViewports( Uint32 &NumViewports, Viewport *pViewports ) +inline void DeviceContextBase<BaseInterface> :: GetViewports( Uint32 &NumViewports, Viewport* pViewports ) { NumViewports = m_NumViewports; if ( pViewports ) @@ -377,7 +377,7 @@ inline void DeviceContextBase<BaseInterface> :: GetViewports( Uint32 &NumViewpor } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 &RTWidth, Uint32 &RTHeight ) +inline void DeviceContextBase<BaseInterface> :: SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32& RTWidth, Uint32& RTHeight ) { if ( RTWidth == 0 || RTHeight == 0 ) { @@ -434,7 +434,7 @@ inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRend for( Uint32 rt = 0; rt < NumRenderTargets; ++rt ) { - auto *pRTView = ppRenderTargets[rt]; + auto* pRTView = ppRenderTargets[rt]; if ( pRTView ) { const auto &RTVDesc = pRTView->GetDesc(); @@ -445,7 +445,7 @@ inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRend // Use this RTV to set the render target size if (m_FramebufferWidth == 0) { - auto *pTex = pRTView->GetTexture(); + auto* pTex = pRTView->GetTexture(); const auto &TexDesc = pTex->GetDesc(); m_FramebufferWidth = std::max(TexDesc.Width >> RTVDesc.MostDetailedMip, 1U); m_FramebufferHeight = std::max(TexDesc.Height >> RTVDesc.MostDetailedMip, 1U); @@ -486,7 +486,7 @@ inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRend // Use depth stencil size to set render target size if (m_FramebufferWidth == 0) { - auto *pTex = pDepthStencil->GetTexture(); + auto* pTex = pDepthStencil->GetTexture(); const auto &TexDesc = pTex->GetDesc(); m_FramebufferWidth = std::max(TexDesc.Width >> DSVDesc.MostDetailedMip, 1U); m_FramebufferHeight = std::max(TexDesc.Height >> DSVDesc.MostDetailedMip, 1U); @@ -519,7 +519,7 @@ inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRend } template<typename BaseInterface> -inline void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRenderTargets, ITextureView **ppRTVs, ITextureView **ppDSV ) +inline void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRenderTargets, ITextureView** ppRTVs, ITextureView** ppDSV ) { NumRenderTargets = m_NumBoundRenderTargets; @@ -543,11 +543,11 @@ inline void DeviceContextBase<BaseInterface> :: GetRenderTargets( Uint32 &NumRen if ( ppDSV ) { - VERIFY( *ppDSV == nullptr, "Non-null DSV pointer found" ); + VERIFY(* ppDSV == nullptr, "Non-null DSV pointer found" ); if ( m_pBoundDepthStencil ) m_pBoundDepthStencil->QueryInterface( IID_TextureView, reinterpret_cast<IObject**>(ppDSV) ); else - *ppDSV = nullptr; + * ppDSV = nullptr; } } diff --git a/Graphics/GraphicsEngine/include/DeviceObjectBase.h b/Graphics/GraphicsEngine/include/DeviceObjectBase.h index 522b40c1..a0038e46 100644 --- a/Graphics/GraphicsEngine/include/DeviceObjectBase.h +++ b/Graphics/GraphicsEngine/include/DeviceObjectBase.h @@ -52,10 +52,10 @@ public: /// \param ObjDesc - object description. /// \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, - const ObjectDescType &ObjDesc, - bool bIsDeviceInternal = false) : + DeviceObjectBase( IReferenceCounters* pRefCounters, + IRenderDevice* 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 ), @@ -119,7 +119,7 @@ public: return m_UniqueID.GetID(); } - IRenderDevice *GetDevice()const{return m_pDevice;} + IRenderDevice* GetDevice()const{return m_pDevice;} template<typename Type> Type* GetDevice()const{return ValidatedCast<Type>(m_pDevice);} @@ -129,7 +129,7 @@ private: RefCntAutoPtr<IRenderDevice> m_spDevice; /// Pointer to the device - IRenderDevice *m_pDevice; + IRenderDevice* m_pDevice; protected: diff --git a/Graphics/GraphicsEngine/include/FenceBase.h b/Graphics/GraphicsEngine/include/FenceBase.h new file mode 100644 index 00000000..f743d157 --- /dev/null +++ b/Graphics/GraphicsEngine/include/FenceBase.h @@ -0,0 +1,66 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Implementation of the Diligent::FenceBase template class + +#include "DeviceObjectBase.h" +#include "GraphicsTypes.h" +#include "RefCntAutoPtr.h" + +namespace Diligent +{ + +class IRenderDevice; +class IFence; + +/// Template class implementing base functionality for a Fence object + +/// \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> +{ +public: + typedef DeviceObjectBase<BaseInterface, 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 ) : + TDeviceObjectBase( pRefCounters, pDevice, Desc, bIsDeviceInternal ) + {} + + ~FenceBase() + { + } + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Fence, TDeviceObjectBase ) +}; + +} diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h index 092122f8..62e8bf91 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.h +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h @@ -38,11 +38,12 @@ namespace Diligent /// Template class implementing base functionality for a pipeline state object. -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IPipelineStateD3D11, Diligent::IPipelineStateD3D12 or Diligent::IPipelineStateGL). +/// \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, -/// or Diligent::IRenderDeviceGLES). +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, +/// Diligent::IRenderDeviceGL, Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). template<class BaseInterface, class RenderDeviceBaseInterface> class PipelineStateBase : public DeviceObjectBase<BaseInterface, PipelineStateDesc> { @@ -55,7 +56,10 @@ public: /// \param PSODesc - pipeline state description. /// \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, const PipelineStateDesc& PSODesc, bool bIsDeviceInternal = false ) : + PipelineStateBase( IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const PipelineStateDesc& PSODesc, + bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, PSODesc, bIsDeviceInternal ), m_LayoutElements( PSODesc.GraphicsPipeline.InputLayout.NumElements, LayoutElement(), STD_ALLOCATOR_RAW_MEM(LayoutElement, GetRawAllocator(), "Allocator for vector<LayoutElement>" ) ), m_NumShaders(0) @@ -222,12 +226,12 @@ public: // This function only compares shader resource layout hashes, so // it can potentially give false negatives - bool IsIncompatibleWith(IPipelineState *pPSO)const + bool IsIncompatibleWith(IPipelineState* pPSO)const { return m_ShaderResourceLayoutHash != ValidatedCast<PipelineStateBase>(pPSO)->m_ShaderResourceLayoutHash; } - virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags )override + virtual void BindShaderResources( IResourceMapping* pResourceMapping, Uint32 Flags )override { for(Uint32 s=0; s < m_NumShaders; ++s) m_ppShaders[s]->BindResources(pResourceMapping, Flags); diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.h b/Graphics/GraphicsEngine/include/RenderDeviceBase.h index 57f7e163..70cf4707 100644 --- a/Graphics/GraphicsEngine/include/RenderDeviceBase.h +++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.h @@ -46,7 +46,7 @@ namespace std template<> struct hash<Diligent::SamplerDesc> { - size_t operator()( const Diligent::SamplerDesc &SamDesc ) const + size_t operator()( const Diligent::SamplerDesc& SamDesc ) const { // Sampler name is ignored in comparison operator // and should not be hashed @@ -72,7 +72,7 @@ namespace std template<> struct hash<Diligent::StencilOpDesc> { - size_t operator()( const Diligent::StencilOpDesc &StOpDesc ) const + size_t operator()( const Diligent::StencilOpDesc& StOpDesc ) const { return Diligent::ComputeHash( static_cast<int>( StOpDesc.StencilFailOp ), static_cast<int>( StOpDesc.StencilDepthFailOp ), @@ -85,7 +85,7 @@ namespace std template<> struct hash<Diligent::DepthStencilStateDesc> { - size_t operator()( const Diligent::DepthStencilStateDesc &DepthStencilDesc ) const + size_t operator()( const Diligent::DepthStencilStateDesc& DepthStencilDesc ) const { return Diligent::ComputeHash( DepthStencilDesc.DepthEnable, DepthStencilDesc.DepthWriteEnable, @@ -102,7 +102,7 @@ namespace std template<> struct hash<Diligent::RasterizerStateDesc> { - size_t operator()( const Diligent::RasterizerStateDesc &RasterizerDesc ) const + size_t operator()( const Diligent::RasterizerStateDesc& RasterizerDesc ) const { return Diligent::ComputeHash( static_cast<int>( RasterizerDesc.FillMode ), static_cast<int>( RasterizerDesc.CullMode ), @@ -120,7 +120,7 @@ namespace std template<> struct hash<Diligent::BlendStateDesc> { - size_t operator()( const Diligent::BlendStateDesc &BSDesc ) const + size_t operator()( const Diligent::BlendStateDesc& BSDesc ) const { std::size_t Seed = 0; for( int i = 0; i < Diligent::BlendStateDesc::MaxRenderTargets; ++i ) @@ -148,7 +148,7 @@ namespace std template<> struct hash<Diligent::TextureViewDesc> { - size_t operator()( const Diligent::TextureViewDesc &TexViewDesc ) const + size_t operator()( const Diligent::TextureViewDesc& TexViewDesc ) const { std::size_t Seed = 0; Diligent::HashCombine( Seed, @@ -187,18 +187,19 @@ public: /// \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) /// \param NumDeferredContexts - number of deferred device contexts - /// \param TextureObjSize - size of the texture object, in bytes - /// \param TexViewObjSize - size of the texture view object, in bytes - /// \param BufferObjSize - size of the buffer object, in bytes - /// \param BuffViewObjSize - size of the buffer view object, in bytes - /// \param ShaderObjSize - size of the shader object, in bytes - /// \param SamplerObjSize - size of the sampler object, in bytes - /// \param PSOSize - size of the pipeline state object, in bytes - /// \param SRBSize - size of the shader resource binding object, in bytes + /// \param TextureObjSize - size of the texture object, in bytes + /// \param TexViewObjSize - size of the texture view object, in bytes + /// \param BufferObjSize - size of the buffer object, in bytes + /// \param BuffViewObjSize - size of the buffer view object, in bytes + /// \param ShaderObjSize - size of the shader object, in bytes + /// \param SamplerObjSize - size of the sampler object, in bytes + /// \param PSOSize - size of the pipeline state object, in bytes + /// \param SRBSize - size of the shader resource binding object, in bytes + /// \param FenceSize - size of the fence object, in bytes /// \remarks Render device uses fixed block allocators (see FixedBlockMemoryAllocator) to allocate memory for /// device objects. The object sizes provided to constructor are used to initialize the allocators. - RenderDeviceBase(IReferenceCounters *pRefCounters, - IMemoryAllocator &RawMemAllocator, + RenderDeviceBase(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, Uint32 NumDeferredContexts, size_t TextureObjSize, size_t TexViewObjSize, @@ -207,21 +208,23 @@ public: size_t ShaderObjSize, size_t SamplerObjSize, size_t PSOSize, - size_t SRBSize) : - TObjectBase(pRefCounters), - m_SamplersRegistry(RawMemAllocator, "sampler"), - m_TextureFormatsInfo( TEX_FORMAT_NUM_FORMATS, TextureFormatInfoExt(), STD_ALLOCATOR_RAW_MEM(TextureFormatInfoExt, RawMemAllocator, "Allocator for vector<TextureFormatInfoExt>") ), - m_TexFmtInfoInitFlags( TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator, "Allocator for vector<bool>") ), - m_wpDeferredContexts(NumDeferredContexts, RefCntWeakPtr<IDeviceContext>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<IDeviceContext>, RawMemAllocator, "Allocator for vector< RefCntWeakPtr<IDeviceContext> >")), - m_TexObjAllocator(RawMemAllocator, TextureObjSize, 64), - m_TexViewObjAllocator(RawMemAllocator, TexViewObjSize, 64), - m_BufObjAllocator(RawMemAllocator, BufferObjSize, 128), - m_BuffViewObjAllocator(RawMemAllocator, BuffViewObjSize, 128), - m_ShaderObjAllocator(RawMemAllocator, ShaderObjSize, 32), - m_SamplerObjAllocator(RawMemAllocator, SamplerObjSize, 32), - m_PSOAllocator(RawMemAllocator, PSOSize, 128), - m_SRBAllocator(RawMemAllocator, SRBSize, 1024), - m_ResMappingAllocator(RawMemAllocator, sizeof(ResourceMappingImpl), 16) + size_t SRBSize, + size_t FenceSize) : + TObjectBase (pRefCounters), + m_SamplersRegistry (RawMemAllocator, "sampler"), + m_TextureFormatsInfo (TEX_FORMAT_NUM_FORMATS, TextureFormatInfoExt(), STD_ALLOCATOR_RAW_MEM(TextureFormatInfoExt, RawMemAllocator, "Allocator for vector<TextureFormatInfoExt>") ), + m_TexFmtInfoInitFlags (TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator, "Allocator for vector<bool>") ), + m_wpDeferredContexts (NumDeferredContexts, RefCntWeakPtr<IDeviceContext>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<IDeviceContext>, RawMemAllocator, "Allocator for vector< RefCntWeakPtr<IDeviceContext> >")), + m_TexObjAllocator (RawMemAllocator, TextureObjSize, 64), + m_TexViewObjAllocator (RawMemAllocator, TexViewObjSize, 64), + m_BufObjAllocator (RawMemAllocator, BufferObjSize, 128), + m_BuffViewObjAllocator (RawMemAllocator, BuffViewObjSize, 128), + m_ShaderObjAllocator (RawMemAllocator, ShaderObjSize, 32), + m_SamplerObjAllocator (RawMemAllocator, SamplerObjSize, 32), + m_PSOAllocator (RawMemAllocator, PSOSize, 128), + m_SRBAllocator (RawMemAllocator, SRBSize, 1024), + m_FenceAllocator (RawMemAllocator, FenceSize, 16), + m_ResMappingAllocator (RawMemAllocator, sizeof(ResourceMappingImpl), 16) { // Initialize texture format info for( Uint32 Fmt = TEX_FORMAT_UNKNOWN; Fmt < TEX_FORMAT_NUM_FORMATS; ++Fmt ) @@ -289,7 +292,7 @@ public: } /// Implementation of IRenderDevice::GetTextureFormatInfo(). - virtual const TextureFormatInfo &GetTextureFormatInfo(TEXTURE_FORMAT TexFormat)override final + virtual const TextureFormatInfo& GetTextureFormatInfo(TEXTURE_FORMAT TexFormat)override final { VERIFY( TexFormat >= TEX_FORMAT_UNKNOWN && TexFormat < TEX_FORMAT_NUM_FORMATS, "Texture format out of range" ); const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat]; @@ -298,7 +301,7 @@ public: } /// Implementation of IRenderDevice::GetTextureFormatInfoExt(). - virtual const TextureFormatInfoExt &GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat )override final + virtual const TextureFormatInfoExt& GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat )override final { VERIFY( TexFormat >= TEX_FORMAT_UNKNOWN && TexFormat < TEX_FORMAT_NUM_FORMATS, "Texture format out of range" ); const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat]; @@ -312,21 +315,21 @@ public: return TexFmtInfo; } - void OnCreateDeviceObject( IDeviceObject *pNewObject ) + void OnCreateDeviceObject( IDeviceObject* pNewObject ) { } StateObjectsRegistry<SamplerDesc>& GetSamplerRegistry(){ return m_SamplersRegistry; } /// Set weak reference to the immediate context - void SetImmediateContext(IDeviceContext *pImmediateContext) + void SetImmediateContext(IDeviceContext* pImmediateContext) { VERIFY( m_wpImmediateContext.Lock() == nullptr, "Immediate context has already been set" ); m_wpImmediateContext = pImmediateContext; } /// Set weak reference to the deferred context - void SetDeferredContext(size_t Ctx, IDeviceContext *pDeferredCtx) + void SetDeferredContext(size_t Ctx, IDeviceContext* pDeferredCtx) { VERIFY( m_wpDeferredContexts[Ctx].Lock() == nullptr, "Deferred context has already been set" ); m_wpDeferredContexts[Ctx] = pDeferredCtx; @@ -378,6 +381,7 @@ protected: FixedBlockMemoryAllocator m_PSOAllocator; ///< Allocator for pipeline state objects FixedBlockMemoryAllocator m_SRBAllocator; ///< Allocator for shader resource binding objects FixedBlockMemoryAllocator m_ResMappingAllocator; ///< Allocator for resource mapping objects + FixedBlockMemoryAllocator m_FenceAllocator; ///< Allocator for fence objects }; @@ -389,11 +393,11 @@ void RenderDeviceBase<BaseInterface>::CreateResourceMapping( const ResourceMappi return; VERIFY( *ppMapping == nullptr, "Overwriting reference to existing object may cause memory leaks" ); - auto *pResourceMapping( NEW_RC_OBJ(m_ResMappingAllocator, "ResourceMappingImpl instance", ResourceMappingImpl)(GetRawAllocator()) ); + auto* pResourceMapping( NEW_RC_OBJ(m_ResMappingAllocator, "ResourceMappingImpl instance", ResourceMappingImpl)(GetRawAllocator()) ); pResourceMapping->QueryInterface( IID_ResourceMapping, reinterpret_cast<IObject**>(ppMapping) ); if( MappingDesc.pEntries ) { - for( auto *pEntry = MappingDesc.pEntries; pEntry->Name && pEntry->pObject; ++pEntry ) + for( auto* pEntry = MappingDesc.pEntries; pEntry->Name && pEntry->pObject; ++pEntry ) { (*ppMapping)->AddResourceArray( pEntry->Name, pEntry->ArrayIndex, &pEntry->pObject, 1, true ); } @@ -416,7 +420,7 @@ void RenderDeviceBase<BaseInterface> :: CreateDeviceObject( const Char *ObjectTy if(!ppObject) return; - VERIFY( *ppObject == nullptr, "Overwriting reference to existing object may cause memory leaks" ); + VERIFY(*ppObject == nullptr, "Overwriting reference to existing object may cause memory leaks" ); // Do not release *ppObject here! // Should this happen, RefCntAutoPtr<> will take care of this! //if( *ppObject ) diff --git a/Graphics/GraphicsEngine/include/ResourceMappingImpl.h b/Graphics/GraphicsEngine/include/ResourceMappingImpl.h index cbbf963a..76337d59 100644 --- a/Graphics/GraphicsEngine/include/ResourceMappingImpl.h +++ b/Graphics/GraphicsEngine/include/ResourceMappingImpl.h @@ -42,7 +42,7 @@ namespace Diligent { } - ResMappingHashKey(ResMappingHashKey &&rhs) : + ResMappingHashKey(ResMappingHashKey&& rhs) : StrKey(std::move(rhs.StrKey)), ArrayIndex(rhs.ArrayIndex) {} @@ -63,7 +63,7 @@ namespace Diligent } - ResMappingHashKey( const ResMappingHashKey& ) = delete; + ResMappingHashKey ( const ResMappingHashKey& ) = delete; ResMappingHashKey& operator = ( const ResMappingHashKey& ) = delete; ResMappingHashKey& operator = ( ResMappingHashKey&& ) = delete; @@ -78,7 +78,7 @@ namespace std template<> struct hash<Diligent::ResMappingHashKey> { - size_t operator()( const Diligent::ResMappingHashKey &Key ) const + size_t operator()( const Diligent::ResMappingHashKey& Key ) const { return Key.GetHash(); } @@ -97,26 +97,26 @@ namespace Diligent /// \param pRefCounters - reference counters object that controls the lifetime of this resource mapping /// \param RawMemAllocator - raw memory allocator that is used by the m_HashTable member - ResourceMappingImpl(IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator) : + ResourceMappingImpl(IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator) : TObjectBase(pRefCounters), m_HashTable(STD_ALLOCATOR_RAW_MEM(HashTableElem, RawMemAllocator, "Allocator for unordered_map< ResMappingHashKey, RefCntAutoPtr<IDeviceObject> >") ) {} ~ResourceMappingImpl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; + virtual void QueryInterface( const Diligent::INTERFACE_ID& IID, IObject** ppInterface )override final; /// Implementation of IResourceMapping::AddResource() - virtual void AddResource( const Char *Name, IDeviceObject *pObject, bool bIsUnique )override final; + virtual void AddResource( const Char* Name, IDeviceObject* pObject, bool bIsUnique )override final; /// Implementation of IResourceMapping::AddResourceArray() - virtual void AddResourceArray( const Char *Name, Uint32 StartIndex, IDeviceObject * const* ppObjects, Uint32 NumElements, bool bIsUnique )override final; + virtual void AddResourceArray( const Char* Name, Uint32 StartIndex, IDeviceObject* const* ppObjects, Uint32 NumElements, bool bIsUnique )override final; /// Implementation of IResourceMapping::RemoveResourceByName() - virtual void RemoveResourceByName( const Char *Name, Uint32 ArrayIndex )override final; + virtual void RemoveResourceByName( const Char* Name, Uint32 ArrayIndex )override final; /// Implementation of IResourceMapping::GetResource() - virtual void GetResource( const Char *Name, IDeviceObject **ppResource, Uint32 ArrayIndex )override final; + virtual void GetResource( const Char* Name, IDeviceObject** ppResource, Uint32 ArrayIndex )override final; /// Returns number of resources in the resource mapping. virtual size_t GetSize()override final; diff --git a/Graphics/GraphicsEngine/include/SamplerBase.h b/Graphics/GraphicsEngine/include/SamplerBase.h index 0eeb37e6..c6e69c7e 100644 --- a/Graphics/GraphicsEngine/include/SamplerBase.h +++ b/Graphics/GraphicsEngine/include/SamplerBase.h @@ -35,10 +35,12 @@ namespace Diligent /// Template class implementing base functionality for a sampler object. -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ISamplerD3D11, Diligent::ISamplerD3D12 or Diligent::ISamplerGL). +/// \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, or Diligent::IRenderDeviceGLES). +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, Diligent::IRenderDeviceGL, +/// Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). template<class BaseInterface, class RenderDeviceBaseInterface> class SamplerBase : public DeviceObjectBase<BaseInterface, SamplerDesc> { @@ -51,7 +53,7 @@ public: /// \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, IRenderDevice* pDevice, const SamplerDesc& SamDesc, bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, SamDesc, bIsDeviceInternal ) {} @@ -59,7 +61,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 = static_cast<TRenderDeviceBase*>(this->GetDevice())->GetSamplerRegistry(); SamplerRegistry.ReportDeletedObject(); } diff --git a/Graphics/GraphicsEngine/include/ShaderBase.h b/Graphics/GraphicsEngine/include/ShaderBase.h index 5b47bcbd..7db44cfe 100644 --- a/Graphics/GraphicsEngine/include/ShaderBase.h +++ b/Graphics/GraphicsEngine/include/ShaderBase.h @@ -69,7 +69,7 @@ static const int DSInd = GetShaderTypeIndex(SHADER_TYPE_DOMAIN); static const int CSInd = GetShaderTypeIndex(SHADER_TYPE_COMPUTE); template<typename TNameCompare> -SHADER_VARIABLE_TYPE GetShaderVariableType(SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc *VariableDesc, Uint32 NumVars, TNameCompare NameCompare) +SHADER_VARIABLE_TYPE GetShaderVariableType(SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc* VariableDesc, Uint32 NumVars, TNameCompare NameCompare) { for (Uint32 v = 0; v < NumVars; ++v) { @@ -82,7 +82,7 @@ SHADER_VARIABLE_TYPE GetShaderVariableType(SHADER_VARIABLE_TYPE DefaultVariableT return DefaultVariableType; } -inline SHADER_VARIABLE_TYPE GetShaderVariableType(const Char* Name, SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc *VariableDesc, Uint32 NumVars) +inline SHADER_VARIABLE_TYPE GetShaderVariableType(const Char* Name, SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc* VariableDesc, Uint32 NumVars) { return GetShaderVariableType(DefaultVariableType, VariableDesc, NumVars, [&](const char *VarName) @@ -117,7 +117,7 @@ inline SHADER_VARIABLE_TYPE GetShaderVariableType(const String& Name, const Shad struct ShaderVariableBase : public IShaderVariable { - ShaderVariableBase(IObject &Owner) : + ShaderVariableBase(IObject& Owner) : // Shader variables are always created as part of the shader, or // shader resource binding, so we must provide owner pointer to // the base class constructor @@ -145,7 +145,7 @@ struct ShaderVariableBase : public IShaderVariable return m_Owner.Release(); } - virtual void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override final + virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override final { if( ppInterface == nullptr ) return; @@ -165,7 +165,7 @@ protected: /// Implementation of a dummy shader variable that silently ignores all operations struct DummyShaderVariable : ShaderVariableBase { - DummyShaderVariable(IObject &Owner) : + DummyShaderVariable(IObject& Owner) : ShaderVariableBase(Owner) {} @@ -184,10 +184,12 @@ struct DummyShaderVariable : ShaderVariableBase /// Template class implementing base functionality for a shader object -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IShaderD3D11, Diligent::IShaderD3D12 or Diligent::IShaderGL). +/// \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, or Diligent::IRenderDeviceGLES). +/// (Diligent::IRenderDeviceD3D11, Diligent::IRenderDeviceD3D12, +/// Diligent::IRenderDeviceGL, Diligent::IRenderDeviceGLES or Diligent::IRenderDeviceVk). template<class BaseInterface, class RenderDeviceBaseInterface> class ShaderBase : public DeviceObjectBase<BaseInterface, ShaderDesc> { @@ -199,11 +201,11 @@ public: /// \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, IRenderDevice* 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>") ), - m_StringPool(ShdrDesc.NumVariables + ShdrDesc.NumStaticSamplers, String(), STD_ALLOCATOR_RAW_MEM(String, GetRawAllocator(), "Allocator for vector<String>")), + m_VariablesDesc (ShdrDesc.NumVariables, ShaderVariableDesc(), STD_ALLOCATOR_RAW_MEM(ShaderVariableDesc, GetRawAllocator(), "Allocator for vector<ShaderVariableDesc>") ), + m_StringPool (ShdrDesc.NumVariables + ShdrDesc.NumStaticSamplers, String(), STD_ALLOCATOR_RAW_MEM(String, GetRawAllocator(), "Allocator for vector<String>")), m_StaticSamplers(ShdrDesc.NumStaticSamplers, StaticSamplerDesc(), STD_ALLOCATOR_RAW_MEM(StaticSamplerDesc, GetRawAllocator(), "Allocator for vector<StaticSamplerDesc>") ) { auto Str = m_StringPool.begin(); diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h index 14e4e89e..822d44b9 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h +++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.h @@ -37,7 +37,8 @@ namespace Diligent /// Template class implementing base functionality for a shader resource binding /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::IShaderResourceBindingGL, Diligent::IShaderResourceBindingD3D11, or Diligent::IShaderResourceBindingD3D12). +/// (Diligent::IShaderResourceBindingGL, Diligent::IShaderResourceBindingD3D11, +/// Diligent::IShaderResourceBindingD3D12 or Diligent::IShaderResourceBindingVk). template<class BaseInterface> class ShaderResourceBindingBase : public ObjectBase<BaseInterface> { @@ -48,7 +49,7 @@ public: /// \param pPSO - pipeline state that this SRB belongs to. /// \param IsInternal - flag indicating if the shader resource binding is an internal PSO object and /// must not keep a strong reference to the PSO. - ShaderResourceBindingBase( IReferenceCounters *pRefCounters, IPipelineState *pPSO, bool IsInternal = false ) : + ShaderResourceBindingBase( IReferenceCounters* pRefCounters, IPipelineState* pPSO, bool IsInternal = false ) : TObjectBase( pRefCounters ), m_spPSO( IsInternal ? nullptr : pPSO ), m_pPSO( pPSO ) @@ -68,7 +69,7 @@ protected: /// shader resource binding uses PSO's memory allocator to allocate /// memory for shader resource cache. RefCntAutoPtr<IPipelineState> m_spPSO; - IPipelineState *m_pPSO; + IPipelineState* const m_pPSO; }; } diff --git a/Graphics/GraphicsEngine/include/StateObjectsRegistry.h b/Graphics/GraphicsEngine/include/StateObjectsRegistry.h index a1bc96bc..75883f5d 100644 --- a/Graphics/GraphicsEngine/include/StateObjectsRegistry.h +++ b/Graphics/GraphicsEngine/include/StateObjectsRegistry.h @@ -61,7 +61,7 @@ namespace Diligent /// Number of outstanding deleted objects to purge the registry. static constexpr int DeletedObjectsToPurge = 32; - StateObjectsRegistry(IMemoryAllocator &RawAllocator, const Char* RegistryName) : + StateObjectsRegistry(IMemoryAllocator& RawAllocator, const Char* RegistryName) : m_DescToObjHashMap(STD_ALLOCATOR_RAW_MEM(HashMapElem, RawAllocator, "Allocator for unordered_map<ResourceDescType, RefCntWeakPtr<IDeviceObject> >") ), m_RegistryName( RegistryName ) {} @@ -88,7 +88,7 @@ namespace Diligent /// assumed to be an expensive operation and should be performed during /// the initialization. Occasional purge operations should not add significant /// cost to it. - void Add( const ResourceDescType& ObjectDesc, IDeviceObject *pObject ) + void Add( const ResourceDescType& ObjectDesc, IDeviceObject* pObject ) { ThreadingTools::LockHelper Lock( m_LockFlag ); @@ -126,7 +126,7 @@ namespace Diligent } /// Finds the object in the registry - void Find( const ResourceDescType &Desc, IDeviceObject **ppObject ) + void Find( const ResourceDescType& Desc, IDeviceObject** ppObject ) { VERIFY( *ppObject == nullptr, "Overwriting reference to existing object may cause memory leaks" ); *ppObject = nullptr; diff --git a/Graphics/GraphicsEngine/include/SwapChainBase.h b/Graphics/GraphicsEngine/include/SwapChainBase.h index c01c7d04..2f74d3c1 100644 --- a/Graphics/GraphicsEngine/include/SwapChainBase.h +++ b/Graphics/GraphicsEngine/include/SwapChainBase.h @@ -36,7 +36,8 @@ namespace Diligent /// Base implementation of the swap chain. /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ISwapChainGL, Diligent::ISwapChainD3D11, or Diligent::ISwapChainD3D12). +/// (Diligent::ISwapChainGL, Diligent::ISwapChainD3D11, +/// Diligent::ISwapChainD3D12 or Diligent::ISwapChainVk). /// \remarks Swap chain holds the strong reference to the device and a weak reference to the /// immediate context. template<class BaseInterface> @@ -49,9 +50,9 @@ public: /// \param pDevice - pointer to the device. /// \param pDeviceContext - pointer to the device context. /// \param SCDesc - swap chain description - SwapChainBase( IReferenceCounters *pRefCounters, - IRenderDevice *pDevice, - IDeviceContext *pDeviceContext, + SwapChainBase( IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pDeviceContext, const SwapChainDesc& SCDesc ) : TObjectBase(pRefCounters), m_pRenderDevice(pDevice), @@ -98,8 +99,8 @@ protected: SwapChainDesc m_SwapChainDesc; private: - SwapChainBase( const SwapChainBase& ); - SwapChainBase( SwapChainBase&& ); + SwapChainBase ( const SwapChainBase& ); + SwapChainBase ( SwapChainBase&& ); const SwapChainBase& operator = ( const SwapChainBase& ); const SwapChainBase& operator = ( SwapChainBase&& ); }; diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h index 60d08e0c..c9abf042 100644 --- a/Graphics/GraphicsEngine/include/TextureBase.h +++ b/Graphics/GraphicsEngine/include/TextureBase.h @@ -36,17 +36,19 @@ namespace Diligent { void ValidateTextureDesc(const TextureDesc& TexDesc); -void ValidateUpdateDataParams( const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData ); -void VliadateCopyTextureDataParams( const TextureDesc &SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, - const TextureDesc &DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice, +void ValidateUpdateDataParams( const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData ); +void VliadateCopyTextureDataParams( const TextureDesc& SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box* pSrcBox, + const TextureDesc& DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ ); /// Base implementation of the ITexture interface -/// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ITextureD3D11, Diligent::ITextureD3D12 or Diligent::ITextureGL). -/// \tparam TTextureViewImpl - type of the texture view implementation -/// (Diligent::TextureViewD3D11Impl, Diligent::TextureViewD3D12Impl or Diligent::TextureViewGLImpl). +/// \tparam BaseInterface - base interface that this class will inheret +/// (Diligent::ITextureD3D11, Diligent::ITextureD3D12, +/// Diligent::ITextureGL or Diligent::ITextureVk). +/// \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> @@ -61,11 +63,11 @@ public: /// \param Desc - texture description /// \param bIsDeviceInternal - flag indicating if the texture is an internal device object and /// must not keep a strong reference to the device - TextureBase( IReferenceCounters *pRefCounters, - TTexViewObjAllocator &TexViewObjAllocator, - IRenderDevice *pDevice, - const TextureDesc& Desc, - bool bIsDeviceInternal = false ) : + TextureBase( IReferenceCounters* pRefCounters, + TTexViewObjAllocator& TexViewObjAllocator, + IRenderDevice* pDevice, + const TextureDesc& Desc, + bool bIsDeviceInternal = false ) : TDeviceObjectBase( pRefCounters, pDevice, Desc, bIsDeviceInternal ), #ifdef _DEBUG m_dbgTexViewObjAllocator(TexViewObjAllocator), @@ -108,17 +110,17 @@ public: /// Implementaiton of ITexture::CreateView(); calls CreateViewInternal() virtual function that /// creates texture view for the specific engine implementation. - virtual void CreateView( const struct TextureViewDesc &ViewDesc, ITextureView **ppView )override + virtual void CreateView( const struct TextureViewDesc& ViewDesc, ITextureView** ppView )override { CreateViewInternal( ViewDesc, ppView, false ); } /// Base implementaiton of ITexture::UpdateData(); validates input parameters - virtual void UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData )override = 0; + virtual void UpdateData( IDeviceContext* pContext, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData )override = 0; /// Base implementaiton of ITexture::CopyData(); validates input parameters - virtual void CopyData( IDeviceContext *pContext, - ITexture *pSrcTexture, + virtual void CopyData( IDeviceContext* pContext, + ITexture* pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, @@ -129,10 +131,10 @@ public: Uint32 DstZ )override = 0; /// Base implementaiton of ITexture::Map() - virtual void Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData )override = 0; + virtual void Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource& MappedData )override = 0; /// Base implementaiton of ITexture::Unmap() - virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override = 0; + virtual void Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override = 0; /// Creates default texture views. @@ -148,7 +150,7 @@ public: protected: /// Pure virtual function that creates texture view for the specific engine implementation. - virtual void CreateViewInternal( const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView ) = 0; + virtual void CreateViewInternal( const struct TextureViewDesc& ViewDesc, ITextureView** ppView, bool bIsDefaultView ) = 0; #ifdef _DEBUG TTexViewObjAllocator &m_dbgTexViewObjAllocator; @@ -176,12 +178,12 @@ protected: } } - void CorrectTextureViewDesc( struct TextureViewDesc &ViewDesc ); + void CorrectTextureViewDesc( struct TextureViewDesc& ViewDesc ); }; template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CorrectTextureViewDesc(struct TextureViewDesc &ViewDesc) +void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CorrectTextureViewDesc(struct TextureViewDesc& ViewDesc) { #define TEX_VIEW_VALIDATION_ERROR(...) LOG_ERROR_AND_THROW( "Texture view \"", ViewDesc.Name ? ViewDesc.Name : "", "\": ", ##__VA_ARGS__ ) @@ -441,14 +443,15 @@ 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 ) +void TextureBase<BaseInterface, 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( IDeviceContext *pContext, - ITexture *pSrcTexture, +void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CopyData( + IDeviceContext* pContext, + ITexture* pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, @@ -465,12 +468,12 @@ void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CopyD } template<class BaseInterface, class TTextureViewImpl, class TTexViewObjAllocator> -void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData ) +void TextureBase<BaseInterface, 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 ) +void TextureBase<BaseInterface, 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 b8e7847a..0837b962 100644 --- a/Graphics/GraphicsEngine/include/TextureViewBase.h +++ b/Graphics/GraphicsEngine/include/TextureViewBase.h @@ -37,7 +37,8 @@ namespace Diligent /// Template class implementing base functionality for a texture view interface /// \tparam BaseInterface - base interface that this class will inheret -/// (Diligent::ITextureViewD3D11, Diligent::ITextureViewD3D12 or Diligent::ITextureViewGL). +/// (Diligent::ITextureViewD3D11, Diligent::ITextureViewD3D12, +/// Diligent::ITextureViewGL or Diligent::ITextureViewVk). template<class BaseInterface> class TextureViewBase : public DeviceObjectBase<BaseInterface, TextureViewDesc> { @@ -52,11 +53,11 @@ public: /// \param bIsDefaultView - flag indicating if the view is default view, and is thus /// part of the texture object. In this case the view will attach /// to the texture's reference counters. - TextureViewBase( IReferenceCounters *pRefCounters, - IRenderDevice *pDevice, + TextureViewBase( IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, const TextureViewDesc& ViewDesc, - class ITexture *pTexture, - bool bIsDefaultView ) : + class ITexture* pTexture, + bool bIsDefaultView ) : // Default views are created as part of the texture, so we cannot not keep strong // reference to the texture to avoid cyclic links. Instead, we will attach to the // reference counters of the texture. @@ -117,7 +118,7 @@ protected: Diligent::RefCntAutoPtr<ISampler> m_pSampler; /// Raw pointer to the texture - ITexture *m_pTexture; + ITexture* const m_pTexture; /// Strong reference to the texture. Used for non-default views /// to keep the texture alive diff --git a/Graphics/GraphicsEngine/interface/Fence.h b/Graphics/GraphicsEngine/interface/Fence.h new file mode 100644 index 00000000..aab72307 --- /dev/null +++ b/Graphics/GraphicsEngine/interface/Fence.h @@ -0,0 +1,63 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Defines Diligent::IFence interface and related data structures + +#include "DeviceObject.h" + +namespace Diligent +{ + +// {3B19184D-32AB-4701-84F4-9A0C03AE1672} +static constexpr INTERFACE_ID IID_Fence = +{ 0x3b19184d, 0x32ab, 0x4701, { 0x84, 0xf4, 0x9a, 0xc, 0x3, 0xae, 0x16, 0x72 } }; + +/// Buffer description +struct FenceDesc : DeviceObjectAttribs +{ + +}; + +/// Fence interface + +/// Fence the methods to manipulate a fence object +class IFence : public IDeviceObject +{ +public: + /// Queries the specific interface, see IObject::QueryInterface() for details + virtual void QueryInterface( const Diligent::INTERFACE_ID& IID, IObject** ppInterface ) = 0; + + /// Returns the fence description used to create the object + virtual const FenceDesc& GetDesc()const = 0; + + /// Returns the last completed value signaled by the GPU + virtual Uint64 GetCompletedValue() = 0; + + /// Resets the fence to the specified value. + virtual void Reset(Uint64 Value) = 0; +}; + +} diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index f99a885a..6f0b8c63 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -39,6 +39,7 @@ #include "TextureView.h" #include "BufferView.h" #include "PipelineState.h" +#include "Fence.h" #include "DepthStencilState.h" #include "RasterizerState.h" @@ -56,7 +57,7 @@ class IRenderDevice : public IObject { public: /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface ) = 0; + virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface ) = 0; /// Creates a new buffer object @@ -76,7 +77,7 @@ public: /// ElementByteStride member of buffer description is set to default value (0). virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData& BuffData, - IBuffer **ppBuffer) = 0; + IBuffer** ppBuffer) = 0; /// Creates a new shader object @@ -86,8 +87,8 @@ public: /// shader interface will be stored. /// The function calls AddRef(), so that the new object will contain /// one refernce. - virtual void CreateShader(const ShaderCreationAttribs &CreationAttribs, - IShader **ppShader) = 0; + virtual void CreateShader(const ShaderCreationAttribs& CreationAttribs, + IShader** ppShader) = 0; /// Creates a new texture object @@ -112,12 +113,12 @@ public: /// For a 15 x 6 x 4 3D texture, the following array of subresources should be provided:\n /// 15x6x4, 7x3x2, 3x1x1, 1x1x1 virtual void CreateTexture(const TextureDesc& TexDesc, - const TextureData &Data, - ITexture **ppTexture) = 0; + const TextureData& Data, + ITexture** ppTexture) = 0; /// Creates a new sampler object - /// \param [in] SamDesc - Sampler description, see Diligent::SamplerDesc for details. + /// \param [in] SamDesc - Sampler description, see Diligent::SamplerDesc for details. /// \param [out] ppSampler - Address of the memory location where the pointer to the /// sampler interface will be stored. /// The function calls AddRef(), so that the new object will contain @@ -126,27 +127,38 @@ public: /// as an existing interface, the same interface will be returned. /// \note In D3D11, 4096 unique sampler state objects can be created on a device at a time. virtual void CreateSampler(const SamplerDesc& SamDesc, - ISampler **ppSampler) = 0; + ISampler** ppSampler) = 0; /// Creates a new resource mapping - /// \param [in] MappingDesc - Resource mapping description, see Diligent::ResourceMappingDesc for details. - /// \param [out] ppMapping - Address of the memory location where the pointer to the - /// resource mapping interface will be stored. - /// The function calls AddRef(), so that the new object will contain - /// one refernce. - virtual void CreateResourceMapping( const ResourceMappingDesc &MappingDesc, - IResourceMapping **ppMapping ) = 0; + /// \param [in] MappingDesc - Resource mapping description, see Diligent::ResourceMappingDesc for details. + /// \param [out] ppMapping - Address of the memory location where the pointer to the + /// resource mapping interface will be stored. + /// The function calls AddRef(), so that the new object will contain + /// one refernce. + virtual void CreateResourceMapping( const ResourceMappingDesc& MappingDesc, + IResourceMapping** ppMapping ) = 0; /// Creates a new pipeline state object - /// \param [in] PipelineDesc - Pipeline state description, see Diligent::PipelineStateDesc for details. + /// \param [in] PipelineDesc - Pipeline state description, see Diligent::PipelineStateDesc for details. /// \param [out] ppPipelineState - Address of the memory location where the pointer to the /// pipeline state interface will be stored. /// The function calls AddRef(), so that the new object will contain /// one refernce. - virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, - IPipelineState **ppPipelineState ) = 0; + virtual void CreatePipelineState( const PipelineStateDesc& PipelineDesc, + IPipelineState** ppPipelineState ) = 0; + + + /// Creates a new pipeline state object + + /// \param [in] Desc - Fence description, see Diligent::FenceDesc for details. + /// \param [out] ppFence - Address of the memory location where the pointer to the + /// fence interface will be stored. + /// The function calls AddRef(), so that the new object will contain + /// one refernce. + virtual void CreateFence( const FenceDesc& Desc, + IFence** ppFence) = 0; /// Gets the device capabilities, see Diligent::DeviceCaps for details @@ -158,7 +170,7 @@ public: /// \param [in] TexFormat - Texture format for which to provide the information /// \return Const reference to the TextureFormatInfo structure containing the /// texture format description. - virtual const TextureFormatInfo &GetTextureFormatInfo( TEXTURE_FORMAT TexFormat ) = 0; + virtual const TextureFormatInfo& GetTextureFormatInfo( TEXTURE_FORMAT TexFormat ) = 0; /// Returns the extended texture format information. @@ -170,7 +182,7 @@ public: /// \remark The first time this method is called for a particular format, it may be /// considerably slower than GetTextureFormatInfo(). If you do not require /// extended information, call GetTextureFormatInfo() instead. - virtual const TextureFormatInfoExt &GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat ) = 0; + virtual const TextureFormatInfoExt& GetTextureFormatInfoExt( TEXTURE_FORMAT TexFormat ) = 0; }; } diff --git a/Graphics/GraphicsEngineD3D11/CMakeLists.txt b/Graphics/GraphicsEngineD3D11/CMakeLists.txt index d8d1759b..79bcb0e2 100644 --- a/Graphics/GraphicsEngineD3D11/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D11/CMakeLists.txt @@ -13,6 +13,7 @@ set(INCLUDE include/DeviceContextD3D11Impl.h include/EngineD3D11Defines.h include/pch.h + include/FenceD3D11Impl.h include/PipelineStateD3D11Impl.h include/RenderDeviceD3D11Impl.h include/SamplerD3D11Impl.h @@ -35,6 +36,7 @@ set(INTERFACE interface/BufferViewD3D11.h interface/DeviceContextD3D11.h interface/EngineD3D11Attribs.h + interface/FenceD3D11.h interface/PipelineStateD3D11.h interface/RenderDeviceD3D11.h interface/RenderDeviceFactoryD3D11.h @@ -54,6 +56,7 @@ set(SRC src/D3D11DebugUtilities.cpp src/D3D11TypeConversions.cpp src/DeviceContextD3D11Impl.cpp + src/FenceD3D11Impl.cpp src/PipelineStateD3D11Impl.cpp src/RenderDeviceD3D11Impl.cpp src/RenderDeviceFactoryD3D11.cpp diff --git a/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h new file mode 100644 index 00000000..44b6a5bf --- /dev/null +++ b/Graphics/GraphicsEngineD3D11/include/FenceD3D11Impl.h @@ -0,0 +1,60 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::FenceD3D11Impl class + +#include "FenceD3D11.h" +#include "RenderDeviceD3D11.h" +#include "FenceBase.h" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Implementation of the Diligent::IFenceD3D11 interface +class FenceD3D11Impl : public FenceBase<IFenceD3D11> +{ +public: + using TFenceBase = FenceBase<IFenceD3D11>; + + FenceD3D11Impl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc); + ~FenceD3D11Impl(); + + virtual Uint64 GetCompletedValue()override final; + + /// Resets the fence to the specified value. + virtual void Reset(Uint64 Value)override final; + + ID3D11Fence* GetD3D11Fence()override final{ return m_pd3d11Fence; } + +private: + CComPtr<ID3D11Fence> m_pd3d11Fence; ///< D3D11 Fence object +}; + +} diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h index d92a5b8c..4ab28877 100644 --- a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h @@ -55,7 +55,9 @@ public: virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)override final; - virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final; + virtual void CreatePipelineState(const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState)override final; + + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final; ID3D11Device* GetD3D11Device()override final{return m_pd3d11Device;} diff --git a/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h b/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h new file mode 100644 index 00000000..01e690e6 --- /dev/null +++ b/Graphics/GraphicsEngineD3D11/interface/FenceD3D11.h @@ -0,0 +1,51 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFenceD3D11 interface + +#include "../../GraphicsEngine/interface/Fence.h" + +namespace Diligent +{ + +// {45F2BE28-652B-4180-B6E4-E75F83F63CC7} +static constexpr INTERFACE_ID IID_FenceD3D11 = +{ 0x45f2be28, 0x652b, 0x4180, { 0xb6, 0xe4, 0xe7, 0x5f, 0x83, 0xf6, 0x3c, 0xc7 } }; + + +/// Interface to the fence object implemented in D3D11 +class IFenceD3D11 : public IFence +{ +public: + + /// Returns a pointer to the ID3D11Fence interface of the internal Direct3D11 object. + + /// The method does *NOT* call AddRef() on the returned interface, + /// so Release() must not be called. + virtual ID3D11Fence* GetD3D11Fence() = 0; +}; + +} diff --git a/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp new file mode 100644 index 00000000..c090b3b8 --- /dev/null +++ b/Graphics/GraphicsEngineD3D11/src/FenceD3D11Impl.cpp @@ -0,0 +1,54 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include <atlbase.h> + +#include "FenceD3D11Impl.h" +#include "EngineMemory.h" + +namespace Diligent +{ + +FenceD3D11Impl :: FenceD3D11Impl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc) : + TFenceBase(pRefCounters, pDevice, Desc) +{ +} + +FenceD3D11Impl :: ~FenceD3D11Impl() +{ +} + +Uint64 FenceD3D11Impl :: GetCompletedValue() +{ + return m_pd3d11Fence->GetCompletedValue(); +} + +void FenceD3D11Impl :: Reset(Uint64 Value) +{ + LOG_ERROR("Resetting D3D11 fence is not supported"); +} + +} diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp index 222be0c5..27b226e9 100644 --- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp @@ -34,6 +34,7 @@ #include "TextureViewD3D11Impl.h" #include "PipelineStateD3D11Impl.h" #include "ShaderResourceBindingD3D11Impl.h" +#include "FenceD3D11Impl.h" #include "EngineMemory.h" namespace Diligent @@ -56,7 +57,8 @@ RenderDeviceD3D11Impl :: RenderDeviceD3D11Impl(IReferenceCounters* pRefCou sizeof(ShaderD3D11Impl), sizeof(SamplerD3D11Impl), sizeof(PipelineStateD3D11Impl), - sizeof(ShaderResourceBindingD3D11Impl) + sizeof(ShaderResourceBindingD3D11Impl), + sizeof(FenceD3D11Impl) }, m_EngineAttribs(EngineAttribs), m_pd3d11Device(pd3d11Device) @@ -378,4 +380,17 @@ void RenderDeviceD3D11Impl::CreatePipelineState(const PipelineStateDesc& Pipelin ); } +void RenderDeviceD3D11Impl::CreateFence(const FenceDesc& Desc, IFence** ppFence) +{ + CreateDeviceObject( "Fence", Desc, ppFence, + [&]() + { + FenceD3D11Impl* pFenceD3D11( NEW_RC_OBJ(m_FenceAllocator, "FenceD3D11Impl instance", FenceD3D11Impl) + (this, Desc) ); + pFenceD3D11->QueryInterface( IID_Fence, reinterpret_cast<IObject**>(ppFence) ); + OnCreateDeviceObject( pFenceD3D11 ); + } + ); +} + } diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt index d124c353..f0902987 100644 --- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt @@ -17,6 +17,7 @@ set(INCLUDE include/DescriptorHeap.h include/DeviceContextD3D12Impl.h include/DynamicUploadHeap.h + include/FenceD3D12Impl.h include/GenerateMips.h include/pch.h include/PipelineStateD3D12Impl.h @@ -38,6 +39,7 @@ set(INTERFACE interface/BufferViewD3D12.h interface/CommandQueueD3D12.h interface/DeviceContextD3D12.h + interface/FenceD3D12.h interface/PipelineStateD3D12.h interface/RenderDeviceD3D12.h interface/RenderDeviceFactoryD3D12.h @@ -62,6 +64,7 @@ set(SRC src/DescriptorHeap.cpp src/DeviceContextD3D12Impl.cpp src/DynamicUploadHeap.cpp + src/FenceD3D12Impl.cpp src/GenerateMips.cpp src/PipelineStateD3D12Impl.cpp src/RenderDeviceD3D12Impl.cpp diff --git a/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h new file mode 100644 index 00000000..7412aeb0 --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/include/FenceD3D12Impl.h @@ -0,0 +1,60 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::FenceD3D12Impl class + +#include "FenceD3D12.h" +#include "RenderDeviceD3D12.h" +#include "FenceBase.h" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Implementation of the Diligent::IFenceD3D12 interface +class FenceD3D12Impl : public FenceBase<IFenceD3D12> +{ +public: + using TFenceBase = FenceBase<IFenceD3D12>; + + FenceD3D12Impl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc); + ~FenceD3D12Impl(); + + virtual Uint64 GetCompletedValue()override final; + + /// Resets the fence to the specified value. + virtual void Reset(Uint64 Value)override final; + + ID3D12Fence* GetD3D12Fence()override final{ return m_pD3D12Fence; } + +private: + CComPtr<ID3D12Fence> m_pD3D12Fence; ///< D3D12 Fence object +}; + +} diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 47c58d99..036cf0b9 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -68,6 +68,8 @@ public: virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler **ppSampler)override final; + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final; + virtual ID3D12Device* GetD3D12Device()override final{return m_pd3d12Device;} virtual void CreateTextureFromD3DResource(ID3D12Resource *pd3d12Texture, ITexture **ppTexture)override final; diff --git a/Graphics/GraphicsEngineD3D12/interface/FenceD3D12.h b/Graphics/GraphicsEngineD3D12/interface/FenceD3D12.h new file mode 100644 index 00000000..2df16af8 --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/interface/FenceD3D12.h @@ -0,0 +1,51 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFenceD3D12 interface + +#include "../../GraphicsEngine/interface/Fence.h" + +namespace Diligent +{ + +// {053C0D8C-3757-4220-A9CC-4749EC4794AD} +static constexpr INTERFACE_ID IID_FenceD3D12 = +{ 0x53c0d8c, 0x3757, 0x4220, { 0xa9, 0xcc, 0x47, 0x49, 0xec, 0x47, 0x94, 0xad } }; + + +/// Interface to the fence object implemented in D3D12 +class IFenceD3D12 : public IFence +{ +public: + + /// Returns a pointer to the ID3D12Fence interface of the internal Direct3D12 object. + + /// The method does *NOT* call AddRef() on the returned interface, + /// so Release() must not be called. + virtual ID3D12Fence* GetD3D12Fence() = 0; +}; + +} diff --git a/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp new file mode 100644 index 00000000..92939fea --- /dev/null +++ b/Graphics/GraphicsEngineD3D12/src/FenceD3D12Impl.cpp @@ -0,0 +1,54 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include <atlbase.h> + +#include "FenceD3D12Impl.h" +#include "EngineMemory.h" + +namespace Diligent +{ + +FenceD3D12Impl :: FenceD3D12Impl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc) : + TFenceBase(pRefCounters, pDevice, Desc) +{ +} + +FenceD3D12Impl :: ~FenceD3D12Impl() +{ +} + +Uint64 FenceD3D12Impl :: GetCompletedValue() +{ + return m_pD3D12Fence->GetCompletedValue(); +} + +void FenceD3D12Impl :: Reset(Uint64 Value) +{ + m_pD3D12Fence->Signal(Value); +} + +} diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 55068388..ea744aff 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -31,6 +31,7 @@ #include "BufferD3D12Impl.h" #include "ShaderResourceBindingD3D12Impl.h" #include "DeviceContextD3D12Impl.h" +#include "FenceD3D12Impl.h" #include "EngineMemory.h" namespace Diligent @@ -54,7 +55,8 @@ RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRef sizeof(ShaderD3D12Impl), sizeof(SamplerD3D12Impl), sizeof(PipelineStateD3D12Impl), - sizeof(ShaderResourceBindingD3D12Impl) + sizeof(ShaderResourceBindingD3D12Impl), + sizeof(FenceD3D12Impl) }, m_pd3d12Device (pd3d12Device), m_pCommandQueue (pCmdQueue), @@ -587,6 +589,19 @@ void RenderDeviceD3D12Impl :: CreateSampler(const SamplerDesc& SamplerDesc, ISam ); } +void RenderDeviceD3D12Impl::CreateFence(const FenceDesc& Desc, IFence** ppFence) +{ + CreateDeviceObject( "Fence", Desc, ppFence, + [&]() + { + FenceD3D12Impl* pFenceD3D12( NEW_RC_OBJ(m_FenceAllocator, "FenceD3D12Impl instance", FenceD3D12Impl) + (this, Desc) ); + pFenceD3D12->QueryInterface( IID_Fence, reinterpret_cast<IObject**>(ppFence) ); + OnCreateDeviceObject( pFenceD3D12 ); + } + ); +} + DescriptorHeapAllocation RenderDeviceD3D12Impl :: AllocateDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count /*= 1*/) { VERIFY(Type >= D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && Type < D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES, "Invalid heap type"); diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index 6b7e2037..b78a7fb2 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -8,6 +8,7 @@ set(INCLUDE include/BufferViewGLImpl.h include/DeviceContextGLImpl.h include/FBOCache.h + include/FenceGLImpl.h include/GLContext.h include/GLContextState.h include/GLObjectWrapper.h @@ -39,6 +40,7 @@ set(INTERFACE interface/BufferViewGL.h interface/DeviceContextGL.h interface/EngineGLAttribs.h + interface/FenceGL.h interface/PipelineStateGL.h interface/RenderDeviceFactoryOpenGL.h interface/RenderDeviceGL.h @@ -55,6 +57,7 @@ set(SOURCE src/BufferViewGLImpl.cpp src/DeviceContextGLImpl.cpp src/FBOCache.cpp + src/FenceGLImpl.cpp src/GLContextState.cpp src/GLObjectWrapper.cpp src/GLProgram.cpp diff --git a/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h new file mode 100644 index 00000000..6756c467 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/FenceGLImpl.h @@ -0,0 +1,58 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::FenceGLImpl class + +#include "FenceGL.h" +#include "RenderDeviceGL.h" +#include "FenceBase.h" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Implementation of the Diligent::IFenceGL interface +class FenceGLImpl : public FenceBase<IFenceGL> +{ +public: + using TFenceBase = FenceBase<IFenceGL>; + + FenceGLImpl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc); + ~FenceGLImpl(); + + virtual Uint64 GetCompletedValue()override final; + + /// Resets the fence to the specified value. + virtual void Reset(Uint64 Value)override final; + +private: + +}; + +} diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h index 15663ce9..36d611cd 100644 --- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h @@ -73,6 +73,8 @@ public: void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState, bool bIsDeviceInternal); virtual void CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState )override final; + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final; + virtual void CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc &TexDesc, ITexture **ppTexture)override final; virtual void CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc &BuffDesc, IBuffer **ppBuffer)override final; diff --git a/Graphics/GraphicsEngineOpenGL/interface/FenceGL.h b/Graphics/GraphicsEngineOpenGL/interface/FenceGL.h new file mode 100644 index 00000000..c6f9eebc --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/interface/FenceGL.h @@ -0,0 +1,47 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFenceGL interface + +#include "../../GraphicsEngine/interface/Fence.h" + +namespace Diligent +{ + +// {8FEACBDA-89D6-4509-88E6-D55DD06220C5} +static constexpr INTERFACE_ID IID_FenceGL = +{ 0x8feacbda, 0x89d6, 0x4509, { 0x88, 0xe6, 0xd5, 0x5d, 0xd0, 0x62, 0x20, 0xc5 } }; + + +/// Interface to the fence object implemented in GL +class IFenceGL : public IFence +{ +public: + /// Returns OpenGL sync object + //virtual IGLFence* GetGLFence() = 0; +}; + +} diff --git a/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp new file mode 100644 index 00000000..99bbe484 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/src/FenceGLImpl.cpp @@ -0,0 +1,55 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include <atlbase.h> + +#include "FenceGLImpl.h" +#include "EngineMemory.h" + +namespace Diligent +{ + +FenceGLImpl :: FenceGLImpl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc) : + TFenceBase(pRefCounters, pDevice, Desc) +{ +} + +FenceGLImpl :: ~FenceGLImpl() +{ +} + +Uint64 FenceGLImpl :: GetCompletedValue() +{ + UNSUPPORTED("Not yet implemented"); + return 0; +} + +void FenceGLImpl :: Reset(Uint64 Value) +{ + UNSUPPORTED("Not yet implemented"); +} + +} diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index b62c1288..9524554e 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -40,20 +40,35 @@ #include "GLTypeConversions.h" #include "PipelineStateGLImpl.h" #include "ShaderResourceBindingGLImpl.h" +#include "FenceGLImpl.h" #include "EngineMemory.h" #include "StringTools.h" namespace Diligent { -RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs): - TRenderDeviceBase(pRefCounters, RawMemAllocator, 0, sizeof(TextureBaseGL), sizeof(TextureViewGLImpl), sizeof(BufferGLImpl), sizeof(BufferViewGLImpl), sizeof(ShaderGLImpl), sizeof(SamplerGLImpl), sizeof(PipelineStateGLImpl), sizeof(ShaderResourceBindingGLImpl)), +RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator& RawMemAllocator, const EngineGLAttribs& InitAttribs): + TRenderDeviceBase + { + pRefCounters, + RawMemAllocator, + 0, + sizeof(TextureBaseGL), + sizeof(TextureViewGLImpl), + sizeof(BufferGLImpl), + sizeof(BufferViewGLImpl), + sizeof(ShaderGLImpl), + sizeof(SamplerGLImpl), + sizeof(PipelineStateGLImpl), + sizeof(ShaderResourceBindingGLImpl), + sizeof(FenceGLImpl) + }, // Device caps must be filled in before the constructor of Pipeline Cache is called! m_GLContext(InitAttribs, m_DeviceCaps), m_TexRegionRender(this) { GLint NumExtensions = 0; - glGetIntegerv( GL_NUM_EXTENSIONS, &NumExtensions ); + glGetIntegerv( GL_NUM_EXTENSIONS,& NumExtensions ); CHECK_GL_ERROR( "Failed to get the number of extensions" ); m_ExtensionStrings.reserve(NumExtensions); for( int Ext = 0; Ext < NumExtensions; ++Ext ) @@ -87,7 +102,7 @@ RenderDeviceGLImpl :: ~RenderDeviceGLImpl() IMPLEMENT_QUERY_INTERFACE( RenderDeviceGLImpl, IID_RenderDeviceGL, TRenderDeviceBase ) -void RenderDeviceGLImpl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer, bool bIsDeviceInternal) +void RenderDeviceGLImpl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData& BuffData, IBuffer **ppBuffer, bool bIsDeviceInternal) { CreateDeviceObject( "buffer", BuffDesc, ppBuffer, [&]() @@ -101,12 +116,12 @@ void RenderDeviceGLImpl :: CreateBuffer(const BufferDesc& BuffDesc, const Buffer ); } -void RenderDeviceGLImpl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData &BuffData, IBuffer **ppBuffer) +void RenderDeviceGLImpl :: CreateBuffer(const BufferDesc& BuffDesc, const BufferData& BuffData, IBuffer **ppBuffer) { CreateBuffer(BuffDesc, BuffData, ppBuffer, false); } -void RenderDeviceGLImpl :: CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc &BuffDesc, IBuffer **ppBuffer) +void RenderDeviceGLImpl :: CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc& BuffDesc, IBuffer **ppBuffer) { VERIFY(GLHandle, "GL buffer handle must not be null"); CreateDeviceObject( "buffer", BuffDesc, ppBuffer, @@ -121,7 +136,7 @@ void RenderDeviceGLImpl :: CreateBufferFromGLHandle(Uint32 GLHandle, const Buffe ); } -void RenderDeviceGLImpl :: CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader, bool bIsDeviceInternal) +void RenderDeviceGLImpl :: CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader **ppShader, bool bIsDeviceInternal) { CreateDeviceObject( "shader", ShaderCreationAttribs.Desc, ppShader, [&]() @@ -135,12 +150,12 @@ void RenderDeviceGLImpl :: CreateShader(const ShaderCreationAttribs &ShaderCreat ); } -void RenderDeviceGLImpl :: CreateShader(const ShaderCreationAttribs &ShaderCreationAttribs, IShader **ppShader) +void RenderDeviceGLImpl :: CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader **ppShader) { CreateShader(ShaderCreationAttribs, ppShader, false); } -void RenderDeviceGLImpl :: CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture, bool bIsDeviceInternal) +void RenderDeviceGLImpl :: CreateTexture(const TextureDesc& TexDesc, const TextureData& Data, ITexture **ppTexture, bool bIsDeviceInternal) { CreateDeviceObject( "texture", TexDesc, ppTexture, [&]() @@ -148,7 +163,7 @@ void RenderDeviceGLImpl :: CreateTexture(const TextureDesc& TexDesc, const Textu auto spDeviceContext = GetImmediateContext(); VERIFY(spDeviceContext, "Immediate device context has been destroyed"); auto pDeviceContext = spDeviceContext.RawPtr<DeviceContextGLImpl>(); - const auto &FmtInfo = GetTextureFormatInfo( TexDesc.Format ); + const auto& FmtInfo = GetTextureFormatInfo( TexDesc.Format ); if( !FmtInfo.Supported ) { LOG_ERROR_AND_THROW( FmtInfo.Name, " is not supported texture format" ); @@ -202,12 +217,12 @@ void RenderDeviceGLImpl :: CreateTexture(const TextureDesc& TexDesc, const Textu ); } -void RenderDeviceGLImpl::CreateTexture(const TextureDesc& TexDesc, const TextureData &Data, ITexture **ppTexture) +void RenderDeviceGLImpl::CreateTexture(const TextureDesc& TexDesc, const TextureData& Data, ITexture **ppTexture) { CreateTexture(TexDesc, Data, ppTexture, false); } -void RenderDeviceGLImpl::CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc &TexDesc, ITexture **ppTexture) +void RenderDeviceGLImpl::CreateTextureFromGLHandle(Uint32 GLHandle, const TextureDesc& TexDesc, ITexture **ppTexture) { VERIFY(GLHandle, "GL texture handle must not be null"); CreateDeviceObject( "texture", TexDesc, ppTexture, @@ -288,12 +303,12 @@ void RenderDeviceGLImpl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler } -void RenderDeviceGLImpl::CreatePipelineState( const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState) +void RenderDeviceGLImpl::CreatePipelineState( const PipelineStateDesc& PipelineDesc, IPipelineState **ppPipelineState) { CreatePipelineState(PipelineDesc, ppPipelineState, false); } -void RenderDeviceGLImpl::CreatePipelineState(const PipelineStateDesc &PipelineDesc, IPipelineState **ppPipelineState, bool bIsDeviceInternal) +void RenderDeviceGLImpl::CreatePipelineState(const PipelineStateDesc& PipelineDesc, IPipelineState **ppPipelineState, bool bIsDeviceInternal) { CreateDeviceObject( "Pipeline state", PipelineDesc, ppPipelineState, [&]() @@ -306,6 +321,18 @@ void RenderDeviceGLImpl::CreatePipelineState(const PipelineStateDesc &PipelineDe ); } +void RenderDeviceGLImpl::CreateFence(const FenceDesc& Desc, IFence** ppFence) +{ + CreateDeviceObject( "Fence", Desc, ppFence, + [&]() + { + FenceGLImpl* pFenceOGL( NEW_RC_OBJ(m_FenceAllocator, "FenceGLImpl instance", FenceGLImpl) + (this, Desc) ); + pFenceOGL->QueryInterface( IID_Fence, reinterpret_cast<IObject**>(ppFence) ); + OnCreateDeviceObject( pFenceOGL ); + } + ); +} bool RenderDeviceGLImpl::CheckExtension( const Char *ExtensionString ) { @@ -314,9 +341,9 @@ bool RenderDeviceGLImpl::CheckExtension( const Char *ExtensionString ) void RenderDeviceGLImpl::FlagSupportedTexFormats() { - const auto &DeviceCaps = GetDeviceCaps(); - bool bGL33OrAbove = DeviceCaps.DevType == DeviceType::OpenGL && - (DeviceCaps.MajorVersion >= 4 || (DeviceCaps.MajorVersion == 3 && DeviceCaps.MinorVersion >= 3) ); + const auto& DeviceCaps = GetDeviceCaps(); + bool bGL33OrAbove = DeviceCaps.DevType == DeviceType::OpenGL&& + (DeviceCaps.MajorVersion >= 4 || (DeviceCaps.MajorVersion == 3&& DeviceCaps.MinorVersion >= 3) ); bool bRGTC = CheckExtension( "GL_ARB_texture_compression_rgtc" ); bool bBPTC = CheckExtension( "GL_ARB_texture_compression_bptc" ); @@ -434,7 +461,7 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats() FLAG_FORMAT(TEX_FORMAT_BC7_UNORM_SRGB, bBPTC ); #ifdef _DEBUG - bool bGL43OrAbove = DeviceCaps.DevType == DeviceType::OpenGL && + bool bGL43OrAbove = DeviceCaps.DevType == DeviceType::OpenGL && (DeviceCaps.MajorVersion >= 5 || (DeviceCaps.MajorVersion == 4 && DeviceCaps.MinorVersion >= 3) ); const int TestTextureDim = 32; @@ -479,7 +506,7 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats() // For some reason glTexStorage2D() may succeed, but upload operation // will later fail. So we need to additionally try to upload some // data to the texture - const auto &TransferAttribs = GetNativePixelTransferAttribs( FmtInfo->Format ); + const auto& TransferAttribs = GetNativePixelTransferAttribs( FmtInfo->Format ); if( FmtInfo->ComponentType != COMPONENT_TYPE_COMPRESSED ) { glTexSubImage2D( GL_TEXTURE_2D, 0, // mip level @@ -495,7 +522,7 @@ void RenderDeviceGLImpl::FlagSupportedTexFormats() } template<typename CreateFuncType> -bool CreateTestGLTexture(GLContextState &GlCtxState, GLenum BindTarget, const GLObjectWrappers::GLTextureObj &GLTexObj, CreateFuncType CreateFunc) +bool CreateTestGLTexture(GLContextState& GlCtxState, GLenum BindTarget, const GLObjectWrappers::GLTextureObj& GLTexObj, CreateFuncType CreateFunc) { GlCtxState.BindTexture(-1, BindTarget, GLTexObj); CreateFunc(); @@ -506,7 +533,7 @@ bool CreateTestGLTexture(GLContextState &GlCtxState, GLenum BindTarget, const GL void RenderDeviceGLImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) { - auto &TexFormatInfo = m_TextureFormatsInfo[TexFormat]; + auto& TexFormatInfo = m_TextureFormatsInfo[TexFormat]; VERIFY( TexFormatInfo.Supported, "Texture format is not supported" ); auto GLFmt = TexFormatToGLInternalTexFormat(TexFormat); @@ -515,14 +542,14 @@ void RenderDeviceGLImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) auto spDeviceContext = GetImmediateContext(); VERIFY(spDeviceContext, "Immediate device context has been destroyed"); auto *pContextGL = spDeviceContext.RawPtr<DeviceContextGLImpl>(); - auto &ContextState = pContextGL->GetContextState(); + auto& ContextState = pContextGL->GetContextState(); const int TestTextureDim = 32; const int TestTextureDepth = 8; // Create test texture 1D TexFormatInfo.Tex1DFmt = false; - if( m_DeviceCaps.TexCaps.bTexture1DSupported && + if( m_DeviceCaps.TexCaps.bTexture1DSupported && TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED ) { GLObjectWrappers::GLTextureObj TestGLTex( true ); @@ -620,7 +647,7 @@ void RenderDeviceGLImpl::TestTextureFormat( TEXTURE_FORMAT TexFormat ) } TexFormatInfo.SupportsMS = false; - if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && + if( TexFormatInfo.ComponentType != COMPONENT_TYPE_COMPRESSED && m_DeviceCaps.TexCaps.bTexture2DMSSupported ) { #if GL_ARB_texture_storage_multisample diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index fc4d36c5..45bc9595 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -10,6 +10,7 @@ set(INCLUDE include/CommandQueueVkImpl.h include/DescriptorPoolManager.h include/DeviceContextVkImpl.h + include/FenceVkImpl.h include/VulkanDynamicHeap.h include/FramebufferCache.h include/GenerateMipsVkHelper.h @@ -51,6 +52,7 @@ set(INTERFACE interface/BufferViewVk.h interface/CommandQueueVk.h interface/DeviceContextVk.h + interface/FenceVk.h interface/PipelineStateVk.h interface/RenderDeviceVk.h interface/RenderDeviceFactoryVk.h @@ -70,6 +72,7 @@ set(SRC src/CommandQueueVkImpl.cpp src/DescriptorPoolManager.cpp src/DeviceContextVkImpl.cpp + src/FenceVkImpl.cpp src/VulkanDynamicHeap.cpp src/FramebufferCache.cpp src/GenerateMipsVkHelper.cpp diff --git a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h new file mode 100644 index 00000000..6d1a9267 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h @@ -0,0 +1,58 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Declaration of Diligent::FenceVkImpl class + +#include "FenceVk.h" +#include "RenderDeviceVk.h" +#include "FenceBase.h" + +namespace Diligent +{ + +class FixedBlockMemoryAllocator; + +/// Implementation of the Diligent::IFenceVk interface +class FenceVkImpl : public FenceBase<IFenceVk> +{ +public: + using TFenceBase = FenceBase<IFenceVk>; + + FenceVkImpl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc); + ~FenceVkImpl(); + + virtual Uint64 GetCompletedValue()override final; + + /// Resets the fence to the specified value. + virtual void Reset(Uint64 Value)override final; + +private: + +}; + +} diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h index 1f40ed6a..e2edd52b 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h @@ -80,6 +80,8 @@ public: virtual void CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)override final; + virtual void CreateFence(const FenceDesc& Desc, IFence** ppFence)override final; + virtual VkDevice GetVkDevice()override final{ return m_LogicalVkDevice->GetVkDevice();} virtual void CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, ITexture** ppTexture)override final; diff --git a/Graphics/GraphicsEngineVulkan/interface/FenceVk.h b/Graphics/GraphicsEngineVulkan/interface/FenceVk.h new file mode 100644 index 00000000..4fa22e51 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/interface/FenceVk.h @@ -0,0 +1,47 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFenceVk interface + +#include "../../GraphicsEngine/interface/Fence.h" + +namespace Diligent +{ + +// {7610B4CD-EDEA-4951-82CF-52F97FAFED2D} +static constexpr INTERFACE_ID IID_FenceVk = +{ 0x7610b4cd, 0xedea, 0x4951, { 0x82, 0xcf, 0x52, 0xf9, 0x7f, 0xaf, 0xed, 0x2d } }; + + +/// Interface to the fence object implemented in GL +class IFenceVk : public IFence +{ +public: + /// Returns OpenGL sync object + //virtual IGLFence* GetGLFence() = 0; +}; + +} diff --git a/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp new file mode 100644 index 00000000..451f70c5 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/src/FenceVkImpl.cpp @@ -0,0 +1,55 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including neVkigence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly neVkigent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include <atlbase.h> + +#include "FenceVkImpl.h" +#include "EngineMemory.h" + +namespace Diligent +{ + +FenceVkImpl :: FenceVkImpl(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + const FenceDesc& Desc) : + TFenceBase(pRefCounters, pDevice, Desc) +{ +} + +FenceVkImpl :: ~FenceVkImpl() +{ +} + +Uint64 FenceVkImpl :: GetCompletedValue() +{ + UNSUPPORTED("Not yet implemented"); + return 0; +} + +void FenceVkImpl :: Reset(Uint64 Value) +{ + UNSUPPORTED("Not yet implemented"); +} + +} diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 0c278c25..762acebd 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -32,6 +32,7 @@ #include "BufferVkImpl.h" #include "ShaderResourceBindingVkImpl.h" #include "DeviceContextVkImpl.h" +#include "FenceVkImpl.h" #include "EngineMemory.h" namespace Diligent @@ -57,7 +58,8 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* sizeof(ShaderVkImpl), sizeof(SamplerVkImpl), sizeof(PipelineStateVkImpl), - sizeof(ShaderResourceBindingVkImpl) + sizeof(ShaderResourceBindingVkImpl), + sizeof(FenceVkImpl) }, m_VulkanInstance(Instance), m_PhysicalDevice(std::move(PhysicalDevice)), @@ -551,4 +553,17 @@ void RenderDeviceVkImpl :: CreateSampler(const SamplerDesc& SamplerDesc, ISample ); } +void RenderDeviceVkImpl::CreateFence(const FenceDesc& Desc, IFence** ppFence) +{ + CreateDeviceObject( "Fence", Desc, ppFence, + [&]() + { + FenceVkImpl* pFenceVk( NEW_RC_OBJ(m_FenceAllocator, "FenceVkImpl instance", FenceVkImpl) + (this, Desc) ); + pFenceVk->QueryInterface( IID_Fence, reinterpret_cast<IObject**>(ppFence) ); + OnCreateDeviceObject( pFenceVk ); + } + ); +} + } |
