+ /* Consume all timer queries that are ready. */
+ timer_query_t *timer = metrics->timer_head;
+
+ while (timer) {
+ GLuint available, elapsed;
+
+ glGetQueryObjectuiv (timer->id,
+ GL_QUERY_RESULT_AVAILABLE, &available);
+ if (! available)
+ break;
+
+ glGetQueryObjectuiv (timer->id,
+ GL_QUERY_RESULT, &elapsed);
+
+ accumulate_program_time (metrics, timer->op, elapsed);
+
+ metrics->timer_head = timer->next;
+ if (metrics->timer_head == NULL)
+ metrics->timer_tail = NULL;
+
+ glDeleteQueries (1, &timer->id);
+
+ free (timer);
+ timer = metrics->timer_head;
+ }
+
+ /* And similarly for all performance monitors that are ready. */
+ monitor_t *monitor = metrics->monitor_head;
+
+ while (monitor) {
+ GLuint available, result_size, *result;
+ GLint bytes_written;
+
+ glGetPerfMonitorCounterDataAMD (monitor->id,
+ GL_PERFMON_RESULT_AVAILABLE_AMD,
+ sizeof (available), &available,
+ NULL);
+ if (! available)
+ break;
+
+ glGetPerfMonitorCounterDataAMD (monitor->id,
+ GL_PERFMON_RESULT_SIZE_AMD,
+ sizeof (result_size),
+ &result_size, NULL);
+
+ result = xmalloc (result_size);
+
+ glGetPerfMonitorCounterDataAMD (monitor->id,
+ GL_PERFMON_RESULT_AMD,
+ result_size, result,
+ &bytes_written);
+
+ accumulate_program_metrics (metrics, monitor->op, result, result_size);
+
+ free (result);
+
+ metrics->monitor_head = monitor->next;
+ if (metrics->monitor_head == NULL)
+ metrics->monitor_tail = NULL;
+
+ glDeletePerfMonitorsAMD (1, &monitor->id);
+
+ free (monitor);
+
+ metrics->monitors_in_flight--;
+
+ monitor = metrics->monitor_head;
+ }