From c2986b3bd72457c0e3f035c973fa2db06beb19b7 Mon Sep 17 00:00:00 2001 From: bzzt Date: Wed, 20 Feb 2019 13:37:00 +0000 Subject: [PATCH 1/3] Do not block the loading thread while compiling composite maps in the draw thread --- components/terrain/compositemaprenderer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 39d00db36..3fc56a882 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -59,26 +59,29 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const while (!mImmediateCompileSet.empty()) { - CompositeMap* node = *mImmediateCompileSet.begin(); + osg::ref_ptr node = *mImmediateCompileSet.begin(); mCompiled.insert(node); + mImmediateCompileSet.erase(node); + mMutex.unlock(); compile(*node, renderInfo, nullptr); - - mImmediateCompileSet.erase(mImmediateCompileSet.begin()); + mMutex.lock(); } double timeLeft = availableTime; while (!mCompileSet.empty() && timeLeft > 0) { - CompositeMap* node = *mCompileSet.begin(); + osg::ref_ptr node = *mCompileSet.begin(); + mMutex.unlock(); compile(*node, renderInfo, &timeLeft); + mMutex.lock(); if (node->mCompiled >= node->mDrawables.size()) { mCompiled.insert(node); - mCompileSet.erase(mCompileSet.begin()); + mCompileSet.erase(node); } } mTimer.setStartTick(); From cad45e96ac4b9f66448b5a8ebde23433e0487957 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Thu, 21 Mar 2019 08:42:48 +0400 Subject: [PATCH 2/3] Remove redundant mCompile set - we do not use data from it anyway --- components/terrain/compositemaprenderer.cpp | 4 ---- components/terrain/compositemaprenderer.hpp | 2 -- 2 files changed, 6 deletions(-) diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 3fc56a882..355ef6c16 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -47,8 +47,6 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const double availableTime = std::max((targetFrameTime - dt)*conservativeTimeRatio, mMinimumTimeAvailable); - mCompiled.clear(); - if (mWorkQueue) mUnrefQueue->flush(mWorkQueue.get()); @@ -60,7 +58,6 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const while (!mImmediateCompileSet.empty()) { osg::ref_ptr node = *mImmediateCompileSet.begin(); - mCompiled.insert(node); mImmediateCompileSet.erase(node); mMutex.unlock(); @@ -80,7 +77,6 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const if (node->mCompiled >= node->mDrawables.size()) { - mCompiled.insert(node); mCompileSet.erase(node); } } diff --git a/components/terrain/compositemaprenderer.hpp b/components/terrain/compositemaprenderer.hpp index 5c81fdca6..201130e30 100644 --- a/components/terrain/compositemaprenderer.hpp +++ b/components/terrain/compositemaprenderer.hpp @@ -76,8 +76,6 @@ namespace Terrain mutable CompileSet mCompileSet; mutable CompileSet mImmediateCompileSet; - mutable CompileSet mCompiled; - mutable OpenThreads::Mutex mMutex; osg::ref_ptr mFBO; From 0e1f5f68b6947eb11d713208ca2a6b0281ba9bcb Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Thu, 21 Mar 2019 08:52:13 +0400 Subject: [PATCH 3/3] Do not allow different threads to compile the same composite map --- components/terrain/compositemaprenderer.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 355ef6c16..ee4a66fcd 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -70,14 +70,17 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const while (!mCompileSet.empty() && timeLeft > 0) { osg::ref_ptr node = *mCompileSet.begin(); + mCompileSet.erase(node); mMutex.unlock(); compile(*node, renderInfo, &timeLeft); mMutex.lock(); - if (node->mCompiled >= node->mDrawables.size()) + if (node->mCompiled < node->mDrawables.size()) { - mCompileSet.erase(node); + // We did not compile the map fully. + // Place it back to queue to continue work in the next time. + mCompileSet.insert(node); } } mTimer.setStartTick();