freedreno/a5xx: fallback to slow-clear for z32
[mesa.git] / src / gallium / drivers / freedreno / freedreno_query.c
index a27ddb5c638d7cd5813740209e02c8220eeb20f8..0d7bc9f205bd4a39f4f6b3e5277c18c14056fcd8 100644 (file)
@@ -63,14 +63,34 @@ 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 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;
 }
 
@@ -79,6 +99,12 @@ 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);
 }