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
;
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_FIRST_PERFCOUNTER (PIPE_QUERY_DRIVER_SPECIFIC + 100)
59 struct r600_query_ops
{
60 void (*destroy
)(struct r600_common_context
*, struct r600_query
*);
61 boolean (*begin
)(struct r600_common_context
*, struct r600_query
*);
62 void (*end
)(struct r600_common_context
*, struct r600_query
*);
63 boolean (*get_result
)(struct r600_common_context
*,
64 struct r600_query
*, boolean wait
,
65 union pipe_query_result
*result
);
69 struct r600_query_ops
*ops
;
71 /* The type of query */
76 R600_QUERY_HW_FLAG_NO_START
= (1 << 0),
77 R600_QUERY_HW_FLAG_TIMER
= (1 << 1),
78 R600_QUERY_HW_FLAG_PREDICATE
= (1 << 2),
81 struct r600_query_hw_ops
{
82 void (*prepare_buffer
)(struct r600_common_context
*,
83 struct r600_query_hw
*,
84 struct r600_resource
*);
85 void (*emit_start
)(struct r600_common_context
*,
86 struct r600_query_hw
*,
87 struct r600_resource
*buffer
, uint64_t va
);
88 void (*emit_stop
)(struct r600_common_context
*,
89 struct r600_query_hw
*,
90 struct r600_resource
*buffer
, uint64_t va
);
91 void (*clear_result
)(struct r600_query_hw
*, union pipe_query_result
*);
92 void (*add_result
)(struct r600_common_context
*ctx
,
93 struct r600_query_hw
*, void *buffer
,
94 union pipe_query_result
*result
);
97 struct r600_query_buffer
{
98 /* The buffer where query results are stored. */
99 struct r600_resource
*buf
;
100 /* Offset of the next free result after current query data */
101 unsigned results_end
;
102 /* If a query buffer is full, a new buffer is created and the old one
103 * is put in here. When we calculate the result, we sum up the samples
104 * from all buffers. */
105 struct r600_query_buffer
*previous
;
108 struct r600_query_hw
{
110 struct r600_query_hw_ops
*ops
;
113 /* The query buffer and how many results are in it. */
114 struct r600_query_buffer buffer
;
115 /* Size of the result in memory for both begin_query and end_query,
116 * this can be one or two numbers, or it could even be a size of a structure. */
117 unsigned result_size
;
118 /* The number of dwords for begin_query or end_query. */
119 unsigned num_cs_dw_begin
;
120 unsigned num_cs_dw_end
;
121 /* Linked list of queries */
122 struct list_head list
;
123 /* For transform feedback: which stream the query is for */
127 boolean
r600_query_hw_init(struct r600_common_context
*rctx
,
128 struct r600_query_hw
*query
);
129 void r600_query_hw_destroy(struct r600_common_context
*rctx
,
130 struct r600_query
*rquery
);
131 boolean
r600_query_hw_begin(struct r600_common_context
*rctx
,
132 struct r600_query
*rquery
);
133 void r600_query_hw_end(struct r600_common_context
*rctx
,
134 struct r600_query
*rquery
);
135 boolean
r600_query_hw_get_result(struct r600_common_context
*rctx
,
136 struct r600_query
*rquery
,
138 union pipe_query_result
*result
);
140 /* Performance counters */
142 /* This block is part of the shader engine */
143 R600_PC_BLOCK_SE
= (1 << 0),
145 /* Expose per-instance groups instead of summing all instances (within
147 R600_PC_BLOCK_INSTANCE_GROUPS
= (1 << 1),
149 /* Expose per-SE groups instead of summing instances across SEs. */
150 R600_PC_BLOCK_SE_GROUPS
= (1 << 2),
153 R600_PC_BLOCK_SHADER
= (1 << 3),
155 /* Non-shader block with perfcounters windowed by shaders. */
156 R600_PC_BLOCK_SHADER_WINDOWED
= (1 << 4),
159 /* Shader enable bits. Chosen to coincide with SQ_PERFCOUNTER_CTRL values */
161 R600_PC_SHADER_PS
= (1 << 0),
162 R600_PC_SHADER_VS
= (1 << 1),
163 R600_PC_SHADER_GS
= (1 << 2),
164 R600_PC_SHADER_ES
= (1 << 3),
165 R600_PC_SHADER_HS
= (1 << 4),
166 R600_PC_SHADER_LS
= (1 << 5),
167 R600_PC_SHADER_CS
= (1 << 6),
169 R600_PC_SHADER_ALL
= R600_PC_SHADER_PS
| R600_PC_SHADER_VS
|
170 R600_PC_SHADER_GS
| R600_PC_SHADER_ES
|
171 R600_PC_SHADER_HS
| R600_PC_SHADER_LS
|
174 R600_PC_SHADER_WINDOWING
= (1 << 31),
177 /* Describes a hardware block with performance counters. Multiple instances of
178 * each block, possibly per-SE, may exist on the chip. Depending on the block
179 * and on the user's configuration, we either
180 * (a) expose every instance as a performance counter group,
181 * (b) expose a single performance counter group that reports the sum over all
183 * (c) expose one performance counter group per instance, but summed over all
186 struct r600_perfcounter_block
{
187 const char *basename
;
189 unsigned num_counters
;
190 unsigned num_selectors
;
191 unsigned num_instances
;
195 unsigned group_name_stride
;
197 char *selector_names
;
198 unsigned selector_name_stride
;
203 struct r600_perfcounters
{
206 struct r600_perfcounter_block
*blocks
;
208 unsigned num_start_cs_dwords
;
209 unsigned num_stop_cs_dwords
;
210 unsigned num_instance_cs_dwords
;
211 unsigned num_shaders_cs_dwords
;
213 void (*get_size
)(struct r600_perfcounter_block
*,
214 unsigned count
, unsigned *selectors
,
215 unsigned *num_select_dw
, unsigned *num_read_dw
);
217 void (*emit_instance
)(struct r600_common_context
*,
218 int se
, int instance
);
219 void (*emit_shaders
)(struct r600_common_context
*, unsigned shaders
);
220 void (*emit_select
)(struct r600_common_context
*,
221 struct r600_perfcounter_block
*,
222 unsigned count
, unsigned *selectors
);
223 void (*emit_start
)(struct r600_common_context
*,
224 struct r600_resource
*buffer
, uint64_t va
);
225 void (*emit_stop
)(struct r600_common_context
*,
226 struct r600_resource
*buffer
, uint64_t va
);
227 void (*emit_read
)(struct r600_common_context
*,
228 struct r600_perfcounter_block
*,
229 unsigned count
, unsigned *selectors
,
230 struct r600_resource
*buffer
, uint64_t va
);
232 void (*cleanup
)(struct r600_common_screen
*);
235 boolean separate_instance
;
238 struct pipe_query
*r600_create_batch_query(struct pipe_context
*ctx
,
239 unsigned num_queries
,
240 unsigned *query_types
);
242 int r600_get_perfcounter_info(struct r600_common_screen
*,
244 struct pipe_driver_query_info
*info
);
245 int r600_get_perfcounter_group_info(struct r600_common_screen
*,
247 struct pipe_driver_query_group_info
*info
);
249 boolean
r600_perfcounters_init(struct r600_perfcounters
*, unsigned num_blocks
);
250 void r600_perfcounters_add_block(struct r600_common_screen
*,
251 struct r600_perfcounters
*,
252 const char *name
, unsigned flags
,
253 unsigned counters
, unsigned selectors
,
254 unsigned instances
, void *data
);
255 void r600_perfcounters_do_destroy(struct r600_perfcounters
*);
257 #endif /* R600_QUERY_H */