101e04c3fSmrg/*
201e04c3fSmrg * Copyright © 2014 Broadcom
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
901e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
2101e04c3fSmrg * IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
247ec681f3Smrg#include "v3d_query.h"
2501e04c3fSmrg
267ec681f3Smrgint
277ec681f3Smrgv3d_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index,
287ec681f3Smrg                                struct pipe_driver_query_group_info *info)
297ec681f3Smrg{
307ec681f3Smrg        struct v3d_screen *screen = v3d_screen(pscreen);
3101e04c3fSmrg
327ec681f3Smrg        return v3d_get_driver_query_group_info_perfcnt(screen, index, info);
337ec681f3Smrg}
347ec681f3Smrg
357ec681f3Smrgint
367ec681f3Smrgv3d_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
377ec681f3Smrg                          struct pipe_driver_query_info *info)
3801e04c3fSmrg{
397ec681f3Smrg        struct v3d_screen *screen = v3d_screen(pscreen);
4001e04c3fSmrg
417ec681f3Smrg        return v3d_get_driver_query_info_perfcnt(screen, index, info);
427ec681f3Smrg}
4301e04c3fSmrg
4401e04c3fSmrgstatic struct pipe_query *
4501e04c3fSmrgv3d_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)
4601e04c3fSmrg{
477ec681f3Smrg        struct v3d_context *v3d = v3d_context(pctx);
4801e04c3fSmrg
497ec681f3Smrg        return v3d_create_query_pipe(v3d, query_type, index);
507ec681f3Smrg}
5101e04c3fSmrg
527ec681f3Smrgstatic struct pipe_query *
537ec681f3Smrgv3d_create_batch_query(struct pipe_context *pctx, unsigned num_queries,
547ec681f3Smrg                       unsigned *query_types)
557ec681f3Smrg{
567ec681f3Smrg        return v3d_create_batch_query_perfcnt(v3d_context(pctx),
577ec681f3Smrg                                              num_queries,
587ec681f3Smrg                                              query_types);
5901e04c3fSmrg}
6001e04c3fSmrg
6101e04c3fSmrgstatic void
6201e04c3fSmrgv3d_destroy_query(struct pipe_context *pctx, struct pipe_query *query)
6301e04c3fSmrg{
647ec681f3Smrg        struct v3d_context *v3d = v3d_context(pctx);
6501e04c3fSmrg        struct v3d_query *q = (struct v3d_query *)query;
6601e04c3fSmrg
677ec681f3Smrg        q->funcs->destroy_query(v3d, q);
6801e04c3fSmrg}
6901e04c3fSmrg
707ec681f3Smrgstatic bool
7101e04c3fSmrgv3d_begin_query(struct pipe_context *pctx, struct pipe_query *query)
7201e04c3fSmrg{
7301e04c3fSmrg        struct v3d_context *v3d = v3d_context(pctx);
7401e04c3fSmrg        struct v3d_query *q = (struct v3d_query *)query;
7501e04c3fSmrg
767ec681f3Smrg        return q->funcs->begin_query(v3d, q);
7701e04c3fSmrg}
7801e04c3fSmrg
7901e04c3fSmrgstatic bool
8001e04c3fSmrgv3d_end_query(struct pipe_context *pctx, struct pipe_query *query)
8101e04c3fSmrg{
8201e04c3fSmrg        struct v3d_context *v3d = v3d_context(pctx);
8301e04c3fSmrg        struct v3d_query *q = (struct v3d_query *)query;
8401e04c3fSmrg
857ec681f3Smrg        return q->funcs->end_query(v3d, q);
8601e04c3fSmrg}
8701e04c3fSmrg
887ec681f3Smrgstatic bool
8901e04c3fSmrgv3d_get_query_result(struct pipe_context *pctx, struct pipe_query *query,
907ec681f3Smrg                     bool wait, union pipe_query_result *vresult)
9101e04c3fSmrg{
927ec681f3Smrg        struct v3d_context *v3d = v3d_context(pctx);
9301e04c3fSmrg        struct v3d_query *q = (struct v3d_query *)query;
947ec681f3Smrg
957ec681f3Smrg        return q->funcs->get_query_result(v3d, q, wait, vresult);
9601e04c3fSmrg}
9701e04c3fSmrg
9801e04c3fSmrgstatic void
997ec681f3Smrgv3d_set_active_query_state(struct pipe_context *pctx, bool enable)
10001e04c3fSmrg{
10101e04c3fSmrg        struct v3d_context *v3d = v3d_context(pctx);
10201e04c3fSmrg
10301e04c3fSmrg        v3d->active_queries = enable;
1047ec681f3Smrg        v3d->dirty |= V3D_DIRTY_OQ;
1057ec681f3Smrg        v3d->dirty |= V3D_DIRTY_STREAMOUT;
10601e04c3fSmrg}
10701e04c3fSmrg
10801e04c3fSmrgvoid
10901e04c3fSmrgv3d_query_init(struct pipe_context *pctx)
11001e04c3fSmrg{
11101e04c3fSmrg        pctx->create_query = v3d_create_query;
1127ec681f3Smrg        pctx->create_batch_query = v3d_create_batch_query;
11301e04c3fSmrg        pctx->destroy_query = v3d_destroy_query;
11401e04c3fSmrg        pctx->begin_query = v3d_begin_query;
11501e04c3fSmrg        pctx->end_query = v3d_end_query;
11601e04c3fSmrg        pctx->get_query_result = v3d_get_query_result;
11701e04c3fSmrg        pctx->set_active_query_state = v3d_set_active_query_state;
11801e04c3fSmrg}
119