From 3d2790cead7eb744341e8b1708b7a6d03524768d Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Fri, 29 Mar 2013 13:56:35 +0100 Subject: gallium/hud: add support for PIPE_QUERY_PIPELINE_STATISTICS Also, renamed "pixels-rendered" to "samples-passed" because the occlusion counter increments even if colour and depth writes are disabled, or (on some implementations) for killed fragments that passed the depth test when PS early_fragment_tests is set. --- src/gallium/auxiliary/hud/hud_context.c | 45 +++++++++++++++++++++++++--- src/gallium/auxiliary/hud/hud_cpu.c | 6 ++-- src/gallium/auxiliary/hud/hud_driver_query.c | 9 ++++-- src/gallium/auxiliary/hud/hud_private.h | 1 + 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index 9b7b63f91ba..5511f8e1011 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -90,6 +90,10 @@ struct hud_context { unsigned max_num_vertices; unsigned num_vertices; } text, bg, whitelines; + + struct { + boolean query_pipeline_statistics; + } cap; }; @@ -719,15 +723,45 @@ hud_parse_env_var(struct hud_context *hud, const char *env) else if (sscanf(name, "cpu%u%s", &i, s) == 1) { hud_cpu_graph_install(pane, i); } - else if (strcmp(name, "pixels-rendered") == 0 && + else if (strcmp(name, "samples-passed") == 0 && has_occlusion_query(hud->pipe->screen)) { - hud_pipe_query_install(pane, hud->pipe, "pixels-rendered", - PIPE_QUERY_OCCLUSION_COUNTER, 0, FALSE); + hud_pipe_query_install(pane, hud->pipe, "samples-passed", + PIPE_QUERY_OCCLUSION_COUNTER, 0, 0, FALSE); } else if (strcmp(name, "primitives-generated") == 0 && has_streamout(hud->pipe->screen)) { hud_pipe_query_install(pane, hud->pipe, "primitives-generated", - PIPE_QUERY_PRIMITIVES_GENERATED, 0, FALSE); + PIPE_QUERY_PRIMITIVES_GENERATED, 0, 0, FALSE); + } + else if (strncmp(name, "pipeline-statistics-", 20) == 0) { + if (hud->cap.query_pipeline_statistics) { + static const char *pipeline_statistics_names[] = + { + "ia-vertices", + "ia-primitives", + "vs-invocations", + "gs-invocations", + "gs-primitives", + "clipper-invocations", + "clipper-primitives-generated", + "ps-invocations", + "hs-invocations", + "ds-invocations", + "cs-invocations" + }; + for (i = 0; i < Elements(pipeline_statistics_names); ++i) + if (strcmp(&name[20], pipeline_statistics_names[i]) == 0) + break; + if (i < Elements(pipeline_statistics_names)) + hud_pipe_query_install(pane, hud->pipe, &name[20], + PIPE_QUERY_PIPELINE_STATISTICS, i, + 0, FALSE); + else + fprintf(stderr, "gallium_hud: invalid pipeline-statistics-*\n"); + } else { + fprintf(stderr, "gallium_hud: PIPE_QUERY_PIPELINE_STATISTICS " + "not supported by the driver\n"); + } } else { if (!hud_driver_query_install(pane, hud->pipe, name)){ @@ -990,6 +1024,9 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso) LIST_INITHEAD(&hud->pane_list); + hud->cap.query_pipeline_statistics = + pipe->screen->get_param(pipe->screen, PIPE_CAP_QUERY_PIPELINE_STATISTICS); + hud_parse_env_var(hud, env); return hud; } diff --git a/src/gallium/auxiliary/hud/hud_cpu.c b/src/gallium/auxiliary/hud/hud_cpu.c index dfd9f686920..ce98115d542 100644 --- a/src/gallium/auxiliary/hud/hud_cpu.c +++ b/src/gallium/auxiliary/hud/hud_cpu.c @@ -32,6 +32,7 @@ #include "os/os_time.h" #include "util/u_memory.h" #include +#include static boolean get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time) @@ -55,8 +56,9 @@ get_cpu_stats(unsigned cpu_index, uint64_t *busy_time, uint64_t *total_time) int i, num; num = sscanf(line, - "%s %llu %llu %llu %llu %llu %llu %llu %llu %llu " - "%llu %llu %llu", + "%s %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64 + " %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64 + " %"PRIu64" %"PRIu64"", cpuname, &v[0], &v[1], &v[2], &v[3], &v[4], &v[5], &v[6], &v[7], &v[8], &v[9], &v[10], &v[11]); if (num < 5) { diff --git a/src/gallium/auxiliary/hud/hud_driver_query.c b/src/gallium/auxiliary/hud/hud_driver_query.c index 798da50e57c..0f52e18cc2d 100644 --- a/src/gallium/auxiliary/hud/hud_driver_query.c +++ b/src/gallium/auxiliary/hud/hud_driver_query.c @@ -42,6 +42,7 @@ struct query_info { struct pipe_context *pipe; unsigned query_type; + unsigned result_index; /* unit depends on query_type */ /* Ring of queries. If a query is busy, we use another slot. */ struct pipe_query *query[NUM_QUERIES]; @@ -67,10 +68,10 @@ query_new_value(struct hud_graph *gr) while (1) { struct pipe_query *query = info->query[info->tail]; union pipe_query_result result; - result.u64 = 0; + uint64_t *res64 = (uint64_t *)&result; if (pipe->get_query_result(pipe, query, FALSE, &result)) { - info->results_cumulative += result.u64; + info->results_cumulative += res64[info->result_index]; info->num_results++; if (info->tail == info->head) @@ -146,6 +147,7 @@ free_query_info(void *ptr) void hud_pipe_query_install(struct hud_pane *pane, struct pipe_context *pipe, const char *name, unsigned query_type, + unsigned result_index, uint64_t max_value, boolean uses_byte_units) { struct hud_graph *gr; @@ -168,6 +170,7 @@ hud_pipe_query_install(struct hud_pane *pane, struct pipe_context *pipe, info = gr->query_data; info->pipe = pipe; info->query_type = query_type; + info->result_index = result_index; hud_pane_add_graph(pane, gr); if (pane->max_value < max_value) @@ -201,7 +204,7 @@ hud_driver_query_install(struct hud_pane *pane, struct pipe_context *pipe, if (!found) return FALSE; - hud_pipe_query_install(pane, pipe, query.name, query.query_type, + hud_pipe_query_install(pane, pipe, query.name, query.query_type, 0, query.max_value, query.uses_byte_units); return TRUE; } diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h index 4c97791c635..2b7d56bb1ad 100644 --- a/src/gallium/auxiliary/hud/hud_private.h +++ b/src/gallium/auxiliary/hud/hud_private.h @@ -84,6 +84,7 @@ void hud_fps_graph_install(struct hud_pane *pane); void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index); void hud_pipe_query_install(struct hud_pane *pane, struct pipe_context *pipe, const char *name, unsigned query_type, + unsigned result_index, uint64_t max_value, boolean uses_byte_units); boolean hud_driver_query_install(struct hud_pane *pane, struct pipe_context *pipe, const char *name); -- cgit v1.2.3