swr/rast: Add autogen of helper llvm intrinsics.
[mesa.git] / src / gallium / drivers / radeonsi / si_query.h
1 /*
2 * Copyright 2015 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #ifndef SI_QUERY_H
26 #define SI_QUERY_H
27
28 #include "util/u_threaded_context.h"
29
30 struct pipe_context;
31 struct pipe_query;
32 struct pipe_resource;
33
34 struct si_screen;
35 struct si_context;
36 struct si_query;
37 struct si_query_hw;
38 struct r600_resource;
39
40 enum {
41 SI_QUERY_DRAW_CALLS = PIPE_QUERY_DRIVER_SPECIFIC,
42 SI_QUERY_DECOMPRESS_CALLS,
43 SI_QUERY_MRT_DRAW_CALLS,
44 SI_QUERY_PRIM_RESTART_CALLS,
45 SI_QUERY_SPILL_DRAW_CALLS,
46 SI_QUERY_COMPUTE_CALLS,
47 SI_QUERY_SPILL_COMPUTE_CALLS,
48 SI_QUERY_DMA_CALLS,
49 SI_QUERY_CP_DMA_CALLS,
50 SI_QUERY_NUM_VS_FLUSHES,
51 SI_QUERY_NUM_PS_FLUSHES,
52 SI_QUERY_NUM_CS_FLUSHES,
53 SI_QUERY_NUM_CB_CACHE_FLUSHES,
54 SI_QUERY_NUM_DB_CACHE_FLUSHES,
55 SI_QUERY_NUM_L2_INVALIDATES,
56 SI_QUERY_NUM_L2_WRITEBACKS,
57 SI_QUERY_NUM_RESIDENT_HANDLES,
58 SI_QUERY_TC_OFFLOADED_SLOTS,
59 SI_QUERY_TC_DIRECT_SLOTS,
60 SI_QUERY_TC_NUM_SYNCS,
61 SI_QUERY_CS_THREAD_BUSY,
62 SI_QUERY_GALLIUM_THREAD_BUSY,
63 SI_QUERY_REQUESTED_VRAM,
64 SI_QUERY_REQUESTED_GTT,
65 SI_QUERY_MAPPED_VRAM,
66 SI_QUERY_MAPPED_GTT,
67 SI_QUERY_BUFFER_WAIT_TIME,
68 SI_QUERY_NUM_MAPPED_BUFFERS,
69 SI_QUERY_NUM_GFX_IBS,
70 SI_QUERY_NUM_SDMA_IBS,
71 SI_QUERY_GFX_BO_LIST_SIZE,
72 SI_QUERY_GFX_IB_SIZE,
73 SI_QUERY_NUM_BYTES_MOVED,
74 SI_QUERY_NUM_EVICTIONS,
75 SI_QUERY_NUM_VRAM_CPU_PAGE_FAULTS,
76 SI_QUERY_VRAM_USAGE,
77 SI_QUERY_VRAM_VIS_USAGE,
78 SI_QUERY_GTT_USAGE,
79 SI_QUERY_GPU_TEMPERATURE,
80 SI_QUERY_CURRENT_GPU_SCLK,
81 SI_QUERY_CURRENT_GPU_MCLK,
82 SI_QUERY_GPU_LOAD,
83 SI_QUERY_GPU_SHADERS_BUSY,
84 SI_QUERY_GPU_TA_BUSY,
85 SI_QUERY_GPU_GDS_BUSY,
86 SI_QUERY_GPU_VGT_BUSY,
87 SI_QUERY_GPU_IA_BUSY,
88 SI_QUERY_GPU_SX_BUSY,
89 SI_QUERY_GPU_WD_BUSY,
90 SI_QUERY_GPU_BCI_BUSY,
91 SI_QUERY_GPU_SC_BUSY,
92 SI_QUERY_GPU_PA_BUSY,
93 SI_QUERY_GPU_DB_BUSY,
94 SI_QUERY_GPU_CP_BUSY,
95 SI_QUERY_GPU_CB_BUSY,
96 SI_QUERY_GPU_SDMA_BUSY,
97 SI_QUERY_GPU_PFP_BUSY,
98 SI_QUERY_GPU_MEQ_BUSY,
99 SI_QUERY_GPU_ME_BUSY,
100 SI_QUERY_GPU_SURF_SYNC_BUSY,
101 SI_QUERY_GPU_CP_DMA_BUSY,
102 SI_QUERY_GPU_SCRATCH_RAM_BUSY,
103 SI_QUERY_NUM_COMPILATIONS,
104 SI_QUERY_NUM_SHADERS_CREATED,
105 SI_QUERY_BACK_BUFFER_PS_DRAW_RATIO,
106 SI_QUERY_NUM_SHADER_CACHE_HITS,
107 SI_QUERY_GPIN_ASIC_ID,
108 SI_QUERY_GPIN_NUM_SIMD,
109 SI_QUERY_GPIN_NUM_RB,
110 SI_QUERY_GPIN_NUM_SPI,
111 SI_QUERY_GPIN_NUM_SE,
112
113 SI_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,
114 };
115
116 enum {
117 SI_QUERY_GROUP_GPIN = 0,
118 SI_NUM_SW_QUERY_GROUPS
119 };
120
121 struct si_query_ops {
122 void (*destroy)(struct si_screen *, struct si_query *);
123 bool (*begin)(struct si_context *, struct si_query *);
124 bool (*end)(struct si_context *, struct si_query *);
125 bool (*get_result)(struct si_context *,
126 struct si_query *, bool wait,
127 union pipe_query_result *result);
128 void (*get_result_resource)(struct si_context *,
129 struct si_query *, bool wait,
130 enum pipe_query_value_type result_type,
131 int index,
132 struct pipe_resource *resource,
133 unsigned offset);
134 };
135
136 struct si_query {
137 struct threaded_query b;
138 struct si_query_ops *ops;
139
140 /* The type of query */
141 unsigned type;
142 };
143
144 enum {
145 SI_QUERY_HW_FLAG_NO_START = (1 << 0),
146 /* gap */
147 /* whether begin_query doesn't clear the result */
148 SI_QUERY_HW_FLAG_BEGIN_RESUMES = (1 << 2),
149 };
150
151 struct si_query_hw_ops {
152 bool (*prepare_buffer)(struct si_screen *,
153 struct si_query_hw *,
154 struct r600_resource *);
155 void (*emit_start)(struct si_context *,
156 struct si_query_hw *,
157 struct r600_resource *buffer, uint64_t va);
158 void (*emit_stop)(struct si_context *,
159 struct si_query_hw *,
160 struct r600_resource *buffer, uint64_t va);
161 void (*clear_result)(struct si_query_hw *, union pipe_query_result *);
162 void (*add_result)(struct si_screen *screen,
163 struct si_query_hw *, void *buffer,
164 union pipe_query_result *result);
165 };
166
167 struct si_query_buffer {
168 /* The buffer where query results are stored. */
169 struct r600_resource *buf;
170 /* Offset of the next free result after current query data */
171 unsigned results_end;
172 /* If a query buffer is full, a new buffer is created and the old one
173 * is put in here. When we calculate the result, we sum up the samples
174 * from all buffers. */
175 struct si_query_buffer *previous;
176 };
177
178 struct si_query_hw {
179 struct si_query b;
180 struct si_query_hw_ops *ops;
181 unsigned flags;
182
183 /* The query buffer and how many results are in it. */
184 struct si_query_buffer buffer;
185 /* Size of the result in memory for both begin_query and end_query,
186 * this can be one or two numbers, or it could even be a size of a structure. */
187 unsigned result_size;
188 /* The number of dwords for end_query. */
189 unsigned num_cs_dw_end;
190 /* Linked list of queries */
191 struct list_head list;
192 /* For transform feedback: which stream the query is for */
193 unsigned stream;
194
195 /* Workaround via compute shader */
196 struct r600_resource *workaround_buf;
197 unsigned workaround_offset;
198 };
199
200 bool si_query_hw_init(struct si_screen *sscreen,
201 struct si_query_hw *query);
202 void si_query_hw_destroy(struct si_screen *sscreen,
203 struct si_query *rquery);
204 bool si_query_hw_begin(struct si_context *sctx,
205 struct si_query *rquery);
206 bool si_query_hw_end(struct si_context *sctx,
207 struct si_query *rquery);
208 bool si_query_hw_get_result(struct si_context *sctx,
209 struct si_query *rquery,
210 bool wait,
211 union pipe_query_result *result);
212
213 /* Performance counters */
214 enum {
215 /* This block is part of the shader engine */
216 SI_PC_BLOCK_SE = (1 << 0),
217
218 /* Expose per-instance groups instead of summing all instances (within
219 * an SE). */
220 SI_PC_BLOCK_INSTANCE_GROUPS = (1 << 1),
221
222 /* Expose per-SE groups instead of summing instances across SEs. */
223 SI_PC_BLOCK_SE_GROUPS = (1 << 2),
224
225 /* Shader block */
226 SI_PC_BLOCK_SHADER = (1 << 3),
227
228 /* Non-shader block with perfcounters windowed by shaders. */
229 SI_PC_BLOCK_SHADER_WINDOWED = (1 << 4),
230 };
231
232 /* Describes a hardware block with performance counters. Multiple instances of
233 * each block, possibly per-SE, may exist on the chip. Depending on the block
234 * and on the user's configuration, we either
235 * (a) expose every instance as a performance counter group,
236 * (b) expose a single performance counter group that reports the sum over all
237 * instances, or
238 * (c) expose one performance counter group per instance, but summed over all
239 * shader engines.
240 */
241 struct si_perfcounter_block {
242 const char *basename;
243 unsigned flags;
244 unsigned num_counters;
245 unsigned num_selectors;
246 unsigned num_instances;
247
248 unsigned num_groups;
249 char *group_names;
250 unsigned group_name_stride;
251
252 char *selector_names;
253 unsigned selector_name_stride;
254
255 void *data;
256 };
257
258 struct si_perfcounters {
259 unsigned num_groups;
260 unsigned num_blocks;
261 struct si_perfcounter_block *blocks;
262
263 unsigned num_stop_cs_dwords;
264 unsigned num_instance_cs_dwords;
265
266 unsigned num_shader_types;
267 const char * const *shader_type_suffixes;
268 const unsigned *shader_type_bits;
269
270 void (*emit_instance)(struct si_context *,
271 int se, int instance);
272 void (*emit_shaders)(struct si_context *, unsigned shaders);
273 void (*emit_select)(struct si_context *,
274 struct si_perfcounter_block *,
275 unsigned count, unsigned *selectors);
276 void (*emit_start)(struct si_context *,
277 struct r600_resource *buffer, uint64_t va);
278 void (*emit_stop)(struct si_context *,
279 struct r600_resource *buffer, uint64_t va);
280 void (*emit_read)(struct si_context *,
281 struct si_perfcounter_block *,
282 unsigned count, unsigned *selectors,
283 struct r600_resource *buffer, uint64_t va);
284
285 void (*cleanup)(struct si_screen *);
286
287 bool separate_se;
288 bool separate_instance;
289 };
290
291 struct pipe_query *si_create_batch_query(struct pipe_context *ctx,
292 unsigned num_queries,
293 unsigned *query_types);
294
295 int si_get_perfcounter_info(struct si_screen *,
296 unsigned index,
297 struct pipe_driver_query_info *info);
298 int si_get_perfcounter_group_info(struct si_screen *,
299 unsigned index,
300 struct pipe_driver_query_group_info *info);
301
302 bool si_perfcounters_init(struct si_perfcounters *, unsigned num_blocks);
303 void si_perfcounters_add_block(struct si_screen *,
304 struct si_perfcounters *,
305 const char *name, unsigned flags,
306 unsigned counters, unsigned selectors,
307 unsigned instances, void *data);
308 void si_perfcounters_do_destroy(struct si_perfcounters *);
309 void si_query_hw_reset_buffers(struct si_context *sctx,
310 struct si_query_hw *query);
311
312 struct si_qbo_state {
313 void *saved_compute;
314 struct pipe_constant_buffer saved_const0;
315 struct pipe_shader_buffer saved_ssbo[3];
316 };
317
318 #endif /* SI_QUERY_H */