Path: blob/21.2-virgl/src/gallium/drivers/freedreno/freedreno_query.c
4570 views
/*1* Copyright (C) 2013 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 "pipe/p_state.h"27#include "util/u_memory.h"2829#include "freedreno_context.h"30#include "freedreno_query.h"31#include "freedreno_query_hw.h"32#include "freedreno_query_sw.h"33#include "freedreno_util.h"3435/*36* Pipe Query interface:37*/3839static struct pipe_query *40fd_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)41{42struct fd_context *ctx = fd_context(pctx);43struct fd_query *q = NULL;4445if (ctx->create_query)46q = ctx->create_query(ctx, query_type, index);47if (!q)48q = fd_sw_create_query(ctx, query_type, index);4950return (struct pipe_query *)q;51}5253static void54fd_destroy_query(struct pipe_context *pctx, struct pipe_query *pq) in_dt55{56struct fd_query *q = fd_query(pq);57q->funcs->destroy_query(fd_context(pctx), q);58}5960static bool61fd_begin_query(struct pipe_context *pctx, struct pipe_query *pq) in_dt62{63struct fd_query *q = fd_query(pq);6465q->funcs->begin_query(fd_context(pctx), q);6667return true;68}6970static bool71fd_end_query(struct pipe_context *pctx, struct pipe_query *pq) in_dt72{73struct fd_query *q = fd_query(pq);7475/* there are a couple special cases, which don't have76* a matching ->begin_query():77*/78if (skip_begin_query(q->type))79fd_begin_query(pctx, pq);8081q->funcs->end_query(fd_context(pctx), q);8283return true;84}8586static bool87fd_get_query_result(struct pipe_context *pctx, struct pipe_query *pq, bool wait,88union pipe_query_result *result)89{90struct fd_query *q = fd_query(pq);9192util_query_clear_result(result, q->type);9394return q->funcs->get_query_result(fd_context(pctx), q, wait, result);95}9697static void98fd_render_condition(struct pipe_context *pctx, struct pipe_query *pq,99bool condition, enum pipe_render_cond_flag mode) in_dt100{101struct fd_context *ctx = fd_context(pctx);102ctx->cond_query = pq;103ctx->cond_cond = condition;104ctx->cond_mode = mode;105}106107#define _Q(_name, _query_type, _type, _result_type) { \108.name = _name, .query_type = _query_type, \109.type = PIPE_DRIVER_QUERY_TYPE_##_type, \110.result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_##_result_type, \111.group_id = ~(unsigned)0, \112}113114#define FQ(_name, _query_type, _type, _result_type) \115_Q(_name, FD_QUERY_##_query_type, _type, _result_type)116117#define PQ(_name, _query_type, _type, _result_type) \118_Q(_name, PIPE_QUERY_##_query_type, _type, _result_type)119120static const struct pipe_driver_query_info sw_query_list[] = {121FQ("draw-calls", DRAW_CALLS, UINT64, AVERAGE),122FQ("batches", BATCH_TOTAL, UINT64, AVERAGE),123FQ("batches-sysmem", BATCH_SYSMEM, UINT64, AVERAGE),124FQ("batches-gmem", BATCH_GMEM, UINT64, AVERAGE),125FQ("batches-nondraw", BATCH_NONDRAW, UINT64, AVERAGE),126FQ("restores", BATCH_RESTORE, UINT64, AVERAGE),127PQ("prims-emitted", PRIMITIVES_EMITTED, UINT64, AVERAGE),128FQ("staging", STAGING_UPLOADS, UINT64, AVERAGE),129FQ("shadow", SHADOW_UPLOADS, UINT64, AVERAGE),130FQ("vsregs", VS_REGS, FLOAT, AVERAGE),131FQ("fsregs", FS_REGS, FLOAT, AVERAGE),132};133134static int135fd_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,136struct pipe_driver_query_info *info)137{138struct fd_screen *screen = fd_screen(pscreen);139140if (!info)141return ARRAY_SIZE(sw_query_list) + screen->num_perfcntr_queries;142143if (index >= ARRAY_SIZE(sw_query_list)) {144index -= ARRAY_SIZE(sw_query_list);145if (index >= screen->num_perfcntr_queries)146return 0;147*info = screen->perfcntr_queries[index];148return 1;149}150151*info = sw_query_list[index];152return 1;153}154155static int156fd_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index,157struct pipe_driver_query_group_info *info)158{159struct fd_screen *screen = fd_screen(pscreen);160161if (!info)162return screen->num_perfcntr_groups;163164if (index >= screen->num_perfcntr_groups)165return 0;166167const struct fd_perfcntr_group *g = &screen->perfcntr_groups[index];168169info->name = g->name;170info->max_active_queries = g->num_counters;171info->num_queries = g->num_countables;172173return 1;174}175176static void177fd_set_active_query_state(struct pipe_context *pctx, bool enable) assert_dt178{179struct fd_context *ctx = fd_context(pctx);180ctx->active_queries = enable;181ctx->update_active_queries = true;182}183184static enum pipe_driver_query_type185query_type(enum fd_perfcntr_type type)186{187#define ENUM(t) \188case FD_PERFCNTR_##t: \189return PIPE_DRIVER_QUERY_##t190switch (type) {191ENUM(TYPE_UINT64);192ENUM(TYPE_UINT);193ENUM(TYPE_FLOAT);194ENUM(TYPE_PERCENTAGE);195ENUM(TYPE_BYTES);196ENUM(TYPE_MICROSECONDS);197ENUM(TYPE_HZ);198ENUM(TYPE_DBM);199ENUM(TYPE_TEMPERATURE);200ENUM(TYPE_VOLTS);201ENUM(TYPE_AMPS);202ENUM(TYPE_WATTS);203default:204unreachable("bad type");205return 0;206}207}208209static enum pipe_driver_query_result_type210query_result_type(enum fd_perfcntr_result_type type)211{212switch (type) {213ENUM(RESULT_TYPE_AVERAGE);214ENUM(RESULT_TYPE_CUMULATIVE);215default:216unreachable("bad type");217return 0;218}219}220221static void222setup_perfcntr_query_info(struct fd_screen *screen)223{224unsigned num_queries = 0;225226for (unsigned i = 0; i < screen->num_perfcntr_groups; i++)227num_queries += screen->perfcntr_groups[i].num_countables;228229screen->perfcntr_queries =230calloc(num_queries, sizeof(screen->perfcntr_queries[0]));231screen->num_perfcntr_queries = num_queries;232233unsigned idx = 0;234for (unsigned i = 0; i < screen->num_perfcntr_groups; i++) {235const struct fd_perfcntr_group *g = &screen->perfcntr_groups[i];236for (unsigned j = 0; j < g->num_countables; j++) {237struct pipe_driver_query_info *info = &screen->perfcntr_queries[idx];238const struct fd_perfcntr_countable *c = &g->countables[j];239240info->name = c->name;241info->query_type = FD_QUERY_FIRST_PERFCNTR + idx;242info->type = query_type(c->query_type);243info->result_type = query_result_type(c->result_type);244info->group_id = i;245info->flags = PIPE_DRIVER_QUERY_FLAG_BATCH;246247idx++;248}249}250}251252void253fd_query_screen_init(struct pipe_screen *pscreen)254{255pscreen->get_driver_query_info = fd_get_driver_query_info;256pscreen->get_driver_query_group_info = fd_get_driver_query_group_info;257setup_perfcntr_query_info(fd_screen(pscreen));258}259260void261fd_query_context_init(struct pipe_context *pctx)262{263pctx->create_query = fd_create_query;264pctx->destroy_query = fd_destroy_query;265pctx->begin_query = fd_begin_query;266pctx->end_query = fd_end_query;267pctx->get_query_result = fd_get_query_result;268pctx->set_active_query_state = fd_set_active_query_state;269pctx->render_condition = fd_render_condition;270}271272273