Added new computation of time to allocate to flushing deleted and compiling OpenGL objects per frame.
This commit is contained in:
parent
c10acfcc47
commit
922dcb0423
@ -15,6 +15,7 @@
|
||||
#define OSGVIEWER_RENDERER 1
|
||||
|
||||
#include <osg/Timer>
|
||||
#include <osgDB/DatabasePager>
|
||||
#include <osgUtil/SceneView>
|
||||
#include <osgViewer/Export>
|
||||
|
||||
@ -65,22 +66,72 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQu
|
||||
void setGraphicsThreadDoesCull(bool flag);
|
||||
bool getGraphicsThreadDoesCull() const { return _graphicsThreadDoesCull; }
|
||||
|
||||
void cull();
|
||||
void draw();
|
||||
void cull_draw();
|
||||
virtual void cull();
|
||||
virtual void draw();
|
||||
virtual void cull_draw();
|
||||
|
||||
virtual void operator () (osg::Object* object);
|
||||
|
||||
virtual void operator () (osg::GraphicsContext* context);
|
||||
|
||||
virtual void release();
|
||||
|
||||
|
||||
/** Set the target frame rate that the DatabasePager should assume.
|
||||
* Typically one would set this to the value refresh rate of your display system i.e. 60Hz.
|
||||
* Default value is 100.
|
||||
* Usage notes. The TargetFrameRate and the MinimumTimeAvailableForGLCompileAndDeletePerFrame
|
||||
* parameters are not directly used by DatabasePager, but are should be used as a guide for how
|
||||
* long to set aside per frame for compiling and deleting OpenGL objects - ie. the value to use
|
||||
* when calling DatabasePager::compileGLObjectgs(state,availableTime,). The longer amount of
|
||||
* time to set aside cthe faster databases will be paged in but with increased chance of frame drops,
|
||||
* the lower the amount of time the set aside the slower databases will paged it but with better
|
||||
* chance of avoid any frame drops. The default values are chosen to achieve the later when running
|
||||
* on a modern mid to high end PC.
|
||||
* The way to compute the amount of available time use a scheme such as :
|
||||
* availableTime = maximum(1.0/targetFrameRate - timeTakenDuringUpdateCullAndDraw, minimumTimeAvailableForGLCompileAndDeletePerFrame).
|
||||
*
|
||||
* Note, the actual TargetFrameRate used is the minimum of this value and that set in the DatabasePager. */
|
||||
void setTargetFrameRate(double tfr) { _targetFrameRate = tfr; }
|
||||
|
||||
/** Get the target frame rate that the DatabasePager should assume.*/
|
||||
double getTargetFrameRate() const { return _targetFrameRate; }
|
||||
|
||||
/** Set the minimum amount of time (in seconds) that should be made available for compiling and delete OpenGL objects per frame.
|
||||
* Default value is 0.001 (1 millisecond).
|
||||
* For usage see notes in setTargetFrameRate.
|
||||
*
|
||||
* Note, the actual TargetFrameRate used is the minimum of this value and that set in the DatabasePager. */
|
||||
void setMinimumTimeAvailableForGLCompileAndDeletePerFrame(double ta) { _minimumTimeAvailableForGLCompileAndDeletePerFrame = ta; }
|
||||
|
||||
/** Get the minimum amount of time that should be made available for compiling and delete OpenGL objects per frame.
|
||||
* For usage see notes in setTargetFrameRate.*/
|
||||
double getMinimumTimeAvailableForGLCompileAndDeletePerFrame() const { return _minimumTimeAvailableForGLCompileAndDeletePerFrame; }
|
||||
|
||||
/** FlushTimeRatio governs how much of the spare time in each frame is used for flushing deleted OpenGL objects.
|
||||
* Default value is 0.5, valid range is 0.1 to 0.9.*/
|
||||
void setFlushTimeRatio(double ratio) { _flushTimeRatio = ratio; }
|
||||
double getFlushTimeRatio() const { return _flushTimeRatio; }
|
||||
|
||||
/** ConservativeTimeRatio governs how much of the measured spare time in each frame is used for flushing deleted and compile new OpenGL objects.
|
||||
* Default value is 0.5, valid range is 0.1 to 1.0.
|
||||
* A ratio near 1.0 will lead to paged databases being compiled and merged quicker but increase the chances of frame drop.
|
||||
* A ratio near 0.1 will lead to paged databases being compiled and merged closer but reduse the chances of frame drop.*/
|
||||
void setConservativeTimeRatio(double ratio) { _conservativeTimeRatio = ratio; }
|
||||
double getConservativeTimeRatio() const { return _conservativeTimeRatio; }
|
||||
|
||||
protected:
|
||||
|
||||
void updateSceneView(osgUtil::SceneView* sceneView);
|
||||
|
||||
virtual ~Renderer();
|
||||
|
||||
virtual void updateSceneView(osgUtil::SceneView* sceneView);
|
||||
virtual void flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager, osg::GraphicsThread* compileThread);
|
||||
|
||||
double _targetFrameRate;
|
||||
double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
|
||||
double _flushTimeRatio;
|
||||
double _conservativeTimeRatio;
|
||||
|
||||
osg::observer_ptr<osg::Camera> _camera;
|
||||
|
||||
bool _done;
|
||||
|
@ -161,6 +161,10 @@ static OpenThreads::Mutex s_drawSerializerMutex;
|
||||
Renderer::Renderer(osg::Camera* camera):
|
||||
osg::GraphicsOperation("Renderer",true),
|
||||
OpenGLQuerySupport(),
|
||||
_targetFrameRate(100.0),
|
||||
_minimumTimeAvailableForGLCompileAndDeletePerFrame(0.001),
|
||||
_flushTimeRatio(0.5),
|
||||
_conservativeTimeRatio(0.5),
|
||||
_camera(camera),
|
||||
_done(false),
|
||||
_graphicsThreadDoesCull(true)
|
||||
@ -389,22 +393,13 @@ void Renderer::draw()
|
||||
|
||||
_availableQueue.add(sceneView);
|
||||
|
||||
double availableTime = 0.004; // 4 ms
|
||||
osg::Timer_t afterDispatchTick = osg::Timer::instance()->tick();
|
||||
|
||||
if (compileThread)
|
||||
{
|
||||
compileThread->add(_flushOperation.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneView->flushDeletedGLObjects(availableTime);
|
||||
}
|
||||
|
||||
if (databasePager && databasePager->requiresExternalCompileGLObjects(sceneView->getState()->getContextID()))
|
||||
{
|
||||
databasePager->compileGLObjects(*(sceneView->getState()), availableTime);
|
||||
}
|
||||
double dispatchTime = osg::Timer::instance()->delta_s(beforeDrawTick, afterDispatchTick);
|
||||
|
||||
// now flush delete OpenGL objects and compile any objects as required by the DatabasePager
|
||||
flushAndCompile(dispatchTime, sceneView, databasePager, compileThread);
|
||||
|
||||
if (acquireGPUStats)
|
||||
{
|
||||
endQuery();
|
||||
@ -512,20 +507,12 @@ void Renderer::cull_draw()
|
||||
sceneView->draw();
|
||||
}
|
||||
|
||||
double availableTime = 0.004; // 4 ms
|
||||
if (databasePager && databasePager->requiresExternalCompileGLObjects(sceneView->getState()->getContextID()))
|
||||
{
|
||||
databasePager->compileGLObjects(*(sceneView->getState()), availableTime);
|
||||
}
|
||||
osg::Timer_t afterDispatchTick = osg::Timer::instance()->tick();
|
||||
double cullAndDispatchTime = osg::Timer::instance()->delta_s(beforeCullTick, afterDispatchTick);
|
||||
|
||||
// now flush delete OpenGL objects and compile any objects as required by the DatabasePager
|
||||
flushAndCompile(cullAndDispatchTime, sceneView, databasePager, compileThread);
|
||||
|
||||
if (compileThread)
|
||||
{
|
||||
compileThread->add(_flushOperation.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneView->flushDeletedGLObjects(availableTime);
|
||||
}
|
||||
|
||||
if (acquireGPUStats)
|
||||
{
|
||||
@ -552,6 +539,54 @@ void Renderer::cull_draw()
|
||||
|
||||
}
|
||||
|
||||
void Renderer::flushAndCompile(double currentElapsedFrameTime, osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager, osg::GraphicsThread* compileThread)
|
||||
{
|
||||
|
||||
double targetFrameRate = _targetFrameRate;
|
||||
double minimumTimeAvailableForGLCompileAndDeletePerFrame = _minimumTimeAvailableForGLCompileAndDeletePerFrame;
|
||||
|
||||
if (databasePager)
|
||||
{
|
||||
targetFrameRate = std::min(targetFrameRate, databasePager->getTargetFrameRate());
|
||||
minimumTimeAvailableForGLCompileAndDeletePerFrame = std::min(minimumTimeAvailableForGLCompileAndDeletePerFrame, databasePager->getMinimumTimeAvailableForGLCompileAndDeletePerFrame());
|
||||
}
|
||||
|
||||
double targetFrameTime = 1.0/targetFrameRate;
|
||||
|
||||
double availableTime = std::max((targetFrameTime - currentElapsedFrameTime)*_conservativeTimeRatio,
|
||||
minimumTimeAvailableForGLCompileAndDeletePerFrame);
|
||||
|
||||
double flushTime = availableTime * _flushTimeRatio;
|
||||
double compileTime = availableTime - flushTime;
|
||||
|
||||
#if 0
|
||||
osg::notify(osg::NOTICE)<<"total availableTime = "<<availableTime*1000.0<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" flushTime = "<<flushTime*1000.0<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" compileTime = "<<compileTime*1000.0<<std::endl;
|
||||
#endif
|
||||
|
||||
if (compileThread)
|
||||
{
|
||||
compileThread->add(_flushOperation.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
sceneView->flushDeletedGLObjects(flushTime);
|
||||
}
|
||||
|
||||
// if any time left over from flush add this to compile time.
|
||||
if (flushTime>0.0) compileTime += flushTime;
|
||||
|
||||
#if 0
|
||||
osg::notify(osg::NOTICE)<<" revised compileTime = "<<compileTime*1000.0<<std::endl;
|
||||
#endif
|
||||
|
||||
if (databasePager && databasePager->requiresExternalCompileGLObjects(sceneView->getState()->getContextID()))
|
||||
{
|
||||
databasePager->compileGLObjects(*(sceneView->getState()), compileTime);
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::operator () (osg::Object* object)
|
||||
{
|
||||
osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
|
||||
|
@ -113,17 +113,17 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Renderer)
|
||||
"",
|
||||
"");
|
||||
I_Method0(void, cull,
|
||||
Properties::NON_VIRTUAL,
|
||||
Properties::VIRTUAL,
|
||||
__void__cull,
|
||||
"",
|
||||
"");
|
||||
I_Method0(void, draw,
|
||||
Properties::NON_VIRTUAL,
|
||||
Properties::VIRTUAL,
|
||||
__void__draw,
|
||||
"",
|
||||
"");
|
||||
I_Method0(void, cull_draw,
|
||||
Properties::NON_VIRTUAL,
|
||||
Properties::VIRTUAL,
|
||||
__void__cull_draw,
|
||||
"",
|
||||
"");
|
||||
@ -132,18 +132,76 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Renderer)
|
||||
__void__release,
|
||||
"if this operation is a barrier then release it. ",
|
||||
"");
|
||||
I_Method1(void, setTargetFrameRate, IN, double, tfr,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setTargetFrameRate__double,
|
||||
"Set the target frame rate that the DatabasePager should assume. ",
|
||||
"Typically one would set this to the value refresh rate of your display system i.e. 60Hz. Default value is 100. Usage notes. The TargetFrameRate and the MinimumTimeAvailableForGLCompileAndDeletePerFrame parameters are not directly used by DatabasePager, but are should be used as a guide for how long to set aside per frame for compiling and deleting OpenGL objects - ie. the value to use when calling DatabasePager::compileGLObjectgs(state,availableTime,). The longer amount of time to set aside cthe faster databases will be paged in but with increased chance of frame drops, the lower the amount of time the set aside the slower databases will paged it but with better chance of avoid any frame drops. The default values are chosen to achieve the later when running on a modern mid to high end PC. The way to compute the amount of available time use a scheme such as : availableTime = maximum(1.0/targetFrameRate - timeTakenDuringUpdateCullAndDraw, minimumTimeAvailableForGLCompileAndDeletePerFrame).Note, the actual TargetFrameRate used is the minimum of this value and that set in the DatabasePager. ");
|
||||
I_Method0(double, getTargetFrameRate,
|
||||
Properties::NON_VIRTUAL,
|
||||
__double__getTargetFrameRate,
|
||||
"Get the target frame rate that the DatabasePager should assume. ",
|
||||
"");
|
||||
I_Method1(void, setMinimumTimeAvailableForGLCompileAndDeletePerFrame, IN, double, ta,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setMinimumTimeAvailableForGLCompileAndDeletePerFrame__double,
|
||||
"Set the minimum amount of time (in seconds) that should be made available for compiling and delete OpenGL objects per frame. ",
|
||||
"Default value is 0.001 (1 millisecond). For usage see notes in setTargetFrameRate.Note, the actual TargetFrameRate used is the minimum of this value and that set in the DatabasePager. ");
|
||||
I_Method0(double, getMinimumTimeAvailableForGLCompileAndDeletePerFrame,
|
||||
Properties::NON_VIRTUAL,
|
||||
__double__getMinimumTimeAvailableForGLCompileAndDeletePerFrame,
|
||||
"Get the minimum amount of time that should be made available for compiling and delete OpenGL objects per frame. ",
|
||||
"For usage see notes in setTargetFrameRate. ");
|
||||
I_Method1(void, setFlushTimeRatio, IN, double, ratio,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setFlushTimeRatio__double,
|
||||
"FlushTimeRatio governs how much of the spare time in each frame is used for flushing deleted OpenGL objects. ",
|
||||
"Default value is 0.5, valid range is 0.1 to 0.9. ");
|
||||
I_Method0(double, getFlushTimeRatio,
|
||||
Properties::NON_VIRTUAL,
|
||||
__double__getFlushTimeRatio,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, setConservativeTimeRatio, IN, double, ratio,
|
||||
Properties::NON_VIRTUAL,
|
||||
__void__setConservativeTimeRatio__double,
|
||||
"ConservativeTimeRatio governs how much of the measured spare time in each frame is used for flushing deleted and compile new OpenGL objects. ",
|
||||
"Default value is 0.5, valid range is 0.1 to 1.0. A ratio near 1.0 will lead to paged databases being compiled and merged quicker but increase the chances of frame drop. A ratio near 0.1 will lead to paged databases being compiled and merged closer but reduse the chances of frame drop. ");
|
||||
I_Method0(double, getConservativeTimeRatio,
|
||||
Properties::NON_VIRTUAL,
|
||||
__double__getConservativeTimeRatio,
|
||||
"",
|
||||
"");
|
||||
I_ProtectedMethod1(void, updateSceneView, IN, osgUtil::SceneView *, sceneView,
|
||||
Properties::NON_VIRTUAL,
|
||||
Properties::VIRTUAL,
|
||||
Properties::NON_CONST,
|
||||
__void__updateSceneView__osgUtil_SceneView_P1,
|
||||
"",
|
||||
"");
|
||||
I_ProtectedMethod4(void, flushAndCompile, IN, double, currentElapsedFrameTime, IN, osgUtil::SceneView *, sceneView, IN, osgDB::DatabasePager *, databasePager, IN, osg::GraphicsThread *, compileThread,
|
||||
Properties::VIRTUAL,
|
||||
Properties::NON_CONST,
|
||||
__void__flushAndCompile__double__osgUtil_SceneView_P1__osgDB_DatabasePager_P1__osg_GraphicsThread_P1,
|
||||
"",
|
||||
"");
|
||||
I_SimpleProperty(double, ConservativeTimeRatio,
|
||||
__double__getConservativeTimeRatio,
|
||||
__void__setConservativeTimeRatio__double);
|
||||
I_SimpleProperty(bool, Done,
|
||||
__bool__getDone,
|
||||
__void__setDone__bool);
|
||||
I_SimpleProperty(double, FlushTimeRatio,
|
||||
__double__getFlushTimeRatio,
|
||||
__void__setFlushTimeRatio__double);
|
||||
I_SimpleProperty(bool, GraphicsThreadDoesCull,
|
||||
__bool__getGraphicsThreadDoesCull,
|
||||
__void__setGraphicsThreadDoesCull__bool);
|
||||
I_SimpleProperty(double, MinimumTimeAvailableForGLCompileAndDeletePerFrame,
|
||||
__double__getMinimumTimeAvailableForGLCompileAndDeletePerFrame,
|
||||
__void__setMinimumTimeAvailableForGLCompileAndDeletePerFrame__double);
|
||||
I_SimpleProperty(double, TargetFrameRate,
|
||||
__double__getTargetFrameRate,
|
||||
__void__setTargetFrameRate__double);
|
||||
END_REFLECTOR
|
||||
|
||||
STD_LIST_REFLECTOR(std::list< osgViewer::OpenGLQuerySupport::QueryFrameNumberPair >)
|
||||
|
Loading…
Reference in New Issue
Block a user