Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a3xx/fd3_query.c
4574 views
/*1* Copyright (C) 2014 Rob Clark <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24*/2526#include "freedreno_batch.h"27#include "freedreno_context.h"28#include "freedreno_query_hw.h"29#include "freedreno_util.h"3031#include "fd3_format.h"32#include "fd3_query.h"3334struct fd_rb_samp_ctrs {35uint64_t ctr[16];36};3738/*39* Occlusion Query:40*41* OCCLUSION_COUNTER and OCCLUSION_PREDICATE differ only in how they42* interpret results43*/4445static struct fd_hw_sample *46occlusion_get_sample(struct fd_batch *batch, struct fd_ringbuffer *ring)47{48struct fd_hw_sample *samp =49fd_hw_sample_init(batch, sizeof(struct fd_rb_samp_ctrs));5051/* Set RB_SAMPLE_COUNT_ADDR to samp->offset plus value of52* HW_QUERY_BASE_REG register:53*/54OUT_PKT3(ring, CP_SET_CONSTANT, 3);55OUT_RING(ring, CP_REG(REG_A3XX_RB_SAMPLE_COUNT_ADDR) | 0x80000000);56OUT_RING(ring, HW_QUERY_BASE_REG);57OUT_RING(ring, samp->offset);5859OUT_PKT0(ring, REG_A3XX_RB_SAMPLE_COUNT_CONTROL, 1);60OUT_RING(ring, A3XX_RB_SAMPLE_COUNT_CONTROL_COPY);6162OUT_PKT3(ring, CP_DRAW_INDX, 3);63OUT_RING(ring, 0x00000000);64OUT_RING(ring, DRAW(DI_PT_POINTLIST_PSIZE, DI_SRC_SEL_AUTO_INDEX,65INDEX_SIZE_IGN, USE_VISIBILITY, 0));66OUT_RING(ring, 0); /* NumIndices */6768fd_event_write(batch, ring, ZPASS_DONE);6970OUT_PKT0(ring, REG_A3XX_RBBM_PERFCTR_CTL, 1);71OUT_RING(ring, A3XX_RBBM_PERFCTR_CTL_ENABLE);7273OUT_PKT0(ring, REG_A3XX_VBIF_PERF_CNT_EN, 1);74OUT_RING(ring, A3XX_VBIF_PERF_CNT_EN_CNT0 | A3XX_VBIF_PERF_CNT_EN_CNT1 |75A3XX_VBIF_PERF_CNT_EN_PWRCNT0 |76A3XX_VBIF_PERF_CNT_EN_PWRCNT1 |77A3XX_VBIF_PERF_CNT_EN_PWRCNT2);7879return samp;80}8182static uint64_t83count_samples(const struct fd_rb_samp_ctrs *start,84const struct fd_rb_samp_ctrs *end)85{86uint64_t n = 0;87unsigned i;8889/* not quite sure what all of these are, possibly different90* counters for each MRT render target:91*/92for (i = 0; i < 16; i += 4)93n += end->ctr[i] - start->ctr[i];9495return n;96}9798static void99occlusion_counter_accumulate_result(struct fd_context *ctx, const void *start,100const void *end,101union pipe_query_result *result)102{103uint64_t n = count_samples(start, end);104result->u64 += n;105}106107static void108occlusion_predicate_accumulate_result(struct fd_context *ctx, const void *start,109const void *end,110union pipe_query_result *result)111{112uint64_t n = count_samples(start, end);113result->b |= (n > 0);114}115116static const struct fd_hw_sample_provider occlusion_counter = {117.query_type = PIPE_QUERY_OCCLUSION_COUNTER,118.get_sample = occlusion_get_sample,119.accumulate_result = occlusion_counter_accumulate_result,120};121122static const struct fd_hw_sample_provider occlusion_predicate = {123.query_type = PIPE_QUERY_OCCLUSION_PREDICATE,124.get_sample = occlusion_get_sample,125.accumulate_result = occlusion_predicate_accumulate_result,126};127128static const struct fd_hw_sample_provider occlusion_predicate_conservative = {129.query_type = PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE,130.get_sample = occlusion_get_sample,131.accumulate_result = occlusion_predicate_accumulate_result,132};133134void135fd3_query_context_init(struct pipe_context *pctx) disable_thread_safety_analysis136{137struct fd_context *ctx = fd_context(pctx);138139ctx->create_query = fd_hw_create_query;140ctx->query_prepare = fd_hw_query_prepare;141ctx->query_prepare_tile = fd_hw_query_prepare_tile;142ctx->query_update_batch = fd_hw_query_update_batch;143144fd_hw_query_register_provider(pctx, &occlusion_counter);145fd_hw_query_register_provider(pctx, &occlusion_predicate);146fd_hw_query_register_provider(pctx, &occlusion_predicate_conservative);147}148149150