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