[Mesa-dev] [PATCH 2/2] svga: add HUD queries for number of draw calls, number of fallbacks

Brian Paul brian.e.paul at gmail.com
Tue Apr 2 07:27:16 PDT 2013


From: Brian Paul <brianp at vmware.com>

The fallbacks count is the number of drawing calls that use a "draw"
module fallback, such as polygon stipple.
---
 src/gallium/drivers/svga/svga_context.h    |    9 +++++++++
 src/gallium/drivers/svga/svga_pipe_draw.c  |    3 +++
 src/gallium/drivers/svga/svga_pipe_query.c |   27 +++++++++++++++++++++++++++
 src/gallium/drivers/svga/svga_screen.c     |   22 ++++++++++++++++++++++
 4 files changed, 61 insertions(+)

diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h
index 32671ec..e27778e 100644
--- a/src/gallium/drivers/svga/svga_context.h
+++ b/src/gallium/drivers/svga/svga_context.h
@@ -42,6 +42,11 @@
 #include "svga3d_shaderdefs.h"
 
 
+/** Non-GPU queries for gallium HUD */
+#define SVGA_QUERY_DRAW_CALLS   (PIPE_QUERY_DRIVER_SPECIFIC + 0)
+#define SVGA_QUERY_FALLBACKS    (PIPE_QUERY_DRIVER_SPECIFIC + 1)
+
+
 struct draw_vertex_shader;
 struct draw_fragment_shader;
 struct svga_shader_result;
@@ -370,6 +375,10 @@ struct svga_context
 
    /** List of buffers with queued transfers */
    struct list_head dirty_buffers;
+
+   /** performance / info queries */
+   uint64_t num_draw_calls;  /**< SVGA_QUERY_DRAW_CALLS */
+   uint64_t num_fallbacks;   /**< SVGA_QUERY_FALLBACKS */
 };
 
 /* A flag for each state_tracker state object:
diff --git a/src/gallium/drivers/svga/svga_pipe_draw.c b/src/gallium/drivers/svga/svga_pipe_draw.c
index e72032e..f0da170 100644
--- a/src/gallium/drivers/svga/svga_pipe_draw.c
+++ b/src/gallium/drivers/svga/svga_pipe_draw.c
@@ -330,6 +330,8 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    enum pipe_error ret = 0;
    boolean needed_swtnl;
 
+   svga->num_draw_calls++;  /* for SVGA_QUERY_DRAW_CALLS */
+
    if (!u_trim_pipe_prim( info->mode, &count ))
       return;
 
@@ -358,6 +360,7 @@ svga_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
 #endif
 
    if (svga->state.sw.need_swtnl) {
+      svga->num_fallbacks++;  /* for SVGA_QUERY_FALLBACKS */
       if (!needed_swtnl) {
          /*
           * We're switching from HW to SW TNL.  SW TNL will require mapping all
diff --git a/src/gallium/drivers/svga/svga_pipe_query.c b/src/gallium/drivers/svga/svga_pipe_query.c
index b83c7d4..6fa6fac 100644
--- a/src/gallium/drivers/svga/svga_pipe_query.c
+++ b/src/gallium/drivers/svga/svga_pipe_query.c
@@ -51,6 +51,9 @@ struct svga_query {
    struct svga_winsys_buffer *hwbuf;
    volatile SVGA3dQueryResult *queryResult;
    struct pipe_fence_handle *fence;
+
+   /** For non-GPU SVGA_QUERY_x queries */
+   uint64_t begin_count, end_count;
 };
 
 /***********************************************************************
@@ -106,6 +109,9 @@ static struct pipe_query *svga_create_query( struct pipe_context *pipe,
        */
       sws->buffer_unmap(sws, sq->hwbuf);
       break;
+   case SVGA_QUERY_DRAW_CALLS:
+   case SVGA_QUERY_FALLBACKS:
+      break;
    default:
       assert(!"unexpected query type in svga_create_query()");
    }
@@ -136,6 +142,10 @@ static void svga_destroy_query(struct pipe_context *pipe,
       sws->buffer_destroy(sws, sq->hwbuf);
       sws->fence_reference(sws, &sq->fence, NULL);
       break;
+   case SVGA_QUERY_DRAW_CALLS:
+   case SVGA_QUERY_FALLBACKS:
+      /* nothing */
+      break;
    default:
       assert(!"svga: unexpected query type in svga_destroy_query()");
    }
@@ -187,6 +197,12 @@ static void svga_begin_query(struct pipe_context *pipe,
 
       svga->sq = sq;
       break;
+   case SVGA_QUERY_DRAW_CALLS:
+      sq->begin_count = svga->num_draw_calls;
+      break;
+   case SVGA_QUERY_FALLBACKS:
+      sq->begin_count = svga->num_fallbacks;
+      break;
    default:
       assert(!"unexpected query type in svga_begin_query()");
    }
@@ -224,6 +240,12 @@ static void svga_end_query(struct pipe_context *pipe,
 
       svga->sq = NULL;
       break;
+   case SVGA_QUERY_DRAW_CALLS:
+      sq->end_count = svga->num_draw_calls;
+      break;
+   case SVGA_QUERY_FALLBACKS:
+      sq->end_count = svga->num_fallbacks;
+      break;
    default:
       assert(!"unexpected query type in svga_end_query()");
    }
@@ -277,6 +299,11 @@ static boolean svga_get_query_result(struct pipe_context *pipe,
 
       *result = (uint64_t)sq->queryResult->result32;
       break;
+   case SVGA_QUERY_DRAW_CALLS:
+      /* fall-through */
+   case SVGA_QUERY_FALLBACKS:
+      vresult->u64 = sq->end_count - sq->begin_count;
+      break;
    default:
       assert(!"unexpected query type in svga_get_query_result");
    }
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index 0558a46..70e2fa8 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -491,6 +491,27 @@ svga_fence_finish(struct pipe_screen *screen,
 }
 
 
+static int
+svga_get_driver_query_info(struct pipe_screen *screen,
+                           unsigned index,
+                           struct pipe_driver_query_info *info)
+{
+   static const struct pipe_driver_query_info queries[] = {
+      {"draw-calls", SVGA_QUERY_DRAW_CALLS, 0, FALSE},
+      {"fallbacks", SVGA_QUERY_FALLBACKS, 0, FALSE}
+   };
+
+   if (!info)
+      return Elements(queries);
+
+   if (index >= Elements(queries))
+      return 0;
+
+   *info = queries[index];
+   return 1;
+}
+
+
 static void
 svga_destroy_screen( struct pipe_screen *screen )
 {
@@ -550,6 +571,7 @@ svga_screen_create(struct svga_winsys_screen *sws)
    screen->fence_reference = svga_fence_reference;
    screen->fence_signalled = svga_fence_signalled;
    screen->fence_finish = svga_fence_finish;
+   screen->get_driver_query_info = svga_get_driver_query_info;
    svgascreen->sws = sws;
 
    svga_init_screen_resource_functions(svgascreen);
-- 
1.7.9.5



More information about the mesa-dev mailing list