xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/v3d/v3d_query.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2014 Broadcom
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #include "v3d_query.h"
25 
26 int
v3d_get_driver_query_group_info(struct pipe_screen * pscreen,unsigned index,struct pipe_driver_query_group_info * info)27 v3d_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index,
28                                 struct pipe_driver_query_group_info *info)
29 {
30         struct v3d_screen *screen = v3d_screen(pscreen);
31         struct v3d_device_info *devinfo = &screen->devinfo;
32 
33         return v3d_X(devinfo, get_driver_query_group_info_perfcnt)(screen,
34                                                                    index,
35                                                                    info);
36 }
37 
38 int
v3d_get_driver_query_info(struct pipe_screen * pscreen,unsigned index,struct pipe_driver_query_info * info)39 v3d_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
40                           struct pipe_driver_query_info *info)
41 {
42         struct v3d_screen *screen = v3d_screen(pscreen);
43         struct v3d_device_info *devinfo = &screen->devinfo;
44 
45         return v3d_X(devinfo, get_driver_query_info_perfcnt)(screen,
46                                                              index,
47                                                              info);
48 }
49 
50 static struct pipe_query *
v3d_create_query(struct pipe_context * pctx,unsigned query_type,unsigned index)51 v3d_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)
52 {
53         struct v3d_context *v3d = v3d_context(pctx);
54 
55         return v3d_create_query_pipe(v3d, query_type, index);
56 }
57 
58 static struct pipe_query *
v3d_create_batch_query(struct pipe_context * pctx,unsigned num_queries,unsigned * query_types)59 v3d_create_batch_query(struct pipe_context *pctx, unsigned num_queries,
60                        unsigned *query_types)
61 {
62         struct v3d_context *v3d = v3d_context(pctx);
63         struct v3d_screen *screen = v3d->screen;
64         struct v3d_device_info *devinfo = &screen->devinfo;
65 
66         return v3d_X(devinfo, create_batch_query_perfcnt)(v3d_context(pctx),
67                                                           num_queries,
68                                                           query_types);
69 }
70 
71 static void
v3d_destroy_query(struct pipe_context * pctx,struct pipe_query * query)72 v3d_destroy_query(struct pipe_context *pctx, struct pipe_query *query)
73 {
74         struct v3d_context *v3d = v3d_context(pctx);
75         struct v3d_query *q = (struct v3d_query *)query;
76 
77         q->funcs->destroy_query(v3d, q);
78 }
79 
80 static bool
v3d_begin_query(struct pipe_context * pctx,struct pipe_query * query)81 v3d_begin_query(struct pipe_context *pctx, struct pipe_query *query)
82 {
83         struct v3d_context *v3d = v3d_context(pctx);
84         struct v3d_query *q = (struct v3d_query *)query;
85 
86         return q->funcs->begin_query(v3d, q);
87 }
88 
89 static bool
v3d_end_query(struct pipe_context * pctx,struct pipe_query * query)90 v3d_end_query(struct pipe_context *pctx, struct pipe_query *query)
91 {
92         struct v3d_context *v3d = v3d_context(pctx);
93         struct v3d_query *q = (struct v3d_query *)query;
94 
95         return q->funcs->end_query(v3d, q);
96 }
97 
98 static bool
v3d_get_query_result(struct pipe_context * pctx,struct pipe_query * query,bool wait,union pipe_query_result * vresult)99 v3d_get_query_result(struct pipe_context *pctx, struct pipe_query *query,
100                      bool wait, union pipe_query_result *vresult)
101 {
102         struct v3d_context *v3d = v3d_context(pctx);
103         struct v3d_query *q = (struct v3d_query *)query;
104 
105         return q->funcs->get_query_result(v3d, q, wait, vresult);
106 }
107 
108 static void
v3d_set_active_query_state(struct pipe_context * pctx,bool enable)109 v3d_set_active_query_state(struct pipe_context *pctx, bool enable)
110 {
111         struct v3d_context *v3d = v3d_context(pctx);
112 
113         v3d->active_queries = enable;
114         v3d->dirty |= V3D_DIRTY_OQ;
115         v3d->dirty |= V3D_DIRTY_STREAMOUT;
116 }
117 
118 static void
v3d_render_condition(struct pipe_context * pipe,struct pipe_query * query,bool condition,enum pipe_render_cond_flag mode)119 v3d_render_condition(struct pipe_context *pipe,
120                      struct pipe_query *query,
121                      bool condition,
122                      enum pipe_render_cond_flag mode)
123 {
124         struct v3d_context *v3d = v3d_context(pipe);
125 
126         v3d->cond_query = query;
127         v3d->cond_cond = condition;
128         v3d->cond_mode = mode;
129 }
130 
131 void
v3d_query_init(struct pipe_context * pctx)132 v3d_query_init(struct pipe_context *pctx)
133 {
134         pctx->create_query = v3d_create_query;
135         pctx->create_batch_query = v3d_create_batch_query;
136         pctx->destroy_query = v3d_destroy_query;
137         pctx->begin_query = v3d_begin_query;
138         pctx->end_query = v3d_end_query;
139         pctx->get_query_result = v3d_get_query_result;
140         pctx->set_active_query_state = v3d_set_active_query_state;
141         pctx->render_condition = v3d_render_condition;
142 }
143