]> git.cworth.org Git - fips/commitdiff
Push glBeginQuery/glEndQuery down into metrics.c
authorCarl Worth <cworth@yoom.(none)>
Mon, 24 Jun 2013 22:24:20 +0000 (22:24 +0000)
committerCarl Worth <cworth@cworth.org>
Mon, 24 Jun 2013 22:27:06 +0000 (15:27 -0700)
The code in metrics.c was already using dynamic dispatch for OpenGL functions.

But the code in glwrap is now, (and cannot since it relies on "real" OpenGL
header files to ensure the wrapped functions have the correct prototypes).

This resulted in link failures since these functions were not called via
dynamic dispatch.

Gix by adding new metrics_counter_start and metrics_counter_stop functions which
call the glBeginQuery/glEndQuery functions via dynamic dispatch.

fips-dispatch-gl.h
glwrap.c
metrics.c
metrics.h

index 928d1396f7852d01761213e0a1de66575488d8f2..f70f4b82cd48df8f7c36fa641b89ef9d02fca04e 100644 (file)
@@ -71,6 +71,7 @@ typedef void (*PFNGLGETQUERYOBJECTUIVPROC)(GLuint, GLenum, GLuint *);
 
 #define GL_QUERY_RESULT 0x8866
 #define GL_QUERY_RESULT_AVAILABLE 0x8867
+#define GL_TIME_ELAPSED 0x88BF
 
 extern PFNGLGENQUERIESPROC fips_dispatch_glGenQueries;
 #define glGenQueries fips_dispatch_glGenQueries
index bcb8111a03e990baa9298c3c939f2f77494a11ad..a7d62c5c1ef2be57d650591302923197c0fbb05f 100644 (file)
--- a/glwrap.c
+++ b/glwrap.c
@@ -67,16 +67,16 @@ glwrap_lookup (char *name)
        return dlwrap_real_dlsym (libgl_handle, name);
 }
 
-/* Execute a glBeginQuery/glEndQuery pair around an OpenGL call. */
+/* Execute an OpenGL call and time it with a GPU metrics counter. */
 #define TIMED_DEFER(function,...) do {                                 \
        if (! inside_new_list) {                                        \
                unsigned counter;                                       \
-               counter = metrics_add_counter ();                       \
-               glBeginQuery (GL_TIME_ELAPSED, counter);                \
+               counter = metrics_counter_new ();                       \
+               metrics_counter_start (counter);                        \
        }                                                               \
        GLWRAP_DEFER(function, __VA_ARGS__);                            \
        if (! inside_new_list) {                                        \
-               glEndQuery (GL_TIME_ELAPSED);                           \
+               metrics_counter_stop ();                                \
        }                                                               \
 } while (0);
 
@@ -337,17 +337,18 @@ glClear (GLbitfield mask)
        TIMED_DEFER (glClear, mask);
 }
 
-/* We can't just use TIMED_DEFER for glBegin/glEnd since the
- * glBeginQuery/glEndQuery calls must both be outside
- * glBegin/glEnd. */
+/* We can't just use TIMED_DEFER for glBegin/glEnd since the metrics
+ * counter must be started before glBegin and stopped after glEnd,
+ * (that is, everything from glBegin to glEnd is counted as a single
+ * operation). */
 void
 glBegin (GLenum mode)
 {
        if (! inside_new_list)
        {
                unsigned counter;
-               counter = metrics_add_counter ();
-               glBeginQuery (GL_TIME_ELAPSED, counter);
+               counter = metrics_counter_new ();
+               metrics_counter_start (counter);
        }
 
        GLWRAP_DEFER (glBegin, mode);
@@ -359,7 +360,7 @@ glEnd (void)
        GLWRAP_DEFER (glEnd);
 
        if (! inside_new_list) {
-               glEndQuery (GL_TIME_ELAPSED);
+               metrics_counter_stop ();
        }
 }
 
index 7298fa82bb093ba225371132e03abb1339df3077..84fc23f6b20b02a2a15ece51ee9b63447d4e5466 100644 (file)
--- a/metrics.c
+++ b/metrics.c
@@ -58,7 +58,7 @@ typedef struct context
 context_t current_context;
 
 unsigned
-metrics_add_counter (void)
+metrics_counter_new (void)
 {
        counter_t *counter;
 
@@ -84,6 +84,18 @@ metrics_add_counter (void)
        return counter->id;
 }
 
+void
+metrics_counter_start (unsigned counter)
+{
+       glBeginQuery (GL_TIME_ELAPSED, counter);
+}
+
+void
+metrics_counter_stop (void)
+{
+       glEndQuery (GL_TIME_ELAPSED);
+}
+
 void
 metrics_set_current_program (unsigned program)
 {
index 261a5a5c13fe3a5771544479d3a02b3ed58f04e2..2d93d908d39026cf1fd4b0b8fda9bd199d24f0ef 100644 (file)
--- a/metrics.h
+++ b/metrics.h
  * The value accumulated in this counter be accounted against the
  * current program (as set with metrics_set_current_program).
  *
- * Returns: A counter ID suitable for use with glBeginQuery/glEndQuery
+ * Returns: A counter ID suitable for use with metrics_counter_start
+ * and metrics_counter_stop.
  */
 unsigned
-metrics_add_counter (void);
+metrics_counter_new (void);
+
+/* Start accumulating GPU time spent into the given counter. */
+void
+metrics_counter_start (unsigned counter);
+
+/* Stop accumulating GPU time (stops the most-recently started counter) */
+void
+metrics_counter_stop (void);
 
 /* Set the ID of the currently executing shader program.
  *