Added IncrementalCompileOperation::compileAllForNextFrame(uint) method and supporting
functionality that tell the IncrementalCompileOperation to compile all pending objects during next draw traversal, for specified number of frames.
This commit is contained in:
parent
a74289614d
commit
8ffa50a88e
@ -21,7 +21,7 @@ extern "C" {
|
||||
#define OPENSCENEGRAPH_MAJOR_VERSION 2
|
||||
#define OPENSCENEGRAPH_MINOR_VERSION 9
|
||||
#define OPENSCENEGRAPH_PATCH_VERSION 12
|
||||
#define OPENSCENEGRAPH_SOVERSION 72
|
||||
#define OPENSCENEGRAPH_SOVERSION 73
|
||||
|
||||
/* Convenience macro that can be used to decide whether a feature is present or not i.e.
|
||||
* #if OSG_MIN_VERSION_REQUIRED(2,9,5)
|
||||
|
@ -134,7 +134,26 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
|
||||
|
||||
|
||||
/** Merge subgraphs that have been compiled.*/
|
||||
void mergeCompiledSubgraphs();
|
||||
void mergeCompiledSubgraphs(const osg::FrameStamp* frameStamp);
|
||||
|
||||
/** Set the current frame number that the IncrementalCompileOperation should use as a reference
|
||||
* value for calculations based on current frame number.
|
||||
* Note, this value is set by the mergeCompiledSubgraphs(..) method so one won't normally need to call
|
||||
* set the CurrentFrameNumber manually.*/
|
||||
void setCurrentFrameNumber(unsigned int fn) { _currentFrameNumber = fn; }
|
||||
unsigned int getCurrentFrameNumber() const { return _currentFrameNumber; }
|
||||
|
||||
/** tell the IncrementalCompileOperation to compile all pending objects during next draw traversal,
|
||||
* for specified number of frames.*/
|
||||
void compileAllForNextFrame(unsigned int numFramesToDoCompileAll=1);
|
||||
|
||||
/** tell the IncrementalCompileOperation to compile all pending objects during next draw traversal,
|
||||
* till specified frame number.*/
|
||||
void setCompileAllTillFrameNumber(unsigned int fn) { _compileAllTillFrameNumber = fn; }
|
||||
unsigned int getCompileAllTillFrameNumber() const { return _compileAllTillFrameNumber; }
|
||||
|
||||
|
||||
|
||||
|
||||
virtual void operator () (osg::GraphicsContext* context);
|
||||
|
||||
@ -142,12 +161,19 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
|
||||
{
|
||||
CompileInfo(osg::GraphicsContext* context, IncrementalCompileOperation* ico);
|
||||
|
||||
double availableTime() { return allocatedTime - timer.elapsedTime(); }
|
||||
|
||||
bool okToCompile(double estimatedTimeForCompile=0.0) const
|
||||
{
|
||||
if (compileAll) return true;
|
||||
if (maxNumObjectsToCompile==0) return false;
|
||||
return (allocatedTime - timer.elapsedTime()) >= estimatedTimeForCompile;
|
||||
}
|
||||
|
||||
IncrementalCompileOperation* incrementalCompileOperation;
|
||||
|
||||
bool compileAll;
|
||||
unsigned int maxNumObjectsToCompile;
|
||||
osg::ElapsedTime timer;
|
||||
double allocatedTime;
|
||||
osg::ElapsedTime timer;
|
||||
};
|
||||
|
||||
struct CompileOp : public osg::Referenced
|
||||
@ -257,32 +283,33 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
|
||||
/** Remove CompileSet from list.*/
|
||||
void remove(CompileSet* compileSet);
|
||||
|
||||
|
||||
OpenThreads::Mutex* getToCompiledMutex() { return &_toCompileMutex; }
|
||||
CompileSets& getToCompile() { return _toCompile; }
|
||||
|
||||
|
||||
OpenThreads::Mutex* getCompiledMutex() { return &_compiledMutex; }
|
||||
CompileSets& getCompiled() { return _compiled; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~IncrementalCompileOperation();
|
||||
|
||||
|
||||
|
||||
double _targetFrameRate;
|
||||
double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
|
||||
unsigned int _maximumNumOfObjectsToCompilePerFrame;
|
||||
double _flushTimeRatio;
|
||||
double _conservativeTimeRatio;
|
||||
|
||||
unsigned int _currentFrameNumber;
|
||||
unsigned int _compileAllTillFrameNumber;
|
||||
|
||||
osg::ref_ptr<osg::Geometry> _forceTextureDownloadGeometry;
|
||||
|
||||
OpenThreads::Mutex _toCompileMutex;
|
||||
CompileSets _toCompile;
|
||||
|
||||
|
||||
OpenThreads::Mutex _compiledMutex;
|
||||
CompileSets _compiled;
|
||||
|
||||
|
||||
ContextSet _contexts;
|
||||
|
||||
};
|
||||
|
@ -301,7 +301,10 @@ bool IncrementalCompileOperation::CompileProgramOp::compile(CompileInfo& compile
|
||||
return true;
|
||||
}
|
||||
|
||||
IncrementalCompileOperation::CompileInfo::CompileInfo(osg::GraphicsContext* context, IncrementalCompileOperation* ico)
|
||||
IncrementalCompileOperation::CompileInfo::CompileInfo(osg::GraphicsContext* context, IncrementalCompileOperation* ico):
|
||||
compileAll(false),
|
||||
maxNumObjectsToCompile(0),
|
||||
allocatedTime(0)
|
||||
{
|
||||
setState(context->getState());
|
||||
incrementalCompileOperation = ico;
|
||||
@ -342,7 +345,7 @@ bool IncrementalCompileOperation::CompileList::compile(CompileInfo& compileInfo)
|
||||
//#define USE_TIME_ESTIMATES
|
||||
|
||||
for(CompileOps::iterator itr = _compileOps.begin();
|
||||
itr != _compileOps.end() && compileInfo.availableTime()>0.0 && compileInfo.maxNumObjectsToCompile>0;
|
||||
itr != _compileOps.end() && compileInfo.okToCompile();
|
||||
)
|
||||
{
|
||||
#ifdef USE_TIME_ESTIMATES
|
||||
@ -444,7 +447,9 @@ bool IncrementalCompileOperation::CompileSet::compile(CompileInfo& compileInfo)
|
||||
IncrementalCompileOperation::IncrementalCompileOperation():
|
||||
osg::GraphicsOperation("IncrementalCompileOperation",true),
|
||||
_flushTimeRatio(0.5),
|
||||
_conservativeTimeRatio(0.5)
|
||||
_conservativeTimeRatio(0.5),
|
||||
_currentFrameNumber(0),
|
||||
_compileAllTillFrameNumber(0)
|
||||
{
|
||||
_targetFrameRate = 100.0;
|
||||
_minimumTimeAvailableForGLCompileAndDeletePerFrame = 0.001; // 1ms.
|
||||
@ -623,13 +628,15 @@ void IncrementalCompileOperation::remove(CompileSet* compileSet)
|
||||
}
|
||||
|
||||
|
||||
void IncrementalCompileOperation::mergeCompiledSubgraphs()
|
||||
void IncrementalCompileOperation::mergeCompiledSubgraphs(const osg::FrameStamp* frameStamp)
|
||||
{
|
||||
// OSG_INFO<<"IncrementalCompileOperation::mergeCompiledSubgraphs()"<<std::endl;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> compilded_lock(_compiledMutex);
|
||||
|
||||
for(CompileSets::iterator itr = _compiled.begin();
|
||||
|
||||
if (frameStamp) _currentFrameNumber = frameStamp->getFrameNumber();
|
||||
|
||||
for(CompileSets::iterator itr = _compiled.begin();
|
||||
itr != _compiled.end();
|
||||
++itr)
|
||||
{
|
||||
@ -673,7 +680,6 @@ void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
|
||||
|
||||
double flushTime = availableTime * _flushTimeRatio;
|
||||
double compileTime = availableTime - flushTime;
|
||||
unsigned int maxNumOfObjectsToCompilePerFrame = _maximumNumOfObjectsToCompilePerFrame;
|
||||
|
||||
#if 1
|
||||
OSG_NOTIFY(level)<<"total availableTime = "<<availableTime*1000.0<<std::endl;
|
||||
@ -696,6 +702,7 @@ void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
|
||||
CompileInfo compileInfo(context, this);
|
||||
compileInfo.maxNumObjectsToCompile = _maximumNumOfObjectsToCompilePerFrame;
|
||||
compileInfo.allocatedTime = compileTime;
|
||||
compileInfo.compileAll = (_compileAllTillFrameNumber > _currentFrameNumber);
|
||||
|
||||
CompileSets toCompileCopy;
|
||||
{
|
||||
@ -704,7 +711,7 @@ void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
|
||||
}
|
||||
|
||||
for(CompileSets::iterator itr = toCompileCopy.begin();
|
||||
itr != toCompileCopy.end() && compileTime>0.0 && maxNumOfObjectsToCompilePerFrame>0;
|
||||
itr != toCompileCopy.end() && compileInfo.okToCompile();
|
||||
++itr)
|
||||
{
|
||||
CompileSet* cs = itr->get();
|
||||
@ -738,4 +745,10 @@ void IncrementalCompileOperation::operator () (osg::GraphicsContext* context)
|
||||
//glFinish();
|
||||
}
|
||||
|
||||
void IncrementalCompileOperation::compileAllForNextFrame(unsigned int numFramesToDoCompileAll)
|
||||
{
|
||||
_compileAllTillFrameNumber = _currentFrameNumber+numFramesToDoCompileAll;
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace osgUtil
|
||||
|
@ -1075,7 +1075,7 @@ void CompositeViewer::updateTraversal()
|
||||
if (_incrementalCompileOperation.valid())
|
||||
{
|
||||
// merge subgraphs that have been compiled by the incremental compiler operation.
|
||||
_incrementalCompileOperation->mergeCompiledSubgraphs();
|
||||
_incrementalCompileOperation->mergeCompiledSubgraphs(getFrameStamp());
|
||||
}
|
||||
|
||||
if (_updateOperations.valid())
|
||||
|
@ -983,7 +983,7 @@ void Viewer::updateTraversal()
|
||||
if (_incrementalCompileOperation.valid())
|
||||
{
|
||||
// merge subgraphs that have been compiled by the incremental compiler operation.
|
||||
_incrementalCompileOperation->mergeCompiledSubgraphs();
|
||||
_incrementalCompileOperation->mergeCompiledSubgraphs(getFrameStamp());
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user