From b5db6a7d5df8fb764d394ec25aafa710aa05733c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 21 Aug 2017 13:26:00 +0200 Subject: [PATCH] Map/unmap vertices once per layer order update Multiple memory map/unmap operations cause a significant delay on GPUs that fetch vertices from RAM. Fixes: lp:1701936 * https://bugs.launchpad.net/kicad/+bug/1701936 --- common/gal/opengl/gpu_manager.cpp | 1 + common/view/view.cpp | 28 ++++++++------------------- include/gal/opengl/vertex_container.h | 8 ++++++++ include/view/view.h | 8 -------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 5e8257b3a0..1f26e74c30 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -183,6 +183,7 @@ void GPU_CACHED_MANAGER::EndDrawing() glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); + cached->ClearDirty(); // Deactivate vertex array glDisableClientState( GL_COLOR_ARRAY ); diff --git a/common/view/view.cpp b/common/view/view.cpp index cc6c740ae5..29860ed1d1 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -717,25 +717,6 @@ struct VIEW::changeItemsDepth }; -void VIEW::ChangeLayerDepth( int aLayer, int aDepth ) -{ - // There is no point in updating non-cached layers - if( !IsCached( aLayer ) ) - return; - - BOX2I r; - - r.SetMaximum(); - - m_gal->BeginUpdate(); - changeItemsDepth visitor( aLayer, aDepth, m_gal ); - m_layers[aLayer].items->Query( r, visitor ); - m_gal->EndUpdate(); - - MarkTargetDirty( m_layers[aLayer].target ); -} - - int VIEW::GetTopLayer() const { if( m_topLayers.size() == 0 ) @@ -814,13 +795,20 @@ void VIEW::ClearTopLayers() void VIEW::UpdateAllLayersOrder() { + BOX2I r; + r.SetMaximum(); + sortLayers(); + m_gal->BeginUpdate(); for( LAYER_MAP::value_type& l : m_layers ) { - ChangeLayerDepth( l.first, l.second.renderingOrder ); + int layer = l.first; + changeItemsDepth visitor( layer, l.second.renderingOrder, m_gal ); + m_layers[layer].items->Query( r, visitor ); } + m_gal->EndUpdate(); MarkDirty(); } diff --git a/include/gal/opengl/vertex_container.h b/include/gal/opengl/vertex_container.h index 7c4c4df32b..474c169ae5 100644 --- a/include/gal/opengl/vertex_container.h +++ b/include/gal/opengl/vertex_container.h @@ -157,6 +157,14 @@ public: m_dirty = true; } + /** + * Clears the dirty flag to prevent reuploading vertices to the GPU memory. + */ + void ClearDirty() + { + m_dirty = false; + } + protected: VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE ); diff --git a/include/view/view.h b/include/view/view.h index c484acde54..df9854b43c 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -469,14 +469,6 @@ public: */ void UpdateAllLayersColor(); - /** - * Function ChangeLayerDepth() - * Changes the depth of items on the given layer. - * @param aLayer is a number of the layer to be updated. - * @param aDepth is the new depth. - */ - void ChangeLayerDepth( int aLayer, int aDepth ); - /** * Function SetTopLayer() * Sets given layer to be displayed on the top or sets back the default order of layers.