Path: blob/21.2-virgl/src/gallium/drivers/freedreno/freedreno_query_hw.h
4570 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#ifndef FREEDRENO_QUERY_HW_H_27#define FREEDRENO_QUERY_HW_H_2829#include "util/list.h"3031#include "freedreno_context.h"32#include "freedreno_query.h"3334/*35* HW Queries:36*37* See: https://github.com/freedreno/freedreno/wiki/Queries#hardware-queries38*39* Hardware queries will be specific to gpu generation, but they need40* some common infrastructure for triggering start/stop samples at41* various points (for example, to exclude mem2gmem/gmem2mem or clear)42* as well as per tile tracking.43*44* NOTE: in at least some cases hw writes sample values to memory addr45* specified in some register. So we don't really have the option to46* just sample the same counter multiple times for multiple different47* queries with the same query_type. So we cache per sample provider48* the most recent sample since the last draw. This way multiple49* sample periods for multiple queries can reference the same sample.50*51* fd_hw_sample_provider:52* - one per query type, registered/implemented by gpu generation53* specific code54* - can construct fd_hw_samples on demand55* - most recent sample (since last draw) cached so multiple56* different queries can ref the same sample57*58* fd_hw_sample:59* - abstracts one snapshot of counter value(s) across N tiles60* - backing object not allocated until submit time when number61* of samples and number of tiles is known62*63* fd_hw_sample_period:64* - consists of start and stop sample65* - a query accumulates a list of sample periods66* - the query result is the sum of the sample periods67*/6869struct fd_hw_sample_provider {70unsigned query_type;7172/* Set if the provider should still count while !ctx->active_queries */73bool always;7475/* Optional hook for enabling a counter. Guaranteed to happen76* at least once before the first ->get_sample() in a batch.77*/78void (*enable)(struct fd_context *ctx, struct fd_ringbuffer *ring) dt;7980/* when a new sample is required, emit appropriate cmdstream81* and return a sample object:82*/83struct fd_hw_sample *(*get_sample)(struct fd_batch *batch,84struct fd_ringbuffer *ring)dt;8586/* accumulate the results from specified sample period: */87void (*accumulate_result)(struct fd_context *ctx, const void *start,88const void *end, union pipe_query_result *result);89};9091struct fd_hw_sample {92struct pipe_reference reference; /* keep this first */9394/* offset and size of the sample are know at the time the95* sample is constructed.96*/97uint32_t size;98uint32_t offset;99100/* backing object, offset/stride/etc are determined not when101* the sample is constructed, but when the batch is submitted.102* This way we can defer allocation until total # of requested103* samples, and total # of tiles, is known.104*/105struct pipe_resource *prsc;106uint32_t num_tiles;107uint32_t tile_stride;108};109110struct fd_hw_sample_period;111112struct fd_hw_query {113struct fd_query base;114115const struct fd_hw_sample_provider *provider;116117/* list of fd_hw_sample_periods: */118struct list_head periods;119120/* if active and not paused, the current sample period (not121* yet added to current_periods):122*/123struct fd_hw_sample_period *period;124125struct list_head list; /* list-node in batch->active_queries */126};127128static inline struct fd_hw_query *129fd_hw_query(struct fd_query *q)130{131return (struct fd_hw_query *)q;132}133134struct fd_query *fd_hw_create_query(struct fd_context *ctx, unsigned query_type,135unsigned index);136/* helper for sample providers: */137struct fd_hw_sample *fd_hw_sample_init(struct fd_batch *batch, uint32_t size);138/* don't call directly, use fd_hw_sample_reference() */139void __fd_hw_sample_destroy(struct fd_context *ctx, struct fd_hw_sample *samp);140void fd_hw_query_prepare(struct fd_batch *batch, uint32_t num_tiles) assert_dt;141void fd_hw_query_prepare_tile(struct fd_batch *batch, uint32_t n,142struct fd_ringbuffer *ring) assert_dt;143void fd_hw_query_update_batch(struct fd_batch *batch, bool end_batch) assert_dt;144void fd_hw_query_enable(struct fd_batch *batch,145struct fd_ringbuffer *ring) assert_dt;146void147fd_hw_query_register_provider(struct pipe_context *pctx,148const struct fd_hw_sample_provider *provider);149void fd_hw_query_init(struct pipe_context *pctx);150void fd_hw_query_fini(struct pipe_context *pctx);151152static inline void153fd_hw_sample_reference(struct fd_context *ctx, struct fd_hw_sample **ptr,154struct fd_hw_sample *samp)155{156struct fd_hw_sample *old_samp = *ptr;157158if (pipe_reference(&(*ptr)->reference, &samp->reference))159__fd_hw_sample_destroy(ctx, old_samp);160*ptr = samp;161}162163#endif /* FREEDRENO_QUERY_HW_H_ */164165166