aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/state_tracker/st_cb_perfmon.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-05-15 19:14:42 +0200
committermarha <marha@users.sourceforge.net>2015-05-15 19:14:42 +0200
commit843964ee791452b197e41dacb0146f5b456ffaa5 (patch)
treeb1b0734c17ce1d488aa4d6e95f27363d80731e10 /mesalib/src/mesa/state_tracker/st_cb_perfmon.c
parenta71d524ecad48837e0124a03124bc05f59a48be7 (diff)
downloadvcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.tar.gz
vcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.tar.bz2
vcxsrv-843964ee791452b197e41dacb0146f5b456ffaa5.zip
randrproto fontconfig libfontenc libxcb mesalib xserver pixman xkeyboard-config git update 15 May 2015
xserver commit bf6344e1913a5d24c2d68eaca999ea3d71e1b707 libxcb commit cb621341a62e6d2233db3e337611f6fdd4f675a6 libxcb/xcb-proto commit 4c550465934164aab2449a125f75f4ca07816233 xkeyboard-config commit 5da6d510b460cad1b31288618cc364e586576826 libX11 commit d3415d1f052530760b4617db45affcb984cfe35c libXdmcp commit b10f382e3aa2e86cd5a2bc27d6758da55f0ab1f6 libXext commit efdcbb7634501e1117d422636a0a75d7ea84b16b libfontenc commit 42f3a39c3085afd9ef904ae39102fd49bbc2e4a5 libXinerama commit edd95182b26eb5d576d4878c559e0f17dddaa909 libXau commit 1e4635be11154dd8262f37b379511bd627defa2a xkbcomp commit 1ae525b3d236b59e6437b2b5433d460e18370973 pixman commit 82f9b4faaf1aa63ec26b0dfd227f1a8e5e139ae2 xextproto commit 66afec3f49e8eb0d4c2e9af7088fc3116d4bafd7 randrproto commit 895ee5264524c7c239ee4ef5e39c4e295323fb51 glproto commit bd3d751e1eb17efb39f65093271bb4ac071aa9e0 mkfontscale commit 87d628f8eec170ec13bb9feefb1ce05aed07d1d6 xwininfo commit 0c49f8f2bd56b1e77721e81030ea948386dcdf4e libXft commit e8a83226bc10afb587f6f34daac44d2ef809c85e libXmu commit 4459e6940fe3fdf26a8d5d4c71989498bc400a62 libxtrans commit 7cbad9fe2e61cd9d5caeaf361826a6f4bd320f03 fontconfig commit 55ff8419274fd5ce59675f220b85035a3986d6cf mesa commit 3687d752e51829b4723c9abb07ae56d2bbcda570
Diffstat (limited to 'mesalib/src/mesa/state_tracker/st_cb_perfmon.c')
-rw-r--r--mesalib/src/mesa/state_tracker/st_cb_perfmon.c425
1 files changed, 425 insertions, 0 deletions
diff --git a/mesalib/src/mesa/state_tracker/st_cb_perfmon.c b/mesalib/src/mesa/state_tracker/st_cb_perfmon.c
new file mode 100644
index 000000000..1bb5be397
--- /dev/null
+++ b/mesalib/src/mesa/state_tracker/st_cb_perfmon.c
@@ -0,0 +1,425 @@
+/*
+ * Copyright (C) 2013 Christoph Bumiller
+ * Copyright (C) 2015 Samuel Pitoiset
+ *
+ * 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 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.
+ */
+
+/**
+ * Performance monitoring counters interface to gallium.
+ */
+
+#include "st_debug.h"
+#include "st_context.h"
+#include "st_cb_bitmap.h"
+#include "st_cb_perfmon.h"
+
+#include "util/bitset.h"
+
+#include "pipe/p_context.h"
+#include "pipe/p_screen.h"
+#include "util/u_memory.h"
+
+/**
+ * Return a PIPE_QUERY_x type >= PIPE_QUERY_DRIVER_SPECIFIC, or -1 if
+ * the driver-specific query doesn't exist.
+ */
+static int
+find_query_type(struct pipe_screen *screen, const char *name)
+{
+ int num_queries;
+ int type = -1;
+ int i;
+
+ num_queries = screen->get_driver_query_info(screen, 0, NULL);
+ if (!num_queries)
+ return type;
+
+ for (i = 0; i < num_queries; i++) {
+ struct pipe_driver_query_info info;
+
+ if (!screen->get_driver_query_info(screen, i, &info))
+ continue;
+
+ if (!strncmp(info.name, name, strlen(name))) {
+ type = info.query_type;
+ break;
+ }
+ }
+ return type;
+}
+
+/**
+ * Return TRUE if the underlying driver expose GPU counters.
+ */
+static bool
+has_gpu_counters(struct pipe_screen *screen)
+{
+ int num_groups, gid;
+
+ num_groups = screen->get_driver_query_group_info(screen, 0, NULL);
+ for (gid = 0; gid < num_groups; gid++) {
+ struct pipe_driver_query_group_info group_info;
+
+ if (!screen->get_driver_query_group_info(screen, gid, &group_info))
+ continue;
+
+ if (group_info.type == PIPE_DRIVER_QUERY_GROUP_TYPE_GPU)
+ return true;
+ }
+ return false;
+}
+
+static bool
+init_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ int gid, cid;
+
+ st_flush_bitmap_cache(st_context(ctx));
+
+ /* Create a query for each active counter. */
+ for (gid = 0; gid < ctx->PerfMonitor.NumGroups; gid++) {
+ const struct gl_perf_monitor_group *g = &ctx->PerfMonitor.Groups[gid];
+
+ if (m->ActiveGroups[gid] > g->MaxActiveCounters) {
+ /* Maximum number of counters reached. Cannot start the session. */
+ if (ST_DEBUG & DEBUG_MESA) {
+ debug_printf("Maximum number of counters reached. "
+ "Cannot start the session!\n");
+ }
+ return false;
+ }
+
+ for (cid = 0; cid < g->NumCounters; cid++) {
+ const struct gl_perf_monitor_counter *c = &g->Counters[cid];
+ struct st_perf_counter_object *cntr;
+ int query_type;
+
+ if (!BITSET_TEST(m->ActiveCounters[gid], cid))
+ continue;
+
+ query_type = find_query_type(screen, c->Name);
+ assert(query_type != -1);
+
+ cntr = CALLOC_STRUCT(st_perf_counter_object);
+ if (!cntr)
+ return false;
+
+ cntr->query = pipe->create_query(pipe, query_type, 0);
+ cntr->id = cid;
+ cntr->group_id = gid;
+
+ list_addtail(&cntr->list, &stm->active_counters);
+ }
+ }
+ return true;
+}
+
+static void
+reset_perf_monitor(struct st_perf_monitor_object *stm,
+ struct pipe_context *pipe)
+{
+ struct st_perf_counter_object *cntr, *tmp;
+
+ LIST_FOR_EACH_ENTRY_SAFE(cntr, tmp, &stm->active_counters, list) {
+ if (cntr->query)
+ pipe->destroy_query(pipe, cntr->query);
+ list_del(&cntr->list);
+ free(cntr);
+ }
+}
+
+static struct gl_perf_monitor_object *
+st_NewPerfMonitor(struct gl_context *ctx)
+{
+ struct st_perf_monitor_object *stq = ST_CALLOC_STRUCT(st_perf_monitor_object);
+ if (stq) {
+ list_inithead(&stq->active_counters);
+ return &stq->base;
+ }
+ return NULL;
+}
+
+static void
+st_DeletePerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+
+ reset_perf_monitor(stm, pipe);
+ FREE(stm);
+}
+
+static GLboolean
+st_BeginPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_perf_counter_object *cntr;
+
+ if (LIST_IS_EMPTY(&stm->active_counters)) {
+ /* Create a query for each active counter before starting
+ * a new monitoring session. */
+ if (!init_perf_monitor(ctx, m))
+ goto fail;
+ }
+
+ /* Start the query for each active counter. */
+ LIST_FOR_EACH_ENTRY(cntr, &stm->active_counters, list) {
+ if (!pipe->begin_query(pipe, cntr->query))
+ goto fail;
+ }
+ return true;
+
+fail:
+ /* Failed to start the monitoring session. */
+ reset_perf_monitor(stm, pipe);
+ return false;
+}
+
+static void
+st_EndPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_perf_counter_object *cntr;
+
+ /* Stop the query for each active counter. */
+ LIST_FOR_EACH_ENTRY(cntr, &stm->active_counters, list)
+ pipe->end_query(pipe, cntr->query);
+}
+
+static void
+st_ResetPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+
+ if (!m->Ended)
+ st_EndPerfMonitor(ctx, m);
+
+ reset_perf_monitor(stm, pipe);
+
+ if (m->Active)
+ st_BeginPerfMonitor(ctx, m);
+}
+
+static GLboolean
+st_IsPerfMonitorResultAvailable(struct gl_context *ctx,
+ struct gl_perf_monitor_object *m)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_perf_counter_object *cntr;
+
+ if (LIST_IS_EMPTY(&stm->active_counters))
+ return false;
+
+ /* The result of a monitoring session is only available if the query of
+ * each active counter is idle. */
+ LIST_FOR_EACH_ENTRY(cntr, &stm->active_counters, list) {
+ union pipe_query_result result;
+ if (!pipe->get_query_result(pipe, cntr->query, FALSE, &result)) {
+ /* The query is busy. */
+ return false;
+ }
+ }
+ return true;
+}
+
+static void
+st_GetPerfMonitorResult(struct gl_context *ctx,
+ struct gl_perf_monitor_object *m,
+ GLsizei dataSize,
+ GLuint *data,
+ GLint *bytesWritten)
+{
+ struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_perf_counter_object *cntr;
+
+ /* 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;
+
+ /* Read query results for each active counter. */
+ LIST_FOR_EACH_ENTRY(cntr, &stm->active_counters, list) {
+ union pipe_query_result result = { 0 };
+ int gid, cid;
+ GLenum type;
+
+ cid = cntr->id;
+ gid = cntr->group_id;
+ type = ctx->PerfMonitor.Groups[gid].Counters[cid].Type;
+
+ if (!pipe->get_query_result(pipe, cntr->query, TRUE, &result))
+ continue;
+
+ data[offset++] = gid;
+ data[offset++] = cid;
+ switch (type) {
+ case GL_UNSIGNED_INT64_AMD:
+ *(uint64_t *)&data[offset] = result.u64;
+ offset += sizeof(uint64_t) / sizeof(GLuint);
+ break;
+ case GL_UNSIGNED_INT:
+ *(uint32_t *)&data[offset] = result.u32;
+ offset += sizeof(uint32_t) / sizeof(GLuint);
+ break;
+ case GL_FLOAT:
+ case GL_PERCENTAGE_AMD:
+ *(GLfloat *)&data[offset] = result.f;
+ offset += sizeof(GLfloat) / sizeof(GLuint);
+ break;
+ }
+ }
+
+ if (bytesWritten)
+ *bytesWritten = offset * sizeof(GLuint);
+}
+
+
+bool
+st_init_perfmon(struct st_context *st)
+{
+ struct gl_perf_monitor_state *perfmon = &st->ctx->PerfMonitor;
+ struct pipe_screen *screen = st->pipe->screen;
+ struct gl_perf_monitor_group *groups = NULL;
+ int num_counters, num_groups;
+ int gid, cid;
+
+ if (!screen->get_driver_query_info || !screen->get_driver_query_group_info)
+ return false;
+
+ if (!has_gpu_counters(screen)) {
+ /* According to the spec, GL_AMD_performance_monitor must only
+ * expose GPU counters. */
+ return false;
+ }
+
+ /* Get the number of available queries. */
+ num_counters = screen->get_driver_query_info(screen, 0, NULL);
+ if (!num_counters)
+ return false;
+
+ /* Get the number of available groups. */
+ num_groups = screen->get_driver_query_group_info(screen, 0, NULL);
+ if (num_groups)
+ groups = CALLOC(num_groups, sizeof(*groups));
+ if (!groups)
+ return false;
+
+ for (gid = 0; gid < num_groups; gid++) {
+ struct gl_perf_monitor_group *g = &groups[perfmon->NumGroups];
+ struct pipe_driver_query_group_info group_info;
+ struct gl_perf_monitor_counter *counters = NULL;
+
+ if (!screen->get_driver_query_group_info(screen, gid, &group_info))
+ continue;
+
+ if (group_info.type != PIPE_DRIVER_QUERY_GROUP_TYPE_GPU)
+ continue;
+
+ g->Name = group_info.name;
+ g->MaxActiveCounters = group_info.max_active_queries;
+ g->NumCounters = 0;
+ g->Counters = NULL;
+
+ if (group_info.num_queries)
+ counters = CALLOC(group_info.num_queries, sizeof(*counters));
+ if (!counters)
+ goto fail;
+
+ for (cid = 0; cid < num_counters; cid++) {
+ struct gl_perf_monitor_counter *c = &counters[g->NumCounters];
+ struct pipe_driver_query_info info;
+
+ if (!screen->get_driver_query_info(screen, cid, &info))
+ continue;
+ if (info.group_id != gid)
+ continue;
+
+ c->Name = info.name;
+ switch (info.type) {
+ case PIPE_DRIVER_QUERY_TYPE_UINT64:
+ c->Minimum.u64 = 0;
+ c->Maximum.u64 = info.max_value.u64 ? info.max_value.u64 : -1;
+ c->Type = GL_UNSIGNED_INT64_AMD;
+ break;
+ case PIPE_DRIVER_QUERY_TYPE_UINT:
+ c->Minimum.u32 = 0;
+ c->Maximum.u32 = info.max_value.u32 ? info.max_value.u32 : -1;
+ c->Type = GL_UNSIGNED_INT;
+ break;
+ case PIPE_DRIVER_QUERY_TYPE_FLOAT:
+ c->Minimum.f = 0.0;
+ c->Maximum.f = info.max_value.f ? info.max_value.f : -1;
+ c->Type = GL_FLOAT;
+ break;
+ case PIPE_DRIVER_QUERY_TYPE_PERCENTAGE:
+ c->Minimum.f = 0.0f;
+ c->Maximum.f = 100.0f;
+ c->Type = GL_PERCENTAGE_AMD;
+ break;
+ default:
+ unreachable("Invalid driver query type!");
+ }
+ g->NumCounters++;
+ }
+ g->Counters = counters;
+ perfmon->NumGroups++;
+ }
+ perfmon->Groups = groups;
+
+ return true;
+
+fail:
+ for (gid = 0; gid < num_groups; gid++)
+ FREE((void *)groups[gid].Counters);
+ FREE(groups);
+ return false;
+}
+
+void
+st_destroy_perfmon(struct st_context *st)
+{
+ struct gl_perf_monitor_state *perfmon = &st->ctx->PerfMonitor;
+ int gid;
+
+ for (gid = 0; gid < perfmon->NumGroups; gid++)
+ FREE((void *)perfmon->Groups[gid].Counters);
+ FREE((void *)perfmon->Groups);
+}
+
+void st_init_perfmon_functions(struct dd_function_table *functions)
+{
+ functions->NewPerfMonitor = st_NewPerfMonitor;
+ functions->DeletePerfMonitor = st_DeletePerfMonitor;
+ functions->BeginPerfMonitor = st_BeginPerfMonitor;
+ functions->EndPerfMonitor = st_EndPerfMonitor;
+ functions->ResetPerfMonitor = st_ResetPerfMonitor;
+ functions->IsPerfMonitorResultAvailable = st_IsPerfMonitorResultAvailable;
+ functions->GetPerfMonitorResult = st_GetPerfMonitorResult;
+}