summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-11-26 00:20:10 +0100
committerwm4 <wm4@nowhere>2015-11-26 00:20:10 +0100
commit8fc8d496f0c27c92b414b3b9753c262cd60bcf60 (patch)
tree17fd496a98952b9ffd42b3241943f368b52c9fb3
parent12eb8b2de8b0ce5a9c45dbcdf3befc5075a35c98 (diff)
downloadmpv-gl-query-timer.tar.bz2
mpv-gl-query-timer.tar.xz
query_timergl-query-timer
-rw-r--r--video/out/opengl/common.c15
-rw-r--r--video/out/opengl/common.h8
-rw-r--r--video/out/vo_opengl.c39
3 files changed, 62 insertions, 0 deletions
diff --git a/video/out/opengl/common.c b/video/out/opengl/common.c
index ae4384ec30..7d405cb97e 100644
--- a/video/out/opengl/common.c
+++ b/video/out/opengl/common.c
@@ -248,6 +248,21 @@ static const struct gl_functions gl_functions[] = {
{0}
},
},
+ {
+ .ver_core = 320,
+ .extension = "GL_ARB_timer_query",
+ .functions = (const struct gl_function[]) {
+ DEF_FN(GenQueries),
+ DEF_FN(DeleteQueries),
+ DEF_FN(QueryCounter),
+ DEF_FN(GetQueryObjectiv),
+ DEF_FN(GetQueryObjecti64v),
+ DEF_FN(GetQueryObjectui64v),
+ // Unclear whether it must exist for the extension
+ DEF_FN(GetInteger64v),
+ {0}
+ },
+ },
// Swap control, always an OS specific extension
// The OSX code loads this manually.
{
diff --git a/video/out/opengl/common.h b/video/out/opengl/common.h
index 8d5bbdbb6d..a9dd210626 100644
--- a/video/out/opengl/common.h
+++ b/video/out/opengl/common.h
@@ -252,6 +252,14 @@ struct GL {
GLenum (GLAPIENTRY *ClientWaitSync)(GLsync, GLbitfield, GLuint64);
void (GLAPIENTRY *DeleteSync)(GLsync sync);
+ void (GLAPIENTRY *GenQueries)(GLsizei, GLuint *);
+ void (GLAPIENTRY *DeleteQueries)(GLsizei, const GLuint *);
+ void (GLAPIENTRY *QueryCounter)(GLuint, GLenum);
+ void (GLAPIENTRY *GetQueryObjectiv)(GLuint, GLenum, GLint *);
+ void (GLAPIENTRY *GetQueryObjecti64v)(GLuint, GLenum, GLint64 *);
+ void (GLAPIENTRY *GetQueryObjectui64v)(GLuint, GLenum, GLuint64 *);
+ void (GLAPIENTRY *GetInteger64v)(GLenum, GLint64 *);
+
void (GLAPIENTRY *VDPAUInitNV)(const GLvoid *, const GLvoid *);
void (GLAPIENTRY *VDPAUFiniNV)(void);
GLvdpauSurfaceNV (GLAPIENTRY *VDPAURegisterOutputSurfaceNV)
diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c
index eb057d139f..f128af1134 100644
--- a/video/out/vo_opengl.c
+++ b/video/out/vo_opengl.c
@@ -53,6 +53,7 @@
#include "opengl/lcms.h"
#define NUM_VSYNC_FENCES 10
+#define NUM_VSYNC_QUERIES 10
struct gl_priv {
struct vo *vo;
@@ -90,6 +91,10 @@ struct gl_priv {
GLsync vsync_fences[NUM_VSYNC_FENCES];
int num_vsync_fences;
+
+ GLuint vsync_queries[NUM_VSYNC_QUERIES];
+ GLint64 vsync_starts[NUM_VSYNC_QUERIES];
+ int num_vsync_queries;
};
static void resize(struct gl_priv *p)
@@ -145,6 +150,40 @@ static void flip_page(struct vo *vo)
struct gl_priv *p = vo->priv;
GL *gl = p->gl;
+ assert(gl->QueryCounter);
+
+ GLint64 glnow = 0;
+ gl->GetInteger64v(GL_TIMESTAMP, &glnow);
+static int relframe;
+ if (p->num_vsync_queries >= NUM_VSYNC_QUERIES) {
+ MP_WARN(vo, "underflwo!!!!!\n");
+ } else {
+ gl->GenQueries(1, &p->vsync_queries[p->num_vsync_queries]);
+ gl->QueryCounter(p->vsync_queries[p->num_vsync_queries], GL_TIMESTAMP);
+ p->vsync_starts[p->num_vsync_queries] = glnow;
+ p->num_vsync_queries++;
+ relframe++;
+ }
+ while (p->num_vsync_queries) {
+ GLint ok = 0;
+ gl->GetQueryObjectiv(p->vsync_queries[0], GL_QUERY_RESULT_AVAILABLE, &ok);
+ if (!ok)
+ break;
+ relframe--;
+ GLint64 t = 0;
+ gl->GetQueryObjectui64v(p->vsync_queries[0], GL_QUERY_RESULT, &t);
+ if (t) {
+ int64_t dur = t - p->vsync_starts[0];
+ MP_WARN(vo, "frame %d took: %f ms, issued before %f ms\n", p->frames_rendered - relframe, dur / 1e6,
+ (glnow - p->vsync_starts[0]) / 1e6);
+ } else
+ abort();
+ gl->DeleteQueries(1, &p->vsync_queries[0]);
+ int d = p->num_vsync_queries;
+ MP_TARRAY_REMOVE_AT(p->vsync_queries, p->num_vsync_queries, 0);
+ MP_TARRAY_REMOVE_AT(p->vsync_starts, d, 0);
+ }
+
mpgl_swap_buffers(p->glctx);
p->frames_rendered++;