[Mesa-dev] [PATCH] gallium/hud: add a simple HUD view that only draws text

Marek Olšák maraeo at gmail.com
Thu Apr 5 00:04:39 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

Add this prefix to the env var: "simple," For example:
    GALLIUM_HUD=simple,fps

The X coordinates are the same, but the Y coordinates are different, because
there is only text.

'+' happens to behave the same as "\n".
',' happens to behave the same as "\n\n".
---
 src/gallium/auxiliary/hud/hud_context.c | 72 ++++++++++++++++++++++++++-------
 src/gallium/auxiliary/hud/hud_private.h |  3 +-
 2 files changed, 60 insertions(+), 15 deletions(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 4d2458eb2e4..1baaabbb38e 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -391,20 +391,40 @@ hud_pane_accumulate_vertices(struct hud_context *hud,
       assert(hud->whitelines.num_vertices + num/2 + 2 <= hud->whitelines.max_num_vertices);
       line_verts[num++] = pane->x1;
       line_verts[num++] = y;
       line_verts[num++] = pane->x2;
       line_verts[num++] = y;
    }
 
    hud->whitelines.num_vertices += num/2;
 }
 
+static void
+hud_pane_accumulate_vertices_simple(struct hud_context *hud,
+                                    const struct hud_pane *pane)
+{
+   struct hud_graph *gr;
+   unsigned i;
+   char str[32];
+
+   /* draw info below the pane */
+   i = 0;
+   LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
+      unsigned x = pane->x1;
+      unsigned y = pane->y_simple + i*hud->font.glyph_height;
+
+      number_to_human_readable(gr->current_value, pane->type, str);
+      hud_draw_string(hud, x, y, "%s: %s", gr->name, str);
+      i++;
+   }
+}
+
 static void
 hud_pane_draw_colored_objects(struct hud_context *hud,
                               const struct hud_pane *pane)
 {
    struct hud_graph *gr;
    unsigned i;
 
    /* draw colored quads below the pane */
    i = 0;
    LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
@@ -540,20 +560,37 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
       hud->constants.scale[0] = 1;
       hud->constants.scale[1] = 1;
 
       cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
       cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
                              &hud->bg.vbuf);
       cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->bg.num_vertices);
    }
    pipe_resource_reference(&hud->bg.vbuf.buffer.resource, NULL);
 
+   /* draw accumulated vertices for text */
+   if (hud->text.num_vertices) {
+      cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
+                             &hud->text.vbuf);
+      cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
+      cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
+   }
+   pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
+
+   if (hud->simple) {
+      cso_restore_state(cso);
+      cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
+
+      pipe_surface_reference(&surf, NULL);
+      return;
+   }
+
    /* draw accumulated vertices for white lines */
    cso_set_blend(cso, &hud->no_blend);
 
    hud->constants.color[0] = 1;
    hud->constants.color[1] = 1;
    hud->constants.color[2] = 1;
    hud->constants.color[3] = 1;
    hud->constants.translate[0] = 0;
    hud->constants.translate[1] = 0;
    hud->constants.scale[0] = 1;
@@ -561,31 +598,22 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex)
    cso_set_constant_buffer(cso, PIPE_SHADER_VERTEX, 0, &hud->constbuf);
 
    if (hud->whitelines.num_vertices) {
       cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
                              &hud->whitelines.vbuf);
       cso_set_fragment_shader_handle(hud->cso, hud->fs_color);
       cso_draw_arrays(cso, PIPE_PRIM_LINES, 0, hud->whitelines.num_vertices);
    }
    pipe_resource_reference(&hud->whitelines.vbuf.buffer.resource, NULL);
 
-   /* draw accumulated vertices for text */
-   cso_set_blend(cso, &hud->alpha_blend);
-   if (hud->text.num_vertices) {
-      cso_set_vertex_buffers(cso, cso_get_aux_vertex_buffer_slot(cso), 1,
-                             &hud->text.vbuf);
-      cso_set_fragment_shader_handle(hud->cso, hud->fs_text);
-      cso_draw_arrays(cso, PIPE_PRIM_QUADS, 0, hud->text.num_vertices);
-   }
-   pipe_resource_reference(&hud->text.vbuf.buffer.resource, NULL);
-
    /* draw the rest */
