From 61bfee05db60a67fb8be6e72b27ba6724f0dd277 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 24 Nov 2018 14:11:02 -0800 Subject: Moved/renamed `IBuffer::UpdateData()` to `IDeviceContext::UpdateBuffer()` Moved/renamed `IBuffer::CopyData()` to `IDeviceContext::CopyBuffer()` --- Graphics/GraphicsEngine/include/BufferBase.h | 21 --------------- .../GraphicsEngine/include/DeviceContextBase.h | 31 +++++++++++++++++++++- Graphics/GraphicsEngine/interface/Buffer.h | 20 +------------- Graphics/GraphicsEngine/interface/DeviceContext.h | 20 ++++++++++++++ 4 files changed, 51 insertions(+), 41 deletions(-) (limited to 'Graphics/GraphicsEngine') 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 > m_pDefaultSRV; }; -template -void BufferBase :: 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 -void BufferBase :: 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 void BufferBase :: 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 +inline void DeviceContextBase :: UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData) +{ + VERIFY(pBuffer != nullptr, "Buffer must not be null"); + const auto& BuffDesc = ValidatedCast(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 +inline void DeviceContextBase :: 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(pSrcBuffer)->GetDesc(); + const auto& DstBufferDesc = ValidatedCast(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 inline bool DeviceContextBase :: DvpVerifyDrawArguments(const DrawAttribs& drawAttribs) @@ -739,7 +768,7 @@ void DeviceContextBase