From 6dcb864fcfa77c4bf4eb7e1c04f00e53f9fee446 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 23 Oct 2013 19:47:20 -0700 Subject: [PATCH] Cleanup outstanding counters at context change. 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 | 2 ++ glxwrap.c | 4 ++++ metrics.c | 42 +++++++++++++++++++++++++++++++++--------- metrics.h | 8 ++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/eglwrap.c b/eglwrap.c index 497779c..73b7a8d 100644 --- 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); diff --git a/glxwrap.c b/glxwrap.c index 9a28d7d..14b79b7 100644 --- 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); diff --git a/metrics.c b/metrics.c index 71fe82d..c24ae3f 100644 --- 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 = ¤t_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 = ¤t_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 (¤t_context.metrics_info); + metrics_info_fini (); } diff --git a/metrics.h b/metrics.h index accafe5..4beda7f 100644 --- 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 -- 2.43.0