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);
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);
GLWRAP_DEFER (glEnd);
if (! inside_new_list) {
- glEndQuery (GL_TIME_ELAPSED);
+ metrics_counter_stop ();
}
}
context_t current_context;
unsigned
-metrics_add_counter (void)
+metrics_counter_new (void)
{
counter_t *counter;
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)
{
* 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.
*