freedreno/a5xx: fallback to slow-clear for z32
[mesa.git] / src / gallium / drivers / freedreno / freedreno_query.c
index cb3b49a5f5831ba6783277651cc77b7eacbe9302..0d7bc9f205bd4a39f4f6b3e5277c18c14056fcd8 100644 (file)
@@ -46,8 +46,8 @@ fd_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)
        struct fd_query *q;
 
        q = fd_sw_create_query(ctx, query_type);
-       if (!q)
-               q = fd_hw_create_query(ctx, query_type);
+       if (!q && ctx->create_query)
+               q = ctx->create_query(ctx, query_type);
 
        return (struct pipe_query *) q;
 }
@@ -59,18 +59,39 @@ fd_destroy_query(struct pipe_context *pctx, struct pipe_query *pq)
        q->funcs->destroy_query(fd_context(pctx), q);
 }
 
-static void
+static boolean
 fd_begin_query(struct pipe_context *pctx, struct pipe_query *pq)
 {
        struct fd_query *q = fd_query(pq);
-       q->funcs->begin_query(fd_context(pctx), q);
+       boolean ret;
+
+       if (q->active)
+               return false;
+
+       ret = q->funcs->begin_query(fd_context(pctx), q);
+       q->active = ret;
+
+       return ret;
 }
 
-static void
+static bool
 fd_end_query(struct pipe_context *pctx, struct pipe_query *pq)
 {
        struct fd_query *q = fd_query(pq);
+
+       /* there are a couple special cases, which don't have
+        * a matching ->begin_query():
+        */
+       if (skip_begin_query(q->type) && !q->active)
+               fd_begin_query(pctx, pq);
+
+       if (!q->active)
+               return false;
+
        q->funcs->end_query(fd_context(pctx), q);
+       q->active = false;
+
+       return true;
 }
 
 static boolean
@@ -78,20 +99,36 @@ fd_get_query_result(struct pipe_context *pctx, struct pipe_query *pq,
                boolean wait, union pipe_query_result *result)
 {
        struct fd_query *q = fd_query(pq);
+
+       if (q->active)
+               return false;
+
+       util_query_clear_result(result, q->type);
+
        return q->funcs->get_query_result(fd_context(pctx), q, wait, result);
 }
 
+static void
+fd_render_condition(struct pipe_context *pctx, struct pipe_query *pq,
+                                       boolean condition, enum pipe_render_cond_flag mode)
+{
+       struct fd_context *ctx = fd_context(pctx);
+       ctx->cond_query = pq;
+       ctx->cond_cond = condition;
+       ctx->cond_mode = mode;
+}
+
 static int
 fd_get_driver_query_info(struct pipe_screen *pscreen,
                unsigned index, struct pipe_driver_query_info *info)
 {
        struct pipe_driver_query_info list[] = {
-                       {"draw-calls", FD_QUERY_DRAW_CALLS, 0},
-                       {"batches", FD_QUERY_BATCH_TOTAL, 0},
-                       {"batches-sysmem", FD_QUERY_BATCH_SYSMEM, 0},
-                       {"batches-gmem", FD_QUERY_BATCH_GMEM, 0},
-                       {"restores", FD_QUERY_BATCH_RESTORE, 0},
-                       {"prims-emitted", PIPE_QUERY_PRIMITIVES_EMITTED, 0},
+                       {"draw-calls", FD_QUERY_DRAW_CALLS, {0}},
+                       {"batches", FD_QUERY_BATCH_TOTAL, {0}},
+                       {"batches-sysmem", FD_QUERY_BATCH_SYSMEM, {0}},
+                       {"batches-gmem", FD_QUERY_BATCH_GMEM, {0}},
+                       {"restores", FD_QUERY_BATCH_RESTORE, {0}},
+                       {"prims-emitted", PIPE_QUERY_PRIMITIVES_EMITTED, {0}},
        };
 
        if (!info)
@@ -104,6 +141,11 @@ fd_get_driver_query_info(struct pipe_screen *pscreen,
        return 1;
 }
 
+static void
+fd_set_active_query_state(struct pipe_context *pipe, boolean enable)
+{
+}
+
 void
 fd_query_screen_init(struct pipe_screen *pscreen)
 {
@@ -118,4 +160,6 @@ fd_query_context_init(struct pipe_context *pctx)
        pctx->begin_query = fd_begin_query;
        pctx->end_query = fd_end_query;
        pctx->get_query_result = fd_get_query_result;
+       pctx->set_active_query_state = fd_set_active_query_state;
+       pctx->render_condition = fd_render_condition;
 }