nv50: expose two groups of compute-related MP perf counters
[mesa.git] / src / gallium / drivers / nouveau / nv50 / nv50_query.c
1 /*
2 * Copyright 2011 Nouveau Project
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 shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Christoph Bumiller
23 */
24
25 #define NV50_PUSH_EXPLICIT_SPACE_CHECKING
26
27 #include "nv50/nv50_context.h"
28 #include "nv50/nv50_query.h"
29 #include "nv50/nv50_query_hw.h"
30 #include "nv50/nv50_query_hw_metric.h"
31 #include "nv50/nv50_query_hw_sm.h"
32
33 static struct pipe_query *
34 nv50_create_query(struct pipe_context *pipe, unsigned type, unsigned index)
35 {
36 struct nv50_context *nv50 = nv50_context(pipe);
37 struct nv50_query *q;
38
39 q = nv50_hw_create_query(nv50, type, index);
40 return (struct pipe_query *)q;
41 }
42
43 static void
44 nv50_destroy_query(struct pipe_context *pipe, struct pipe_query *pq)
45 {
46 struct nv50_query *q = nv50_query(pq);
47 q->funcs->destroy_query(nv50_context(pipe), q);
48 }
49
50 static boolean
51 nv50_begin_query(struct pipe_context *pipe, struct pipe_query *pq)
52 {
53 struct nv50_query *q = nv50_query(pq);
54 return q->funcs->begin_query(nv50_context(pipe), q);
55 }
56
57 static void
58 nv50_end_query(struct pipe_context *pipe, struct pipe_query *pq)
59 {
60 struct nv50_query *q = nv50_query(pq);
61 q->funcs->end_query(nv50_context(pipe), q);
62 }
63
64 static boolean
65 nv50_get_query_result(struct pipe_context *pipe, struct pipe_query *pq,
66 boolean wait, union pipe_query_result *result)
67 {
68 struct nv50_query *q = nv50_query(pq);
69 return q->funcs->get_query_result(nv50_context(pipe), q, wait, result);
70 }
71
72 static void
73 nv50_render_condition(struct pipe_context *pipe,
74 struct pipe_query *pq,
75 boolean condition, uint mode)
76 {
77 struct nv50_context *nv50 = nv50_context(pipe);
78 struct nouveau_pushbuf *push = nv50->base.pushbuf;
79 struct nv50_query *q = nv50_query(pq);
80 struct nv50_hw_query *hq = nv50_hw_query(q);
81 uint32_t cond;
82 bool wait =
83 mode != PIPE_RENDER_COND_NO_WAIT &&
84 mode != PIPE_RENDER_COND_BY_REGION_NO_WAIT;
85
86 if (!pq) {
87 cond = NV50_3D_COND_MODE_ALWAYS;
88 }
89 else {
90 /* NOTE: comparison of 2 queries only works if both have completed */
91 switch (q->type) {
92 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
93 cond = condition ? NV50_3D_COND_MODE_EQUAL :
94 NV50_3D_COND_MODE_NOT_EQUAL;
95 wait = true;
96 break;
97 case PIPE_QUERY_OCCLUSION_COUNTER:
98 case PIPE_QUERY_OCCLUSION_PREDICATE:
99 if (likely(!condition)) {
100 if (unlikely(hq->nesting))
101 cond = wait ? NV50_3D_COND_MODE_NOT_EQUAL :
102 NV50_3D_COND_MODE_ALWAYS;
103 else
104 cond = NV50_3D_COND_MODE_RES_NON_ZERO;
105 } else {
106 cond = wait ? NV50_3D_COND_MODE_EQUAL : NV50_3D_COND_MODE_ALWAYS;
107 }
108 break;
109 default:
110 assert(!"render condition query not a predicate");
111 cond = NV50_3D_COND_MODE_ALWAYS;
112 break;
113 }
114 }
115
116 nv50->cond_query = pq;
117 nv50->cond_cond = condition;
118 nv50->cond_condmode = cond;
119 nv50->cond_mode = mode;
120
121 if (!pq) {
122 PUSH_SPACE(push, 2);
123 BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
124 PUSH_DATA (push, cond);
125 return;
126 }
127
128 PUSH_SPACE(push, 9);
129
130 if (wait) {
131 BEGIN_NV04(push, SUBC_3D(NV50_GRAPH_SERIALIZE), 1);
132 PUSH_DATA (push, 0);
133 }
134
135 PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
136 BEGIN_NV04(push, NV50_3D(COND_ADDRESS_HIGH), 3);
137 PUSH_DATAh(push, hq->bo->offset + hq->offset);
138 PUSH_DATA (push, hq->bo->offset + hq->offset);
139 PUSH_DATA (push, cond);
140
141 BEGIN_NV04(push, NV50_2D(COND_ADDRESS_HIGH), 2);
142 PUSH_DATAh(push, hq->bo->offset + hq->offset);
143 PUSH_DATA (push, hq->bo->offset + hq->offset);
144 }
145
146 void
147 nv50_init_query_functions(struct nv50_context *nv50)
148 {
149 struct pipe_context *pipe = &nv50->base.pipe;
150
151 pipe->create_query = nv50_create_query;
152 pipe->destroy_query = nv50_destroy_query;
153 pipe->begin_query = nv50_begin_query;
154 pipe->end_query = nv50_end_query;
155 pipe->get_query_result = nv50_get_query_result;
156 pipe->render_condition = nv50_render_condition;
157 nv50->cond_condmode = NV50_3D_COND_MODE_ALWAYS;
158 }
159
160 int
161 nv50_screen_get_driver_query_info(struct pipe_screen *pscreen,
162 unsigned id,
163 struct pipe_driver_query_info *info)
164 {
165 struct nv50_screen *screen = nv50_screen(pscreen);
166 int num_hw_queries = 0;
167
168 num_hw_queries = nv50_hw_get_driver_query_info(screen, 0, NULL);
169
170 if (!info)
171 return num_hw_queries;
172
173 /* Init default values. */
174 info->name = "this_is_not_the_query_you_are_looking_for";
175 info->query_type = 0xdeadd01d;
176 info->max_value.u64 = 0;
177 info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;
178 info->group_id = -1;
179 info->flags = 0;
180
181 return nv50_hw_get_driver_query_info(screen, id, info);
182 }
183
184 int
185 nv50_screen_get_driver_query_group_info(struct pipe_screen *pscreen,
186 unsigned id,
187 struct pipe_driver_query_group_info *info)
188 {
189 struct nv50_screen *screen = nv50_screen(pscreen);
190 int count = 0;
191
192 if (screen->compute)
193 if (screen->base.class_3d >= NV84_3D_CLASS)
194 count += 2;
195
196 if (!info)
197 return count;
198
199 if (id == NV50_HW_SM_QUERY_GROUP) {
200 if (screen->compute) {
201 if (screen->base.class_3d >= NV84_3D_CLASS) {
202 info->name = "MP counters";
203
204 /* Because we can't expose the number of hardware counters needed
205 * for each different query, we don't want to allow more than one
206 * active query simultaneously to avoid failure when the maximum
207 * number of counters is reached. Note that these groups of GPU
208 * counters are currently only used by AMD_performance_monitor.
209 */
210 info->max_active_queries = 1;
211 info->num_queries = NV50_HW_SM_QUERY_COUNT;
212 return 1;
213 }
214 }
215 } else
216 if (id == NV50_HW_METRIC_QUERY_GROUP) {
217 if (screen->compute) {
218 if (screen->base.class_3d >= NV84_3D_CLASS) {
219 info->name = "Performance metrics";
220 info->max_active_queries = 1;
221 info->num_queries = NV50_HW_METRIC_QUERY_COUNT;
222 return 1;
223 }
224 }
225 }
226
227 /* user asked for info about non-existing query group */
228 info->name = "this_is_not_the_query_group_you_are_looking_for";
229 info->max_active_queries = 0;
230 info->num_queries = 0;
231 return 0;
232 }