diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-11-24 22:11:02 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-11-24 22:11:02 +0000 |
| commit | 61bfee05db60a67fb8be6e72b27ba6724f0dd277 (patch) | |
| tree | b4595056fc881ccbca6fd50c7163d4df1cf54f19 /Graphics | |
| parent | Updated debug message about required shader resource binding object (diff) | |
| download | DiligentCore-61bfee05db60a67fb8be6e72b27ba6724f0dd277.tar.gz DiligentCore-61bfee05db60a67fb8be6e72b27ba6724f0dd277.zip | |
Moved/renamed `IBuffer::UpdateData()` to `IDeviceContext::UpdateBuffer()`
Moved/renamed `IBuffer::CopyData()` to `IDeviceContext::CopyBuffer()`
Diffstat (limited to 'Graphics')
20 files changed, 162 insertions, 144 deletions
diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h index 93f752ef..f2414c82 100644 --- a/Graphics/GraphicsEngine/include/BufferBase.h +++ b/Graphics/GraphicsEngine/include/BufferBase.h @@ -113,12 +113,6 @@ 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; - - /// Base implementation of IBuffer::CopyData(); validates input parameters. - 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; @@ -184,21 +178,6 @@ protected: std::unique_ptr<BufferViewImplType, STDDeleter<BufferViewImplType, TBuffViewObjAllocator> > m_pDefaultSRV; }; -template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) -{ - VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DEFAULT, "Only default usage buffers can be updated with UpdateData()" ); - VERIFY_BUFFER( Offset < this->m_Desc.uiSizeInBytes, "Offset (", Offset, ") exceeds the buffer size (", this->m_Desc.uiSizeInBytes, ")" ); - VERIFY_BUFFER( Size + Offset <= this->m_Desc.uiSizeInBytes, "Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); -} - -template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) -{ - VERIFY_BUFFER( DstOffset + Size <= this->m_Desc.uiSizeInBytes, "Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); - VERIFY_BUFFER( SrcOffset + Size <= pSrcBuffer->GetDesc().uiSizeInBytes, "Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,",this->m_Desc.uiSizeInBytes,")" ); -} - template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 23861605..d3afa0f3 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -108,6 +108,12 @@ public: /// from the cached value and false otherwise. inline bool SetRenderTargets( Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil, Uint32 Dummy = 0 ); + /// Base implementation of IDeviceContext::UpdateBuffer(); validates input parameters. + virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override = 0; + + /// Base implementation of IDeviceContext::CopyBuffer(); validates input parameters. + virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)override = 0; + /// Sets the strong pointer to the swap chain virtual void SetSwapChain( ISwapChain* pSwapChain )override final { m_pSwapChain = pSwapChain; } @@ -627,6 +633,29 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType m_pBoundDepthStencil.Release(); } + +template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) +{ + VERIFY(pBuffer != nullptr, "Buffer must not be null"); + const auto& BuffDesc = ValidatedCast<BufferImplType>(pBuffer)->GetDesc(); + DEV_CHECK_ERR(BuffDesc.Usage == USAGE_DEFAULT, "Unable to update buffer '", BuffDesc.Name, "': only USAGE_DEFAULT buffers can be updated with UpdateData()"); + DEV_CHECK_ERR(Offset < BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': offset (", Offset, ") exceeds the buffer size (", BuffDesc.uiSizeInBytes, ")" ); + DEV_CHECK_ERR(Size + Offset <= BuffDesc.uiSizeInBytes, "Unable to update buffer '", BuffDesc.Name, "': Update region [", Offset, ",", Size + Offset, ") is out of buffer bounds [0,", BuffDesc.uiSizeInBytes, ")" ); +} + +template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) +{ + VERIFY(pSrcBuffer != nullptr, "Source buffer must not be null"); + VERIFY(pDstBuffer != nullptr, "Destination buffer must not be null"); + const auto& SrcBufferDesc = ValidatedCast<BufferImplType>(pSrcBuffer)->GetDesc(); + const auto& DstBufferDesc = ValidatedCast<BufferImplType>(pDstBuffer)->GetDesc(); + DEV_CHECK_ERR( DstOffset + Size <= DstBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Destination range [", DstOffset, ",", DstOffset + Size, ") is out of buffer bounds [0,", DstBufferDesc.uiSizeInBytes, ")" ); + DEV_CHECK_ERR( SrcOffset + Size <= SrcBufferDesc.uiSizeInBytes, "Failed to copy buffer '", SrcBufferDesc.Name, "' to '", DstBufferDesc.Name, "': Source range [", SrcOffset, ",", SrcOffset + Size, ") is out of buffer bounds [0,", SrcBufferDesc.uiSizeInBytes, ")" ); +} + + #ifdef DEVELOPMENT template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> inline bool DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: DvpVerifyDrawArguments(const DrawAttribs& drawAttribs) @@ -739,7 +768,7 @@ void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, Pipel } } -#endif +#endif // DEVELOPMENT } diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index 6be6b2c6..3f7d5ad6 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -153,31 +153,13 @@ public: /// Returns the buffer description used to create the object virtual const BufferDesc& GetDesc()const = 0; - /// Updates the data in the buffer - - /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation. - /// \param [in] Offset - Offset in bytes from the beginning of the buffer to the update region. - /// \param [in] Size - Size in bytes of the data region to update. - /// \param [in] pData - Pointer to the data to store in the buffer. - virtual void UpdateData( class IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData) = 0; - - /// Copies the data from other buffer - - /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation. - /// \param [in] pSrcBuffer - Source buffer to copy data from. - /// \param [in] SrcOffset - Offset in bytes from the beginning of the source buffer to the beginning of data to copy. - /// \param [in] DstOffset - Offset in bytes from the beginning of the destination buffer to the beginning - /// of the destination region. - /// \param [in] Size - Size in bytes of data to copy. - virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) = 0; - /// Maps the buffer /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation. /// \param [in] MapType - Type of the map operation. See Diligent::MAP_TYPE. /// \param [in] MapFlags - Special map flags. See Diligent::MAP_FLAGS. /// \param [out] pMappedData - Reference to the void pointer to store the address of the mapped region. - virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; + virtual void Map( class IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; /// Unmaps the previously mapped buffer /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation. diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 62adfd72..8e97e86a 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -526,6 +526,26 @@ public: /// Flushes the command buffer virtual void Flush() = 0; + + /// Updates the data in the buffer + + /// \param [in] pBuffer - Pointer to the buffer to updates. + /// \param [in] Offset - Offset in bytes from the beginning of the buffer to the update region. + /// \param [in] Size - Size in bytes of the data region to update. + /// \param [in] pData - Pointer to the data to write to the buffer. + virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) = 0; + + /// Copies the data from one buffer to another + + /// \param [in] pSrcBuffer - Source buffer to copy data from. + /// \param [in] pSrcBuffer - Destination buffer to copy data to. + /// \param [in] SrcOffset - Offset in bytes from the beginning of the source buffer to the beginning of data to copy. + /// \param [in] DstOffset - Offset in bytes from the beginning of the destination buffer to the beginning + /// of the destination region. + /// \param [in] Size - Size in bytes of data to copy. + virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) = 0; + + /// Sets the swap chain in the device context /// The swap chain is used by the device context to work with the diff --git a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h index 5fc77aa3..93aaa715 100644 --- a/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/BufferD3D11Impl.h @@ -60,8 +60,6 @@ public: virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final; - virtual void UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override final; - virtual void CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override final; virtual void Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override final; virtual void Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags )override final; virtual ID3D11Buffer* GetD3D11Buffer()override final{ return m_pd3d11Buffer; } diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index fe9d4e66..cede1c42 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -86,6 +86,10 @@ public: virtual void Flush()override final;
+ virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final;
+
+ virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)override final;
+
virtual void FinishFrame()override final;
virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers)override final;
diff --git a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp index d0888937..b2af447b 100644 --- a/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/BufferD3D11Impl.cpp @@ -178,40 +178,6 @@ BufferD3D11Impl :: ~BufferD3D11Impl() IMPLEMENT_QUERY_INTERFACE( BufferD3D11Impl, IID_BufferD3D11, TBufferBase ) -void BufferD3D11Impl::UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) -{ - TBufferBase::UpdateData( pContext, Offset, Size, pData ); - - auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext(); - - D3D11_BOX DstBox; - DstBox.left = Offset; - DstBox.right = Offset + Size; - DstBox.top = 0; - DstBox.bottom = 1; - DstBox.front = 0; - DstBox.back = 1; - auto *pDstBox = (Offset == 0 && Size == m_Desc.uiSizeInBytes) ? nullptr : &DstBox; - pd3d11DeviceContext->UpdateSubresource(m_pd3d11Buffer, 0, pDstBox, pData, 0, 0); -} - -void BufferD3D11Impl :: CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) -{ - TBufferBase::CopyData( pContext, pSrcBuffer, SrcOffset, DstOffset, Size ); - - auto *pd3d11DeviceContext = static_cast<DeviceContextD3D11Impl*>(pContext)->GetD3D11DeviceContext(); - auto *pSrBufferD3D11Impl = static_cast<BufferD3D11Impl*>( pSrcBuffer ); - - D3D11_BOX SrcBox; - SrcBox.left = SrcOffset; - SrcBox.right = SrcOffset + Size; - SrcBox.top = 0; - SrcBox.bottom = 1; - SrcBox.front = 0; - SrcBox.back = 1; - pd3d11DeviceContext->CopySubresourceRegion(m_pd3d11Buffer, 0, DstOffset, 0, 0, pSrBufferD3D11Impl->m_pd3d11Buffer, 0, &SrcBox); -} - void BufferD3D11Impl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData) { TBufferBase::Map( pContext, MapType, MapFlags, pMappedData ); diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 241c7b20..a3fabea1 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -938,6 +938,41 @@ namespace Diligent m_pd3d11DeviceContext->Flush();
}
+ void DeviceContextD3D11Impl::UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)
+ {
+ TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData);
+
+ auto* pBufferD3D11Impl = ValidatedCast<BufferD3D11Impl>( pBuffer );
+
+ D3D11_BOX DstBox;
+ DstBox.left = Offset;
+ DstBox.right = Offset + Size;
+ DstBox.top = 0;
+ DstBox.bottom = 1;
+ DstBox.front = 0;
+ DstBox.back = 1;
+ auto* pDstBox = (Offset == 0 && Size == pBufferD3D11Impl->GetDesc().uiSizeInBytes) ? nullptr : &DstBox;
+ m_pd3d11DeviceContext->UpdateSubresource(pBufferD3D11Impl->m_pd3d11Buffer, 0, pDstBox, pData, 0, 0);
+ }
+
+ void DeviceContextD3D11Impl::CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)
+ {
+ TDeviceContextBase::CopyBuffer(pSrcBuffer, pDstBuffer, SrcOffset, DstOffset, Size);
+
+ auto* pSrcBufferD3D11Impl = ValidatedCast<BufferD3D11Impl>( pSrcBuffer );
+ auto* pDstBufferD3D11Impl = ValidatedCast<BufferD3D11Impl>( pDstBuffer );
+
+ D3D11_BOX SrcBox;
+ SrcBox.left = SrcOffset;
+ SrcBox.right = SrcOffset + Size;
+ SrcBox.top = 0;
+ SrcBox.bottom = 1;
+ SrcBox.front = 0;
+ SrcBox.back = 1;
+ m_pd3d11DeviceContext->CopySubresourceRegion(pDstBufferD3D11Impl->m_pd3d11Buffer, 0, DstOffset, 0, 0, pSrcBufferD3D11Impl->m_pd3d11Buffer, 0, &SrcBox);
+ }
+
+
void DeviceContextD3D11Impl::FinishFrame()
{
}
diff --git a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h index de757995..60bb6907 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h @@ -60,8 +60,6 @@ public: virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; - virtual void UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override; - virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override; virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override; virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags )override; diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index f0bc93b5..eb3f4112 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -88,6 +88,10 @@ public: virtual void Flush()override final; + virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final; + + virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)override final; + virtual void FinishFrame()override final; virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers)override final; diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 53bb1b36..82a94489 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -304,22 +304,6 @@ BufferD3D12Impl :: ~BufferD3D12Impl() IMPLEMENT_QUERY_INTERFACE( BufferD3D12Impl, IID_BufferD3D12, TBufferBase ) -void BufferD3D12Impl::UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) -{ - TBufferBase::UpdateData( pContext, Offset, Size, pData ); - - // We must use cmd context from the device context provided, otherwise there will - // be resource barrier issues in the cmd list in the device context - auto *pDeviceContextD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pContext); - pDeviceContextD3D12->UpdateBufferRegion(this, pData, Offset, Size); -} - -void BufferD3D12Impl :: CopyData(IDeviceContext* pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) -{ - TBufferBase::CopyData( pContext, pSrcBuffer, SrcOffset, DstOffset, Size ); - auto *pDeviceContextD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pContext); - pDeviceContextD3D12->CopyBufferRegion(ValidatedCast<BufferD3D12Impl>(pSrcBuffer), this, SrcOffset, DstOffset, Size); -} void BufferD3D12Impl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData) { diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index ef8bf180..2afce274 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -898,18 +898,27 @@ namespace Diligent ++m_State.NumCommands; } - void DeviceContextD3D12Impl::UpdateBufferRegion(BufferD3D12Impl* pBuffD3D12, const void* pData, Uint64 DstOffset, Uint64 NumBytes) + void DeviceContextD3D12Impl::UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) { + TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData); + + // We must use cmd context from the device context provided, otherwise there will + // be resource barrier issues in the cmd list in the device context + auto* pBuffD3D12 = ValidatedCast<BufferD3D12Impl>(pBuffer); VERIFY(pBuffD3D12->GetDesc().Usage != USAGE_DYNAMIC, "Dynamic buffers must be updated via Map()"); - VERIFY_EXPR( static_cast<size_t>(NumBytes) == NumBytes ); constexpr size_t DefaultAlginment = 16; - auto TmpSpace = m_DynamicHeap.Allocate(static_cast<size_t>(NumBytes), DefaultAlginment, m_ContextFrameNumber); - memcpy(TmpSpace.CPUAddress, pData, static_cast<size_t>(NumBytes)); - UpdateBufferRegion(pBuffD3D12, TmpSpace, DstOffset, NumBytes); + auto TmpSpace = m_DynamicHeap.Allocate(Size, DefaultAlginment, m_ContextFrameNumber); + memcpy(TmpSpace.CPUAddress, pData, Size); + UpdateBufferRegion(pBuffD3D12, TmpSpace, Offset, Size); } - void DeviceContextD3D12Impl::CopyBufferRegion(BufferD3D12Impl* pSrcBuffD3D12, BufferD3D12Impl* pDstBuffD3D12, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes) + void DeviceContextD3D12Impl::CopyBuffer(IBuffer* pSrcBuffer, IBuffer* pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) { + TDeviceContextBase::CopyBuffer(pSrcBuffer, pDstBuffer, SrcOffset, DstOffset, Size); + + auto* pSrcBuffD3D12 = ValidatedCast<BufferD3D12Impl>(pSrcBuffer); + auto* pDstBuffD3D12 = ValidatedCast<BufferD3D12Impl>(pDstBuffer); + VERIFY(pDstBuffD3D12->GetDesc().Usage != USAGE_DYNAMIC, "Dynamic buffers cannot be copy destinations"); auto& CmdCtx = GetCmdContext(); @@ -924,7 +933,7 @@ namespace Diligent size_t SrcDataStartByteOffset; auto* pd3d12SrcBuff = pSrcBuffD3D12->GetD3D12Buffer(SrcDataStartByteOffset, this); CmdCtx.FlushResourceBarriers(); - CmdCtx.GetCommandList()->CopyBufferRegion( pd3d12DstBuff, DstOffset + DstDataStartByteOffset, pd3d12SrcBuff, SrcOffset+SrcDataStartByteOffset, NumBytes); + CmdCtx.GetCommandList()->CopyBufferRegion( pd3d12DstBuff, DstOffset + DstDataStartByteOffset, pd3d12SrcBuff, SrcOffset+SrcDataStartByteOffset, Size); ++m_State.NumCommands; } diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h index 1d990493..9609eadc 100644 --- a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.h @@ -30,6 +30,7 @@ #include "BaseInterfacesGL.h" #include "BufferViewGLImpl.h" #include "RenderDeviceGLImpl.h" +#include "GLContextState.h" namespace Diligent { @@ -59,8 +60,8 @@ public: /// Queries the specific interface, see IObject::QueryInterface() for details virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; - virtual void UpdateData(IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData)override; - virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override; + void UpdateData(GLContextState& CtxState, Uint32 Offset, Uint32 Size, const PVoid pData); + void CopyData(GLContextState& CtxState, BufferGLImpl& SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size); virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )override; virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags )override; diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h index 6727bfb2..c88e8410 100644 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h @@ -78,6 +78,10 @@ public: virtual void Flush()override final; + virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final; + + virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)override final; + virtual void FinishFrame()override final; virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers)override final; diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp index ff2d46de..ed9cfed5 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp @@ -184,18 +184,14 @@ BufferGLImpl::~BufferGLImpl() IMPLEMENT_QUERY_INTERFACE( BufferGLImpl, IID_BufferGL, TBufferBase ) -void BufferGLImpl :: UpdateData(IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData) +void BufferGLImpl :: UpdateData(GLContextState& CtxState, Uint32 Offset, Uint32 Size, const PVoid pData) { - TBufferBase::UpdateData( pContext, Offset, Size, pData ); - - auto *pDeviceContextGL = ValidatedCast<DeviceContextGLImpl>(pContext); - BufferMemoryBarrier( GL_BUFFER_UPDATE_BARRIER_BIT,// Reads or writes to buffer objects via any OpenGL API functions that allow // modifying their contents will reflect data written by shaders prior to the barrier. // Additionally, writes via these commands issued after the barrier will wait on // the completion of any shader writes to the same memory initiated prior to the barrier. - pDeviceContextGL->GetContextState()); + CtxState); glBindBuffer(GL_ARRAY_BUFFER, m_GlBuffer); // All buffer bind targets (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER etc.) relate to the same @@ -206,21 +202,17 @@ void BufferGLImpl :: UpdateData(IDeviceContext *pContext, Uint32 Offset, Uint32 } -void BufferGLImpl :: CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) +void BufferGLImpl :: CopyData(GLContextState& CtxState, BufferGLImpl& SrcBufferGL, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) { - TBufferBase::CopyData( pContext, pSrcBuffer, SrcOffset, DstOffset, Size ); - - auto *pDeviceContextGL = ValidatedCast<DeviceContextGLImpl>(pContext); - auto *pSrcBufferGL = static_cast<BufferGLImpl*>( pSrcBuffer ); BufferMemoryBarrier( GL_BUFFER_UPDATE_BARRIER_BIT,// Reads or writes to buffer objects via any OpenGL API functions that allow // modifying their contents will reflect data written by shaders prior to the barrier. // Additionally, writes via these commands issued after the barrier will wait on // the completion of any shader writes to the same memory initiated prior to the barrier. - pDeviceContextGL->GetContextState()); - pSrcBufferGL->BufferMemoryBarrier( + CtxState); + SrcBufferGL.BufferMemoryBarrier( GL_BUFFER_UPDATE_BARRIER_BIT, - pDeviceContextGL->GetContextState() ); + CtxState); // Whilst glCopyBufferSubData() can be used to copy data between buffers bound to any two targets, // the targets GL_COPY_READ_BUFFER and GL_COPY_WRITE_BUFFER are provided specifically for this purpose. @@ -228,7 +220,7 @@ void BufferGLImpl :: CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uin // the purposes of copying or staging data without disturbing OpenGL state or needing to keep track of // what was bound to the target before your copy. glBindBuffer(GL_COPY_WRITE_BUFFER, m_GlBuffer); - glBindBuffer(GL_COPY_READ_BUFFER, pSrcBufferGL->m_GlBuffer); + glBindBuffer(GL_COPY_READ_BUFFER, SrcBufferGL.m_GlBuffer); glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, SrcOffset, DstOffset, Size); CHECK_GL_ERROR("glCopyBufferSubData() failed"); glBindBuffer(GL_COPY_READ_BUFFER, 0); diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 946f8ee9..57c684ff 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -1011,6 +1011,23 @@ namespace Diligent return true; } + void DeviceContextGLImpl::UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) + { + TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData); + + auto* pBufferGL = ValidatedCast<BufferGLImpl>(pBuffer); + pBufferGL->UpdateData(m_ContextState, Offset, Size, pData); + } + + void DeviceContextGLImpl::CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) + { + TDeviceContextBase::CopyBuffer(pSrcBuffer, pDstBuffer, SrcOffset, DstOffset, Size); + + auto* pSrcBufferGL = ValidatedCast<BufferGLImpl>(pSrcBuffer); + auto* pDstBufferGL = ValidatedCast<BufferGLImpl>(pDstBuffer); + pDstBufferGL->CopyData(m_ContextState, *pSrcBufferGL, SrcOffset, DstOffset, Size); + } + void DeviceContextGLImpl::TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers) { diff --git a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h index 9e888bec..ef93d90c 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h @@ -65,8 +65,6 @@ public: virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override; - virtual void UpdateData( IDeviceContext* pContext, Uint32 Offset, Uint32 Size, const PVoid pData )override; - virtual void CopyData( IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size )override; virtual void Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData )override; virtual void Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags )override; diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 23d10485..c2176442 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -95,6 +95,10 @@ public: virtual void Flush()override final; + virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final; + + virtual void CopyBuffer(IBuffer *pSrcBuffer, IBuffer *pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)override final; + virtual void FinishCommandList(class ICommandList** ppCommandList)override final; virtual void ExecuteCommandList(class ICommandList* pCommandList)override final; diff --git a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp index c31ac7c3..cb0fc958 100644 --- a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp @@ -303,22 +303,6 @@ BufferVkImpl :: ~BufferVkImpl() IMPLEMENT_QUERY_INTERFACE( BufferVkImpl, IID_BufferVk, TBufferBase ) -void BufferVkImpl::UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData ) -{ - TBufferBase::UpdateData( pContext, Offset, Size, pData ); - - // We must use cmd context from the device context provided, otherwise there will - // be resource barrier issues in the cmd list in the device context - auto *pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pContext); - pDeviceContextVk->UpdateBufferRegion(this, pData, Offset, Size); -} - -void BufferVkImpl :: CopyData(IDeviceContext* pContext, IBuffer* pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) -{ - TBufferBase::CopyData( pContext, pSrcBuffer, SrcOffset, DstOffset, Size ); - auto *pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pContext); - pDeviceContextVk->CopyBufferRegion(ValidatedCast<BufferVkImpl>(pSrcBuffer), this, SrcOffset, DstOffset, Size); -} void BufferVkImpl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData) { diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index e8316daf..3b2d961a 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1212,8 +1212,14 @@ namespace Diligent ++m_State.NumCommands; } - void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl *pBuffVk, const void *pData, Uint64 DstOffset, Uint64 NumBytes) + void DeviceContextVkImpl::UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) { + TDeviceContextBase::UpdateBuffer(pBuffer, Offset, Size, pData); + + // We must use cmd context from the device context provided, otherwise there will + // be resource barrier issues in the cmd list in the device context + auto* pBuffVk = ValidatedCast<BufferVkImpl>(pBuffer); + #ifdef DEVELOPMENT if (pBuffVk->GetDesc().Usage == USAGE_DYNAMIC) { @@ -1222,18 +1228,22 @@ namespace Diligent } #endif - VERIFY_EXPR( static_cast<size_t>(NumBytes) == NumBytes ); constexpr size_t Alignment = 4; // Source buffer offset must be multiple of 4 (18.4) - auto TmpSpace = m_UploadHeap.Allocate(static_cast<size_t>(NumBytes), Alignment); - memcpy(TmpSpace.CPUAddress, pData, static_cast<size_t>(NumBytes)); - UpdateBufferRegion(pBuffVk, DstOffset, NumBytes, TmpSpace.vkBuffer, TmpSpace.AlignedOffset); + auto TmpSpace = m_UploadHeap.Allocate(Size, Alignment); + memcpy(TmpSpace.CPUAddress, pData, Size); + UpdateBufferRegion(pBuffVk, Offset, Size, TmpSpace.vkBuffer, TmpSpace.AlignedOffset); // The allocation will stay in the upload heap until the end of the frame at which point all upload // pages will be discarded } - void DeviceContextVkImpl::CopyBufferRegion(BufferVkImpl *pSrcBuffVk, BufferVkImpl *pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes) + void DeviceContextVkImpl::CopyBuffer(IBuffer* pSrcBuffer, IBuffer* pDstBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) { + TDeviceContextBase::CopyBuffer(pSrcBuffer, pDstBuffer, SrcOffset, DstOffset, Size); + + auto *pSrcBuffVk = ValidatedCast<BufferVkImpl>(pSrcBuffer); + auto *pDstBuffVk = ValidatedCast<BufferVkImpl>(pDstBuffer); + #ifdef DEVELOPMENT if (pDstBuffVk->GetDesc().Usage == USAGE_DYNAMIC) { @@ -1263,7 +1273,7 @@ namespace Diligent VkBufferCopy CopyRegion; CopyRegion.srcOffset = SrcOffset + pSrcBuffVk->GetDynamicOffset(m_ContextId, this); CopyRegion.dstOffset = DstOffset; - CopyRegion.size = NumBytes; + CopyRegion.size = Size; VERIFY(pDstBuffVk->m_VulkanBuffer != VK_NULL_HANDLE, "Copy destination buffer must not be suballocated"); VERIFY_EXPR(pDstBuffVk->GetDynamicOffset(m_ContextId, this) == 0); m_CommandBuffer.CopyBuffer(pSrcBuffVk->GetVkBuffer(), pDstBuffVk->GetVkBuffer(), 1, &CopyRegion); |
