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