mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / performance_monitor.c
index 17cae5183627f32086c5c647ab8c4917e113c15f..e62f7701217b1e8903a7c6d07e9e2939b73240b5 100644 (file)
@@ -62,6 +62,10 @@ new_performance_monitor(struct gl_context *ctx, GLuint index)
    if (m == NULL)
       return NULL;
 
+   m->Name = index;
+
+   m->Active = false;
+
    m->ActiveGroups =
       rzalloc_array(NULL, unsigned, ctx->PerfMonitor.NumGroups);
 
@@ -89,6 +93,25 @@ fail:
    return NULL;
 }
 
+static void
+free_performance_monitor(GLuint key, void *data, void *user)
+{
+   struct gl_perf_monitor_object *m = data;
+   struct gl_context *ctx = user;
+
+   ralloc_free(m->ActiveGroups);
+   ralloc_free(m->ActiveCounters);
+   ctx->Driver.DeletePerfMonitor(ctx, m);
+}
+
+void
+_mesa_free_performance_monitors(struct gl_context *ctx)
+{
+   _mesa_HashDeleteAll(ctx->PerfMonitor.Monitors,
+                       free_performance_monitor, ctx);
+   _mesa_DeleteHashTable(ctx->PerfMonitor.Monitors);
+}
+
 static inline struct gl_perf_monitor_object *
 lookup_monitor(struct gl_context *ctx, GLuint id)
 {
@@ -355,8 +378,10 @@ _mesa_DeletePerfMonitorsAMD(GLsizei n, GLuint *monitors)
 
       if (m) {
          /* Give the driver a chance to stop the monitor if it's active. */
-         if (m->Active)
+         if (m->Active) {
             ctx->Driver.ResetPerfMonitor(ctx, m);
+            m->Ended = false;
+         }
 
          _mesa_HashRemove(ctx->PerfMonitor.Monitors, monitors[i]);
          ralloc_free(m->ActiveGroups);
@@ -474,6 +499,7 @@ _mesa_BeginPerfMonitorAMD(GLuint monitor)
     */
    if (ctx->Driver.BeginPerfMonitor(ctx, m)) {
       m->Active = true;
+      m->Ended = false;
    } else {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glBeginPerfMonitor(driver unable to begin monitoring)");
@@ -503,6 +529,7 @@ _mesa_EndPerfMonitorAMD(GLuint monitor)
    ctx->Driver.EndPerfMonitor(ctx, m);
 
    m->Active = false;
+   m->Ended = true;
 }
 
 /**
@@ -539,6 +566,7 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname,
    GET_CURRENT_CONTEXT(ctx);
 
    struct gl_perf_monitor_object *m = lookup_monitor(ctx, monitor);
+   bool result_available;
 
    if (m == NULL) {
       _mesa_error(ctx, GL_INVALID_VALUE,
@@ -560,8 +588,12 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname,
       return;
    }
 
+   /* If the monitor has never ended, there is no result. */
+   result_available = m->Ended &&
+      ctx->Driver.IsPerfMonitorResultAvailable(ctx, m);
+
    /* AMD appears to return 0 for all queries unless a result is available. */
-   if (!ctx->Driver.IsPerfMonitorResultAvailable(ctx, m)) {
+   if (!result_available) {
       *data = 0;
       if (bytesWritten != NULL)
          *bytesWritten = sizeof(GLuint);