[Mesa-dev] [PATCH 2/2] gallium/hud: disable queries during HUD draw calls

Marek Olšák maraeo at gmail.com
Mon Jan 16 01:59:37 UTC 2017


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

---
 src/gallium/auxiliary/hud/hud_context.c      | 10 ++++++++++
 src/gallium/auxiliary/hud/hud_driver_query.c | 18 +++++++++++++++++-
 src/gallium/auxiliary/hud/hud_private.h      |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c
index 9f067f3..fd9a7bc 100644
--- a/src/gallium/auxiliary/hud/hud_context.c
+++ b/src/gallium/auxiliary/hud/hud_context.c
@@ -655,20 +655,30 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
    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);
+
+   /* Start queries. */
+   hud_batch_query_begin(hud->batch_query);
+
+   LIST_FOR_EACH_ENTRY(pane, &hud->pane_list, head) {
+      LIST_FOR_EACH_ENTRY(gr, &pane->graph_list, head) {
+         if (gr->begin_query)
+            gr->begin_query(gr);
+      }
+   }
 }
 
 static void
 fixup_bytes(enum pipe_driver_query_type type, int position, uint64_t *exp10)
 {
    if (type == PIPE_DRIVER_QUERY_TYPE_BYTES && position % 3 == 0)
       *exp10 = (*exp10 / 1000) * 1024;
 }
 
 /**
diff --git a/src/gallium/auxiliary/hud/hud_driver_query.c b/src/gallium/auxiliary/hud/hud_driver_query.c
index d80b8ed..6a97dbd 100644
--- a/src/gallium/auxiliary/hud/hud_driver_query.c
+++ b/src/gallium/auxiliary/hud/hud_driver_query.c
@@ -109,22 +109,29 @@ hud_batch_query_update(struct hud_batch_query_context *bq)
                                                      bq->query_types);
 
       if (!bq->query[bq->head]) {
          fprintf(stderr,
                  "gallium_hud: create_batch_query failed. You may have "
                  "selected too many or incompatible queries.\n");
          bq->failed = TRUE;
          return;
       }
    }
+}
+
+void
+hud_batch_query_begin(struct hud_batch_query_context *bq)
+{
+   if (!bq || bq->failed || !bq->query[bq->head])
+      return;
 
-   if (!pipe->begin_query(pipe, bq->query[bq->head])) {
+   if (!bq->pipe->begin_query(bq->pipe, bq->query[bq->head])) {
       fprintf(stderr,
               "gallium_hud: could not begin batch query. You may have "
               "selected too many or incompatible queries.\n");
       bq->failed = TRUE;
    }
 }
 
 static boolean
 batch_query_add(struct hud_batch_query_context **pbq,
                 struct pipe_context *pipe, unsigned query_type,
@@ -270,21 +277,29 @@ query_new_value_normal(struct query_info *info)
                }
             }
             break;
          }
       }
    }
    else {
       /* initialize */
       info->query[info->head] = pipe->create_query(pipe, info->query_type, 0);
    }
+}
+
+static void
+begin_query(struct hud_graph *gr)
+{
+   struct query_info *info = gr->query_data;
+   struct pipe_context *pipe = info->pipe;
 
+   assert(!info->batch);
    if (info->query[info->head])
       pipe->begin_query(pipe, info->query[info->head]);
 }
 
 static void
 query_new_value(struct hud_graph *gr)
 {
    struct query_info *info = gr->query_data;
    uint64_t now = os_time_get();
 
@@ -367,20 +382,21 @@ hud_pipe_query_install(struct hud_batch_query_context **pbq,
 
    info = gr->query_data;
    info->pipe = pipe;
    info->result_type = result_type;
 
    if (flags & PIPE_DRIVER_QUERY_FLAG_BATCH) {
       if (!batch_query_add(pbq, pipe, query_type, &info->result_index))
          goto fail_info;
       info->batch = *pbq;
    } else {
+      gr->begin_query = begin_query;
       info->query_type = query_type;
       info->result_index = result_index;
    }
 
    hud_graph_set_dump_file(gr);
 
    hud_pane_add_graph(pane, gr);
    pane->type = type; /* must be set before updating the max_value */
 
    if (pane->max_value < max_value)
diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h
index d719e5f..b23439e 100644
--- a/src/gallium/auxiliary/hud/hud_private.h
+++ b/src/gallium/auxiliary/hud/hud_private.h
@@ -34,20 +34,21 @@
 struct hud_graph {
    /* initialized by common code */
    struct list_head head;
    struct hud_pane *pane;
    float color[3];
    float *vertices; /* ring buffer of vertices */
 
    /* name and query */
    char name[128];
    void *query_data;
+   void (*begin_query)(struct hud_graph *gr);
    void (*query_new_value)(struct hud_graph *gr);
    void (*free_query_data)(void *ptr); /**< do not use ordinary free() */
 
    /* mutable variables */
    unsigned num_vertices;
    unsigned index; /* vertex index being updated */
    uint64_t current_value;
    FILE *fd;
 };
 
@@ -96,20 +97,21 @@ void hud_pipe_query_install(struct hud_batch_query_context **pbq,
                             struct hud_pane *pane, struct pipe_context *pipe,
                             const char *name, unsigned query_type,
                             unsigned result_index,
                             uint64_t max_value,
                             enum pipe_driver_query_type type,
                             enum pipe_driver_query_result_type result_type,
                             unsigned flags);
 boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
                                  struct hud_pane *pane,
                                  struct pipe_context *pipe, const char *name);
+void hud_batch_query_begin(struct hud_batch_query_context *bq);
 void hud_batch_query_update(struct hud_batch_query_context *bq);
 void hud_batch_query_cleanup(struct hud_batch_query_context **pbq);
 
 void hud_graph_set_dump_file(struct hud_graph *gr);
 
 #if HAVE_GALLIUM_EXTRA_HUD
 int hud_get_num_nics(bool displayhelp);
 #define NIC_DIRECTION_RX 1
 #define NIC_DIRECTION_TX 2
 #define NIC_RSSI_DBM     3
-- 
2.7.4



More information about the mesa-dev mailing list