radeonsi: constify a bunch of the perfcounter structs.
[mesa.git] / src / gallium / drivers / radeon / r600_query.h
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Nicolai Hähnle <nicolai.haehnle@amd.com>
25 *
26 */
27
28 #ifndef R600_QUERY_H
29 #define R600_QUERY_H
30
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
33 #include "util/list.h"
34
35 struct pipe_context;
36 struct pipe_query;
37 struct pipe_resource;
38
39 struct r600_common_context;
40 struct r600_common_screen;
41 struct r600_query;
42 struct r600_query_hw;
43 struct r600_resource;
44
45 enum {
46 R600_QUERY_DRAW_CALLS = PIPE_QUERY_DRIVER_SPECIFIC,
47 R600_QUERY_PRIM_RESTART_CALLS,
48 R600_QUERY_SPILL_DRAW_CALLS,
49 R600_QUERY_COMPUTE_CALLS,
50 R600_QUERY_SPILL_COMPUTE_CALLS,
51 R600_QUERY_DMA_CALLS,
52 R600_QUERY_CP_DMA_CALLS,
53 R600_QUERY_NUM_VS_FLUSHES,
54 R600_QUERY_NUM_PS_FLUSHES,
55 R600_QUERY_NUM_CS_FLUSHES,
56 R600_QUERY_NUM_FB_CACHE_FLUSHES,
57 R600_QUERY_NUM_L2_INVALIDATES,
58 R600_QUERY_NUM_L2_WRITEBACKS,
59 R600_QUERY_CS_THREAD_BUSY,
60 R600_QUERY_REQUESTED_VRAM,
61 R600_QUERY_REQUESTED_GTT,
62 R600_QUERY_MAPPED_VRAM,
63 R600_QUERY_MAPPED_GTT,
64 R600_QUERY_BUFFER_WAIT_TIME,
65 R600_QUERY_NUM_MAPPED_BUFFERS,
66 R600_QUERY_NUM_GFX_IBS,
67 R600_QUERY_NUM_SDMA_IBS,
68 R600_QUERY_NUM_BYTES_MOVED,
69 R600_QUERY_NUM_EVICTIONS,
70 R600_QUERY_VRAM_USAGE,
71 R600_QUERY_VRAM_VIS_USAGE,
72 R600_QUERY_GTT_USAGE,
73 R600_QUERY_GPU_TEMPERATURE,
74 R600_QUERY_CURRENT_GPU_SCLK,
75 R600_QUERY_CURRENT_GPU_MCLK,
76 R600_QUERY_GPU_LOAD,
77 R600_QUERY_GPU_SHADERS_BUSY,
78 R600_QUERY_GPU_TA_BUSY,
79 R600_QUERY_GPU_GDS_BUSY,
80 R600_QUERY_GPU_VGT_BUSY,
81 R600_QUERY_GPU_IA_BUSY,
82 R600_QUERY_GPU_SX_BUSY,
83 R600_QUERY_GPU_WD_BUSY,
84 R600_QUERY_GPU_BCI_BUSY,
85 R600_QUERY_GPU_SC_BUSY,
86 R600_QUERY_GPU_PA_BUSY,
87 R600_QUERY_GPU_DB_BUSY,
88 R600_QUERY_GPU_CP_BUSY,
89 R600_QUERY_GPU_CB_BUSY,
90 R600_QUERY_GPU_SDMA_BUSY,
91 R600_QUERY_GPU_PFP_BUSY,
92 R600_QUERY_GPU_MEQ_BUSY,
93 R600_QUERY_GPU_ME_BUSY,
94 R600_QUERY_GPU_SURF_SYNC_BUSY,
95 R600_QUERY_GPU_DMA_BUSY,
96 R600_QUERY_GPU_SCRATCH_RAM_BUSY,
97 R600_QUERY_GPU_CE_BUSY,
98 R600_QUERY_NUM_COMPILATIONS,
99 R600_QUERY_NUM_SHADERS_CREATED,
100 R600_QUERY_BACK_BUFFER_PS_DRAW_RATIO,
101 R600_QUERY_NUM_SHADER_CACHE_HITS,
102 R600_QUERY_GPIN_ASIC_ID,
103 R600_QUERY_GPIN_NUM_SIMD,
104 R600_QUERY_GPIN_NUM_RB,
105 R600_QUERY_GPIN_NUM_SPI,
106 R600_QUERY_GPIN_NUM_SE,
107
108 R600_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,
109 };
110
111 enum {
112 R600_QUERY_GROUP_GPIN = 0,
113 R600_NUM_SW_QUERY_GROUPS
114 };
115
116 struct r600_query_ops {
117 void (*destroy)(struct r600_common_screen *, struct r600_query *);
118 bool (*begin)(struct r600_common_context *, struct r600_query *);
119 bool (*end)(struct r600_common_context *, struct r600_query *);
120 bool (*get_result)(struct r600_common_context *,
121 struct r600_query *, bool wait,
122 union pipe_query_result *result);
123 void (*get_result_resource)(struct r600_common_context *,
124 struct r600_query *, bool wait,
125 enum pipe_query_value_type result_type,
126 int index,
127 struct pipe_resource *resource,
128 unsigned offset);
129 };
130
131 struct r600_query {
132 struct r600_query_ops *ops;
133
134 /* The type of query */
135 unsigned type;
136 };
137
138 enum {
139 R600_QUERY_HW_FLAG_NO_START = (1 << 0),
140 /* gap */
141 /* whether begin_query doesn't clear the result */
142 R600_QUERY_HW_FLAG_BEGIN_RESUMES = (1 << 2),
143 };
144
145 struct r600_query_hw_ops {
146 bool (*prepare_buffer)(struct r600_common_screen *,
147 struct r600_query_hw *,
148 struct r600_resource *);
149 void (*emit_start)(struct r600_common_context *,
150 struct r600_query_hw *,
151 struct r600_resource *buffer, uint64_t va);
152 void (*emit_stop)(struct r600_common_context *,
153 struct r600_query_hw *,
154 struct r600_resource *buffer, uint64_t va);
155 void (*clear_result)(struct r600_query_hw *, union pipe_query_result *);
156 void (*add_result)(struct r600_common_screen *screen,
157 struct r600_query_hw *, void *buffer,
158 union pipe_query_result *result);
159 };
160
161 struct r600_query_buffer {
162 /* The buffer where query results are stored. */
163 struct r600_resource *buf;
164 /* Offset of the next free result after current query data */
165 unsigned results_end;
166 /* If a query buffer is full, a new buffer is created and the old one
167 * is put in here. When we calculate the result, we sum up the samples
168 * from all buffers. */
169 struct r600_query_buffer *previous;
170 };
171
172 struct r600_query_hw {
173 struct r600_query b;
174 struct r600_query_hw_ops *ops;
175 unsigned flags;
176
177 /* The query buffer and how many results are in it. */
178 struct r600_query_buffer buffer;
179 /* Size of the result in memory for both begin_query and end_query,
180 * this can be one or two numbers, or it could even be a size of a structure. */
181 unsigned result_size;
182 /* The number of dwords for begin_query or end_query. */
183 unsigned num_cs_dw_begin;
184 unsigned num_cs_dw_end;
185 /* Linked list of queries */
186 struct list_head list;
187 /* For transform feedback: which stream the query is for */
188 unsigned stream;
189 };
190
191 bool r600_query_hw_init(struct r600_common_screen *rscreen,
192 struct r600_query_hw *query);
193 void r600_query_hw_destroy(struct r600_common_screen *rscreen,
194 struct r600_query *rquery);
195 bool r600_query_hw_begin(struct r600_common_context *rctx,
196 struct r600_query *rquery);
197 bool r600_query_hw_end(struct r600_common_context *rctx,
198 struct r600_query *rquery);
199 bool r600_query_hw_get_result(struct r600_common_context *rctx,
200 struct r600_query *rquery,
201 bool wait,
202 union pipe_query_result *result);
203
204 /* Performance counters */
205 enum {
206 /* This block is part of the shader engine */
207 R600_PC_BLOCK_SE = (1 << 0),
208
209 /* Expose per-instance groups instead of summing all instances (within
210 * an SE). */
211 R600_PC_BLOCK_INSTANCE_GROUPS = (1 << 1),
212
213 /* Expose per-SE groups instead of summing instances across SEs. */
214 R600_PC_BLOCK_SE_GROUPS = (1 << 2),
215
216 /* Shader block */
217 R600_PC_BLOCK_SHADER = (1 << 3),
218
219 /* Non-shader block with perfcounters windowed by shaders. */
220 R600_PC_BLOCK_SHADER_WINDOWED = (1 << 4),
221 };
222
223 /* Describes a hardware block with performance counters. Multiple instances of
224 * each block, possibly per-SE, may exist on the chip. Depending on the block
225 * and on the user's configuration, we either
226 * (a) expose every instance as a performance counter group,
227 * (b) expose a single performance counter group that reports the sum over all
228 * instances, or
229 * (c) expose one performance counter group per instance, but summed over all
230 * shader engines.
231 */
232 struct r600_perfcounter_block {
233 const char *basename;
234 unsigned flags;
235 unsigned num_counters;
236 unsigned num_selectors;
237 unsigned num_instances;
238
239 unsigned num_groups;
240 char *group_names;
241 unsigned group_name_stride;
242
243 char *selector_names;
244 unsigned selector_name_stride;
245
246 const void *data;
247 };
248
249 struct r600_perfcounters {
250 unsigned num_groups;
251 unsigned num_blocks;
252 struct r600_perfcounter_block *blocks;
253
254 unsigned num_start_cs_dwords;
255 unsigned num_stop_cs_dwords;
256 unsigned num_instance_cs_dwords;
257 unsigned num_shaders_cs_dwords;
258
259 unsigned num_shader_types;
260 const char * const *shader_type_suffixes;
261 const unsigned *shader_type_bits;
262
263 void (*get_size)(struct r600_perfcounter_block *,
264 unsigned count, unsigned *selectors,
265 unsigned *num_select_dw, unsigned *num_read_dw);
266
267 void (*emit_instance)(struct r600_common_context *,
268 int se, int instance);
269 void (*emit_shaders)(struct r600_common_context *, unsigned shaders);
270 void (*emit_select)(struct r600_common_context *,
271 struct r600_perfcounter_block *,
272 unsigned count, unsigned *selectors);
273 void (*emit_start)(struct r600_common_context *,
274 struct r600_resource *buffer, uint64_t va);
275 void (*emit_stop)(struct r600_common_context *,
276 struct r600_resource *buffer, uint64_t va);
277 void (*emit_read)(struct r600_common_context *,
278 struct r600_perfcounter_block *,
279 unsigned count, unsigned *selectors,
280 struct r600_resource *buffer, uint64_t va);
281
282 void (*cleanup)(struct r600_common_screen *);
283
284 bool separate_se;
285 bool separate_instance;
286 };
287
288 struct pipe_query *r600_create_batch_query(struct pipe_context *ctx,
289 unsigned num_queries,
290 unsigned *query_types);
291
292 int r600_get_perfcounter_info(struct r600_common_screen *,
293 unsigned index,
294 struct pipe_driver_query_info *info);
295 int r600_get_perfcounter_group_info(struct r600_common_screen *,
296 unsigned index,
297 struct pipe_driver_query_group_info *info);
298
299 bool r600_perfcounters_init(struct r600_perfcounters *, unsigned num_blocks);
300 void r600_perfcounters_add_block(struct r600_common_screen *,
301 struct r600_perfcounters *,
302 const char *name, unsigned flags,
303 unsigned counters, unsigned selectors,
304 unsigned instances, const void *data);
305 void r600_perfcounters_do_destroy(struct r600_perfcounters *);
306 void r600_query_hw_reset_buffers(struct r600_common_context *rctx,
307 struct r600_query_hw *query);
308
309 struct r600_qbo_state {
310 void *saved_compute;
311 struct pipe_constant_buffer saved_const0;
312 struct pipe_shader_buffer saved_ssbo[3];
313 };
314
315 #endif /* R600_QUERY_H */