From 499af6e2043af80750f5b2a2866ebb430e085851 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 24 May 2013 11:11:15 -0700 Subject: [PATCH] Avoid inserting timer queries while constructing a display list We only want to time actual drawing operations. When between glNewList and glEndList, calls that look like drawing operations are not really, instead these are just calls that are being recorded to be later executed with glCallList. (And it won't work to put our timer queries inside the display list.) So, track when we are within glNewList/glEndList and don't add timer queries. Instead, we will time these operations as a whole with a timer query around the glCallList call itself. --- glwrap.c | 36 +++++++++++++++++++++++++++++------- libfips.sym | 2 ++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/glwrap.c b/glwrap.c index a90ef8c..8e8b64d 100644 --- a/glwrap.c +++ b/glwrap.c @@ -47,6 +47,8 @@ #include "dlwrap.h" +static int inside_new_list = 0; + void * glwrap_lookup (char *name) { @@ -65,13 +67,17 @@ glwrap_lookup (char *name) return dlwrap_real_dlsym (libgl_handle, name); } -/* Execute a glBegineQuery/glEndQuery pair around an OpenGL call. */ -#define TIMED_DEFER(function,...) do { \ - unsigned counter; \ - counter = metrics_add_counter (); \ - glBeginQuery (GL_TIME_ELAPSED, counter); \ - GLWRAP_DEFER(function, __VA_ARGS__); \ - glEndQuery (GL_TIME_ELAPSED); \ +/* Execute a glBeginQuery/glEndQuery pair around an OpenGL call. */ +#define TIMED_DEFER(function,...) do { \ + if (! inside_new_list) { \ + unsigned counter; \ + counter = metrics_add_counter (); \ + glBeginQuery (GL_TIME_ELAPSED, counter); \ + } \ + GLWRAP_DEFER(function, __VA_ARGS__); \ + if (! inside_new_list) { \ + glEndQuery (GL_TIME_ELAPSED); \ + } \ } while (0); /* Thanks to apitrace source code for the list of OpenGL draw calls. */ @@ -358,6 +364,22 @@ glEnd (void) } } +/* And we need to track display lists to avoid inserting queries + * inside the list while it's being constructed. */ +void +glNewList (GLuint list, GLenum mode) +{ + inside_new_list = 1; + GLWRAP_DEFER (glNewList, list, mode); +} + +void +glEndList (void) +{ + GLWRAP_DEFER (glEndList); + inside_new_list = 0; +} + void glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) diff --git a/libfips.sym b/libfips.sym index 6ad1337..f703cb7 100644 --- a/libfips.sym +++ b/libfips.sym @@ -36,6 +36,8 @@ global: glClear; glBegin; glEnd; + glNewList; + glEndList; glDrawPixels; glBlitFramebuffer; glBlitFramebufferEXT; -- 2.43.0