+ /* Initialize the timer_query object. */
+ glGenQueries (1, &metrics->timer_begun_id);
+
+ /* Most everything else in this function is
+ * performance-monitor related. If we don't have that
+ * extension, just start the timer query and be done. */
+ if (! metrics->info->have_perfmon) {
+ glBeginQuery (GL_TIME_ELAPSED, metrics->timer_begun_id);
+ return;
+ }
+
+ /* Initialize the performance-monitor object */
+ glGenPerfMonitorsAMD (1, &metrics->monitor_begun_id);
+
+ for (i = 0; i < metrics->info->num_groups; i++)
+ {
+ metrics_group_info_t *group;
+ int num_counters;
+
+ group = &metrics->info->groups[i];
+
+ num_counters = group->num_counters;
+ if (group->max_active_counters < group->num_counters)
+ {
+ fprintf (stderr, "Warning: Only monitoring %d/%d counters from group %d\n",
+ group->max_active_counters,
+ group->num_counters, i);
+ num_counters = group->max_active_counters;
+
+ }
+
+ glSelectPerfMonitorCountersAMD(metrics->monitor_begun_id,
+ GL_TRUE, group->id,
+ num_counters,
+ group->counter_ids);
+ }
+
+ /* Start the queries */
+ glBeginQuery (GL_TIME_ELAPSED, metrics->timer_begun_id);
+
+ glBeginPerfMonitorAMD (metrics->monitor_begun_id);
+}
+
+void
+metrics_counter_stop (metrics_t *metrics)
+{
+ timer_query_t *timer;
+ monitor_t *monitor;
+
+ /* Stop the current timer and monitor. */
+ glEndQuery (GL_TIME_ELAPSED);
+
+ if (metrics->info->have_perfmon)
+ glEndPerfMonitorAMD (metrics->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 = metrics->op;
+ timer->id = metrics->timer_begun_id;
+ timer->next = NULL;
+
+ if (metrics->timer_tail) {
+ metrics->timer_tail->next = timer;
+ metrics->timer_tail = timer;