Skip to content

Commit

Permalink
vo_opengl: go back to using GL_TIME_ELAPSED
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haasn committed Aug 8, 2017
1 parent 7f9193b commit 6087f63
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
41 changes: 25 additions & 16 deletions video/out/opengl/ra_gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions video/out/opengl/ra_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6087f63

Please sign in to comment.