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