diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-11-25 20:08:42 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-11-25 20:08:42 +0000 |
| commit | 3494f0538a108730f9bb25d79416136d2b329af4 (patch) | |
| tree | c0e82cd48d811954f1cd722f113f8042561b6caf /Graphics/GraphicsEngine | |
| parent | Moved ITextureView::GenerateMips() to IDeviceContext::GenerateMips() (diff) | |
| download | DiligentCore-3494f0538a108730f9bb25d79416136d2b329af4.tar.gz DiligentCore-3494f0538a108730f9bb25d79416136d2b329af4.zip | |
Renamed/moved IBuffer::Map() to IDeviceContext::MapBuffer()
Renamed/moved IBuffer::Unmap() to IDeviceContext::UnmapBuffer()
Closed https://github.com/DiligentGraphics/DiligentCore/issues/30 (Removed map type, map flag parameters from IBuffer::Unmap function)
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/BufferBase.h | 53 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 62 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/Buffer.h | 16 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/DeviceContext.h | 18 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/MapHelper.h | 4 |
5 files changed, 81 insertions, 72 deletions
diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h index f2414c82..7cd75be8 100644 --- a/Graphics/GraphicsEngine/include/BufferBase.h +++ b/Graphics/GraphicsEngine/include/BufferBase.h @@ -74,7 +74,7 @@ public: m_pDefaultSRV(nullptr, STDDeleter<BufferViewImplType, TBuffViewObjAllocator>(BuffViewObjAllocator) ) { #ifdef DEVELOPMENT -# define VERIFY_BUFFER(Expr, ...) if (!(Expr)) LOG_ERROR("Buffer \"", this->m_Desc.Name ? this->m_Desc.Name : "", "\": ", ##__VA_ARGS__) +# define VERIFY_BUFFER(Expr, ...) if (!(Expr)) LOG_ERROR("Buffer '", this->m_Desc.Name ? this->m_Desc.Name : "", "': ", ##__VA_ARGS__) #else # define VERIFY_BUFFER(...)do{}while(false) #endif @@ -113,12 +113,6 @@ public: IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Buffer, TDeviceObjectBase ) - /// Base implementation of IBuffer::Map(); validates input parameters. - 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; - /// 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; @@ -179,51 +173,6 @@ protected: }; -template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) -{ - pMappedData = nullptr; - switch( MapType ) - { - case MAP_READ: - VERIFY_BUFFER( this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read from" ); - VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading was not created with CPU_ACCESS_READ flag" ); - VERIFY_BUFFER( (MapFlags & MAP_FLAG_DISCARD) == 0, "MAP_FLAG_DISCARD is not valid when mapping buffer for reading" ); - break; - - case MAP_WRITE: - VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DYNAMIC || this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE or USAGE_DYNAMIC can be mapped for writing" ); - VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for writing was not created with CPU_ACCESS_WRITE flag" ); - break; - - case MAP_READ_WRITE: - VERIFY_BUFFER( this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be mapped for reading and writing" ); - VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_WRITE flag" ); - VERIFY_BUFFER( (this->m_Desc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_READ flag" ); - VERIFY_BUFFER( (MapFlags & MAP_FLAG_DISCARD) == 0, "MAP_FLAG_DISCARD is not valid when mapping buffer for reading and writing" ); - break; - - default: UNEXPECTED( "Unknown map type" ); - } - - if (this->m_Desc.Usage == USAGE_DYNAMIC) - { - VERIFY_BUFFER((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0 && MapType == MAP_WRITE, "Dynamic buffers can only be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flag"); - VERIFY_BUFFER((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE), "When mapping dynamic buffer, only one of MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flags must be specified"); - } - - if ( (MapFlags & MAP_FLAG_DISCARD) != 0 ) - { - VERIFY_BUFFER( this->m_Desc.Usage == USAGE_DYNAMIC || this->m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Only dynamic and staging buffers can be mapped with discard flag" ); - VERIFY_BUFFER( MapType == MAP_WRITE, "MAP_FLAG_DISCARD is only valid when mapping buffer for writing" ); - } -} - -template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> -void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffViewObjAllocator> :: Unmap( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags ) -{ - -} template<class BaseInterface, class RenderDeviceImplType, class BufferViewImplType, class TBuffViewObjAllocator> diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index b176359c..ad012626 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -110,11 +110,17 @@ public: 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; + 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, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size)override = 0; + /// Base implementation of IDeviceContext::MapBuffer(); validates input parameters. + virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData)override = 0; + + /// Base implementation of IDeviceContext::UnmapBuffer() + virtual void UnmapBuffer(IBuffer* pBuffer)override = 0; + /// Base implementaiton of IDeviceContext::UpdateData(); validates input parameters virtual void UpdateTexture( ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData )override = 0; @@ -687,10 +693,62 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType 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, ")" ); } +template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: + MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData ) +{ + VERIFY(pBuffer, "pBuffer must not be null"); + + const auto& BuffDesc = pBuffer->GetDesc(); + + pMappedData = nullptr; + switch( MapType ) + { + case MAP_READ: + DEV_CHECK_ERR( BuffDesc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read from" ); + DEV_CHECK_ERR( (BuffDesc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading was not created with CPU_ACCESS_READ flag" ); + DEV_CHECK_ERR( (MapFlags & MAP_FLAG_DISCARD) == 0, "MAP_FLAG_DISCARD is not valid when mapping buffer for reading" ); + break; + + case MAP_WRITE: + DEV_CHECK_ERR( BuffDesc.Usage == USAGE_DYNAMIC || BuffDesc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE or USAGE_DYNAMIC can be mapped for writing" ); + DEV_CHECK_ERR( (BuffDesc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for writing was not created with CPU_ACCESS_WRITE flag" ); + break; + + case MAP_READ_WRITE: + DEV_CHECK_ERR( BuffDesc.Usage == USAGE_CPU_ACCESSIBLE, "Only buffers with usage USAGE_CPU_ACCESSIBLE can be mapped for reading and writing" ); + DEV_CHECK_ERR( (BuffDesc.CPUAccessFlags & CPU_ACCESS_WRITE), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_WRITE flag" ); + DEV_CHECK_ERR( (BuffDesc.CPUAccessFlags & CPU_ACCESS_READ), "Buffer being mapped for reading & writing was not created with CPU_ACCESS_READ flag" ); + DEV_CHECK_ERR( (MapFlags & MAP_FLAG_DISCARD) == 0, "MAP_FLAG_DISCARD is not valid when mapping buffer for reading and writing" ); + break; + + default: UNEXPECTED( "Unknown map type" ); + } + + if (BuffDesc.Usage == USAGE_DYNAMIC) + { + DEV_CHECK_ERR((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0 && MapType == MAP_WRITE, "Dynamic buffers can only be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flag"); + DEV_CHECK_ERR((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE), "When mapping dynamic buffer, only one of MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flags must be specified"); + } + + if ( (MapFlags & MAP_FLAG_DISCARD) != 0 ) + { + DEV_CHECK_ERR( BuffDesc.Usage == USAGE_DYNAMIC || BuffDesc.Usage == USAGE_CPU_ACCESSIBLE, "Only dynamic and staging buffers can be mapped with discard flag" ); + DEV_CHECK_ERR( MapType == MAP_WRITE, "MAP_FLAG_DISCARD is only valid when mapping buffer for writing" ); + } +} + +template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> +inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: + UnmapBuffer(IBuffer* pBuffer) +{ + VERIFY(pBuffer, "pBuffer must not be null"); +} + template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType> inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: - UpdateTexture( ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData ) + UpdateTexture(ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData) { VERIFY( pTexture != nullptr, "pTexture must not be null" ); ValidateUpdateTextureParams( pTexture->GetDesc(), MipLevel, Slice, DstBox, SubresData ); diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index 3f7d5ad6..d8ba656d 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -153,22 +153,6 @@ public: /// Returns the buffer description used to create the object virtual const BufferDesc& GetDesc()const = 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( 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. - /// \param [in] MapType - Type of the map operation. This parameter must match the type that was - /// provided to the Map() method. - /// \param [in] MapFlags - Map flags. This parameter must match the flags that were provided to - /// the Map() method. - virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags ) = 0; - /// Creates a new buffer view /// \param [in] ViewDesc - View description. See Diligent::BufferViewDesc for details. diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index d1280fde..8559e85c 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -546,6 +546,24 @@ public: virtual void CopyBuffer(IBuffer* pSrcBuffer, Uint32 SrcOffset, IBuffer* pDstBuffer, Uint32 DstOffset, Uint32 Size) = 0; + /// Maps the buffer + + /// \param [in] pBuffer - Pointer to the buffer to map. + /// \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 MapBuffer( IBuffer* pBuffer, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0; + + /// Unmaps the previously mapped buffer + + /// \param [in] pBuffer - Pointer to the buffer to unmap. + /// \param [in] MapType - Type of the map operation. This parameter must match the type that was + /// provided to the Map() method. + /// \param [in] MapFlags - Map flags. This parameter must match the flags that were provided to + /// the Map() method. + virtual void UnmapBuffer( IBuffer* pBuffer ) = 0; + + /// Updates the data in the texture /// \param [in] pTexture - Pointer to the device context interface to be used to perform the operation. diff --git a/Graphics/GraphicsEngine/interface/MapHelper.h b/Graphics/GraphicsEngine/interface/MapHelper.h index 5134a0d1..aae341c5 100644 --- a/Graphics/GraphicsEngine/interface/MapHelper.h +++ b/Graphics/GraphicsEngine/interface/MapHelper.h @@ -114,7 +114,7 @@ public: auto &BuffDesc = pBuffer->GetDesc(); VERIFY(sizeof(DataType) <= BuffDesc.uiSizeInBytes, "Data type size exceeds buffer size"); #endif - pBuffer->Map(pContext, MapType, MapFlags, (PVoid&)m_pMappedData); + pContext->MapBuffer(pBuffer, MapType, MapFlags, (PVoid&)m_pMappedData); if(m_pMappedData != nullptr) { m_pContext = pContext; @@ -129,7 +129,7 @@ public: { if( m_pBuffer ) { - m_pBuffer->Unmap(m_pContext, m_MapType, m_MapFlags); + m_pContext->UnmapBuffer(m_pBuffer); m_pBuffer = nullptr; m_MapType = static_cast<MAP_TYPE>(-1); m_MapFlags = static_cast<Uint32>(-1); |
