1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright (c) 2016 Etnaviv Project 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 12bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 13bf215546Sopenharmony_ci * of the Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: 24bf215546Sopenharmony_ci * Rob Clark <robclark@freedesktop.org> 25bf215546Sopenharmony_ci * Christian Gmeiner <christian.gmeiner@gmail.com> 26bf215546Sopenharmony_ci */ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "pipe/p_screen.h" 29bf215546Sopenharmony_ci#include "util/u_inlines.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "etnaviv_context.h" 32bf215546Sopenharmony_ci#include "etnaviv_perfmon.h" 33bf215546Sopenharmony_ci#include "etnaviv_query.h" 34bf215546Sopenharmony_ci#include "etnaviv_query_acc.h" 35bf215546Sopenharmony_ci#include "etnaviv_query_sw.h" 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_cistatic struct pipe_query * 38bf215546Sopenharmony_cietna_create_query(struct pipe_context *pctx, unsigned query_type, 39bf215546Sopenharmony_ci unsigned index) 40bf215546Sopenharmony_ci{ 41bf215546Sopenharmony_ci struct etna_context *ctx = etna_context(pctx); 42bf215546Sopenharmony_ci struct etna_query *q; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci q = etna_sw_create_query(ctx, query_type); 45bf215546Sopenharmony_ci if (!q) 46bf215546Sopenharmony_ci q = etna_acc_create_query(ctx, query_type); 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci return (struct pipe_query *)q; 49bf215546Sopenharmony_ci} 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_cistatic void 52bf215546Sopenharmony_cietna_destroy_query(struct pipe_context *pctx, struct pipe_query *pq) 53bf215546Sopenharmony_ci{ 54bf215546Sopenharmony_ci struct etna_query *q = etna_query(pq); 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci q->funcs->destroy_query(etna_context(pctx), q); 57bf215546Sopenharmony_ci} 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_cistatic bool 60bf215546Sopenharmony_cietna_begin_query(struct pipe_context *pctx, struct pipe_query *pq) 61bf215546Sopenharmony_ci{ 62bf215546Sopenharmony_ci struct etna_query *q = etna_query(pq); 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci q->funcs->begin_query(etna_context(pctx), q); 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci return true; 67bf215546Sopenharmony_ci} 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_cistatic bool 70bf215546Sopenharmony_cietna_end_query(struct pipe_context *pctx, struct pipe_query *pq) 71bf215546Sopenharmony_ci{ 72bf215546Sopenharmony_ci struct etna_query *q = etna_query(pq); 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci q->funcs->end_query(etna_context(pctx), q); 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci return true; 77bf215546Sopenharmony_ci} 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_cistatic bool 80bf215546Sopenharmony_cietna_get_query_result(struct pipe_context *pctx, struct pipe_query *pq, 81bf215546Sopenharmony_ci bool wait, union pipe_query_result *result) 82bf215546Sopenharmony_ci{ 83bf215546Sopenharmony_ci struct etna_query *q = etna_query(pq); 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci util_query_clear_result(result, q->type); 86bf215546Sopenharmony_ci 87bf215546Sopenharmony_ci return q->funcs->get_query_result(etna_context(pctx), q, wait, result); 88bf215546Sopenharmony_ci} 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_cistatic int 91bf215546Sopenharmony_cietna_get_driver_query_info(struct pipe_screen *pscreen, unsigned index, 92bf215546Sopenharmony_ci struct pipe_driver_query_info *info) 93bf215546Sopenharmony_ci{ 94bf215546Sopenharmony_ci int nr_sw_queries = etna_sw_get_driver_query_info(pscreen, 0, NULL); 95bf215546Sopenharmony_ci int nr_pm_queries = etna_pm_get_driver_query_info(pscreen, 0, NULL); 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_ci if (!info) 98bf215546Sopenharmony_ci return nr_sw_queries + nr_pm_queries; 99bf215546Sopenharmony_ci 100bf215546Sopenharmony_ci if (index < nr_sw_queries) 101bf215546Sopenharmony_ci return etna_sw_get_driver_query_info(pscreen, index, info); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci return etna_pm_get_driver_query_info(pscreen, index - nr_sw_queries, info); 104bf215546Sopenharmony_ci} 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_cistatic int 107bf215546Sopenharmony_cietna_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index, 108bf215546Sopenharmony_ci struct pipe_driver_query_group_info *info) 109bf215546Sopenharmony_ci{ 110bf215546Sopenharmony_ci int nr_sw_groups = etna_sw_get_driver_query_group_info(pscreen, 0, NULL); 111bf215546Sopenharmony_ci int nr_pm_groups = etna_pm_get_driver_query_group_info(pscreen, 0, NULL); 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ci if (!info) 114bf215546Sopenharmony_ci return nr_sw_groups + nr_pm_groups; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci if (index < nr_sw_groups) 117bf215546Sopenharmony_ci return etna_sw_get_driver_query_group_info(pscreen, index, info); 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci return etna_pm_get_driver_query_group_info(pscreen, index, info); 120bf215546Sopenharmony_ci} 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_cistatic void 123bf215546Sopenharmony_cietna_set_active_query_state(struct pipe_context *pctx, bool enable) 124bf215546Sopenharmony_ci{ 125bf215546Sopenharmony_ci struct etna_context *ctx = etna_context(pctx); 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci if (enable) { 128bf215546Sopenharmony_ci list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node) 129bf215546Sopenharmony_ci etna_acc_query_resume(aq, ctx); 130bf215546Sopenharmony_ci } else { 131bf215546Sopenharmony_ci list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node) 132bf215546Sopenharmony_ci etna_acc_query_suspend(aq, ctx); 133bf215546Sopenharmony_ci } 134bf215546Sopenharmony_ci} 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_civoid 137bf215546Sopenharmony_cietna_query_screen_init(struct pipe_screen *pscreen) 138bf215546Sopenharmony_ci{ 139bf215546Sopenharmony_ci pscreen->get_driver_query_info = etna_get_driver_query_info; 140bf215546Sopenharmony_ci pscreen->get_driver_query_group_info = etna_get_driver_query_group_info; 141bf215546Sopenharmony_ci} 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_civoid 144bf215546Sopenharmony_cietna_query_context_init(struct pipe_context *pctx) 145bf215546Sopenharmony_ci{ 146bf215546Sopenharmony_ci pctx->create_query = etna_create_query; 147bf215546Sopenharmony_ci pctx->destroy_query = etna_destroy_query; 148bf215546Sopenharmony_ci pctx->begin_query = etna_begin_query; 149bf215546Sopenharmony_ci pctx->end_query = etna_end_query; 150bf215546Sopenharmony_ci pctx->get_query_result = etna_get_query_result; 151bf215546Sopenharmony_ci pctx->set_active_query_state = etna_set_active_query_state; 152bf215546Sopenharmony_ci} 153