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

@@ -21,38 +21,23 @@
namespace osgViewer {
class OSGVIEWER_EXPORT OpenGLQuerySupport
class OSGVIEWER_EXPORT OpenGLQuerySupport : public osg::Referenced
{
public:
OpenGLQuerySupport();
typedef std::pair<GLuint, int> QueryFrameNumberPair;
typedef std::list<QueryFrameNumberPair> QueryFrameNumberList;
typedef std::vector<GLuint> QueryList;
void setStartTick(osg::Timer_t startTick) { _startTick = startTick; }
osg::Timer_t getStartTick() const { return _startTick; }
void checkQuery(osg::Stats* stats);
virtual void checkQuery(osg::Stats* stats, osg::State* state,
osg::Timer_t startTick) = 0;
GLuint createQueryObject();
void beginQuery(int frameNumber);
void endQuery();
void initialize(osg::State* state);
virtual void beginQuery(int frameNumber, osg::State* state) = 0;
virtual void endQuery(osg::State* state) = 0;
virtual void initialize(osg::State* state, osg::Timer_t startTick);
protected:
osg::Timer_t _startTick;
bool _initialized;
bool _timerQuerySupported;
const osg::Drawable::Extensions* _extensions;
QueryFrameNumberList _queryFrameNumberList;
QueryList _availableQueryObjects;
double _previousQueryTime;
};
class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQuerySupport
class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation
{
public:
@@ -132,7 +117,7 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQu
bool getCameraRequiresSetUp() const;
protected:
void initialize(osg::State* state);
virtual ~Renderer();
virtual void updateSceneView(osgUtil::SceneView* sceneView);
@@ -178,6 +163,9 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQu
ThreadSafeQueue _availableQueue;
ThreadSafeQueue _drawQueue;
bool _initialized;
osg::ref_ptr<OpenGLQuerySupport> _querySupport;
osg::Timer_t _startTick;
};
}