From 85a434072645c13b50e9486e54c9b7854a33c989 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 24 Jul 2018 20:16:15 -0700 Subject: Fixed performance issue with resetting unchanged vertex buffers --- Graphics/GraphicsEngine/include/DeviceContextBase.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index d84956b1..aae0ef1f 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -215,8 +215,13 @@ inline void DeviceContextBase :: SetVertexBuffers( Uint32 StartSl if ( Flags & SET_VERTEX_BUFFERS_FLAG_RESET ) { - for(Uint32 s=0; s < m_NumVertexStreams; ++s) - m_VertexStreams[s] = VertexStreamInfo(); + // Reset only these buffer slots that are not being set. + // It is very important to not reset buffers that stay unchanged + // as AddRef()/Release() are not free + for (Uint32 s = 0; s < StartSlot; ++s) + m_VertexStreams[s] = VertexStreamInfo{}; + for (Uint32 s = StartSlot + NumBuffersSet; s < m_NumVertexStreams; ++s) + m_VertexStreams[s] = VertexStreamInfo{}; m_NumVertexStreams = 0; } m_NumVertexStreams = std::max(m_NumVertexStreams, StartSlot + NumBuffersSet ); @@ -224,7 +229,7 @@ inline void DeviceContextBase :: SetVertexBuffers( Uint32 StartSl for( Uint32 Buff = 0; Buff < NumBuffersSet; ++Buff ) { auto &CurrStream = m_VertexStreams[StartSlot + Buff]; - CurrStream.pBuffer = RefCntAutoPtr( ppBuffers ? ppBuffers[Buff] : nullptr ); + CurrStream.pBuffer = ppBuffers ? ppBuffers[Buff] : nullptr; CurrStream.Offset = pOffsets ? pOffsets[Buff] : 0; #ifdef DEVELOPMENT if ( CurrStream.pBuffer ) @@ -239,7 +244,7 @@ inline void DeviceContextBase :: SetVertexBuffers( Uint32 StartSl } // Remove null buffers from the end of the array while(m_NumVertexStreams > 0 && !m_VertexStreams[m_NumVertexStreams-1].pBuffer) - m_VertexStreams[m_NumVertexStreams--] = VertexStreamInfo(); + m_VertexStreams[m_NumVertexStreams--] = VertexStreamInfo{}; } template -- cgit v1.2.3