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

@@ -844,6 +844,7 @@ Drawable::Extensions::Extensions(const Extensions& rhs):
_isMultiTexSupported = rhs._isMultiTexSupported;
_isOcclusionQuerySupported = rhs._isOcclusionQuerySupported;
_isTimerQuerySupported = rhs._isTimerQuerySupported;
_isARBTimerQuerySupported = rhs._isARBTimerQuerySupported;
_glFogCoordfv = rhs._glFogCoordfv;
_glSecondaryColor3ubv = rhs._glSecondaryColor3ubv;
@@ -880,6 +881,7 @@ Drawable::Extensions::Extensions(const Extensions& rhs):
_gl_get_query_objectiv_arb = rhs._gl_get_query_objectiv_arb;
_gl_get_query_objectuiv_arb = rhs._gl_get_query_objectuiv_arb;
_gl_get_query_objectui64v = rhs._gl_get_query_objectui64v;
_glGetInteger64v = rhs._glGetInteger64v;
}
@@ -893,6 +895,7 @@ void Drawable::Extensions::lowestCommonDenominator(const Extensions& rhs)
if (!rhs._isARBOcclusionQuerySupported) _isARBOcclusionQuerySupported = false;
if (!rhs._isTimerQuerySupported) _isTimerQuerySupported = false;
if (!rhs._isARBTimerQuerySupported) _isARBTimerQuerySupported = false;
if (!rhs._glFogCoordfv) _glFogCoordfv = 0;
if (!rhs._glSecondaryColor3ubv) _glSecondaryColor3ubv = 0;
@@ -939,6 +942,7 @@ void Drawable::Extensions::lowestCommonDenominator(const Extensions& rhs)
if (!rhs._gl_get_query_objectiv_arb) _gl_get_query_objectiv_arb = 0;
if (!rhs._gl_get_query_objectuiv_arb) _gl_get_query_objectuiv_arb = 0;
if (!rhs._gl_get_query_objectui64v) _gl_get_query_objectui64v = 0;
if (!rhs._glGetInteger64v) _glGetInteger64v = 0;
}
void Drawable::Extensions::setupGLExtensions(unsigned int contextID)
@@ -950,7 +954,8 @@ void Drawable::Extensions::setupGLExtensions(unsigned int contextID)
_isOcclusionQuerySupported = osg::isGLExtensionSupported(contextID, "GL_NV_occlusion_query" );
_isARBOcclusionQuerySupported = OSG_GL3_FEATURES || osg::isGLExtensionSupported(contextID, "GL_ARB_occlusion_query" );
_isTimerQuerySupported = osg::isGLExtensionSupported(contextID, "GL_EXT_timer_query" );;
_isTimerQuerySupported = osg::isGLExtensionSupported(contextID, "GL_EXT_timer_query" );
_isARBTimerQuerySupported = osg::isGLExtensionSupported(contextID, "GL_ARB_timer_query");
setGLExtensionFuncPtr(_glFogCoordfv, "glFogCoordfv","glFogCoordfvEXT");
@@ -1008,6 +1013,8 @@ void Drawable::Extensions::setupGLExtensions(unsigned int contextID)
setGLExtensionFuncPtr(_gl_get_query_objectiv_arb, "glGetQueryObjectiv","glGetQueryObjectivARB");
setGLExtensionFuncPtr(_gl_get_query_objectuiv_arb, "glGetQueryObjectuiv","glGetQueryObjectuivARB");
setGLExtensionFuncPtr(_gl_get_query_objectui64v, "glGetQueryObjectui64v","glGetQueryObjectui64vEXT");
setGLExtensionFuncPtr(_glQueryCounter, "glQueryCounter");
setGLExtensionFuncPtr(_glGetInteger64v, "glGetInteger64v");
}
void Drawable::Extensions::glFogCoordfv(const GLfloat* coord) const
@@ -1471,6 +1478,14 @@ void Drawable::Extensions::glEndQuery(GLenum target) const
OSG_WARN << "Error: glEndQuery not supported by OpenGL driver" << std::endl;
}
void Drawable::Extensions::glQueryCounter(GLuint id, GLenum target) const
{
if (_glQueryCounter)
_glQueryCounter(id, target);
else
OSG_WARN << "Error: glQueryCounter not supported by OpenGL driver\n";
}
GLboolean Drawable::Extensions::glIsQuery(GLuint id) const
{
if (_gl_is_query_arb) return _gl_is_query_arb(id);
@@ -1510,3 +1525,12 @@ void Drawable::Extensions::glGetQueryObjectui64v(GLuint id, GLenum pname, GLuint
else
OSG_WARN << "Error: glGetQueryObjectui64v not supported by OpenGL driver" << std::endl;
}
void Drawable::Extensions::glGetInteger64v(GLenum pname, GLint64EXT *params)
const
{
if (_glGetInteger64v)
_glGetInteger64v(pname, params);
else
OSG_WARN << "Error: glGetInteger64v not supported by OpenGL driver\n";
}