freedreno: Fix detection of being in a blit for acc queries.
authorEric Anholt <eric@anholt.net>
Sat, 28 Mar 2020 00:23:19 +0000 (17:23 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 30 Mar 2020 21:35:21 +0000 (21:35 +0000)
The batch might not have stage == FD_STAGE_BLIT set because
fd_blitter_pipe_begin was sticking the stage on some random batch (or none
at all) rather than the one that would be used in the meta operation.

What we actually wanted to be looking at was set_active_query_state(),
which is already called by util_blitter and whose state we just needed to
track.

Fixes piglit occlusion_query_meta_no_fragments.  I haven't changed
query_hw.c's stage handling to clean the rest up because I don't have a
db410c/db820c at home to iterate over the piglit tests.

Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4356>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4356>

src/gallium/drivers/freedreno/a2xx/fd2_query.c
src/gallium/drivers/freedreno/a5xx/fd5_query.c
src/gallium/drivers/freedreno/a6xx/fd6_query.c
src/gallium/drivers/freedreno/freedreno_blitter.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h
src/gallium/drivers/freedreno/freedreno_query.c
src/gallium/drivers/freedreno/freedreno_query_acc.c
src/gallium/drivers/freedreno/freedreno_query_acc.h
src/gallium/drivers/freedreno/freedreno_query_hw.c

index b51903fcf97ad93a96428af5bd9436d266e1d2f1..5261a6911bb4500df14da0c75890da1e9f6d8dc9 100644 (file)
@@ -151,7 +151,7 @@ perfcntr_accumulate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider perfcntr = {
                .query_type = FD_QUERY_FIRST_PERFCNTR,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .resume = perfcntr_resume,
                .pause = perfcntr_pause,
                .result = perfcntr_accumulate_result,
index 6cf9e2d614029f200a2f5003570eb1fb39cd6ce0..ac11dbb86ee55d8f61f27a9556a9dd9a6cfcb738 100644 (file)
@@ -134,7 +134,6 @@ occlusion_predicate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider occlusion_counter = {
                .query_type = PIPE_QUERY_OCCLUSION_COUNTER,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd5_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -143,7 +142,6 @@ static const struct fd_acc_sample_provider occlusion_counter = {
 
 static const struct fd_acc_sample_provider occlusion_predicate = {
                .query_type = PIPE_QUERY_OCCLUSION_PREDICATE,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd5_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -152,7 +150,6 @@ static const struct fd_acc_sample_provider occlusion_predicate = {
 
 static const struct fd_acc_sample_provider occlusion_predicate_conservative = {
                .query_type = PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd5_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -229,7 +226,7 @@ timestamp_accumulate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider time_elapsed = {
                .query_type = PIPE_QUERY_TIME_ELAPSED,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .size = sizeof(struct fd5_query_sample),
                .resume = timestamp_resume,
                .pause = timestamp_pause,
@@ -245,7 +242,7 @@ static const struct fd_acc_sample_provider time_elapsed = {
 
 static const struct fd_acc_sample_provider timestamp = {
                .query_type = PIPE_QUERY_TIMESTAMP,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .size = sizeof(struct fd5_query_sample),
                .resume = timestamp_resume,
                .pause = timestamp_pause,
@@ -366,7 +363,7 @@ perfcntr_accumulate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider perfcntr = {
                .query_type = FD_QUERY_FIRST_PERFCNTR,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .resume = perfcntr_resume,
                .pause = perfcntr_pause,
                .result = perfcntr_accumulate_result,
index 6354e037f39b84f1f3801a9bd35e30b3b0a97200..90b93288d2afbf09db9e6b5b2363e6ae19893ff3 100644 (file)
@@ -134,7 +134,6 @@ occlusion_predicate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider occlusion_counter = {
                .query_type = PIPE_QUERY_OCCLUSION_COUNTER,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd6_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -143,7 +142,6 @@ static const struct fd_acc_sample_provider occlusion_counter = {
 
 static const struct fd_acc_sample_provider occlusion_predicate = {
                .query_type = PIPE_QUERY_OCCLUSION_PREDICATE,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd6_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -152,7 +150,6 @@ static const struct fd_acc_sample_provider occlusion_predicate = {
 
 static const struct fd_acc_sample_provider occlusion_predicate_conservative = {
                .query_type = PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE,
-               .active = FD_STAGE_DRAW,
                .size = sizeof(struct fd6_query_sample),
                .resume = occlusion_resume,
                .pause = occlusion_pause,
@@ -235,7 +232,7 @@ timestamp_accumulate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider time_elapsed = {
                .query_type = PIPE_QUERY_TIME_ELAPSED,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .size = sizeof(struct fd6_query_sample),
                .resume = timestamp_resume,
                .pause = time_elapsed_pause,
@@ -251,7 +248,7 @@ static const struct fd_acc_sample_provider time_elapsed = {
 
 static const struct fd_acc_sample_provider timestamp = {
                .query_type = PIPE_QUERY_TIMESTAMP,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .size = sizeof(struct fd6_query_sample),
                .resume = timestamp_resume,
                .pause = timestamp_pause,
@@ -377,7 +374,6 @@ primitives_generated_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider primitives_generated = {
        .query_type = PIPE_QUERY_PRIMITIVES_GENERATED,
-       .active = FD_STAGE_DRAW,
        .size = sizeof(struct fd6_primitives_sample),
        .resume = primitives_generated_resume,
        .pause = primitives_generated_pause,
@@ -432,7 +428,6 @@ primitives_emitted_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider primitives_emitted = {
        .query_type = PIPE_QUERY_PRIMITIVES_EMITTED,
-       .active = FD_STAGE_DRAW,
        .size = sizeof(struct fd6_primitives_sample),
        .resume = primitives_emitted_resume,
        .pause = primitives_emitted_pause,
@@ -553,7 +548,7 @@ perfcntr_accumulate_result(struct fd_acc_query *aq, void *buf,
 
 static const struct fd_acc_sample_provider perfcntr = {
                .query_type = FD_QUERY_FIRST_PERFCNTR,
-               .active = FD_STAGE_ALL,
+               .always = true,
                .resume = perfcntr_resume,
                .pause = perfcntr_pause,
                .result = perfcntr_accumulate_result,
index 63906c3bba58f13aacbf79d4fbcd4921cf3fe638..237e86f3a765395c51380f6aee669f3280cf25a3 100644 (file)
@@ -120,8 +120,6 @@ fd_blitter_pipe_begin(struct fd_context *ctx, bool render_cond, bool discard,
 static void
 fd_blitter_pipe_end(struct fd_context *ctx)
 {
-       if (ctx->batch)
-               fd_batch_set_stage(ctx->batch, FD_STAGE_NULL);
        ctx->in_discard_blit = false;
 }
 
index fc7ecff0e7dbb2c2f082e8c3af1bc773a312930b..bc2b1455c612018fbff996b51b2f6299f007a34a 100644 (file)
@@ -367,6 +367,7 @@ fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
         * set some state:
         */
        ctx->sample_mask = 0xffff;
+       ctx->active_queries = true;
 
        pctx = &ctx->base;
        pctx->screen = pscreen;
index e2edf15daa93ba47dc4e71210c7a85e0fbe91e05..f724d7b6840e285dd6ee35ee83bbd0be191b776e 100644 (file)
@@ -207,6 +207,11 @@ struct fd_context {
         */
        bool update_active_queries;
 
+       /* Current state of pctx->set_active_query_state() (i.e. "should drawing
+        * be counted against non-perfcounter queries")
+        */
+       bool active_queries;
+
        /* table with PIPE_PRIM_MAX entries mapping PIPE_PRIM_x to
         * DI_PT_x value to use for draw initiator.  There are some
         * slight differences between generation:
@@ -468,15 +473,6 @@ fd_batch_set_stage(struct fd_batch *batch, enum fd_render_stage stage)
 {
        struct fd_context *ctx = batch->ctx;
 
-       /* special case: internal blits (like mipmap level generation)
-        * go through normal draw path (via util_blitter_blit()).. but
-        * we need to ignore the FD_STAGE_DRAW which will be set, so we
-        * don't enable queries which should be paused during internal
-        * blits:
-        */
-       if (batch->stage == FD_STAGE_BLIT && stage != FD_STAGE_NULL)
-               stage = FD_STAGE_BLIT;
-
        if (ctx->query_set_stage)
                ctx->query_set_stage(batch, stage);
 
index 1ac7e1cdd4b12ebcd287b20b4faf33d4469dc40a..010d01bc385ca1a66d835091e1e5200dee64f858 100644 (file)
@@ -176,8 +176,11 @@ fd_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index,
 }
 
 static void
-fd_set_active_query_state(struct pipe_context *pipe, bool enable)
+fd_set_active_query_state(struct pipe_context *pctx, bool enable)
 {
+       struct fd_context *ctx = fd_context(pctx);
+       ctx->active_queries = enable;
+       ctx->update_active_queries = true;
 }
 
 static enum pipe_driver_query_type
index 3bcf9ac964e5848c08ec711265731a84aed791d9..46efe61aae98dc66d79f998616010d849b3d60f8 100644 (file)
 #include "freedreno_resource.h"
 #include "freedreno_util.h"
 
-
-static bool
-is_active(struct fd_acc_query *aq, enum fd_render_stage stage)
-{
-       return !!(aq->provider->active & stage);
-}
-
 static void
 fd_acc_destroy_query(struct fd_context *ctx, struct fd_query *q)
 {
@@ -245,7 +238,8 @@ fd_acc_query_set_stage(struct fd_batch *batch, enum fd_render_stage stage)
                LIST_FOR_EACH_ENTRY(aq, &ctx->acc_active_queries, node) {
                        bool batch_change = aq->batch != batch;
                        bool was_active = aq->batch != NULL;
-                       bool now_active = is_active(aq, stage);
+                       bool now_active = stage != FD_STAGE_NULL &&
+                               (ctx->active_queries || aq->provider->always);
 
                        if (was_active && (!now_active || batch_change))
                                fd_acc_query_pause(aq);
index 15d5b880eaf84884743d20ad96f37566b2cccbe2..2092aba4ff3c81710bf30e6da37cb9e1366ce19d 100644 (file)
@@ -59,8 +59,8 @@ struct fd_acc_query;
 struct fd_acc_sample_provider {
        unsigned query_type;
 
-       /* stages applicable to the query type: */
-       enum fd_render_stage active;
+       /* Set if the provider should still count while !ctx->active_queries */
+       bool always;
 
        unsigned size;
 
index 8d44fd4a79595f65cc1d7af48d150b71222f59f6..961e9c607d22963d7934a5a300e2a15feb6824df 100644 (file)
@@ -379,6 +379,15 @@ fd_hw_query_prepare_tile(struct fd_batch *batch, uint32_t n,
 void
 fd_hw_query_set_stage(struct fd_batch *batch, enum fd_render_stage stage)
 {
+       /* special case: internal blits (like mipmap level generation)
+        * go through normal draw path (via util_blitter_blit()).. but
+        * we need to ignore the FD_STAGE_DRAW which will be set, so we
+        * don't enable queries which should be paused during internal
+        * blits:
+        */
+       if (batch->stage == FD_STAGE_BLIT && stage != FD_STAGE_NULL)
+               stage = FD_STAGE_BLIT;
+
        if (stage != batch->stage) {
                struct fd_hw_query *hq;
                LIST_FOR_EACH_ENTRY(hq, &batch->ctx->hw_active_queries, list) {