From Tim More and Robert Osfield, implementation of ARB_timer_query based GPU timing stats syncronization.

Initial email from Tim : "I've implemented using a timestamp, available with ARB_timer_query and OpenGL 3.3, to gather GPU stats. This is nice because it can accurately fix the GPU draw time with respect to the other times on the stats graph, rather than having to estimate the wall time of the end of GPU drawing. This also prevents anomalies like the GPU phase starting before the draw phase..."
Changes to Tim's submission by Robert:  Removal of need for swap buffer callback in ViewerBase.cpp, by
integrating a osg::State::frameCompleted() method that does the stats timing collection.  Introduction of a
GraphicsContext::swapBuffersCallbackOrImplementation() method that calls the State::frameCompleted() and
the swap buffers callback or the swapImplementation as required.
This commit is contained in:
Robert Osfield
2010-11-10 16:58:58 +00:00
parent 40c6d99c15
commit 68f37c4dcb
9 changed files with 352 additions and 120 deletions

View File

@@ -20,6 +20,7 @@
#include <osg/Uniform>
#include <osg/BufferObject>
#include <osg/Observer>
#include <osg/Timer>
#include <osg/ShaderComposer>
#include <osg/FrameStamp>
@@ -1366,6 +1367,31 @@ class OSG_EXPORT State : public Referenced, public Observer
/** get the helper class for dispatching osg::Arrays as OpenGL attribute data.*/
inline ArrayDispatchers& getArrayDispatchers() { return _arrayDispatchers; }
/** Support for synchronizing the system time and the timestamp
* counter available with ARB_timer_query. Note that State
* doesn't update these values itself.
*/
Timer_t getStartTick() const { return _startTick; }
void setStartTick(Timer_t tick) { _startTick = tick; }
Timer_t getGpuTick() const { return _gpuTick; }
double getGpuTime() const
{
return osg::Timer::instance()->delta_s(_startTick, _gpuTick);
}
GLuint64EXT getGpuTimestamp() const { return _gpuTimestamp; }
void setGpuTimestamp(Timer_t tick, GLuint64EXT timestamp)
{
_gpuTick = tick;
_gpuTimestamp = timestamp;
}
int getTimestampBits() const { return _timestampBits; }
void setTimestampBits(int bits) { _timestampBits = bits; }
/** called by the GraphicsContext just before GraphicsContext::swapBuffersImplementation().*/
virtual void frameCompleted();
protected:
virtual ~State();
@@ -1776,7 +1802,10 @@ class OSG_EXPORT State : public Referenced, public Observer
GLBeginEndAdapter _glBeginEndAdapter;
ArrayDispatchers _arrayDispatchers;
Timer_t _startTick;
Timer_t _gpuTick;
GLuint64EXT _gpuTimestamp;
int _timestampBits;
};
inline void State::pushModeList(ModeMap& modeMap,const StateSet::ModeList& modeList)