freedreno: wire up core pipe_debug_callback
[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 "util/list.h"
33
34 struct pipe_context;
35 struct pipe_query;
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_REQUESTED_VRAM,
46 R600_QUERY_REQUESTED_GTT,
47 R600_QUERY_BUFFER_WAIT_TIME,
48 R600_QUERY_NUM_CS_FLUSHES,
49 R600_QUERY_NUM_BYTES_MOVED,
50 R600_QUERY_VRAM_USAGE,
51 R600_QUERY_GTT_USAGE,
52 R600_QUERY_GPU_TEMPERATURE,
53 R600_QUERY_CURRENT_GPU_SCLK,
54 R600_QUERY_CURRENT_GPU_MCLK,
55 R600_QUERY_GPU_LOAD,
56 R600_QUERY_NUM_COMPILATIONS,
57 R600_QUERY_NUM_SHADERS_CREATED,
58 R600_QUERY_GPIN_ASIC_ID,
59 R600_QUERY_GPIN_NUM_SIMD,
60 R600_QUERY_GPIN_NUM_RB,
61 R600_QUERY_GPIN_NUM_SPI,
62 R600_QUERY_GPIN_NUM_SE,
63
64 R600_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,
65 };
66
67 enum {
68 R600_QUERY_GROUP_GPIN = 0,
69 R600_NUM_SW_QUERY_GROUPS
70 };
71
72 struct r600_query_ops {
73 void (*destroy)(struct r600_common_context *, struct r600_query *);
74 boolean (*begin)(struct r600_common_context *, struct r600_query *);
75 bool (*end)(struct r600_common_context *, struct r600_query *);
76 boolean (*get_result)(struct r600_common_context *,
77 struct r600_query *, boolean wait,
78 union pipe_query_result *result);
79 };
80
81 struct r600_query {
82 struct r600_query_ops *ops;
83
84 /* The type of query */
85 unsigned type;
86 };
87
88 enum {
89 R600_QUERY_HW_FLAG_NO_START = (1 << 0),
90 R600_QUERY_HW_FLAG_PREDICATE = (1 << 1),
91 };
92
93 struct r600_query_hw_ops {
94 bool (*prepare_buffer)(struct r600_common_context *,
95 struct r600_query_hw *,
96 struct r600_resource *);
97 void (*emit_start)(struct r600_common_context *,
98 struct r600_query_hw *,
99 struct r600_resource *buffer, uint64_t va);
100 void (*emit_stop)(struct r600_common_context *,
101 struct r600_query_hw *,
102 struct r600_resource *buffer, uint64_t va);
103 void (*clear_result)(struct r600_query_hw *, union pipe_query_result *);
104 void (*add_result)(struct r600_common_context *ctx,
105 struct r600_query_hw *, void *buffer,
106 union pipe_query_result *result);
107 };
108
109 struct r600_query_buffer {
110 /* The buffer where query results are stored. */
111 struct r600_resource *buf;
112 /* Offset of the next free result after current query data */
113 unsigned results_end;
114 /* If a query buffer is full, a new buffer is created and the old one
115 * is put in here. When we calculate the result, we sum up the samples
116 * from all buffers. */
117 struct r600_query_buffer *previous;
118 };
119
120 struct r600_query_hw {
121 struct r600_query b;
122 struct r600_query_hw_ops *ops;
123 unsigned flags;
124
125 /* The query buffer and how many results are in it. */
126 struct r600_query_buffer buffer;
127 /* Size of the result in memory for both begin_query and end_query,
128 * this can be one or two numbers, or it could even be a size of a structure. */
129 unsigned result_size;
130 /* The number of dwords for begin_query or end_query. */
131 unsigned num_cs_dw_begin;
132 unsigned num_cs_dw_end;
133 /* Linked list of queries */
134 struct list_head list;
135 /* For transform feedback: which stream the query is for */
136 unsigned stream;
137 };
138
139 boolean r600_query_hw_init(struct r600_common_context *rctx,
140 struct r600_query_hw *query);
141 void r600_query_hw_destroy(struct r600_common_context *rctx,
142 struct r600_query *rquery);
143 boolean r600_query_hw_begin(struct r600_common_context *rctx,
144 struct r600_query *rquery);
145 bool r600_query_hw_end(struct r600_common_context *rctx,
146 struct r600_query *rquery);
147 boolean r600_query_hw_get_result(struct r600_common_context *rctx,
148 struct r600_query *rquery,
149 boolean wait,
150 union pipe_query_result *result);
151
152 /* Performance counters */
153 enum {
154 /* This block is part of the shader engine */
155 R600_PC_BLOCK_SE = (1 << 0),
156
157 /* Expose per-instance groups instead of summing all instances (within
158 * an SE). */
159 R600_PC_BLOCK_INSTANCE_GROUPS = (1 << 1),
160
161 /* Expose per-SE groups instead of summing instances across SEs. */
162 R600_PC_BLOCK_SE_GROUPS = (1 << 2),
163
164 /* Shader block */
165 R600_PC_BLOCK_SHADER = (1 << 3),
166
167 /* Non-shader block with perfcounters windowed by shaders. */
168 R600_PC_BLOCK_SHADER_WINDOWED = (1 << 4),
169 };
170
171 /* Describes a hardware block with performance counters. Multiple instances of
172 * each block, possibly per-SE, may exist on the chip. Depending on the block
173 * and on the user's configuration, we either
174 * (a) expose every instance as a performance counter group,
175 * (b) expose a single performance counter group that reports the sum over all
176 * instances, or
177 * (c) expose one performance counter group per instance, but summed over all
178 * shader engines.
179 */
180 struct r600_perfcounter_block {
181 const char *basename;
182 unsigned flags;
183 unsigned num_counters;
184 unsigned num_selectors;
185 unsigned num_instances;
186
187 unsigned num_groups;
188 char *group_names;
189 unsigned group_name_stride;
190
191 char *selector_names;
192 unsigned selector_name_stride;
193
194 void *data;
195 };
196
197 struct r600_perfcounters {
198 unsigned num_groups;
199 unsigned num_blocks;
200 struct r600_perfcounter_block *blocks;
201
202 unsigned num_start_cs_dwords;
203 unsigned num_stop_cs_dwords;
204 unsigned num_instance_cs_dwords;
205 unsigned num_shaders_cs_dwords;
206
207 unsigned num_shader_types;
208 const char * const *shader_type_suffixes;
209 const unsigned *shader_type_bits;
210
211 void (*get_size)(struct r600_perfcounter_block *,
212 unsigned count, unsigned *selectors,
213 unsigned *num_select_dw, unsigned *num_read_dw);
214
215 void (*emit_instance)(struct r600_common_context *,
216 int se, int instance);
217 void (*emit_shaders)(struct r600_common_context *, unsigned shaders);
218 void (*emit_select)(struct r600_common_context *,
219 struct r600_perfcounter_block *,
220 unsigned count, unsigned *selectors);
221 void (*emit_start)(struct r600_common_context *,
222 struct r600_resource *buffer, uint64_t va);
223 void (*emit_stop)(struct r600_common_context *,
224 struct r600_resource *buffer, uint64_t va);
225 void (*emit_read)(struct r600_common_context *,
226 struct r600_perfcounter_block *,
227 unsigned count, unsigned *selectors,
228 struct r600_resource *buffer, uint64_t va);
229
230 void (*cleanup)(struct r600_common_screen *);
231
232 boolean separate_se;
233 boolean separate_instance;
234 };
235
236 struct pipe_query *r600_create_batch_query(struct pipe_context *ctx,
237 unsigned num_queries,
238 unsigned *query_types);
239
240 int r600_get_perfcounter_info(struct r600_common_screen *,
241 unsigned index,
242 struct pipe_driver_query_info *info);
243 int r600_get_perfcounter_group_info(struct r600_common_screen *,
244 unsigned index,
245 struct pipe_driver_query_group_info *info);
246
247 boolean r600_perfcounters_init(struct r600_perfcounters *, unsigned num_blocks);
248 void r600_perfcounters_add_block(struct r600_common_screen *,
249 struct r600_perfcounters *,
250 const char *name, unsigned flags,
251 unsigned counters, unsigned selectors,
252 unsigned instances, void *data);
253 void r600_perfcounters_do_destroy(struct r600_perfcounters *);
254
255 #endif /* R600_QUERY_H */