]> git.cworth.org Git - fips/commitdiff
Cleanup outstanding counters at context change.
authorCarl Worth <cworth@cworth.org>
Thu, 24 Oct 2013 02:47:20 +0000 (19:47 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 24 Oct 2013 17:20:11 +0000 (10:20 -0700)
Without this, and given an application that calls glxMakeCurrent (or
similar) the implementation gets quite confused as fips starts
requesting query results for counter IDs that were only valid for the
previous context.

eglwrap.c
glxwrap.c
metrics.c
metrics.h

index 497779ce3fd2048f03f518a98f51c70575c37d07..73b7a8d39699001dab539a2c54a0875d6120fad0 100644 (file)
--- a/eglwrap.c
+++ b/eglwrap.c
@@ -108,6 +108,8 @@ eglMakeCurrent (EGLDisplay display, EGLSurface draw, EGLSurface read,
 {
        EGLBoolean ret;
 
+       metrics_info_fini ();
+
        fips_dispatch_init (FIPS_API_EGL);
 
        EGLWRAP_DEFER_WITH_RETURN (ret, eglMakeCurrent, display, draw, read, context);
index 9a28d7d0f231cb395b818ceadee564e1a3767cca..14b79b7b3b1e09dc79e65e0acaf72db212d5d133 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
@@ -84,6 +84,8 @@ glXMakeCurrent (Display *dpy, GLXDrawable drawable, GLXContext ctx)
 {
        Bool ret;
 
+       metrics_info_fini ();
+
        fips_dispatch_init (FIPS_API_GLX);
 
        GLWRAP_DEFER_WITH_RETURN (ret, glXMakeCurrent, dpy, drawable, ctx);
@@ -101,6 +103,8 @@ glXMakeContextCurrent (Display *dpy, GLXDrawable drawable, GLXDrawable read, GLX
 {
        Bool ret;
 
+       metrics_info_fini ();
+
        fips_dispatch_init (FIPS_API_GLX);
 
        GLWRAP_DEFER_WITH_RETURN (ret, glXMakeContextCurrent, dpy, drawable, read, ctx);
index 71fe82da1b3d5ff06cf6dd94aa541f14f0b38a33..c24ae3f27d298cfb7c5a692ef855ebd168534c78 100644 (file)
--- a/metrics.c
+++ b/metrics.c
@@ -191,9 +191,6 @@ metrics_group_info_fini (metrics_group_info_t *group)
        free (group->name);
 }
 
-static void
-metrics_info_fini (metrics_info_t *info);
-
 /* A helper function, part of metrics_info_init below. */
 
 typedef enum {
@@ -265,9 +262,6 @@ metrics_info_init (void)
        GLuint *group_ids;
        metrics_info_t *info = &current_context.metrics_info;
 
-       if (info->initialized)
-               metrics_info_fini (info);
-
        glGetPerfMonitorGroupsAMD ((int *) &info->num_groups, 0, NULL);
 
        group_ids = xmalloc (info->num_groups * sizeof (GLuint));
@@ -306,20 +300,50 @@ metrics_info_init (void)
        info->initialized = 1;
 }
 
-static void
-metrics_info_fini (metrics_info_t *info)
+void
+metrics_info_fini (void)
 {
+       metrics_info_t *info = &current_context.metrics_info;
        unsigned i;
+       timer_query_t *timer, *timer_next;
+       monitor_t *monitor, *monitor_next;
+
+       if (! info->initialized)
+               return;
+
+       for (timer = current_context.timer_head;
+            timer;
+            timer = timer_next)
+       {
+               timer_next = timer->next;
+               free (timer);
+       }
+       current_context.timer_head = NULL;
+       current_context.timer_tail = NULL;
+
+       for (monitor = current_context.monitor_head;
+            monitor;
+            monitor = monitor_next)
+       {
+               monitor_next = monitor->next;
+               free (monitor);
+       }
+       current_context.monitor_head = NULL;
+       current_context.monitor_tail = NULL;
 
        for (i = 0; i < info->num_groups; i++)
                metrics_group_info_fini (&info->groups[i]);
 
        free (info->groups);
+       info->groups = NULL;
 
        for (i = 0; i < info->num_shader_stages; i++)
                free (info->stages[i].name);
 
        free (info->stages);
+       info->stages = NULL;
+
+       info->initialized = 0;
 }
 
 static const char *
@@ -776,7 +800,7 @@ metrics_exit (void)
        if (verbose)
                printf ("fips: terminating\n");
 
-       metrics_info_fini (&current_context.metrics_info);
+       metrics_info_fini ();
 }
 
 
index accafe5f8e91f2660e46687dfc39cbf959b107cc..4beda7f5e41b1eddfb959b29b9a0a2583bf0b73b 100644 (file)
--- a/metrics.h
+++ b/metrics.h
@@ -59,6 +59,14 @@ typedef enum
 void
 metrics_info_init (void);
 
+/* Finalize metrics info state.
+ *
+ * The function should be called just before setting a new, current,
+ * OpenGL context.
+ */
+void
+metrics_info_fini (void);
+
 /* Start accumulating GPU time.
  *
  * The time accumulated will be accounted against the