Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_query.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 "pipe/p_screen.h"28#include "util/u_inlines.h"2930#include "etnaviv_context.h"31#include "etnaviv_perfmon.h"32#include "etnaviv_query.h"33#include "etnaviv_query_acc.h"34#include "etnaviv_query_sw.h"3536static struct pipe_query *37etna_create_query(struct pipe_context *pctx, unsigned query_type,38unsigned index)39{40struct etna_context *ctx = etna_context(pctx);41struct etna_query *q;4243q = etna_sw_create_query(ctx, query_type);44if (!q)45q = etna_acc_create_query(ctx, query_type);4647return (struct pipe_query *)q;48}4950static void51etna_destroy_query(struct pipe_context *pctx, struct pipe_query *pq)52{53struct etna_query *q = etna_query(pq);5455q->funcs->destroy_query(etna_context(pctx), q);56}5758static bool59etna_begin_query(struct pipe_context *pctx, struct pipe_query *pq)60{61struct etna_query *q = etna_query(pq);6263q->funcs->begin_query(etna_context(pctx), q);6465return true;66}6768static bool69etna_end_query(struct pipe_context *pctx, struct pipe_query *pq)70{71struct etna_query *q = etna_query(pq);7273q->funcs->end_query(etna_context(pctx), q);7475return true;76}7778static bool79etna_get_query_result(struct pipe_context *pctx, struct pipe_query *pq,80bool wait, union pipe_query_result *result)81{82struct etna_query *q = etna_query(pq);8384util_query_clear_result(result, q->type);8586return q->funcs->get_query_result(etna_context(pctx), q, wait, result);87}8889static int90etna_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,91struct pipe_driver_query_info *info)92{93int nr_sw_queries = etna_sw_get_driver_query_info(pscreen, 0, NULL);94int nr_pm_queries = etna_pm_get_driver_query_info(pscreen, 0, NULL);9596if (!info)97return nr_sw_queries + nr_pm_queries;9899if (index < nr_sw_queries)100return etna_sw_get_driver_query_info(pscreen, index, info);101102return etna_pm_get_driver_query_info(pscreen, index - nr_sw_queries, info);103}104105static int106etna_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index,107struct pipe_driver_query_group_info *info)108{109int nr_sw_groups = etna_sw_get_driver_query_group_info(pscreen, 0, NULL);110int nr_pm_groups = etna_pm_get_driver_query_group_info(pscreen, 0, NULL);111112if (!info)113return nr_sw_groups + nr_pm_groups;114115if (index < nr_sw_groups)116return etna_sw_get_driver_query_group_info(pscreen, index, info);117118return etna_pm_get_driver_query_group_info(pscreen, index, info);119}120121static void122etna_set_active_query_state(struct pipe_context *pctx, bool enable)123{124struct etna_context *ctx = etna_context(pctx);125126if (enable) {127list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node)128etna_acc_query_resume(aq, ctx);129} else {130list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node)131etna_acc_query_suspend(aq, ctx);132}133}134135void136etna_query_screen_init(struct pipe_screen *pscreen)137{138pscreen->get_driver_query_info = etna_get_driver_query_info;139pscreen->get_driver_query_group_info = etna_get_driver_query_group_info;140}141142void143etna_query_context_init(struct pipe_context *pctx)144{145pctx->create_query = etna_create_query;146pctx->destroy_query = etna_destroy_query;147pctx->begin_query = etna_begin_query;148pctx->end_query = etna_end_query;149pctx->get_query_result = etna_get_query_result;150pctx->set_active_query_state = etna_set_active_query_state;151}152153154