gallium/hud: add support for PIPE_QUERY_PIPELINE_STATISTICS
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Fri, 29 Mar 2013 12:56:35 +0000 (13:56 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Wed, 3 Apr 2013 10:54:43 +0000 (12:54 +0200)
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
src/gallium/auxiliary/hud/hud_cpu.c
src/gallium/auxiliary/hud/hud_driver_query.c
src/gallium/auxiliary/hud/hud_private.h

index 9b7b63f91bac9b79711eb1c9ab4fbaa7382dc223..5511f8e1011b9b664d165c79f965ad02f0a59933 100644 (file)
@@ -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;
 }
index dfd9f6869201a0bde11f8c124a7c8bd05636e328..ce98115d5428ae8d0d7e3470a0ca0866dd172472 100644 (file)
@@ -32,6 +32,7 @@
 #include "os/os_time.h"
 #include "util/u_memory.h"
 #include <stdio.h>
+#include <inttypes.h>
 
 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) {
index 798da50e57c4af117eafd12fdd57c53cb4a80939..0f52e18cc2db258d69ff15c3334cc8b4e5485499 100644 (file)
@@ -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;
 }
index 4c97791c635ec841920593b4a1d002d876e96c04..2b7d56bb1ad0fea3b608bc939dd6ea0702941907 100644 (file)
@@ -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);