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