freedreno/ir3: move per-generation compiler config
[mesa.git] / src / gallium / drivers / freedreno / freedreno_query_hw.c
index b61ea0d5e080c344cf07b7a642479a0321c1c6c4..86a46faa7308c58ea4c98f6095f3baa6bae3f947 100644 (file)
@@ -40,26 +40,6 @@ struct fd_hw_sample_period {
        struct list_head list;
 };
 
-/* maps query_type to sample provider idx: */
-static int pidx(unsigned query_type)
-{
-       switch (query_type) {
-       case PIPE_QUERY_OCCLUSION_COUNTER:
-               return 0;
-       case PIPE_QUERY_OCCLUSION_PREDICATE:
-               return 1;
-       /* TODO currently queries only emitted in main pass (not in binning pass)..
-        * which is fine for occlusion query, but pretty much not anything else.
-        */
-       case PIPE_QUERY_TIME_ELAPSED:
-               return 2;
-       case PIPE_QUERY_TIMESTAMP:
-               return 3;
-       default:
-               return -1;
-       }
-}
-
 static struct fd_hw_sample *
 get_sample(struct fd_batch *batch, struct fd_ringbuffer *ring,
                unsigned query_type)
@@ -72,7 +52,7 @@ get_sample(struct fd_batch *batch, struct fd_ringbuffer *ring,
 
        if (!batch->sample_cache[idx]) {
                struct fd_hw_sample *new_samp =
-                       ctx->sample_providers[idx]->get_sample(batch, ring);
+                       ctx->hw_sample_providers[idx]->get_sample(batch, ring);
                fd_hw_sample_reference(ctx, &batch->sample_cache[idx], new_samp);
                util_dynarray_append(&batch->samples, struct fd_hw_sample *, new_samp);
                batch->needs_flush = true;
@@ -104,13 +84,14 @@ resume_query(struct fd_batch *batch, struct fd_hw_query *hq,
                struct fd_ringbuffer *ring)
 {
        int idx = pidx(hq->provider->query_type);
+       DBG("%p", hq);
        assert(idx >= 0);   /* query never would have been created otherwise */
        assert(!hq->period);
        batch->active_providers |= (1 << idx);
-       hq->period = util_slab_alloc(&batch->ctx->sample_period_pool);
+       hq->period = slab_alloc_st(&batch->ctx->sample_period_pool);
        list_inithead(&hq->period->list);
        hq->period->start = get_sample(batch, ring, hq->base.type);
-       /* NOTE: util_slab_alloc() does not zero out the buffer: */
+       /* NOTE: slab_alloc_st() does not zero out the buffer: */
        hq->period->end = NULL;
 }
 
@@ -119,6 +100,7 @@ pause_query(struct fd_batch *batch, struct fd_hw_query *hq,
                struct fd_ringbuffer *ring)
 {
        int idx = pidx(hq->provider->query_type);
+       DBG("%p", hq);
        assert(idx >= 0);   /* query never would have been created otherwise */
        assert(hq->period && !hq->period->end);
        assert(batch->active_providers & (1 << idx));
@@ -135,7 +117,7 @@ destroy_periods(struct fd_context *ctx, struct fd_hw_query *hq)
                fd_hw_sample_reference(ctx, &period->start, NULL);
                fd_hw_sample_reference(ctx, &period->end, NULL);
                list_del(&period->list);
-               util_slab_free(&ctx->sample_period_pool, period);
+               slab_free_st(&ctx->sample_period_pool, period);
        }
 }
 
@@ -144,6 +126,8 @@ fd_hw_destroy_query(struct fd_context *ctx, struct fd_query *q)
 {
        struct fd_hw_query *hq = fd_hw_query(q);
 
+       DBG("%p: active=%d", q, q->active);
+
        destroy_periods(ctx, hq);
        list_del(&hq->list);
 
@@ -156,8 +140,7 @@ fd_hw_begin_query(struct fd_context *ctx, struct fd_query *q)
        struct fd_batch *batch = ctx->batch;
        struct fd_hw_query *hq = fd_hw_query(q);
 
-       if (q->active)
-               return false;
+       DBG("%p: active=%d", q, q->active);
 
        /* begin_query() should clear previous results: */
        destroy_periods(ctx, hq);
@@ -165,11 +148,9 @@ fd_hw_begin_query(struct fd_context *ctx, struct fd_query *q)
        if (batch && is_active(hq, batch->stage))
                resume_query(batch, hq, batch->draw);
 
-       q->active = true;
-
        /* add to active list: */
        assert(list_empty(&hq->list));
-       list_addtail(&hq->list, &ctx->active_queries);
+       list_addtail(&hq->list, &ctx->hw_active_queries);
 
        return true;
 }
@@ -179,17 +160,12 @@ fd_hw_end_query(struct fd_context *ctx, struct fd_query *q)
 {
        struct fd_batch *batch = ctx->batch;
        struct fd_hw_query *hq = fd_hw_query(q);
-       /* there are a couple special cases, which don't have
-        * a matching ->begin_query():
-        */
-       if (skip_begin_query(q->type) && !q->active) {
-               fd_hw_begin_query(ctx, q);
-       }
-       if (!q->active)
-               return;
+
+       DBG("%p: active=%d", q, q->active);
+
        if (batch && is_active(hq, batch->stage))
                pause_query(batch, hq, batch->draw);
-       q->active = false;
+
        /* remove from active list: */
        list_delinit(&hq->list);
 }
@@ -208,10 +184,7 @@ fd_hw_get_query_result(struct fd_context *ctx, struct fd_query *q,
        const struct fd_hw_sample_provider *p = hq->provider;
        struct fd_hw_sample_period *period;
 
-       if (q->active)
-               return false;
-
-       util_query_clear_result(result, q->type);
+       DBG("%p: wait=%d, active=%d", q, wait, q->active);
 
        if (LIST_IS_EMPTY(&hq->periods))
                return true;
@@ -238,14 +211,14 @@ fd_hw_get_query_result(struct fd_context *ctx, struct fd_query *q,
                         * spin forever:
                         */
                        if (hq->no_wait_cnt++ > 5)
-                               fd_batch_flush(rsc->write_batch, false);
+                               fd_batch_flush(rsc->write_batch, false, false);
                        return false;
                }
 
                if (!rsc->bo)
                        return false;
 
-               ret = fd_bo_cpu_prep(rsc->bo, ctx->screen->pipe,
+               ret = fd_bo_cpu_prep(rsc->bo, ctx->pipe,
                                DRM_FREEDRENO_PREP_READ | DRM_FREEDRENO_PREP_NOSYNC);
                if (ret)
                        return false;
@@ -266,13 +239,13 @@ fd_hw_get_query_result(struct fd_context *ctx, struct fd_query *q,
                struct fd_resource *rsc = fd_resource(start->prsc);
 
                if (rsc->write_batch)
-                       fd_batch_flush(rsc->write_batch, true);
+                       fd_batch_flush(rsc->write_batch, true, false);
 
                /* some piglit tests at least do query with no draws, I guess: */
                if (!rsc->bo)
                        continue;
 
-               fd_bo_cpu_prep(rsc->bo, ctx->screen->pipe, DRM_FREEDRENO_PREP_READ);
+               fd_bo_cpu_prep(rsc->bo, ctx->pipe, DRM_FREEDRENO_PREP_READ);
 
                void *ptr = fd_bo_map(rsc->bo);
 
@@ -301,14 +274,16 @@ fd_hw_create_query(struct fd_context *ctx, unsigned query_type)
        struct fd_query *q;
        int idx = pidx(query_type);
 
-       if ((idx < 0) || !ctx->sample_providers[idx])
+       if ((idx < 0) || !ctx->hw_sample_providers[idx])
                return NULL;
 
        hq = CALLOC_STRUCT(fd_hw_query);
        if (!hq)
                return NULL;
 
-       hq->provider = ctx->sample_providers[idx];
+       DBG("%p: query_type=%u", hq, query_type);
+
+       hq->provider = ctx->hw_sample_providers[idx];
 
        list_inithead(&hq->periods);
        list_inithead(&hq->list);
@@ -323,13 +298,13 @@ fd_hw_create_query(struct fd_context *ctx, unsigned query_type)
 struct fd_hw_sample *
 fd_hw_sample_init(struct fd_batch *batch, uint32_t size)
 {
-       struct fd_hw_sample *samp = util_slab_alloc(&batch->ctx->sample_pool);
+       struct fd_hw_sample *samp = slab_alloc_st(&batch->ctx->sample_pool);
        pipe_reference_init(&samp->reference, 1);
        samp->size = size;
-       debug_assert(util_is_power_of_two(size));
+       debug_assert(util_is_power_of_two_or_zero(size));
        batch->next_sample_offset = align(batch->next_sample_offset, size);
        samp->offset = batch->next_sample_offset;
-       /* NOTE: util_slab_alloc() does not zero out the buffer: */
+       /* NOTE: slab_alloc_st() does not zero out the buffer: */
        samp->prsc = NULL;
        samp->num_tiles = 0;
        samp->tile_stride = 0;
@@ -360,7 +335,7 @@ void
 __fd_hw_sample_destroy(struct fd_context *ctx, struct fd_hw_sample *samp)
 {
        pipe_resource_reference(&samp->prsc, NULL);
-       util_slab_free(&ctx->sample_pool, samp);
+       slab_free_st(&ctx->sample_pool, samp);
 }
 
 /* called from gmem code once total storage requirements are known (ie.
@@ -399,39 +374,27 @@ fd_hw_query_prepare_tile(struct fd_batch *batch, uint32_t n,
        if (tile_stride == 0)
                return;
 
-       fd_wfi(batch->ctx, ring);
+       fd_wfi(batch, ring);
        OUT_PKT0 (ring, HW_QUERY_BASE_REG, 1);
        OUT_RELOCW(ring, fd_resource(batch->query_buf)->bo, offset, 0, 0);
 }
 
 void
-fd_hw_query_set_stage(struct fd_batch *batch, struct fd_ringbuffer *ring,
-               enum fd_render_stage stage)
+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))
-               return;
-
        if (stage != batch->stage) {
                struct fd_hw_query *hq;
-               LIST_FOR_EACH_ENTRY(hq, &batch->ctx->active_queries, list) {
+               LIST_FOR_EACH_ENTRY(hq, &batch->ctx->hw_active_queries, list) {
                        bool was_active = is_active(hq, batch->stage);
                        bool now_active = is_active(hq, stage);
 
                        if (now_active && !was_active)
-                               resume_query(batch, hq, ring);
+                               resume_query(batch, hq, batch->draw);
                        else if (was_active && !now_active)
-                               pause_query(batch, hq, ring);
+                               pause_query(batch, hq, batch->draw);
                }
        }
        clear_sample_cache(batch);
-       batch->stage = stage;
 }
 
 /* call the provider->enable() for all the hw queries that were active
@@ -444,9 +407,9 @@ fd_hw_query_enable(struct fd_batch *batch, struct fd_ringbuffer *ring)
        struct fd_context *ctx = batch->ctx;
        for (int idx = 0; idx < MAX_HW_SAMPLE_PROVIDERS; idx++) {
                if (batch->active_providers & (1 << idx)) {
-                       assert(ctx->sample_providers[idx]);
-                       if (ctx->sample_providers[idx]->enable)
-                               ctx->sample_providers[idx]->enable(ctx, ring);
+                       assert(ctx->hw_sample_providers[idx]);
+                       if (ctx->hw_sample_providers[idx]->enable)
+                               ctx->hw_sample_providers[idx]->enable(ctx, ring);
                }
        }
        batch->active_providers = 0;  /* clear it for next frame */
@@ -460,9 +423,9 @@ fd_hw_query_register_provider(struct pipe_context *pctx,
        int idx = pidx(provider->query_type);
 
        assert((0 <= idx) && (idx < MAX_HW_SAMPLE_PROVIDERS));
-       assert(!ctx->sample_providers[idx]);
+       assert(!ctx->hw_sample_providers[idx]);
 
-       ctx->sample_providers[idx] = provider;
+       ctx->hw_sample_providers[idx] = provider;
 }
 
 void
@@ -470,11 +433,10 @@ fd_hw_query_init(struct pipe_context *pctx)
 {
        struct fd_context *ctx = fd_context(pctx);
 
-       util_slab_create(&ctx->sample_pool, sizeof(struct fd_hw_sample),
-                       16, UTIL_SLAB_SINGLETHREADED);
-       util_slab_create(&ctx->sample_period_pool, sizeof(struct fd_hw_sample_period),
-                       16, UTIL_SLAB_SINGLETHREADED);
-       list_inithead(&ctx->active_queries);
+       slab_create(&ctx->sample_pool, sizeof(struct fd_hw_sample),
+                       16);
+       slab_create(&ctx->sample_period_pool, sizeof(struct fd_hw_sample_period),
+                       16);
 }
 
 void
@@ -482,6 +444,6 @@ fd_hw_query_fini(struct pipe_context *pctx)
 {
        struct fd_context *ctx = fd_context(pctx);
 
-       util_slab_destroy(&ctx->sample_pool);
-       util_slab_destroy(&ctx->sample_period_pool);
+       slab_destroy(&ctx->sample_pool);
+       slab_destroy(&ctx->sample_period_pool);
 }