--- /dev/null
+/*
+ * 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 */
+}