From 111636445d2e19420468cdf78ffd2b87b7ad6489 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 2 Dec 2018 10:22:22 -0800 Subject: Brought back MapType paramter to UnmapBuffer() function. The performance hit of keeping track of mapped buffers turned out to be unacceptable --- .../GraphicsEngine/include/DeviceContextBase.h | 25 ++++++++++++++++++++-- Graphics/GraphicsEngine/interface/DeviceContext.h | 4 +--- Graphics/GraphicsEngine/interface/MapHelper.h | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) (limited to 'Graphics/GraphicsEngine') 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 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 m_DbgMappedBuffers; +#endif }; @@ -714,6 +724,11 @@ inline void DeviceContextBaseGetDesc(); +#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 inline void DeviceContextBase :: - 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(-1); m_MapFlags = static_cast(-1); -- cgit v1.2.3