Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_query_sw.c
4570 views
/*1* Copyright (c) 2016 Etnaviv Project2*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, sub license,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 the11* next paragraph) shall be included in all copies or substantial portions12* of the 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 NON-INFRINGEMENT. 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, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22* Authors:23* Rob Clark <[email protected]>24* Christian Gmeiner <[email protected]>25*/2627#include "util/os_time.h"28#include "pipe/p_state.h"29#include "util/u_memory.h"30#include "util/u_string.h"3132#include "etnaviv_context.h"33#include "etnaviv_query_sw.h"3435static void36etna_sw_destroy_query(struct etna_context *ctx, struct etna_query *q)37{38struct etna_sw_query *sq = etna_sw_query(q);3940FREE(sq);41}4243static uint64_t44read_counter(struct etna_context *ctx, unsigned type)45{46switch (type) {47case PIPE_QUERY_PRIMITIVES_GENERATED:48return ctx->stats.prims_generated;49case ETNA_QUERY_DRAW_CALLS:50return ctx->stats.draw_calls;51case ETNA_QUERY_RS_OPERATIONS:52return ctx->stats.rs_operations;53}5455return 0;56}5758static void59etna_sw_begin_query(struct etna_context *ctx, struct etna_query *q)60{61struct etna_sw_query *sq = etna_sw_query(q);6263sq->begin_value = read_counter(ctx, q->type);64}6566static void67etna_sw_end_query(struct etna_context *ctx, struct etna_query *q)68{69struct etna_sw_query *sq = etna_sw_query(q);7071sq->end_value = read_counter(ctx, q->type);72}7374static bool75etna_sw_get_query_result(struct etna_context *ctx, struct etna_query *q,76bool wait, union pipe_query_result *result)77{78struct etna_sw_query *sq = etna_sw_query(q);7980result->u64 = sq->end_value - sq->begin_value;8182return true;83}8485static const struct etna_query_funcs sw_query_funcs = {86.destroy_query = etna_sw_destroy_query,87.begin_query = etna_sw_begin_query,88.end_query = etna_sw_end_query,89.get_query_result = etna_sw_get_query_result,90};9192struct etna_query *93etna_sw_create_query(struct etna_context *ctx, unsigned query_type)94{95struct etna_sw_query *sq;96struct etna_query *q;9798switch (query_type) {99case PIPE_QUERY_PRIMITIVES_GENERATED:100case ETNA_QUERY_DRAW_CALLS:101case ETNA_QUERY_RS_OPERATIONS:102break;103default:104return NULL;105}106107sq = CALLOC_STRUCT(etna_sw_query);108if (!sq)109return NULL;110111q = &sq->base;112q->funcs = &sw_query_funcs;113q->type = query_type;114115return q;116}117118static const struct pipe_driver_query_info list[] = {119{"prims-generated", PIPE_QUERY_PRIMITIVES_GENERATED, { 0 }},120{"draw-calls", ETNA_QUERY_DRAW_CALLS, { 0 }},121{"rs-operations", ETNA_QUERY_RS_OPERATIONS, { 0 }},122};123124int125etna_sw_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,126struct pipe_driver_query_info *info)127{128if (!info)129return ARRAY_SIZE(list);130131if (index >= ARRAY_SIZE(list))132return 0;133134*info = list[index];135136return 1;137}138139int140etna_sw_get_driver_query_group_info(struct pipe_screen *pscreen,141unsigned index,142struct pipe_driver_query_group_info *info)143{144if (!info)145return 1;146147if (index != 0)148return 0;149150info->name = "driver";151info->max_active_queries = ARRAY_SIZE(list);152info->num_queries = ARRAY_SIZE(list);153154return 1;155}156157158