iris/perf: get monitor results
authorMark Janes <mark.a.janes@intel.com>
Wed, 3 Jul 2019 23:13:26 +0000 (16:13 -0700)
committerMark Janes <mark.a.janes@intel.com>
Sat, 10 Aug 2019 02:28:32 +0000 (19:28 -0700)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/iris/iris_monitor.c
src/gallium/drivers/iris/iris_monitor.h

index e072bf6b5a874e8b8e90a1b05f88bf2f570513dc..0e4d497fe406a3679c12db1fde0ed15cd568ff94 100644 (file)
@@ -411,3 +411,63 @@ iris_end_monitor(struct pipe_context *ctx,
    gen_perf_end_query(perf_ctx, monitor->query);
    return true;
 }
+
+bool
+iris_get_monitor_result(struct pipe_context *ctx,
+                        struct iris_monitor_object *monitor,
+                        bool wait,
+                        union pipe_numeric_type_union *result)
+{
+   struct iris_context *ice = (void *) ctx;
+   struct gen_perf_context *perf_ctx = ice->perf_ctx;
+
+   bool monitor_ready = gen_perf_is_query_ready(perf_ctx, monitor->query,
+                                                &ice->batches[IRIS_BATCH_RENDER]);
+
+   if (!monitor_ready) {
+      if (!wait)
+         return false;
+      gen_perf_wait_query(perf_ctx, monitor->query,
+                          &ice->batches[IRIS_BATCH_RENDER]);
+   }
+
+   assert (gen_perf_is_query_ready(perf_ctx, monitor->query,
+                                   &ice->batches[IRIS_BATCH_RENDER]));
+
+   unsigned bytes_written;
+   gen_perf_get_query_data(perf_ctx, monitor->query,
+                           monitor->result_size,
+                           (unsigned*) monitor->result_buffer,
+                           &bytes_written);
+   if (bytes_written != monitor->result_size)
+      return false;
+
+   /* copy metrics into the batch result */
+   for (int i = 0; i < monitor->num_active_counters; ++i) {
+      int current_counter = monitor->active_counters[i];
+      const struct gen_perf_query_info *info =
+         gen_perf_query_info(monitor->query);
+      const struct gen_perf_query_counter *counter =
+         &info->counters[current_counter];
+      assert(gen_perf_query_counter_get_size(counter));
+      switch (counter->data_type) {
+      case GEN_PERF_COUNTER_DATA_TYPE_UINT64:
+         result[i].u64 = *(uint64_t*)(monitor->result_buffer + counter->offset);
+         break;
+      case GEN_PERF_COUNTER_DATA_TYPE_FLOAT:
+         result[i].f = *(float*)(monitor->result_buffer + counter->offset);
+         break;
+      case GEN_PERF_COUNTER_DATA_TYPE_UINT32:
+      case GEN_PERF_COUNTER_DATA_TYPE_BOOL32:
+         result[i].u64 = *(uint32_t*)(monitor->result_buffer + counter->offset);
+         break;
+      case GEN_PERF_COUNTER_DATA_TYPE_DOUBLE: {
+         double v = *(double*)(monitor->result_buffer + counter->offset);
+         result[i].f = v;
+      }
+      default:
+         unreachable("unexpected counter data type");
+      }
+   }
+   return true;
+}
index 9616ff16df5a7115fb9a8309dab804cae9f124ff..e2546b0dcaab9e2691e1777e83fd1a9826cf2e2b 100644 (file)
@@ -64,4 +64,10 @@ bool
 iris_end_monitor(struct pipe_context *ctx,
                  struct iris_monitor_object *monitor);
 
+bool
+iris_get_monitor_result(struct pipe_context *ctx,
+                        struct iris_monitor_object *monitor,
+                        bool wait,
+                        union pipe_numeric_type_union *result);
+
 #endif