From c1e32ef74283e63b1ae448f6cd21d58561bfea89 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 28 Mar 2008 15:52:10 +0000 Subject: [PATCH] Rewrote the DatabasePager::removeExpiredSubgraphs(double) routine as it as not expiring subgraphs quick enough to enable reasonable load balancing. New version isn't perfect and will need further work, but does at least reduce the memory footprint by as much as half on test paths on big databases. The rewritten method no longer uses the the MaximumNumOfRemovedChildPagedLODs and MinimumNumOfInactivePagedLODs variables so these and associated methods for accessing them have been removed. - /** Set the maximum number of PagedLOD child to remove per frame */ - void setMaximumNumOfRemovedChildPagedLODs(unsigned int number) { _maximumNumOfRemovedChildPagedLODs = number; } - - /** Get the maximum number of PagedLOD child to remove per frame */ - unsigned int getMaximumNumOfRemovedChildPagedLODs() const { return _maximumNumOfRemovedChildPagedLODs; } - - /** Set the minimum number of inactive PagedLOD child to keep */ - void setMinimumNumOfInactivePagedLODs(unsigned int number) { _minimumNumOfInactivePagedLODs = number; } - - /** Get the minimum number of inactive PagedLOD child to keep */ - unsigned int getMinimumNumOfInactivePagedLODs() const { return _minimumNumOfInactivePagedLODs; } --- include/osgDB/DatabasePager | 20 +--- src/osgDB/DatabasePager.cpp | 227 ++++++++++++------------------------ 2 files changed, 75 insertions(+), 172 deletions(-) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index 045850808..3aa00e76c 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -251,18 +251,6 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl /** Reset the Stats variables.*/ void resetStats(); - /** Set the maximum number of PagedLOD child to remove per frame */ - void setMaximumNumOfRemovedChildPagedLODs(unsigned int number) { _maximumNumOfRemovedChildPagedLODs = number; } - - /** Get the maximum number of PagedLOD child to remove per frame */ - unsigned int getMaximumNumOfRemovedChildPagedLODs() const { return _maximumNumOfRemovedChildPagedLODs; } - - /** Set the minimum number of inactive PagedLOD child to keep */ - void setMinimumNumOfInactivePagedLODs(unsigned int number) { _minimumNumOfInactivePagedLODs = number; } - - /** Get the minimum number of inactive PagedLOD child to keep */ - unsigned int getMinimumNumOfInactivePagedLODs() const { return _minimumNumOfInactivePagedLODs; } - typedef std::list< osg::ref_ptr > PagedLODList; typedef std::set< osg::ref_ptr > StateSetList; typedef std::vector< osg::ref_ptr > DrawableList; @@ -310,6 +298,8 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl class FindCompileableGLObjectsVisitor; friend class FindCompileableGLObjectsVisitor; + class MarkPagedLODsVisitor; + class FindPagedLODsVisitor; friend class FindPagedLODsVisitor; @@ -444,9 +434,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl DatabaseRequestList _dataToMergeList; mutable OpenThreads::Mutex _dataToMergeListMutex; - - PagedLODList _activePagedLODList; - PagedLODList _inactivePagedLODList; + PagedLODList _pagedLODList; double _expiryDelay; @@ -457,8 +445,6 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl double _targetFrameRate; double _minimumTimeAvailableForGLCompileAndDeletePerFrame; unsigned int _maximumNumOfObjectsToCompilePerFrame; - unsigned int _maximumNumOfRemovedChildPagedLODs; - unsigned int _minimumNumOfInactivePagedLODs; double _minimumTimeToMergeTile; double _maximumTimeToMergeTile; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 67164ec5e..14a31f171 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -27,8 +27,6 @@ static osg::ApplicationUsageProxy DatabasePager_e1(osg::ApplicationUsage::ENVIRO static osg::ApplicationUsageProxy DatabasePager_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME ","maximum number of OpenGL objects to compile per frame in database pager."); static osg::ApplicationUsageProxy DatabasePager_e3(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DATABASE_PAGER_DRAWABLE ","Set the drawable policy for setting of loaded drawable to specified type. mode can be one of DoNotModify, DisplayList, VBO or VertexArrays>."); static osg::ApplicationUsageProxy DatabasePager_e4(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DATABASE_PAGER_PRIORITY ", "Set the thread priority to DEFAULT, MIN, LOW, NOMINAL, HIGH or MAX."); -static osg::ApplicationUsageProxy DatabasePager_e5(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DATABASE_PAGER_CHILDREN_TO_REMOVE_PER_FRAME ", "Set the maximum number of PagedLOD child to remove per frame."); -static osg::ApplicationUsageProxy DatabasePager_e6(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DATABASE_PAGER_MINIMUM_INACTIVE_PAGEDLOD ", "Set the minimum number of inactive PagedLOD child to keep."); static osg::ApplicationUsageProxy DatabasePager_e7(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_EXPIRY_DELAY ","Set the length of time a PagedLOD child is kept in memory, without being used, before its tagged as expired, and ear marked to deletion."); // Convert function objects that take pointer args into functions that a // reference to an osg::ref_ptr. This is quite useful for doing STL @@ -160,14 +158,17 @@ DatabasePager::DatabasePager() _valueAnisotropy = 1.0f; -#if 1 - _deleteRemovedSubgraphsInDatabaseThread = true; -#else - _deleteRemovedSubgraphsInDatabaseThread = false; -#endif const char* ptr=0; + _deleteRemovedSubgraphsInDatabaseThread = true; + if( (ptr = getenv("OSG_DELETE_IN_DATABASE_THREAD")) != 0) + { + _deleteRemovedSubgraphsInDatabaseThread = strcmp(ptr,"yes")==0 || strcmp(ptr,"YES")==0 || + strcmp(ptr,"on")==0 || strcmp(ptr,"ON")==0; + + } + _expiryDelay = 10.0; if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0) { @@ -195,17 +196,6 @@ DatabasePager::DatabasePager() _maximumNumOfObjectsToCompilePerFrame = atoi(ptr); } - _maximumNumOfRemovedChildPagedLODs = 1; - if( (ptr = getenv("OSG_DATABASE_PAGER_CHILDREN_TO_REMOVE_PER_FRAME")) != 0) - { - _maximumNumOfRemovedChildPagedLODs = atoi(ptr); - } - _minimumNumOfInactivePagedLODs = 100; - if( (ptr = getenv("OSG_DATABASE_PAGER_MINIMUM_INACTIVE_PAGEDLOD")) != 0) - { - _minimumNumOfInactivePagedLODs = atoi(ptr); - } - // initialize the stats variables resetStats(); @@ -245,8 +235,6 @@ DatabasePager::DatabasePager(const DatabasePager& rhs) _targetFrameRate = rhs._targetFrameRate; _minimumTimeAvailableForGLCompileAndDeletePerFrame = rhs._minimumTimeAvailableForGLCompileAndDeletePerFrame; _maximumNumOfObjectsToCompilePerFrame = rhs._maximumNumOfObjectsToCompilePerFrame; - _maximumNumOfRemovedChildPagedLODs = rhs._maximumNumOfRemovedChildPagedLODs; - _minimumNumOfInactivePagedLODs = rhs._minimumNumOfInactivePagedLODs; // initialize the stats variables resetStats(); @@ -324,10 +312,9 @@ void DatabasePager::clear() _dataToMergeList.clear(); } - // no mutex?? - _activePagedLODList.clear(); - _inactivePagedLODList.clear(); - + // note, no need to use a mutex as the list is only accessed from the update thread. + _pagedLODList.clear(); + // ?? // _activeGraphicsContexts } @@ -934,142 +921,53 @@ void DatabasePager::addLoadedDataToSceneGraph(double timeStamp) } +class DatabasePager::MarkPagedLODsVisitor : public osg::NodeVisitor +{ +public: + MarkPagedLODsVisitor(const std::string& marker): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), + _marker(marker) + { + } + + virtual void apply(osg::PagedLOD& plod) + { + plod.setName(_marker); + + traverse(plod); + } + + std::string _marker; +}; void DatabasePager::removeExpiredSubgraphs(double currentFrameTime) { - //osg::notify(osg::NOTICE)<<"DatabasePager::removeExpiredSubgraphs()"<tick(); +// osg::notify(osg::NOTICE)<<"DatabasePager::new_removeExpiredSubgraphs()"<get(); - bool remove_plod = false; - if (plod->referenceCount()<=1) - { - // prune PageLOD's that are no longer externally referenced - childrenRemoved.push_back(const_cast(plod)); - //osg::notify(osg::NOTICE)<<"_activePagedLODList : pruning no longer externally referenced"<getFrameNumberOfLastTraversal()<_frameNumber) - { - // osg::notify(osg::NOTICE)<<"_activePagedLODList : moving PageLOD to inactive list"<get(); + plod->removeExpiredChildren(expiryTime,childrenRemoved); } - unsigned int i = 0; - // unsigned int numberOfPagedLODToTest = _inactivePagedLODList.size(); - unsigned int targetNumOfRemovedChildPagedLODs = 0; - if (_inactivePagedLODList.size() > _minimumNumOfInactivePagedLODs) targetNumOfRemovedChildPagedLODs = _inactivePagedLODList.size() - _minimumNumOfInactivePagedLODs; - - if (targetNumOfRemovedChildPagedLODs > _maximumNumOfRemovedChildPagedLODs) targetNumOfRemovedChildPagedLODs = _maximumNumOfRemovedChildPagedLODs; - - - // filter out singly referenced PagedLOD and move reactivated PagedLOD into the active list - for(PagedLODList::iterator inactive_itr = _inactivePagedLODList.begin(); - inactive_itr!=_inactivePagedLODList.end(); - ) - { - const osg::PagedLOD* plod = inactive_itr->get(); - bool remove_plod = false; - if (plod->referenceCount()<=1) - { - // prune PageLOD's that are no longer externally referenced - childrenRemoved.push_back(const_cast(plod)); - //osg::notify(osg::NOTICE)<<"_activePagedLODList : pruning no longer externally referenced"<getFrameNumberOfLastTraversal()>=_frameNumber) - { - // osg::notify(osg::NOTICE)<<"_inactivePagedLODList : moving PageLOD to active list"<(plod)->removeExpiredChildren(expiryTime,childrenRemoved)) - { - //osg::notify(osg::NOTICE)<<"Some children removed from PLod"<delta_m(before,osg::Timer::instance()->tick()); - //osg::notify(osg::NOTICE)<<" time 1 "<accept(markerVistor); + } + + // osg::notify(osg::NOTICE)<<"Children to remove "<get()); } + updateDatabasePagerThreadBlock(); } - childrenRemoved.clear(); - } + // osg::notify(osg::NOTICE)<<" time 2 "<delta_m(before,osg::Timer::instance()->tick())<<" ms "<get(); + if (plod && plod->getName() != markerVistor._marker) + { + ++itr; + } + else + { + PagedLODList::iterator itr_to_erase = itr; + ++itr; - // osg::notify(osg::NOTICE)<<" time 2 "<delta_m(before,osg::Timer::instance()->tick())<<" ms "<getSharedStateManager()) @@ -1097,14 +1014,12 @@ void DatabasePager::removeExpiredSubgraphs(double currentFrameTime) osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime); - // osg::notify(osg::NOTICE)<<"Done DatabasePager::removeExpiredSubgraphs() "<delta_m(before,osg::Timer::instance()->tick())<<" ms "<accept(fplv); + if (!subgraph) return; + + FindPagedLODsVisitor fplv(_pagedLODList); + subgraph->accept(fplv); } bool DatabasePager::requiresCompileGLObjects() const