+   cso_set_blend(cso, &hud->alpha_blend);
    cso_set_rasterizer(cso, &hud->rasterizer_aa_lines);
    LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
       if (pane)
          hud_pane_draw_colored_objects(hud, pane);
    }
 
    cso_restore_state(cso);
    cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
 
    pipe_surface_reference(&surf, NULL);
@@ -671,21 +699,24 @@ hud_stop_queries(struct hud_context *hud, struct pipe_context *pipe)
              * per frame. It will eventually reach an equilibrium.
              */
             if (gr->current_value <
                 LIST_ENTRY(struct hud_graph, next, head)->current_value) {
                LIST_DEL(&gr->head);
                LIST_ADD(&gr->head, &next->head);
             }
          }
       }
 
-      hud_pane_accumulate_vertices(hud, pane);
+      if (hud->simple)
+         hud_pane_accumulate_vertices_simple(hud, pane);
+      else
+         hud_pane_accumulate_vertices(hud, pane);
    }
 
    /* unmap the uploader's vertex buffer before drawing */
    u_upload_unmap(pipe->stream_uploader);
 }
 
 /**
  * Record queries and draw the HUD. The "cso" parameter acts as a filter.
  * If "cso" is not the recording context, recording is skipped.
  * If "cso" is not the drawing context, drawing is skipped.
@@ -835,33 +866,35 @@ hud_pane_update_dyn_ceiling(struct hud_graph *gr, struct hud_pane *pane)
    /*
     * Mark this adjustment run so we could avoid repeating a full update
     * again needlessly in case the pane has more than one graph.
     */
    pane->dyn_ceil_last_ran = gr->index;
 }
 
 static struct hud_pane *
 hud_pane_create(struct hud_context *hud,
                 unsigned x1, unsigned y1, unsigned x2, unsigned y2,
+                unsigned y_simple,
                 unsigned period, uint64_t max_value, uint64_t ceiling,
                 boolean dyn_ceiling, boolean sort_items)
 {
    struct hud_pane *pane = CALLOC_STRUCT(hud_pane);
 
    if (!pane)
       return NULL;
 
    pane->hud = hud;
    pane->x1 = x1;
    pane->y1 = y1;
    pane->x2 = x2;
    pane->y2 = y2;
+   pane->y_simple = y_simple;
    pane->inner_x1 = x1 + 1;
    pane->inner_x2 = x2 - 1;
    pane->inner_y1 = y1 + 1;
    pane->inner_y2 = y2 - 1;
    pane->inner_width = pane->inner_x2 - pane->inner_x1;
    pane->inner_height = pane->inner_y2 - pane->inner_y1;
    pane->period = period;
    pane->max_num_vertices = (x2 - x1 + 2) / 2;
    pane->ceiling = ceiling;
    pane->dyn_ceiling = dyn_ceiling;
@@ -1149,30 +1182,35 @@ has_pipeline_stats_query(struct pipe_screen *screen)
 }
 
 static void
 hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
                   const char *env)
 {
    unsigned num, i;
    char name_a[256], s[256];
    char *name;
    struct hud_pane *pane = NULL;
-   unsigned x = 10, y = 10;
+   unsigned x = 10, y = 10, y_simple = 10;
    unsigned width = 251, height = 100;
    unsigned period = 500 * 1000;  /* default period (1/2 second) */
    uint64_t ceiling = UINT64_MAX;
    unsigned column_width = 251;
    boolean dyn_ceiling = false;
    boolean reset_colors = false;
    boolean sort_items = false;
    const char *period_env;
 
+   if (util_strncmp(env, "simple,", 7) == 0) {
+      hud->simple = true;
+      env += 7;
+   }
+
    /*
     * The GALLIUM_HUD_PERIOD env var sets the graph update rate.
     * The env var is in seconds (a float).
     * Zero means update after every frame.
     */
    period_env = getenv("GALLIUM_HUD_PERIOD");
    if (period_env) {
       float p = (float) atof(period_env);
       if (p >= 0.0f) {
          period = (unsigned) (p * 1000 * 1000);
@@ -1187,22 +1225,22 @@ hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
                                 &dyn_ceiling, &reset_colors, &sort_items);
 
      /*
       * Keep track of overall column width to avoid pane overlapping in case
       * later we create a new column while the bottom pane in the current
       * column is less wide than the rest of the panes in it.
       */
      column_width = width > column_width ? width : column_width;
 
       if (!pane) {
-         pane = hud_pane_create(hud, x, y, x + width, y + height, period, 10,
-                                ceiling, dyn_ceiling, sort_items);
+         pane = hud_pane_create(hud, x, y, x + width, y + height, y_simple,
+                                period, 10, ceiling, dyn_ceiling, sort_items);
          if (!pane)
             return;
       }
 
       if (reset_colors) {
          pane->next_color = 0;
          reset_colors = false;
       }
 
       /* Add a graph. */
@@ -1407,31 +1445,33 @@ hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
       case '+':
          env++;
          break;
 
       case ',':
          env++;
          if (!pane)
             break;
 
          y += height + hud->font.glyph_height * (pane->num_graphs + 2);
+         y_simple += hud->font.glyph_height * (pane->num_graphs + 1);
          height = 100;
 
          if (pane && pane->num_graphs) {
             LIST_ADDTAIL(&pane->head, &hud->pane_list);
             pane = NULL;
          }
          break;
 
       case ';':
          env++;
          y = 10;
+         y_simple = 10;
          x += column_width + hud->font.glyph_width * 9;
          height = 100;
 
          if (pane && pane->num_graphs) {
             LIST_ADDTAIL(&pane->head, &hud->pane_list);
             pane = NULL;
          }
 
          /* Starting a new column; reset column width. */
          column_width = 251;
@@ -1506,20 +1546,24 @@ print_help(struct pipe_screen *screen)
    puts("             the ceiling allows, the value is clamped.");
    puts("  'd' activates dynamic Y axis readjustment to set the value of");
    puts("      the Y axis to match the highest value still visible in the graph.");
    puts("  'r' resets the color counter (the next color will be green)");
    puts("  's' sort items below graphs in descending order");
    puts("");
    puts("  If 'c' and 'd' modifiers are used simultaneously, both are in effect:");
    puts("  the Y axis does not go above the restriction imposed by 'c' while");
    puts("  still adjusting the value of the Y axis down when appropriate.");
    puts("");
+   puts("  You can change behavior of the whole HUD by adding these options at");
+   puts("  the beginning of the environment variable:");
+   puts("  'simple,' disables all the fancy stuff and only draws text.");
+   puts("");
    puts("  Example: GALLIUM_HUD=\".w256.h64.x1600.y520.d.c1000fps+cpu,.datom-count\"");
    puts("");
    puts("  Available names:");
    puts("    fps");
    puts("    cpu");
 
    for (i = 0; i < num_cpus; i++)
       printf("    cpu%i\n", i);
 
    if (has_occlusion_query(screen))
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index a51436ff5f1..b64e29e93e5 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -34,20 +34,21 @@
 #include "hud/font.h"
 
 enum hud_counter {
    HUD_COUNTER_OFFLOADED,
    HUD_COUNTER_DIRECT,
    HUD_COUNTER_SYNCS,
 };
 
 struct hud_context {
    int refcount;
+   bool simple;
 
    /* Context where queries are executed. */
    struct pipe_context *record_pipe;
 
    /* Context where the HUD is drawn: */
    struct pipe_context *pipe;
    struct cso_context *cso;
 
    struct hud_batch_query_context *batch_query;
    struct list_head pane_list;
@@ -111,21 +112,21 @@ struct hud_graph {
    /* mutable variables */
    unsigned num_vertices;
    unsigned index; /* vertex index being updated */
    double current_value;
    FILE *fd;
 };
 
 struct hud_pane {
    struct list_head head;
    struct hud_context *hud;
-   unsigned x1, y1, x2, y2;
+   unsigned x1, y1, x2, y2, y_simple;
    unsigned inner_x1;
    unsigned inner_y1;
    unsigned inner_x2;
    unsigned inner_y2;
    unsigned inner_width;
    unsigned inner_height;
    float yscale;
    unsigned max_num_vertices;
    unsigned last_line; /* index of the last describing line in the graph */
    uint64_t max_value;
-- 
2.15.1



More information about the mesa-dev mailing list