freedreno/a5xx: fallback to slow-clear for z32
[mesa.git] / src / gallium / drivers / freedreno / freedreno_query.c
index b87e825071941df80dd7e981f7bb85c2bb0a961f..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;
 }
@@ -63,14 +63,35 @@ static boolean
 fd_begin_query(struct pipe_context *pctx, struct pipe_query *pq)
 {
        struct fd_query *q = fd_query(pq);
-       return 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,12 +99,18 @@ 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, uint mode)
+                                       boolean condition, enum pipe_render_cond_flag mode)
 {
        struct fd_context *ctx = fd_context(pctx);
        ctx->cond_query = pq;
@@ -114,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)
 {
@@ -128,5 +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;
 }