i965: Add basic driver hooks and plumbing for AMD_performance_monitor.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 31 Oct 2013 22:42:09 +0000 (15:42 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Nov 2013 23:01:13 +0000 (15:01 -0800)
These stub functions will be filled out in later patches.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/Makefile.sources
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_performance_monitor.c [new file with mode: 0644]

index ac1363c776bcfee25aad5c60b28403055045fcbf..193f2db3bc757ce1362f42ad82d0624de4fddd8e 100644 (file)
@@ -73,6 +73,7 @@ i965_FILES = \
        brw_lower_unnormalized_offset.cpp \
        brw_misc_state.c \
        brw_object_purgeable.c \
+       brw_performance_monitor.c \
        brw_program.c \
        brw_primitive_restart.c \
        brw_queryobj.c \
index d1f3ce12c3c002f6b1f7834e9f9031657c07a717..4e09038477ce83e039b7e50cf4181156b1a1a31c 100644 (file)
@@ -801,6 +801,10 @@ brwCreateContext(gl_api api,
    _mesa_initialize_dispatch_tables(ctx);
    _mesa_initialize_vbo_vtxfmt(ctx);
 
+   if (ctx->Extensions.AMD_performance_monitor) {
+      brw_init_performance_monitors(brw);
+   }
+
    return true;
 }
 
index fe9e3a8fa08ae7f6031c4dc507dfea9af420a716..8d373ff780b015dbdb323567eca5668609b0c192 100644 (file)
@@ -1613,6 +1613,10 @@ bool brw_is_hiz_depth_format(struct brw_context *ctx, gl_format format);
 bool brw_render_target_supported(struct brw_context *brw,
                                  struct gl_renderbuffer *rb);
 
+/* brw_performance_monitor.c */
+void brw_init_performance_monitors(struct brw_context *brw);
+void brw_dump_perf_monitors(struct brw_context *brw);
+
 /* intel_extensions.c */
 extern void intelInitExtensions(struct gl_context *ctx);
 
diff --git a/src/mesa/drivers/dri/i965/brw_performance_monitor.c b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
new file mode 100644 (file)
index 0000000..c9673c5
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file brw_performance_monitor.c
+ *
+ * Implementation of the GL_AMD_performance_monitor extension.
+ */
+
+#include <limits.h>
+
+#include "main/bitset.h"
+#include "main/hash.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
+#include "main/performance_monitor.h"
+
+#include "glsl/ralloc.h"
+
+#include "brw_context.h"
+#include "brw_defines.h"
+#include "intel_batchbuffer.h"
+
+#define FILE_DEBUG_FLAG DEBUG_PERFMON
+
+/**
+ * i965 representation of a performance monitor object.
+ */
+struct brw_perf_monitor_object
+{
+   /** The base class. */
+   struct gl_perf_monitor_object base;
+};
+
+/** Downcasting convenience macro. */
+static inline struct brw_perf_monitor_object *
+brw_perf_monitor(struct gl_perf_monitor_object *m)
+{
+   return (struct brw_perf_monitor_object *) m;
+}
+
+/******************************************************************************/
+
+static GLboolean brw_is_perf_monitor_result_available(struct gl_context *, struct gl_perf_monitor_object *);
+
+static void
+dump_perf_monitor_callback(GLuint name, void *monitor_void, void *brw_void)
+{
+   struct gl_context *ctx = brw_void;
+   struct gl_perf_monitor_object *m = monitor_void;
+
+   DBG("%4d  %-7s %-6s %-11s\n",
+       name,
+       m->Active ? "Active" : "",
+       m->Ended ? "Ended" : "",
+       brw_is_perf_monitor_result_available(ctx, m) ? "Available" : "");
+}
+
+void
+brw_dump_perf_monitors(struct brw_context *brw)
+{
+   struct gl_context *ctx = &brw->ctx;
+   DBG("Monitors:\n");
+   _mesa_HashWalk(ctx->PerfMonitor.Monitors, dump_perf_monitor_callback, brw);
+}
+
+/******************************************************************************/
+
+/**
+ * Initialize a monitor to sane starting state; throw away old buffers.
+ */
+static void
+reinitialize_perf_monitor(struct brw_context *brw,
+                          struct brw_perf_monitor_object *monitor)
+{
+}
+
+/**
+ * Driver hook for glBeginPerformanceMonitorAMD().
+ */
+static GLboolean
+brw_begin_perf_monitor(struct gl_context *ctx,
+                       struct gl_perf_monitor_object *m)
+{
+   struct brw_context *brw = brw_context(ctx);
+   struct brw_perf_monitor_object *monitor = brw_perf_monitor(m);
+
+   DBG("Begin(%d)\n", m->Name);
+
+   reinitialize_perf_monitor(brw, monitor);
+
+   return true;
+}
+
+/**
+ * Driver hook for glEndPerformanceMonitorAMD().
+ */
+static void
+brw_end_perf_monitor(struct gl_context *ctx,
+                     struct gl_perf_monitor_object *m)
+{
+   DBG("End(%d)\n", m->Name);
+}
+
+/**
+ * Reset a performance monitor, throwing away any results.
+ */
+static void
+brw_reset_perf_monitor(struct gl_context *ctx,
+                       struct gl_perf_monitor_object *m)
+{
+   struct brw_context *brw = brw_context(ctx);
+   struct brw_perf_monitor_object *monitor = brw_perf_monitor(m);
+
+   reinitialize_perf_monitor(brw, monitor);
+
+   if (m->Active) {
+      brw_begin_perf_monitor(ctx, m);
+   }
+}
+
+/**
+ * Is a performance monitor result available?
+ */
+static GLboolean
+brw_is_perf_monitor_result_available(struct gl_context *ctx,
+                                     struct gl_perf_monitor_object *m)
+{
+   /* ...need to actually check if counters are available, once we have some. */
+
+   return true;
+}
+
+/**
+ * Get the performance monitor result.
+ */
+static void
+brw_get_perf_monitor_result(struct gl_context *ctx,
+                            struct gl_perf_monitor_object *m,
+                            GLsizei data_size,
+                            GLuint *data,
+                            GLint *bytes_written)
+{
+   DBG("GetResult(%d)\n", m->Name);
+
+   /* This hook should only be called when results are available. */
+   assert(m->Ended);
+
+   /* Copy data to the supplied array (data).
+    *
+    * The output data format is: <group ID, counter ID, value> for each
+    * active counter.  The API allows counters to appear in any order.
+    */
+   GLsizei offset = 0;
+
+   /* ...but, we don't actually expose anything yet, so nothing to do here */
+
+   if (bytes_written)
+      *bytes_written = offset * sizeof(uint32_t);
+}
+
+/**
+ * Create a new performance monitor object.
+ */
+static struct gl_perf_monitor_object *
+brw_new_perf_monitor(struct gl_context *ctx)
+{
+   return calloc(1, sizeof(struct brw_perf_monitor_object));
+}
+
+/**
+ * Delete a performance monitor object.
+ */
+static void
+brw_delete_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+   struct brw_perf_monitor_object *monitor = brw_perf_monitor(m);
+   DBG("Delete(%d)\n", m->Name);
+   reinitialize_perf_monitor(brw_context(ctx), monitor);
+   free(monitor);
+}
+
+/******************************************************************************/
+
+void
+brw_init_performance_monitors(struct brw_context *brw)
+{
+   struct gl_context *ctx = &brw->ctx;
+
+   ctx->Driver.NewPerfMonitor = brw_new_perf_monitor;
+   ctx->Driver.DeletePerfMonitor = brw_delete_perf_monitor;
+   ctx->Driver.BeginPerfMonitor = brw_begin_perf_monitor;
+   ctx->Driver.EndPerfMonitor = brw_end_perf_monitor;
+   ctx->Driver.ResetPerfMonitor = brw_reset_perf_monitor;
+   ctx->Driver.IsPerfMonitorResultAvailable = brw_is_perf_monitor_result_available;
+   ctx->Driver.GetPerfMonitorResult = brw_get_perf_monitor_result;
+
+   /* ...need to set ctx->PerfMonitor.Groups and ctx->PerfMonitor.NumGroups */
+}