2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
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
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
24 * Nicolai Hähnle <nicolai.haehnle@amd.com>
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
33 #include "util/list.h"
39 struct r600_common_context
;
40 struct r600_common_screen
;
46 R600_QUERY_DRAW_CALLS
= PIPE_QUERY_DRIVER_SPECIFIC
,
47 R600_QUERY_SPILL_DRAW_CALLS
,
48 R600_QUERY_COMPUTE_CALLS
,
49 R600_QUERY_SPILL_COMPUTE_CALLS
,
51 R600_QUERY_CP_DMA_CALLS
,
52 R600_QUERY_NUM_VS_FLUSHES
,
53 R600_QUERY_NUM_PS_FLUSHES
,
54 R600_QUERY_NUM_CS_FLUSHES
,
55 R600_QUERY_NUM_FB_CACHE_FLUSHES
,
56 R600_QUERY_NUM_L2_INVALIDATES
,
57 R600_QUERY_NUM_L2_WRITEBACKS
,
58 R600_QUERY_CS_THREAD_BUSY
,
59 R600_QUERY_REQUESTED_VRAM
,
60 R600_QUERY_REQUESTED_GTT
,
61 R600_QUERY_MAPPED_VRAM
,
62 R600_QUERY_MAPPED_GTT
,
63 R600_QUERY_BUFFER_WAIT_TIME
,
64 R600_QUERY_NUM_MAPPED_BUFFERS
,
65 R600_QUERY_NUM_GFX_IBS
,
66 R600_QUERY_NUM_SDMA_IBS
,
67 R600_QUERY_NUM_BYTES_MOVED
,
68 R600_QUERY_NUM_EVICTIONS
,
69 R600_QUERY_VRAM_USAGE
,
70 R600_QUERY_VRAM_VIS_USAGE
,
72 R600_QUERY_GPU_TEMPERATURE
,
73 R600_QUERY_CURRENT_GPU_SCLK
,
74 R600_QUERY_CURRENT_GPU_MCLK
,
76 R600_QUERY_GPU_SHADERS_BUSY
,
77 R600_QUERY_GPU_TA_BUSY
,
78 R600_QUERY_GPU_GDS_BUSY
,
79 R600_QUERY_GPU_VGT_BUSY
,
80 R600_QUERY_GPU_IA_BUSY
,
81 R600_QUERY_GPU_SX_BUSY
,
82 R600_QUERY_GPU_WD_BUSY
,
83 R600_QUERY_GPU_BCI_BUSY
,
84 R600_QUERY_GPU_SC_BUSY
,
85 R600_QUERY_GPU_PA_BUSY
,
86 R600_QUERY_GPU_DB_BUSY
,
87 R600_QUERY_GPU_CP_BUSY
,
88 R600_QUERY_GPU_CB_BUSY
,
89 R600_QUERY_GPU_SDMA_BUSY
,
90 R600_QUERY_GPU_PFP_BUSY
,
91 R600_QUERY_GPU_MEQ_BUSY
,
92 R600_QUERY_GPU_ME_BUSY
,
93 R600_QUERY_GPU_SURF_SYNC_BUSY
,
94 R600_QUERY_GPU_DMA_BUSY
,
95 R600_QUERY_GPU_SCRATCH_RAM_BUSY
,
96 R600_QUERY_GPU_CE_BUSY
,
97 R600_QUERY_NUM_COMPILATIONS
,
98 R600_QUERY_NUM_SHADERS_CREATED
,
99 R600_QUERY_BACK_BUFFER_PS_DRAW_RATIO
,
100 R600_QUERY_NUM_SHADER_CACHE_HITS
,
101 R600_QUERY_GPIN_ASIC_ID
,
102 R600_QUERY_GPIN_NUM_SIMD
,
103 R600_QUERY_GPIN_NUM_RB
,
104 R600_QUERY_GPIN_NUM_SPI
,
105 R600_QUERY_GPIN_NUM_SE
,
107 R600_QUERY_FIRST_PERFCOUNTER
= PIPE_QUERY_DRIVER_SPECIFIC
+ 100,
111 R600_QUERY_GROUP_GPIN
= 0,
112 R600_NUM_SW_QUERY_GROUPS
115 struct r600_query_ops
{
116 void (*destroy
)(struct r600_common_screen
*, struct r600_query
*);
117 bool (*begin
)(struct r600_common_context
*, struct r600_query
*);
118 bool (*end
)(struct r600_common_context
*, struct r600_query
*);
119 bool (*get_result
)(struct r600_common_context
*,
120 struct r600_query
*, bool wait
,
121 union pipe_query_result
*result
);
122 void (*get_result_resource
)(struct r600_common_context
*,
123 struct r600_query
*, bool wait
,
124 enum pipe_query_value_type result_type
,
126 struct pipe_resource
*resource
,
131 struct r600_query_ops
*ops
;
133 /* The type of query */
138 R600_QUERY_HW_FLAG_NO_START
= (1 << 0),
140 /* whether begin_query doesn't clear the result */
141 R600_QUERY_HW_FLAG_BEGIN_RESUMES
= (1 << 2),
144 struct r600_query_hw_ops
{
145 bool (*prepare_buffer
)(struct r600_common_screen
*,
146 struct r600_query_hw
*,
147 struct r600_resource
*);
148 void (*emit_start
)(struct r600_common_context
*,
149 struct r600_query_hw
*,
150 struct r600_resource
*buffer
, uint64_t va
);
151 void (*emit_stop
)(struct r600_common_context
*,
152 struct r600_query_hw
*,
153 struct r600_resource
*buffer
, uint64_t va
);
154 void (*clear_result
)(struct r600_query_hw
*, union pipe_query_result
*);
155 void (*add_result
)(struct r600_common_context
*ctx
,
156 struct r600_query_hw
*, void *buffer
,
157 union pipe_query_result
*result
);
160 struct r600_query_buffer
{
161 /* The buffer where query results are stored. */
162 struct r600_resource
*buf
;
163 /* Offset of the next free result after current query data */
164 unsigned results_end
;
165 /* If a query buffer is full, a new buffer is created and the old one
166 * is put in here. When we calculate the result, we sum up the samples
167 * from all buffers. */
168 struct r600_query_buffer
*previous
;
171 struct r600_query_hw
{
173 struct r600_query_hw_ops
*ops
;
176 /* The query buffer and how many results are in it. */
177 struct r600_query_buffer buffer
;
178 /* Size of the result in memory for both begin_query and end_query,
179 * this can be one or two numbers, or it could even be a size of a structure. */
180 unsigned result_size
;
181 /* The number of dwords for begin_query or end_query. */
182 unsigned num_cs_dw_begin
;
183 unsigned num_cs_dw_end
;
184 /* Linked list of queries */
185 struct list_head list
;
186 /* For transform feedback: which stream the query is for */
190 bool r600_query_hw_init(struct r600_common_screen
*rscreen
,
191 struct r600_query_hw
*query
);
192 void r600_query_hw_destroy(struct r600_common_screen
*rscreen
,
193 struct r600_query
*rquery
);
194 bool r600_query_hw_begin(struct r600_common_context
*rctx
,
195 struct r600_query
*rquery
);
196 bool r600_query_hw_end(struct r600_common_context
*rctx
,
197 struct r600_query
*rquery
);
198 bool r600_query_hw_get_result(struct r600_common_context
*rctx
,
199 struct r600_query
*rquery
,
201 union pipe_query_result
*result
);
203 /* Performance counters */
205 /* This block is part of the shader engine */
206 R600_PC_BLOCK_SE
= (1 << 0),
208 /* Expose per-instance groups instead of summing all instances (within
210 R600_PC_BLOCK_INSTANCE_GROUPS
= (1 << 1),
212 /* Expose per-SE groups instead of summing instances across SEs. */
213 R600_PC_BLOCK_SE_GROUPS
= (1 << 2),
216 R600_PC_BLOCK_SHADER
= (1 << 3),
218 /* Non-shader block with perfcounters windowed by shaders. */
219 R600_PC_BLOCK_SHADER_WINDOWED
= (1 << 4),
222 /* Describes a hardware block with performance counters. Multiple instances of
223 * each block, possibly per-SE, may exist on the chip. Depending on the block
224 * and on the user's configuration, we either
225 * (a) expose every instance as a performance counter group,
226 * (b) expose a single performance counter group that reports the sum over all
228 * (c) expose one performance counter group per instance, but summed over all
231 struct r600_perfcounter_block
{
232 const char *basename
;
234 unsigned num_counters
;
235 unsigned num_selectors
;
236 unsigned num_instances
;
240 unsigned group_name_stride
;
242 char *selector_names
;
243 unsigned selector_name_stride
;
248 struct r600_perfcounters
{
251 struct r600_perfcounter_block
*blocks
;
253 unsigned num_start_cs_dwords
;
254 unsigned num_stop_cs_dwords
;
255 unsigned num_instance_cs_dwords
;
256 unsigned num_shaders_cs_dwords
;
258 unsigned num_shader_types
;
259 const char * const *shader_type_suffixes
;
260 const unsigned *shader_type_bits
;
262 void (*get_size
)(struct r600_perfcounter_block
*,
263 unsigned count
, unsigned *selectors
,
264 unsigned *num_select_dw
, unsigned *num_read_dw
);
266 void (*emit_instance
)(struct r600_common_context
*,
267 int se
, int instance
);
268 void (*emit_shaders
)(struct r600_common_context
*, unsigned shaders
);
269 void (*emit_select
)(struct r600_common_context
*,
270 struct r600_perfcounter_block
*,
271 unsigned count
, unsigned *selectors
);
272 void (*emit_start
)(struct r600_common_context
*,
273 struct r600_resource
*buffer
, uint64_t va
);
274 void (*emit_stop
)(struct r600_common_context
*,
275 struct r600_resource
*buffer
, uint64_t va
);
276 void (*emit_read
)(struct r600_common_context
*,
277 struct r600_perfcounter_block
*,
278 unsigned count
, unsigned *selectors
,
279 struct r600_resource
*buffer
, uint64_t va
);
281 void (*cleanup
)(struct r600_common_screen
*);
284 bool separate_instance
;
287 struct pipe_query
*r600_create_batch_query(struct pipe_context
*ctx
,
288 unsigned num_queries
,
289 unsigned *query_types
);
291 int r600_get_perfcounter_info(struct r600_common_screen
*,
293 struct pipe_driver_query_info
*info
);
294 int r600_get_perfcounter_group_info(struct r600_common_screen
*,
296 struct pipe_driver_query_group_info
*info
);
298 bool r600_perfcounters_init(struct r600_perfcounters
*, unsigned num_blocks
);
299 void r600_perfcounters_add_block(struct r600_common_screen
*,
300 struct r600_perfcounters
*,
301 const char *name
, unsigned flags
,
302 unsigned counters
, unsigned selectors
,
303 unsigned instances
, void *data
);
304 void r600_perfcounters_do_destroy(struct r600_perfcounters
*);
305 void r600_query_hw_reset_buffers(struct r600_common_context
*rctx
,
306 struct r600_query_hw
*query
);
308 struct r600_qbo_state
{
310 struct pipe_constant_buffer saved_const0
;
311 struct pipe_shader_buffer saved_ssbo
[3];
314 #endif /* R600_QUERY_H */