+ glEndPerfMonitorAMD (ctx->monitor_begun_id);
+
+ /* Add these IDs to our lists of outstanding queries and
+ * monitors so the results can be collected later. */
+ timer = xmalloc (sizeof (timer_query_t));
+
+ timer->op = ctx->op;
+ timer->id = ctx->timer_begun_id;
+ timer->next = NULL;
+
+ if (ctx->timer_tail) {
+ ctx->timer_tail->next = timer;
+ ctx->timer_tail = timer;
+ } else {
+ ctx->timer_tail = timer;
+ ctx->timer_head = timer;
+ }
+
+ /* Create a new performance-monitor query */
+ monitor = xmalloc (sizeof (monitor_t));
+
+ monitor->op = ctx->op;
+ monitor->id = ctx->monitor_begun_id;
+ monitor->next = NULL;
+
+ if (ctx->monitor_tail) {
+ ctx->monitor_tail->next = monitor;
+ ctx->monitor_tail = monitor;
+ } else {
+ ctx->monitor_tail = monitor;
+ ctx->monitor_head = monitor;
+ }
+
+ ctx->monitors_in_flight++;
+
+ /* Avoid being a resource hog and collect outstanding results
+ * once we have sent off a large number of
+ * queries. (Presumably, many of the outstanding queries are
+ * available by now.)
+ */
+ if (ctx->monitors_in_flight > MAX_MONITORS_IN_FLIGHT)
+ metrics_collect_available ();