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