2 * Copyright 2015 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include "util/u_threaded_context.h"
37 struct si_query_buffer
;
42 SI_QUERY_DRAW_CALLS
= PIPE_QUERY_DRIVER_SPECIFIC
,
43 SI_QUERY_DECOMPRESS_CALLS
,
44 SI_QUERY_MRT_DRAW_CALLS
,
45 SI_QUERY_PRIM_RESTART_CALLS
,
46 SI_QUERY_SPILL_DRAW_CALLS
,
47 SI_QUERY_COMPUTE_CALLS
,
48 SI_QUERY_SPILL_COMPUTE_CALLS
,
50 SI_QUERY_CP_DMA_CALLS
,
51 SI_QUERY_NUM_VS_FLUSHES
,
52 SI_QUERY_NUM_PS_FLUSHES
,
53 SI_QUERY_NUM_CS_FLUSHES
,
54 SI_QUERY_NUM_CB_CACHE_FLUSHES
,
55 SI_QUERY_NUM_DB_CACHE_FLUSHES
,
56 SI_QUERY_NUM_L2_INVALIDATES
,
57 SI_QUERY_NUM_L2_WRITEBACKS
,
58 SI_QUERY_NUM_RESIDENT_HANDLES
,
59 SI_QUERY_TC_OFFLOADED_SLOTS
,
60 SI_QUERY_TC_DIRECT_SLOTS
,
61 SI_QUERY_TC_NUM_SYNCS
,
62 SI_QUERY_CS_THREAD_BUSY
,
63 SI_QUERY_GALLIUM_THREAD_BUSY
,
64 SI_QUERY_REQUESTED_VRAM
,
65 SI_QUERY_REQUESTED_GTT
,
68 SI_QUERY_BUFFER_WAIT_TIME
,
69 SI_QUERY_NUM_MAPPED_BUFFERS
,
71 SI_QUERY_NUM_SDMA_IBS
,
72 SI_QUERY_GFX_BO_LIST_SIZE
,
74 SI_QUERY_NUM_BYTES_MOVED
,
75 SI_QUERY_NUM_EVICTIONS
,
76 SI_QUERY_NUM_VRAM_CPU_PAGE_FAULTS
,
78 SI_QUERY_VRAM_VIS_USAGE
,
80 SI_QUERY_GPU_TEMPERATURE
,
81 SI_QUERY_CURRENT_GPU_SCLK
,
82 SI_QUERY_CURRENT_GPU_MCLK
,
84 SI_QUERY_GPU_SHADERS_BUSY
,
86 SI_QUERY_GPU_GDS_BUSY
,
87 SI_QUERY_GPU_VGT_BUSY
,
91 SI_QUERY_GPU_BCI_BUSY
,
97 SI_QUERY_GPU_SDMA_BUSY
,
98 SI_QUERY_GPU_PFP_BUSY
,
99 SI_QUERY_GPU_MEQ_BUSY
,
100 SI_QUERY_GPU_ME_BUSY
,
101 SI_QUERY_GPU_SURF_SYNC_BUSY
,
102 SI_QUERY_GPU_CP_DMA_BUSY
,
103 SI_QUERY_GPU_SCRATCH_RAM_BUSY
,
104 SI_QUERY_NUM_COMPILATIONS
,
105 SI_QUERY_NUM_SHADERS_CREATED
,
106 SI_QUERY_BACK_BUFFER_PS_DRAW_RATIO
,
107 SI_QUERY_NUM_SHADER_CACHE_HITS
,
108 SI_QUERY_GPIN_ASIC_ID
,
109 SI_QUERY_GPIN_NUM_SIMD
,
110 SI_QUERY_GPIN_NUM_RB
,
111 SI_QUERY_GPIN_NUM_SPI
,
112 SI_QUERY_GPIN_NUM_SE
,
113 SI_QUERY_TIME_ELAPSED_SDMA
,
114 SI_QUERY_TIME_ELAPSED_SDMA_SI
, /* emulated, measured on the CPU */
115 SI_QUERY_PD_NUM_PRIMS_ACCEPTED
,
116 SI_QUERY_PD_NUM_PRIMS_REJECTED
,
117 SI_QUERY_PD_NUM_PRIMS_INELIGIBLE
,
119 SI_QUERY_FIRST_PERFCOUNTER
= PIPE_QUERY_DRIVER_SPECIFIC
+ 100,
123 SI_QUERY_GROUP_GPIN
= 0,
124 SI_NUM_SW_QUERY_GROUPS
127 struct si_query_ops
{
128 void (*destroy
)(struct si_context
*, struct si_query
*);
129 bool (*begin
)(struct si_context
*, struct si_query
*);
130 bool (*end
)(struct si_context
*, struct si_query
*);
131 bool (*get_result
)(struct si_context
*,
132 struct si_query
*, bool wait
,
133 union pipe_query_result
*result
);
134 void (*get_result_resource
)(struct si_context
*,
135 struct si_query
*, bool wait
,
136 enum pipe_query_value_type result_type
,
138 struct pipe_resource
*resource
,
141 void (*suspend
)(struct si_context
*, struct si_query
*);
142 void (*resume
)(struct si_context
*, struct si_query
*);
146 struct threaded_query b
;
147 const struct si_query_ops
*ops
;
149 /* The PIPE_QUERY_xxx type of query */
152 /* The number of dwords for suspend. */
153 unsigned num_cs_dw_suspend
;
155 /* Linked list of queries that must be suspended at end of CS. */
156 struct list_head active_list
;
160 SI_QUERY_HW_FLAG_NO_START
= (1 << 0),
162 /* whether begin_query doesn't clear the result */
163 SI_QUERY_HW_FLAG_BEGIN_RESUMES
= (1 << 2),
166 struct si_query_hw_ops
{
167 bool (*prepare_buffer
)(struct si_context
*, struct si_query_buffer
*);
168 void (*emit_start
)(struct si_context
*,
169 struct si_query_hw
*,
170 struct si_resource
*buffer
, uint64_t va
);
171 void (*emit_stop
)(struct si_context
*,
172 struct si_query_hw
*,
173 struct si_resource
*buffer
, uint64_t va
);
174 void (*clear_result
)(struct si_query_hw
*, union pipe_query_result
*);
175 void (*add_result
)(struct si_screen
*screen
,
176 struct si_query_hw
*, void *buffer
,
177 union pipe_query_result
*result
);
180 struct si_query_buffer
{
181 /* The buffer where query results are stored. */
182 struct si_resource
*buf
;
183 /* If a query buffer is full, a new buffer is created and the old one
184 * is put in here. When we calculate the result, we sum up the samples
185 * from all buffers. */
186 struct si_query_buffer
*previous
;
187 /* Offset of the next free result after current query data */
188 unsigned results_end
;
192 void si_query_buffer_destroy(struct si_screen
*sctx
, struct si_query_buffer
*buffer
);
193 void si_query_buffer_reset(struct si_context
*sctx
, struct si_query_buffer
*buffer
);
194 bool si_query_buffer_alloc(struct si_context
*sctx
, struct si_query_buffer
*buffer
,
195 bool (*prepare_buffer
)(struct si_context
*, struct si_query_buffer
*),
201 struct si_query_hw_ops
*ops
;
204 /* The query buffer and how many results are in it. */
205 struct si_query_buffer buffer
;
206 /* Size of the result in memory for both begin_query and end_query,
207 * this can be one or two numbers, or it could even be a size of a structure. */
208 unsigned result_size
;
209 /* For transform feedback: which stream the query is for */
212 /* Workaround via compute shader */
213 struct si_resource
*workaround_buf
;
214 unsigned workaround_offset
;
217 void si_query_hw_destroy(struct si_context
*sctx
,
218 struct si_query
*squery
);
219 bool si_query_hw_begin(struct si_context
*sctx
,
220 struct si_query
*squery
);
221 bool si_query_hw_end(struct si_context
*sctx
,
222 struct si_query
*squery
);
223 bool si_query_hw_get_result(struct si_context
*sctx
,
224 struct si_query
*squery
,
226 union pipe_query_result
*result
);
227 void si_query_hw_suspend(struct si_context
*sctx
, struct si_query
*query
);
228 void si_query_hw_resume(struct si_context
*sctx
, struct si_query
*query
);
231 /* Performance counters */
232 struct si_perfcounters
{
235 struct si_pc_block
*blocks
;
237 unsigned num_stop_cs_dwords
;
238 unsigned num_instance_cs_dwords
;
241 bool separate_instance
;
244 struct pipe_query
*si_create_batch_query(struct pipe_context
*ctx
,
245 unsigned num_queries
,
246 unsigned *query_types
);
248 int si_get_perfcounter_info(struct si_screen
*,
250 struct pipe_driver_query_info
*info
);
251 int si_get_perfcounter_group_info(struct si_screen
*,
253 struct pipe_driver_query_group_info
*info
);
255 struct si_qbo_state
{
257 struct pipe_constant_buffer saved_const0
;
258 struct pipe_shader_buffer saved_ssbo
[3];
259 unsigned saved_ssbo_writable_mask
;
262 #endif /* SI_QUERY_H */