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 "util/list.h"
37 struct r600_common_context
;
38 struct r600_common_screen
;
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
,
52 R600_QUERY_GPU_TEMPERATURE
,
53 R600_QUERY_CURRENT_GPU_SCLK
,
54 R600_QUERY_CURRENT_GPU_MCLK
,
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
,
64 R600_QUERY_FIRST_PERFCOUNTER
= PIPE_QUERY_DRIVER_SPECIFIC
+ 100,
68 R600_QUERY_GROUP_GPIN
= 0,
69 R600_NUM_SW_QUERY_GROUPS
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 void (*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
);
82 struct r600_query_ops
*ops
;
84 /* The type of query */
89 R600_QUERY_HW_FLAG_NO_START
= (1 << 0),
90 R600_QUERY_HW_FLAG_PREDICATE
= (1 << 1),
93 struct r600_query_hw_ops
{
94 void (*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
);
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
;
120 struct r600_query_hw
{
122 struct r600_query_hw_ops
*ops
;
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 */
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 void 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
,
150 union pipe_query_result
*result
);
152 /* Performance counters */
154 /* This block is part of the shader engine */
155 R600_PC_BLOCK_SE
= (1 << 0),
157 /* Expose per-instance groups instead of summing all instances (within
159 R600_PC_BLOCK_INSTANCE_GROUPS
= (1 << 1),
161 /* Expose per-SE groups instead of summing instances across SEs. */
162 R600_PC_BLOCK_SE_GROUPS
= (1 << 2),
165 R600_PC_BLOCK_SHADER
= (1 << 3),
167 /* Non-shader block with perfcounters windowed by shaders. */
168 R600_PC_BLOCK_SHADER_WINDOWED
= (1 << 4),
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
177 * (c) expose one performance counter group per instance, but summed over all
180 struct r600_perfcounter_block
{
181 const char *basename
;
183 unsigned num_counters
;
184 unsigned num_selectors
;
185 unsigned num_instances
;
189 unsigned group_name_stride
;
191 char *selector_names
;
192 unsigned selector_name_stride
;
197 struct r600_perfcounters
{
200 struct r600_perfcounter_block
*blocks
;
202 unsigned num_start_cs_dwords
;
203 unsigned num_stop_cs_dwords
;
204 unsigned num_instance_cs_dwords
;
205 unsigned num_shaders_cs_dwords
;
207 unsigned num_shader_types
;
208 const char * const *shader_type_suffixes
;
209 const unsigned *shader_type_bits
;
211 void (*get_size
)(struct r600_perfcounter_block
*,
212 unsigned count
, unsigned *selectors
,
213 unsigned *num_select_dw
, unsigned *num_read_dw
);
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
);
230 void (*cleanup
)(struct r600_common_screen
*);
233 boolean separate_instance
;
236 struct pipe_query
*r600_create_batch_query(struct pipe_context
*ctx
,
237 unsigned num_queries
,
238 unsigned *query_types
);
240 int r600_get_perfcounter_info(struct r600_common_screen
*,
242 struct pipe_driver_query_info
*info
);
243 int r600_get_perfcounter_group_info(struct r600_common_screen
*,
245 struct pipe_driver_query_group_info
*info
);
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
*);
255 #endif /* R600_QUERY_H */