r600g: re-enable single-sample fast clear
[mesa.git] / src / gallium / drivers / svga / svga_pipe_query.c
index 11f6a052730b4373395844e406009db6125ddf48..208a2cd14bffab6f4c8cb342c483b46f8325410a 100644 (file)
@@ -42,6 +42,7 @@ struct pipe_query {
    int dummy;
 };
 
+
 struct svga_query {
    struct pipe_query base;
    unsigned type;                  /**< PIPE_QUERY_x or SVGA_QUERY_x */
@@ -56,23 +57,26 @@ struct svga_query {
    uint64_t begin_count, end_count;
 };
 
-/***********************************************************************
- * Inline conversion functions.  These are better-typed than the
- * macros used previously:
- */
-static INLINE struct svga_query *
+
+/** cast wrapper */
+static inline struct svga_query *
 svga_query( struct pipe_query *q )
 {
    return (struct svga_query *)q;
 }
 
-static boolean svga_get_query_result(struct pipe_context *pipe, 
-                                     struct pipe_query *q,
-                                     boolean wait,
-                                     union pipe_query_result *result);
 
-static struct pipe_query *svga_create_query( struct pipe_context *pipe,
-                                             unsigned query_type )
+static boolean
+svga_get_query_result(struct pipe_context *pipe,
+                      struct pipe_query *q,
+                      boolean wait,
+                      union pipe_query_result *result);
+
+
+static struct pipe_query *
+svga_create_query(struct pipe_context *pipe,
+                  unsigned query_type,
+                  unsigned index)
 {
    struct svga_context *svga = svga_context( pipe );
    struct svga_screen *svgascreen = svga_screen(pipe->screen);
@@ -92,13 +96,17 @@ static struct pipe_query *svga_create_query( struct pipe_context *pipe,
       sq->hwbuf = svga_winsys_buffer_create(svga, 1,
                                             SVGA_BUFFER_USAGE_PINNED,
                                             sizeof *sq->queryResult);
-      if (!sq->hwbuf)
+      if (!sq->hwbuf) {
+         debug_printf("svga: failed to alloc query object!\n");
          goto no_hwbuf;
+      }
 
       sq->queryResult = (SVGA3dQueryResult *)
          sws->buffer_map(sws, sq->hwbuf, PIPE_TRANSFER_WRITE);
-      if (!sq->queryResult)
+      if (!sq->queryResult) {
+         debug_printf("svga: failed to map query object!\n");
          goto no_query_result;
+      }
 
       sq->queryResult->totalSize = sizeof *sq->queryResult;
       sq->queryResult->state = SVGA3D_QUERYSTATE_NEW;
@@ -111,6 +119,7 @@ static struct pipe_query *svga_create_query( struct pipe_context *pipe,
       break;
    case SVGA_QUERY_DRAW_CALLS:
    case SVGA_QUERY_FALLBACKS:
+   case SVGA_QUERY_MEMORY_USED:
       break;
    default:
       assert(!"unexpected query type in svga_create_query()");
@@ -128,8 +137,9 @@ no_sq:
    return NULL;
 }
 
-static void svga_destroy_query(struct pipe_context *pipe,
-                               struct pipe_query *q)
+
+static void
+svga_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
 {
    struct svga_screen *svgascreen = svga_screen(pipe->screen);
    struct svga_winsys_screen *sws = svgascreen->sws;
@@ -140,10 +150,12 @@ static void svga_destroy_query(struct pipe_context *pipe,
    switch (sq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
       sws->buffer_destroy(sws, sq->hwbuf);
+      sq->hwbuf = NULL;
       sws->fence_reference(sws, &sq->fence, NULL);
       break;
    case SVGA_QUERY_DRAW_CALLS:
    case SVGA_QUERY_FALLBACKS:
+   case SVGA_QUERY_MEMORY_USED:
       /* nothing */
       break;
    default:
@@ -153,8 +165,9 @@ static void svga_destroy_query(struct pipe_context *pipe,
    FREE(sq);
 }
 
-static void svga_begin_query(struct pipe_context *pipe, 
-                             struct pipe_query *q)
+
+static boolean
+svga_begin_query(struct pipe_context *pipe, struct pipe_query *q)
 {
    struct svga_screen *svgascreen = svga_screen(pipe->screen);
    struct svga_winsys_screen *sws = svgascreen->sws;
@@ -163,22 +176,22 @@ static void svga_begin_query(struct pipe_context *pipe,
    enum pipe_error ret;
 
    SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__);
-   
+
    /* Need to flush out buffered drawing commands so that they don't
     * get counted in the query results.
     */
    svga_hwtnl_flush_retry(svga);
-   
+
    switch (sq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
       assert(!svga->sq);
       if (sq->queryResult->state == SVGA3D_QUERYSTATE_PENDING) {
-         /* The application doesn't care for the pending query result. We cannot
-          * let go the existing buffer and just get a new one because its storage
-          * may be reused for other purposes and clobbered by the host when it
-          * determines the query result. So the only option here is to wait for
-          * the existing query's result -- not a big deal, given that no sane
-          * application would do this.
+         /* The application doesn't care for the pending query result.
+          * We cannot let go of the existing buffer and just get a new one
+          * because its storage may be reused for other purposes and clobbered
+          * by the host when it determines the query result.  So the only
+          * option here is to wait for the existing query's result -- not a
+          * big deal, given that no sane application would do this.
           */
          uint64_t result;
          svga_get_query_result(pipe, q, TRUE, (void*)&result);
@@ -203,13 +216,18 @@ static void svga_begin_query(struct pipe_context *pipe,
    case SVGA_QUERY_FALLBACKS:
       sq->begin_count = svga->num_fallbacks;
       break;
+   case SVGA_QUERY_MEMORY_USED:
+      /* nothing */
+      break;
    default:
       assert(!"unexpected query type in svga_begin_query()");
    }
+   return true;
 }
 
-static void svga_end_query(struct pipe_context *pipe, 
-                           struct pipe_query *q)
+
+static void
+svga_end_query(struct pipe_context *pipe, struct pipe_query *q)
 {
    struct svga_context *svga = svga_context( pipe );
    struct svga_query *sq = svga_query( q );
@@ -218,7 +236,7 @@ static void svga_end_query(struct pipe_context *pipe,
    SVGA_DBG(DEBUG_QUERY, "%s\n", __FUNCTION__);
 
    svga_hwtnl_flush_retry(svga);
-   
+
    switch (sq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
       assert(svga->sq == sq);
@@ -233,9 +251,10 @@ static void svga_end_query(struct pipe_context *pipe,
          assert(ret == PIPE_OK);
       }
 
-      /* TODO: Delay flushing. We don't really need to flush here, just ensure 
-       * that there is one flush before svga_get_query_result attempts to get the
-       * result */
+      /* TODO: Delay flushing. We don't really need to flush here, just ensure
+       * that there is one flush before svga_get_query_result attempts to get
+       * the result.
+       */
       svga_context_flush(svga, NULL);
 
       svga->sq = NULL;
@@ -246,30 +265,35 @@ static void svga_end_query(struct pipe_context *pipe,
    case SVGA_QUERY_FALLBACKS:
       sq->end_count = svga->num_fallbacks;
       break;
+   case SVGA_QUERY_MEMORY_USED:
+      /* nothing */
+      break;
    default:
       assert(!"unexpected query type in svga_end_query()");
    }
 }
 
-static boolean svga_get_query_result(struct pipe_context *pipe, 
-                                     struct pipe_query *q,
-                                     boolean wait,
-                                     union pipe_query_result *vresult)
+
+static boolean
+svga_get_query_result(struct pipe_context *pipe,
+                      struct pipe_query *q,
+                      boolean wait,
+                      union pipe_query_result *vresult)
 {
    struct svga_context *svga = svga_context( pipe );
    struct svga_screen *svgascreen = svga_screen( pipe->screen );
    struct svga_winsys_screen *sws = svgascreen->sws;
    struct svga_query *sq = svga_query( q );
    SVGA3dQueryState state;
-   uint64_t *result = (uint64_t*)vresult;
-   
+   uint64_t *result = (uint64_t *) vresult;
+
    SVGA_DBG(DEBUG_QUERY, "%s wait: %d\n", __FUNCTION__);
 
    switch (sq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
-      /* The query status won't be updated by the host unless 
-       * SVGA_3D_CMD_WAIT_FOR_QUERY is emitted. Unfortunately this will cause a 
-       * synchronous wait on the host.
+      /* The query status won't be updated by the host unless
+       * SVGA_3D_CMD_WAIT_FOR_QUERY is emitted. Unfortunately this will cause
+       * synchronous wait on the host.
        */
       if (!sq->fence) {
          enum pipe_error ret;
@@ -294,16 +318,19 @@ static boolean svga_get_query_result(struct pipe_context *pipe,
          state = sq->queryResult->state;
       }
 
-      assert(state == SVGA3D_QUERYSTATE_SUCCEEDED || 
+      assert(state == SVGA3D_QUERYSTATE_SUCCEEDED ||
              state == SVGA3D_QUERYSTATE_FAILED);
 
-      *result = (uint64_t)sq->queryResult->result32;
+      *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;
+   case SVGA_QUERY_MEMORY_USED:
+      vresult->u64 = svgascreen->total_resource_bytes;
+      break;
    default:
       assert(!"unexpected query type in svga_get_query_result");
    }
@@ -314,8 +341,8 @@ static boolean svga_get_query_result(struct pipe_context *pipe,
 }
 
 
-
-void svga_init_query_functions( struct svga_context *svga )
+void
+svga_init_query_functions(struct svga_context *svga)
 {
    svga->pipe.create_query = svga_create_query;
    svga->pipe.destroy_query = svga_destroy_query;