From 6087f63003351812996823877a4abbd51a1f9530 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Tue, 8 Aug 2017 17:06:45 +0200 Subject: vo_opengl: go back to using GL_TIME_ELAPSED Less flexible than GL_TIMESTAMP but supported by more platforms. This will mean that nested queries have to be detected and silently omitted, but oh well. Not much use for them anyway. Fixes #4721. --- video/out/opengl/ra_gl.c | 41 +++++++++++++++++++++++++---------------- video/out/opengl/ra_gl.h | 1 + 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/video/out/opengl/ra_gl.c b/video/out/opengl/ra_gl.c index 7783baf2f1..18689abe05 100644 --- a/video/out/opengl/ra_gl.c +++ b/video/out/opengl/ra_gl.c @@ -919,10 +919,10 @@ static void gl_renderpass_run(struct ra *ra, #define GL_QUERY_OBJECT_NUM 8 struct gl_timer { - GLuint start[GL_QUERY_OBJECT_NUM]; - GLuint stop[GL_QUERY_OBJECT_NUM]; + GLuint query[GL_QUERY_OBJECT_NUM]; int idx; uint64_t result; + bool active; }; static ra_timer *gl_timer_create(struct ra *ra) @@ -933,8 +933,7 @@ static ra_timer *gl_timer_create(struct ra *ra) return NULL; struct gl_timer *timer = talloc_zero(NULL, struct gl_timer); - gl->GenQueries(GL_QUERY_OBJECT_NUM, timer->start); - gl->GenQueries(GL_QUERY_OBJECT_NUM, timer->stop); + gl->GenQueries(GL_QUERY_OBJECT_NUM, timer->query); return (ra_timer *)timer; } @@ -947,35 +946,45 @@ static void gl_timer_destroy(struct ra *ra, ra_timer *ratimer) GL *gl = ra_gl_get(ra); struct gl_timer *timer = ratimer; - gl->DeleteQueries(GL_QUERY_OBJECT_NUM, timer->start); - gl->DeleteQueries(GL_QUERY_OBJECT_NUM, timer->stop); + gl->DeleteQueries(GL_QUERY_OBJECT_NUM, timer->query); talloc_free(timer); } static void gl_timer_start(struct ra *ra, ra_timer *ratimer) { - GL *gl = ra_gl_get(ra); + struct ra_gl *p = ra->priv; + GL *gl = p->gl; struct gl_timer *timer = ratimer; + // GL_TIME_ELAPSED queries are not re-entrant, so just do nothing instead + // of crashing. Work-around for shitty GL limitations + if (p->timer_active) + return; + // If this query object already contains a result, we need to retrieve it timer->result = 0; - if (gl->IsQuery(timer->start[timer->idx])) { - uint64_t start = 0, stop = 0; - gl->GetQueryObjectui64v(timer->start[timer->idx], GL_QUERY_RESULT, &start); - gl->GetQueryObjectui64v(timer->stop[timer->idx], GL_QUERY_RESULT, &stop); - timer->result = stop - start; + if (gl->IsQuery(timer->query[timer->idx])) { + gl->GetQueryObjectui64v(timer->query[timer->idx], GL_QUERY_RESULT, + &timer->result); } - gl->QueryCounter(timer->start[timer->idx], GL_TIMESTAMP); + gl->BeginQuery(GL_TIME_ELAPSED, timer->query[timer->idx++]); + timer->idx %= GL_QUERY_OBJECT_NUM; + + p->timer_active = timer->active = true; } static uint64_t gl_timer_stop(struct ra *ra, ra_timer *ratimer) { - GL *gl = ra_gl_get(ra); + struct ra_gl *p = ra->priv; + GL *gl = p->gl; struct gl_timer *timer = ratimer; - gl->QueryCounter(timer->stop[timer->idx++], GL_TIMESTAMP); - timer->idx %= GL_QUERY_OBJECT_NUM; + if (!timer->active) + return 0; + + gl->EndQuery(GL_TIME_ELAPSED); + p->timer_active = timer->active = false; return timer->result; } diff --git a/video/out/opengl/ra_gl.h b/video/out/opengl/ra_gl.h index 08f0197433..3b6202cbfb 100644 --- a/video/out/opengl/ra_gl.h +++ b/video/out/opengl/ra_gl.h @@ -8,6 +8,7 @@ struct ra_gl { GL *gl; bool debug_enable; + bool timer_active; // hack for GL_TIME_ELAPSED limitations }; // For ra_tex.priv -- cgit v1.2.3