diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-12-02 18:22:22 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-12-02 18:22:22 +0000 |
| commit | 111636445d2e19420468cdf78ffd2b87b7ad6489 (patch) | |
| tree | adb5457b4f0cd56a323c99f1cedc5a2fce0667ee /Graphics/GraphicsEngine | |
| parent | Added explicit state transition control to UpdateBuffer and UpdateTexture com... (diff) | |
| download | DiligentCore-111636445d2e19420468cdf78ffd2b87b7ad6489.tar.gz DiligentCore-111636445d2e19420468cdf78ffd2b87b7ad6489.zip | |
Brought back MapType paramter to UnmapBuffer() function. The performance hit of keeping track of mapped buffers turned out to be unacceptable
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 25 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/DeviceContext.h | 4 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/MapHelper.h | 2 |
3 files changed, 25 insertions, 6 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index d8dfd94b..9de83dec 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -120,7 +120,7 @@ public: virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override = 0; /// Base implementation of IDeviceContext::UnmapBuffer() - virtual void UnmapBuffer(IBuffer* pBuffer)override = 0; + virtual void UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType)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, @@ -263,6 +263,16 @@ protected: RefCntAutoPtr<TextureViewImplType> m_pBoundDepthStencil; const bool m_bIsDeferred = false; + +#ifdef _DEBUG + // std::unordered_map is unbelievably slow. Keeping track of mapped buffers + // in release builds is not feasible + struct DbgMappedBufferInfo + { + MAP_TYPE MapType; + }; + std::unordered_map<IBuffer*, DbgMappedBufferInfo> m_DbgMappedBuffers; +#endif }; @@ -714,6 +724,11 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, Pi const auto& BuffDesc = pBuffer->GetDesc(); +#ifdef _DEBUG + VERIFY(m_DbgMappedBuffers.find(pBuffer) == m_DbgMappedBuffers.end(), "Buffer '", BuffDesc.Name, "' has already been mapped"); + m_DbgMappedBuffers[pBuffer] = DbgMappedBufferInfo{MapType}; +#endif + pMappedData = nullptr; switch( MapType ) { @@ -753,9 +768,15 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, Pi template<typename BaseInterface, typename BufferImplType, typename TextureImplType, typename PipelineStateImplType> inline void DeviceContextBase<BaseInterface, BufferImplType, TextureImplType, PipelineStateImplType> :: - UnmapBuffer(IBuffer* pBuffer) + UnmapBuffer(IBuffer* pBuffer, MAP_TYPE MapType) { VERIFY(pBuffer, "pBuffer must not be null"); +#ifdef _DEBUG + auto MappedBufferIt = m_DbgMappedBuffers.find(pBuffer); + VERIFY(MappedBufferIt != m_DbgMappedBuffers.end(), "Buffer '", pBuffer->GetDesc().Name, "' has not been mapped."); + VERIFY(MappedBufferIt->second.MapType == MapType, "MapType (", MapType, ") does not match the map type that was used to map the buffer ", MappedBufferIt->second.MapType); + m_DbgMappedBuffers.erase(MappedBufferIt); +#endif } diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index d1235dbe..2d252810 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -706,9 +706,7 @@ public: /// \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; + virtual void UnmapBuffer( IBuffer* pBuffer, MAP_TYPE MapType ) = 0; /// Updates the data in the texture diff --git a/Graphics/GraphicsEngine/interface/MapHelper.h b/Graphics/GraphicsEngine/interface/MapHelper.h index 71264c3b..64e34247 100644 --- a/Graphics/GraphicsEngine/interface/MapHelper.h +++ b/Graphics/GraphicsEngine/interface/MapHelper.h @@ -129,7 +129,7 @@ public: { if( m_pBuffer ) { - m_pContext->UnmapBuffer(m_pBuffer); + m_pContext->UnmapBuffer(m_pBuffer, m_MapType); m_pBuffer = nullptr; m_MapType = static_cast<MAP_TYPE>(-1); m_MapFlags = static_cast<Uint32>(-1); |
