2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 * Copyright 2014 Marek Olšák <marek.olsak@amd.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "r600_query.h"
27 #include "util/u_memory.h"
29 /* Queries without buffer handling or suspend/resume. */
30 struct r600_query_sw
{
33 uint64_t begin_result
;
35 /* Fence for GPU_FINISHED. */
36 struct pipe_fence_handle
*fence
;
39 static void r600_query_sw_destroy(struct r600_common_context
*rctx
,
40 struct r600_query
*rquery
)
42 struct pipe_screen
*screen
= rctx
->b
.screen
;
43 struct r600_query_sw
*query
= (struct r600_query_sw
*)rquery
;
45 screen
->fence_reference(screen
, &query
->fence
, NULL
);
49 static enum radeon_value_id
winsys_id_from_type(unsigned type
)
52 case R600_QUERY_REQUESTED_VRAM
: return RADEON_REQUESTED_VRAM_MEMORY
;
53 case R600_QUERY_REQUESTED_GTT
: return RADEON_REQUESTED_GTT_MEMORY
;
54 case R600_QUERY_BUFFER_WAIT_TIME
: return RADEON_BUFFER_WAIT_TIME_NS
;
55 case R600_QUERY_NUM_CS_FLUSHES
: return RADEON_NUM_CS_FLUSHES
;
56 case R600_QUERY_NUM_BYTES_MOVED
: return RADEON_NUM_BYTES_MOVED
;
57 case R600_QUERY_VRAM_USAGE
: return RADEON_VRAM_USAGE
;
58 case R600_QUERY_GTT_USAGE
: return RADEON_GTT_USAGE
;
59 case R600_QUERY_GPU_TEMPERATURE
: return RADEON_GPU_TEMPERATURE
;
60 case R600_QUERY_CURRENT_GPU_SCLK
: return RADEON_CURRENT_SCLK
;
61 case R600_QUERY_CURRENT_GPU_MCLK
: return RADEON_CURRENT_MCLK
;
62 default: unreachable("query type does not correspond to winsys id");
66 static boolean
r600_query_sw_begin(struct r600_common_context
*rctx
,
67 struct r600_query
*rquery
)
69 struct r600_query_sw
*query
= (struct r600_query_sw
*)rquery
;
71 switch(query
->b
.type
) {
72 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
73 case PIPE_QUERY_GPU_FINISHED
:
75 case R600_QUERY_DRAW_CALLS
:
76 query
->begin_result
= rctx
->num_draw_calls
;
78 case R600_QUERY_REQUESTED_VRAM
:
79 case R600_QUERY_REQUESTED_GTT
:
80 case R600_QUERY_VRAM_USAGE
:
81 case R600_QUERY_GTT_USAGE
:
82 case R600_QUERY_GPU_TEMPERATURE
:
83 case R600_QUERY_CURRENT_GPU_SCLK
:
84 case R600_QUERY_CURRENT_GPU_MCLK
:
85 query
->begin_result
= 0;
87 case R600_QUERY_BUFFER_WAIT_TIME
:
88 case R600_QUERY_NUM_CS_FLUSHES
:
89 case R600_QUERY_NUM_BYTES_MOVED
: {
90 enum radeon_value_id ws_id
= winsys_id_from_type(query
->b
.type
);
91 query
->begin_result
= rctx
->ws
->query_value(rctx
->ws
, ws_id
);
94 case R600_QUERY_GPU_LOAD
:
95 query
->begin_result
= r600_gpu_load_begin(rctx
->screen
);
97 case R600_QUERY_NUM_COMPILATIONS
:
98 query
->begin_result
= p_atomic_read(&rctx
->screen
->num_compilations
);
100 case R600_QUERY_NUM_SHADERS_CREATED
:
101 query
->begin_result
= p_atomic_read(&rctx
->screen
->num_shaders_created
);
103 case R600_QUERY_GPIN_ASIC_ID
:
104 case R600_QUERY_GPIN_NUM_SIMD
:
105 case R600_QUERY_GPIN_NUM_RB
:
106 case R600_QUERY_GPIN_NUM_SPI
:
107 case R600_QUERY_GPIN_NUM_SE
:
110 unreachable("r600_query_sw_begin: bad query type");
116 static void r600_query_sw_end(struct r600_common_context
*rctx
,
117 struct r600_query
*rquery
)
119 struct r600_query_sw
*query
= (struct r600_query_sw
*)rquery
;
121 switch(query
->b
.type
) {
122 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
124 case PIPE_QUERY_GPU_FINISHED
:
125 rctx
->b
.flush(&rctx
->b
, &query
->fence
, 0);
127 case R600_QUERY_DRAW_CALLS
:
128 query
->end_result
= rctx
->num_draw_calls
;
130 case R600_QUERY_REQUESTED_VRAM
:
131 case R600_QUERY_REQUESTED_GTT
:
132 case R600_QUERY_VRAM_USAGE
:
133 case R600_QUERY_GTT_USAGE
:
134 case R600_QUERY_GPU_TEMPERATURE
:
135 case R600_QUERY_CURRENT_GPU_SCLK
:
136 case R600_QUERY_CURRENT_GPU_MCLK
:
137 case R600_QUERY_BUFFER_WAIT_TIME
:
138 case R600_QUERY_NUM_CS_FLUSHES
:
139 case R600_QUERY_NUM_BYTES_MOVED
: {
140 enum radeon_value_id ws_id
= winsys_id_from_type(query
->b
.type
);
141 query
->end_result
= rctx
->ws
->query_value(rctx
->ws
, ws_id
);
144 case R600_QUERY_GPU_LOAD
:
145 query
->end_result
= r600_gpu_load_end(rctx
->screen
,
146 query
->begin_result
);
147 query
->begin_result
= 0;
149 case R600_QUERY_NUM_COMPILATIONS
:
150 query
->end_result
= p_atomic_read(&rctx
->screen
->num_compilations
);
152 case R600_QUERY_NUM_SHADERS_CREATED
:
153 query
->end_result
= p_atomic_read(&rctx
->screen
->num_shaders_created
);
155 case R600_QUERY_GPIN_ASIC_ID
:
156 case R600_QUERY_GPIN_NUM_SIMD
:
157 case R600_QUERY_GPIN_NUM_RB
:
158 case R600_QUERY_GPIN_NUM_SPI
:
159 case R600_QUERY_GPIN_NUM_SE
:
162 unreachable("r600_query_sw_end: bad query type");
166 static boolean
r600_query_sw_get_result(struct r600_common_context
*rctx
,
167 struct r600_query
*rquery
,
169 union pipe_query_result
*result
)
171 struct r600_query_sw
*query
= (struct r600_query_sw
*)rquery
;
173 switch (query
->b
.type
) {
174 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
175 /* Convert from cycles per millisecond to cycles per second (Hz). */
176 result
->timestamp_disjoint
.frequency
=
177 (uint64_t)rctx
->screen
->info
.r600_clock_crystal_freq
* 1000;
178 result
->timestamp_disjoint
.disjoint
= FALSE
;
180 case PIPE_QUERY_GPU_FINISHED
: {
181 struct pipe_screen
*screen
= rctx
->b
.screen
;
182 result
->b
= screen
->fence_finish(screen
, query
->fence
,
183 wait
? PIPE_TIMEOUT_INFINITE
: 0);
187 case R600_QUERY_GPIN_ASIC_ID
:
190 case R600_QUERY_GPIN_NUM_SIMD
:
191 result
->u32
= rctx
->screen
->info
.num_good_compute_units
;
193 case R600_QUERY_GPIN_NUM_RB
:
194 result
->u32
= rctx
->screen
->info
.r600_num_backends
;
196 case R600_QUERY_GPIN_NUM_SPI
:
197 result
->u32
= 1; /* all supported chips have one SPI per SE */
199 case R600_QUERY_GPIN_NUM_SE
:
200 result
->u32
= rctx
->screen
->info
.max_se
;
204 result
->u64
= query
->end_result
- query
->begin_result
;
206 switch (query
->b
.type
) {
207 case R600_QUERY_BUFFER_WAIT_TIME
:
208 case R600_QUERY_GPU_TEMPERATURE
:
211 case R600_QUERY_CURRENT_GPU_SCLK
:
212 case R600_QUERY_CURRENT_GPU_MCLK
:
213 result
->u64
*= 1000000;
220 static struct r600_query_ops sw_query_ops
= {
221 .destroy
= r600_query_sw_destroy
,
222 .begin
= r600_query_sw_begin
,
223 .end
= r600_query_sw_end
,
224 .get_result
= r600_query_sw_get_result
227 static struct pipe_query
*r600_query_sw_create(struct pipe_context
*ctx
,
230 struct r600_query_sw
*query
;
232 query
= CALLOC_STRUCT(r600_query_sw
);
236 query
->b
.type
= query_type
;
237 query
->b
.ops
= &sw_query_ops
;
239 return (struct pipe_query
*)query
;
242 void r600_query_hw_destroy(struct r600_common_context
*rctx
,
243 struct r600_query
*rquery
)
245 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
246 struct r600_query_buffer
*prev
= query
->buffer
.previous
;
248 /* Release all query buffers. */
250 struct r600_query_buffer
*qbuf
= prev
;
251 prev
= prev
->previous
;
252 pipe_resource_reference((struct pipe_resource
**)&qbuf
->buf
, NULL
);
256 pipe_resource_reference((struct pipe_resource
**)&query
->buffer
.buf
, NULL
);
260 static struct r600_resource
*r600_new_query_buffer(struct r600_common_context
*ctx
,
261 struct r600_query_hw
*query
)
263 unsigned buf_size
= MAX2(query
->result_size
, 4096);
265 /* Queries are normally read by the CPU after
266 * being written by the gpu, hence staging is probably a good
269 struct r600_resource
*buf
= (struct r600_resource
*)
270 pipe_buffer_create(ctx
->b
.screen
, PIPE_BIND_CUSTOM
,
271 PIPE_USAGE_STAGING
, buf_size
);
273 if (query
->flags
& R600_QUERY_HW_FLAG_PREDICATE
)
274 query
->ops
->prepare_buffer(ctx
, query
, buf
);
279 static void r600_query_hw_prepare_buffer(struct r600_common_context
*ctx
,
280 struct r600_query_hw
*query
,
281 struct r600_resource
*buffer
)
283 /* Callers ensure that the buffer is currently unused by the GPU. */
284 uint32_t *results
= ctx
->ws
->buffer_map(buffer
->buf
, NULL
,
285 PIPE_TRANSFER_WRITE
|
286 PIPE_TRANSFER_UNSYNCHRONIZED
);
288 memset(results
, 0, buffer
->b
.b
.width0
);
290 if (query
->b
.type
== PIPE_QUERY_OCCLUSION_COUNTER
||
291 query
->b
.type
== PIPE_QUERY_OCCLUSION_PREDICATE
) {
292 unsigned num_results
;
295 /* Set top bits for unused backends. */
296 num_results
= buffer
->b
.b
.width0
/ (16 * ctx
->max_db
);
297 for (j
= 0; j
< num_results
; j
++) {
298 for (i
= 0; i
< ctx
->max_db
; i
++) {
299 if (!(ctx
->backend_mask
& (1<<i
))) {
300 results
[(i
* 4)+1] = 0x80000000;
301 results
[(i
* 4)+3] = 0x80000000;
304 results
+= 4 * ctx
->max_db
;
309 static struct r600_query_ops query_hw_ops
= {
310 .destroy
= r600_query_hw_destroy
,
311 .begin
= r600_query_hw_begin
,
312 .end
= r600_query_hw_end
,
313 .get_result
= r600_query_hw_get_result
,
316 static void r600_query_hw_do_emit_start(struct r600_common_context
*ctx
,
317 struct r600_query_hw
*query
,
318 struct r600_resource
*buffer
,
320 static void r600_query_hw_do_emit_stop(struct r600_common_context
*ctx
,
321 struct r600_query_hw
*query
,
322 struct r600_resource
*buffer
,
324 static void r600_query_hw_add_result(struct r600_common_context
*ctx
,
325 struct r600_query_hw
*, void *buffer
,
326 union pipe_query_result
*result
);
327 static void r600_query_hw_clear_result(struct r600_query_hw
*,
328 union pipe_query_result
*);
330 static struct r600_query_hw_ops query_hw_default_hw_ops
= {
331 .prepare_buffer
= r600_query_hw_prepare_buffer
,
332 .emit_start
= r600_query_hw_do_emit_start
,
333 .emit_stop
= r600_query_hw_do_emit_stop
,
334 .clear_result
= r600_query_hw_clear_result
,
335 .add_result
= r600_query_hw_add_result
,
338 boolean
r600_query_hw_init(struct r600_common_context
*rctx
,
339 struct r600_query_hw
*query
)
341 query
->buffer
.buf
= r600_new_query_buffer(rctx
, query
);
342 if (!query
->buffer
.buf
)
348 static struct pipe_query
*r600_query_hw_create(struct r600_common_context
*rctx
,
352 struct r600_query_hw
*query
= CALLOC_STRUCT(r600_query_hw
);
356 query
->b
.type
= query_type
;
357 query
->b
.ops
= &query_hw_ops
;
358 query
->ops
= &query_hw_default_hw_ops
;
360 switch (query_type
) {
361 case PIPE_QUERY_OCCLUSION_COUNTER
:
362 case PIPE_QUERY_OCCLUSION_PREDICATE
:
363 query
->result_size
= 16 * rctx
->max_db
;
364 query
->num_cs_dw_begin
= 6;
365 query
->num_cs_dw_end
= 6;
366 query
->flags
|= R600_QUERY_HW_FLAG_PREDICATE
;
368 case PIPE_QUERY_TIME_ELAPSED
:
369 query
->result_size
= 16;
370 query
->num_cs_dw_begin
= 8;
371 query
->num_cs_dw_end
= 8;
372 query
->flags
= R600_QUERY_HW_FLAG_TIMER
;
374 case PIPE_QUERY_TIMESTAMP
:
375 query
->result_size
= 8;
376 query
->num_cs_dw_end
= 8;
377 query
->flags
= R600_QUERY_HW_FLAG_TIMER
|
378 R600_QUERY_HW_FLAG_NO_START
;
380 case PIPE_QUERY_PRIMITIVES_EMITTED
:
381 case PIPE_QUERY_PRIMITIVES_GENERATED
:
382 case PIPE_QUERY_SO_STATISTICS
:
383 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
384 /* NumPrimitivesWritten, PrimitiveStorageNeeded. */
385 query
->result_size
= 32;
386 query
->num_cs_dw_begin
= 6;
387 query
->num_cs_dw_end
= 6;
388 query
->stream
= index
;
389 query
->flags
|= R600_QUERY_HW_FLAG_PREDICATE
;
391 case PIPE_QUERY_PIPELINE_STATISTICS
:
392 /* 11 values on EG, 8 on R600. */
393 query
->result_size
= (rctx
->chip_class
>= EVERGREEN
? 11 : 8) * 16;
394 query
->num_cs_dw_begin
= 6;
395 query
->num_cs_dw_end
= 6;
403 if (!r600_query_hw_init(rctx
, query
)) {
408 return (struct pipe_query
*)query
;
411 static void r600_update_occlusion_query_state(struct r600_common_context
*rctx
,
412 unsigned type
, int diff
)
414 if (type
== PIPE_QUERY_OCCLUSION_COUNTER
||
415 type
== PIPE_QUERY_OCCLUSION_PREDICATE
) {
416 bool old_enable
= rctx
->num_occlusion_queries
!= 0;
419 rctx
->num_occlusion_queries
+= diff
;
420 assert(rctx
->num_occlusion_queries
>= 0);
422 enable
= rctx
->num_occlusion_queries
!= 0;
424 if (enable
!= old_enable
) {
425 rctx
->set_occlusion_query_state(&rctx
->b
, enable
);
430 static unsigned event_type_for_stream(struct r600_query_hw
*query
)
432 switch (query
->stream
) {
434 case 0: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS
;
435 case 1: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS1
;
436 case 2: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS2
;
437 case 3: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS3
;
441 static void r600_query_hw_do_emit_start(struct r600_common_context
*ctx
,
442 struct r600_query_hw
*query
,
443 struct r600_resource
*buffer
,
446 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
448 switch (query
->b
.type
) {
449 case PIPE_QUERY_OCCLUSION_COUNTER
:
450 case PIPE_QUERY_OCCLUSION_PREDICATE
:
451 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
452 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
454 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
456 case PIPE_QUERY_PRIMITIVES_EMITTED
:
457 case PIPE_QUERY_PRIMITIVES_GENERATED
:
458 case PIPE_QUERY_SO_STATISTICS
:
459 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
460 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
461 radeon_emit(cs
, EVENT_TYPE(event_type_for_stream(query
)) | EVENT_INDEX(3));
463 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
465 case PIPE_QUERY_TIME_ELAPSED
:
466 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE_EOP
, 4, 0));
467 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT
) | EVENT_INDEX(5));
469 radeon_emit(cs
, (3 << 29) | ((va
>> 32) & 0xFFFF));
473 case PIPE_QUERY_PIPELINE_STATISTICS
:
474 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
475 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_SAMPLE_PIPELINESTAT
) | EVENT_INDEX(2));
477 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
482 r600_emit_reloc(ctx
, &ctx
->gfx
, query
->buffer
.buf
, RADEON_USAGE_WRITE
,
486 static void r600_query_hw_emit_start(struct r600_common_context
*ctx
,
487 struct r600_query_hw
*query
)
491 r600_update_occlusion_query_state(ctx
, query
->b
.type
, 1);
492 r600_update_prims_generated_query_state(ctx
, query
->b
.type
, 1);
494 ctx
->need_gfx_cs_space(&ctx
->b
, query
->num_cs_dw_begin
+ query
->num_cs_dw_end
,
497 /* Get a new query buffer if needed. */
498 if (query
->buffer
.results_end
+ query
->result_size
> query
->buffer
.buf
->b
.b
.width0
) {
499 struct r600_query_buffer
*qbuf
= MALLOC_STRUCT(r600_query_buffer
);
500 *qbuf
= query
->buffer
;
501 query
->buffer
.buf
= r600_new_query_buffer(ctx
, query
);
502 query
->buffer
.results_end
= 0;
503 query
->buffer
.previous
= qbuf
;
506 /* emit begin query */
507 va
= query
->buffer
.buf
->gpu_address
+ query
->buffer
.results_end
;
509 query
->ops
->emit_start(ctx
, query
, query
->buffer
.buf
, va
);
511 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
512 ctx
->num_cs_dw_timer_queries_suspend
+= query
->num_cs_dw_end
;
514 ctx
->num_cs_dw_nontimer_queries_suspend
+= query
->num_cs_dw_end
;
517 static void r600_query_hw_do_emit_stop(struct r600_common_context
*ctx
,
518 struct r600_query_hw
*query
,
519 struct r600_resource
*buffer
,
522 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
524 switch (query
->b
.type
) {
525 case PIPE_QUERY_OCCLUSION_COUNTER
:
526 case PIPE_QUERY_OCCLUSION_PREDICATE
:
528 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
529 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
531 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
533 case PIPE_QUERY_PRIMITIVES_EMITTED
:
534 case PIPE_QUERY_PRIMITIVES_GENERATED
:
535 case PIPE_QUERY_SO_STATISTICS
:
536 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
537 va
+= query
->result_size
/2;
538 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
539 radeon_emit(cs
, EVENT_TYPE(event_type_for_stream(query
)) | EVENT_INDEX(3));
541 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
543 case PIPE_QUERY_TIME_ELAPSED
:
544 va
+= query
->result_size
/2;
546 case PIPE_QUERY_TIMESTAMP
:
547 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE_EOP
, 4, 0));
548 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT
) | EVENT_INDEX(5));
550 radeon_emit(cs
, (3 << 29) | ((va
>> 32) & 0xFFFF));
554 case PIPE_QUERY_PIPELINE_STATISTICS
:
555 va
+= query
->result_size
/2;
556 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
557 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_SAMPLE_PIPELINESTAT
) | EVENT_INDEX(2));
559 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
564 r600_emit_reloc(ctx
, &ctx
->gfx
, query
->buffer
.buf
, RADEON_USAGE_WRITE
,
568 static void r600_query_hw_emit_stop(struct r600_common_context
*ctx
,
569 struct r600_query_hw
*query
)
573 /* The queries which need begin already called this in begin_query. */
574 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
) {
575 ctx
->need_gfx_cs_space(&ctx
->b
, query
->num_cs_dw_end
, FALSE
);
579 va
= query
->buffer
.buf
->gpu_address
+ query
->buffer
.results_end
;
581 query
->ops
->emit_stop(ctx
, query
, query
->buffer
.buf
, va
);
583 query
->buffer
.results_end
+= query
->result_size
;
585 if (!(query
->flags
& R600_QUERY_HW_FLAG_NO_START
)) {
586 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
587 ctx
->num_cs_dw_timer_queries_suspend
-= query
->num_cs_dw_end
;
589 ctx
->num_cs_dw_nontimer_queries_suspend
-= query
->num_cs_dw_end
;
592 r600_update_occlusion_query_state(ctx
, query
->b
.type
, -1);
593 r600_update_prims_generated_query_state(ctx
, query
->b
.type
, -1);
596 static void r600_emit_query_predication(struct r600_common_context
*ctx
,
597 struct r600_atom
*atom
)
599 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
600 struct r600_query_hw
*query
= (struct r600_query_hw
*)ctx
->render_cond
;
601 struct r600_query_buffer
*qbuf
;
608 flag_wait
= ctx
->render_cond_mode
== PIPE_RENDER_COND_WAIT
||
609 ctx
->render_cond_mode
== PIPE_RENDER_COND_BY_REGION_WAIT
;
611 switch (query
->b
.type
) {
612 case PIPE_QUERY_OCCLUSION_COUNTER
:
613 case PIPE_QUERY_OCCLUSION_PREDICATE
:
614 op
= PRED_OP(PREDICATION_OP_ZPASS
);
616 case PIPE_QUERY_PRIMITIVES_EMITTED
:
617 case PIPE_QUERY_PRIMITIVES_GENERATED
:
618 case PIPE_QUERY_SO_STATISTICS
:
619 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
620 op
= PRED_OP(PREDICATION_OP_PRIMCOUNT
);
627 /* if true then invert, see GL_ARB_conditional_render_inverted */
628 if (ctx
->render_cond_invert
)
629 op
|= PREDICATION_DRAW_NOT_VISIBLE
; /* Draw if not visable/overflow */
631 op
|= PREDICATION_DRAW_VISIBLE
; /* Draw if visable/overflow */
633 op
|= flag_wait
? PREDICATION_HINT_WAIT
: PREDICATION_HINT_NOWAIT_DRAW
;
635 /* emit predicate packets for all data blocks */
636 for (qbuf
= &query
->buffer
; qbuf
; qbuf
= qbuf
->previous
) {
637 unsigned results_base
= 0;
638 uint64_t va
= qbuf
->buf
->gpu_address
;
640 while (results_base
< qbuf
->results_end
) {
641 radeon_emit(cs
, PKT3(PKT3_SET_PREDICATION
, 1, 0));
642 radeon_emit(cs
, va
+ results_base
);
643 radeon_emit(cs
, op
| (((va
+ results_base
) >> 32) & 0xFF));
644 r600_emit_reloc(ctx
, &ctx
->gfx
, qbuf
->buf
, RADEON_USAGE_READ
,
646 results_base
+= query
->result_size
;
648 /* set CONTINUE bit for all packets except the first */
649 op
|= PREDICATION_CONTINUE
;
654 static struct pipe_query
*r600_create_query(struct pipe_context
*ctx
, unsigned query_type
, unsigned index
)
656 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
658 if (query_type
== PIPE_QUERY_TIMESTAMP_DISJOINT
||
659 query_type
== PIPE_QUERY_GPU_FINISHED
||
660 query_type
>= PIPE_QUERY_DRIVER_SPECIFIC
)
661 return r600_query_sw_create(ctx
, query_type
);
663 return r600_query_hw_create(rctx
, query_type
, index
);
666 static void r600_destroy_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
668 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
669 struct r600_query
*rquery
= (struct r600_query
*)query
;
671 rquery
->ops
->destroy(rctx
, rquery
);
674 static boolean
r600_begin_query(struct pipe_context
*ctx
,
675 struct pipe_query
*query
)
677 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
678 struct r600_query
*rquery
= (struct r600_query
*)query
;
680 return rquery
->ops
->begin(rctx
, rquery
);
683 static void r600_query_hw_reset_buffers(struct r600_common_context
*rctx
,
684 struct r600_query_hw
*query
)
686 struct r600_query_buffer
*prev
= query
->buffer
.previous
;
688 /* Discard the old query buffers. */
690 struct r600_query_buffer
*qbuf
= prev
;
691 prev
= prev
->previous
;
692 pipe_resource_reference((struct pipe_resource
**)&qbuf
->buf
, NULL
);
696 if (query
->flags
& R600_QUERY_HW_FLAG_PREDICATE
) {
697 /* Obtain a new buffer if the current one can't be mapped without a stall. */
698 if (r600_rings_is_buffer_referenced(rctx
, query
->buffer
.buf
->buf
, RADEON_USAGE_READWRITE
) ||
699 !rctx
->ws
->buffer_wait(query
->buffer
.buf
->buf
, 0, RADEON_USAGE_READWRITE
)) {
700 pipe_resource_reference((struct pipe_resource
**)&query
->buffer
.buf
, NULL
);
701 query
->buffer
.buf
= r600_new_query_buffer(rctx
, query
);
703 query
->ops
->prepare_buffer(rctx
, query
, query
->buffer
.buf
);
707 query
->buffer
.results_end
= 0;
708 query
->buffer
.previous
= NULL
;
711 boolean
r600_query_hw_begin(struct r600_common_context
*rctx
,
712 struct r600_query
*rquery
)
714 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
716 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
) {
721 r600_query_hw_reset_buffers(rctx
, query
);
723 r600_query_hw_emit_start(rctx
, query
);
725 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
726 LIST_ADDTAIL(&query
->list
, &rctx
->active_timer_queries
);
728 LIST_ADDTAIL(&query
->list
, &rctx
->active_nontimer_queries
);
732 static void r600_end_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
734 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
735 struct r600_query
*rquery
= (struct r600_query
*)query
;
737 rquery
->ops
->end(rctx
, rquery
);
740 void r600_query_hw_end(struct r600_common_context
*rctx
,
741 struct r600_query
*rquery
)
743 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
745 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
)
746 r600_query_hw_reset_buffers(rctx
, query
);
748 r600_query_hw_emit_stop(rctx
, query
);
750 if (!(query
->flags
& R600_QUERY_HW_FLAG_NO_START
))
751 LIST_DELINIT(&query
->list
);
754 static unsigned r600_query_read_result(void *map
, unsigned start_index
, unsigned end_index
,
755 bool test_status_bit
)
757 uint32_t *current_result
= (uint32_t*)map
;
760 start
= (uint64_t)current_result
[start_index
] |
761 (uint64_t)current_result
[start_index
+1] << 32;
762 end
= (uint64_t)current_result
[end_index
] |
763 (uint64_t)current_result
[end_index
+1] << 32;
765 if (!test_status_bit
||
766 ((start
& 0x8000000000000000UL
) && (end
& 0x8000000000000000UL
))) {
772 static void r600_query_hw_add_result(struct r600_common_context
*ctx
,
773 struct r600_query_hw
*query
,
775 union pipe_query_result
*result
)
777 switch (query
->b
.type
) {
778 case PIPE_QUERY_OCCLUSION_COUNTER
: {
779 unsigned results_base
= 0;
780 while (results_base
!= query
->result_size
) {
782 r600_query_read_result(buffer
+ results_base
, 0, 2, true);
787 case PIPE_QUERY_OCCLUSION_PREDICATE
: {
788 unsigned results_base
= 0;
789 while (results_base
!= query
->result_size
) {
790 result
->b
= result
->b
||
791 r600_query_read_result(buffer
+ results_base
, 0, 2, true) != 0;
796 case PIPE_QUERY_TIME_ELAPSED
:
797 result
->u64
+= r600_query_read_result(buffer
, 0, 2, false);
799 case PIPE_QUERY_TIMESTAMP
:
801 uint32_t *current_result
= (uint32_t*)buffer
;
802 result
->u64
= (uint64_t)current_result
[0] |
803 (uint64_t)current_result
[1] << 32;
806 case PIPE_QUERY_PRIMITIVES_EMITTED
:
807 /* SAMPLE_STREAMOUTSTATS stores this structure:
809 * u64 NumPrimitivesWritten;
810 * u64 PrimitiveStorageNeeded;
812 * We only need NumPrimitivesWritten here. */
813 result
->u64
+= r600_query_read_result(buffer
, 2, 6, true);
815 case PIPE_QUERY_PRIMITIVES_GENERATED
:
816 /* Here we read PrimitiveStorageNeeded. */
817 result
->u64
+= r600_query_read_result(buffer
, 0, 4, true);
819 case PIPE_QUERY_SO_STATISTICS
:
820 result
->so_statistics
.num_primitives_written
+=
821 r600_query_read_result(buffer
, 2, 6, true);
822 result
->so_statistics
.primitives_storage_needed
+=
823 r600_query_read_result(buffer
, 0, 4, true);
825 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
826 result
->b
= result
->b
||
827 r600_query_read_result(buffer
, 2, 6, true) !=
828 r600_query_read_result(buffer
, 0, 4, true);
830 case PIPE_QUERY_PIPELINE_STATISTICS
:
831 if (ctx
->chip_class
>= EVERGREEN
) {
832 result
->pipeline_statistics
.ps_invocations
+=
833 r600_query_read_result(buffer
, 0, 22, false);
834 result
->pipeline_statistics
.c_primitives
+=
835 r600_query_read_result(buffer
, 2, 24, false);
836 result
->pipeline_statistics
.c_invocations
+=
837 r600_query_read_result(buffer
, 4, 26, false);
838 result
->pipeline_statistics
.vs_invocations
+=
839 r600_query_read_result(buffer
, 6, 28, false);
840 result
->pipeline_statistics
.gs_invocations
+=
841 r600_query_read_result(buffer
, 8, 30, false);
842 result
->pipeline_statistics
.gs_primitives
+=
843 r600_query_read_result(buffer
, 10, 32, false);
844 result
->pipeline_statistics
.ia_primitives
+=
845 r600_query_read_result(buffer
, 12, 34, false);
846 result
->pipeline_statistics
.ia_vertices
+=
847 r600_query_read_result(buffer
, 14, 36, false);
848 result
->pipeline_statistics
.hs_invocations
+=
849 r600_query_read_result(buffer
, 16, 38, false);
850 result
->pipeline_statistics
.ds_invocations
+=
851 r600_query_read_result(buffer
, 18, 40, false);
852 result
->pipeline_statistics
.cs_invocations
+=
853 r600_query_read_result(buffer
, 20, 42, false);
855 result
->pipeline_statistics
.ps_invocations
+=
856 r600_query_read_result(buffer
, 0, 16, false);
857 result
->pipeline_statistics
.c_primitives
+=
858 r600_query_read_result(buffer
, 2, 18, false);
859 result
->pipeline_statistics
.c_invocations
+=
860 r600_query_read_result(buffer
, 4, 20, false);
861 result
->pipeline_statistics
.vs_invocations
+=
862 r600_query_read_result(buffer
, 6, 22, false);
863 result
->pipeline_statistics
.gs_invocations
+=
864 r600_query_read_result(buffer
, 8, 24, false);
865 result
->pipeline_statistics
.gs_primitives
+=
866 r600_query_read_result(buffer
, 10, 26, false);
867 result
->pipeline_statistics
.ia_primitives
+=
868 r600_query_read_result(buffer
, 12, 28, false);
869 result
->pipeline_statistics
.ia_vertices
+=
870 r600_query_read_result(buffer
, 14, 30, false);
872 #if 0 /* for testing */
873 printf("Pipeline stats: IA verts=%llu, IA prims=%llu, VS=%llu, HS=%llu, "
874 "DS=%llu, GS=%llu, GS prims=%llu, Clipper=%llu, "
875 "Clipper prims=%llu, PS=%llu, CS=%llu\n",
876 result
->pipeline_statistics
.ia_vertices
,
877 result
->pipeline_statistics
.ia_primitives
,
878 result
->pipeline_statistics
.vs_invocations
,
879 result
->pipeline_statistics
.hs_invocations
,
880 result
->pipeline_statistics
.ds_invocations
,
881 result
->pipeline_statistics
.gs_invocations
,
882 result
->pipeline_statistics
.gs_primitives
,
883 result
->pipeline_statistics
.c_invocations
,
884 result
->pipeline_statistics
.c_primitives
,
885 result
->pipeline_statistics
.ps_invocations
,
886 result
->pipeline_statistics
.cs_invocations
);
894 static boolean
r600_get_query_result(struct pipe_context
*ctx
,
895 struct pipe_query
*query
, boolean wait
,
896 union pipe_query_result
*result
)
898 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
899 struct r600_query
*rquery
= (struct r600_query
*)query
;
901 return rquery
->ops
->get_result(rctx
, rquery
, wait
, result
);
904 static void r600_query_hw_clear_result(struct r600_query_hw
*query
,
905 union pipe_query_result
*result
)
907 util_query_clear_result(result
, query
->b
.type
);
910 boolean
r600_query_hw_get_result(struct r600_common_context
*rctx
,
911 struct r600_query
*rquery
,
912 boolean wait
, union pipe_query_result
*result
)
914 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
915 struct r600_query_buffer
*qbuf
;
917 query
->ops
->clear_result(query
, result
);
919 for (qbuf
= &query
->buffer
; qbuf
; qbuf
= qbuf
->previous
) {
920 unsigned results_base
= 0;
923 map
= r600_buffer_map_sync_with_rings(rctx
, qbuf
->buf
,
925 (wait
? 0 : PIPE_TRANSFER_DONTBLOCK
));
929 while (results_base
!= qbuf
->results_end
) {
930 query
->ops
->add_result(rctx
, query
, map
+ results_base
,
932 results_base
+= query
->result_size
;
936 /* Convert the time to expected units. */
937 if (rquery
->type
== PIPE_QUERY_TIME_ELAPSED
||
938 rquery
->type
== PIPE_QUERY_TIMESTAMP
) {
939 result
->u64
= (1000000 * result
->u64
) / rctx
->screen
->info
.r600_clock_crystal_freq
;
944 static void r600_render_condition(struct pipe_context
*ctx
,
945 struct pipe_query
*query
,
949 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
950 struct r600_query_hw
*rquery
= (struct r600_query_hw
*)query
;
951 struct r600_query_buffer
*qbuf
;
952 struct r600_atom
*atom
= &rctx
->render_cond_atom
;
954 rctx
->render_cond
= query
;
955 rctx
->render_cond_invert
= condition
;
956 rctx
->render_cond_mode
= mode
;
958 /* Compute the size of SET_PREDICATION packets. */
961 for (qbuf
= &rquery
->buffer
; qbuf
; qbuf
= qbuf
->previous
)
962 atom
->num_dw
+= (qbuf
->results_end
/ rquery
->result_size
) * 5;
965 rctx
->set_atom_dirty(rctx
, atom
, query
!= NULL
);
968 static void r600_suspend_queries(struct r600_common_context
*ctx
,
969 struct list_head
*query_list
,
970 unsigned *num_cs_dw_queries_suspend
)
972 struct r600_query_hw
*query
;
974 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
975 r600_query_hw_emit_stop(ctx
, query
);
977 assert(*num_cs_dw_queries_suspend
== 0);
980 void r600_suspend_nontimer_queries(struct r600_common_context
*ctx
)
982 r600_suspend_queries(ctx
, &ctx
->active_nontimer_queries
,
983 &ctx
->num_cs_dw_nontimer_queries_suspend
);
986 void r600_suspend_timer_queries(struct r600_common_context
*ctx
)
988 r600_suspend_queries(ctx
, &ctx
->active_timer_queries
,
989 &ctx
->num_cs_dw_timer_queries_suspend
);
992 static unsigned r600_queries_num_cs_dw_for_resuming(struct r600_common_context
*ctx
,
993 struct list_head
*query_list
)
995 struct r600_query_hw
*query
;
998 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
1000 num_dw
+= query
->num_cs_dw_begin
+ query
->num_cs_dw_end
;
1002 /* Workaround for the fact that
1003 * num_cs_dw_nontimer_queries_suspend is incremented for every
1004 * resumed query, which raises the bar in need_cs_space for
1005 * queries about to be resumed.
1007 num_dw
+= query
->num_cs_dw_end
;
1009 /* primitives generated query */
1010 num_dw
+= ctx
->streamout
.enable_atom
.num_dw
;
1011 /* guess for ZPASS enable or PERFECT_ZPASS_COUNT enable updates */
1017 static void r600_resume_queries(struct r600_common_context
*ctx
,
1018 struct list_head
*query_list
,
1019 unsigned *num_cs_dw_queries_suspend
)
1021 struct r600_query_hw
*query
;
1022 unsigned num_cs_dw
= r600_queries_num_cs_dw_for_resuming(ctx
, query_list
);
1024 assert(*num_cs_dw_queries_suspend
== 0);
1026 /* Check CS space here. Resuming must not be interrupted by flushes. */
1027 ctx
->need_gfx_cs_space(&ctx
->b
, num_cs_dw
, TRUE
);
1029 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
1030 r600_query_hw_emit_start(ctx
, query
);
1034 void r600_resume_nontimer_queries(struct r600_common_context
*ctx
)
1036 r600_resume_queries(ctx
, &ctx
->active_nontimer_queries
,
1037 &ctx
->num_cs_dw_nontimer_queries_suspend
);
1040 void r600_resume_timer_queries(struct r600_common_context
*ctx
)
1042 r600_resume_queries(ctx
, &ctx
->active_timer_queries
,
1043 &ctx
->num_cs_dw_timer_queries_suspend
);
1046 /* Get backends mask */
1047 void r600_query_init_backend_mask(struct r600_common_context
*ctx
)
1049 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
1050 struct r600_resource
*buffer
;
1052 unsigned num_backends
= ctx
->screen
->info
.r600_num_backends
;
1053 unsigned i
, mask
= 0;
1055 /* if backend_map query is supported by the kernel */
1056 if (ctx
->screen
->info
.r600_backend_map_valid
) {
1057 unsigned num_tile_pipes
= ctx
->screen
->info
.r600_num_tile_pipes
;
1058 unsigned backend_map
= ctx
->screen
->info
.r600_backend_map
;
1059 unsigned item_width
, item_mask
;
1061 if (ctx
->chip_class
>= EVERGREEN
) {
1069 while(num_tile_pipes
--) {
1070 i
= backend_map
& item_mask
;
1072 backend_map
>>= item_width
;
1075 ctx
->backend_mask
= mask
;
1080 /* otherwise backup path for older kernels */
1082 /* create buffer for event data */
1083 buffer
= (struct r600_resource
*)
1084 pipe_buffer_create(ctx
->b
.screen
, PIPE_BIND_CUSTOM
,
1085 PIPE_USAGE_STAGING
, ctx
->max_db
*16);
1089 /* initialize buffer with zeroes */
1090 results
= r600_buffer_map_sync_with_rings(ctx
, buffer
, PIPE_TRANSFER_WRITE
);
1092 memset(results
, 0, ctx
->max_db
* 4 * 4);
1094 /* emit EVENT_WRITE for ZPASS_DONE */
1095 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
1096 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
1097 radeon_emit(cs
, buffer
->gpu_address
);
1098 radeon_emit(cs
, buffer
->gpu_address
>> 32);
1100 r600_emit_reloc(ctx
, &ctx
->gfx
, buffer
,
1101 RADEON_USAGE_WRITE
, RADEON_PRIO_QUERY
);
1103 /* analyze results */
1104 results
= r600_buffer_map_sync_with_rings(ctx
, buffer
, PIPE_TRANSFER_READ
);
1106 for(i
= 0; i
< ctx
->max_db
; i
++) {
1107 /* at least highest bit will be set if backend is used */
1108 if (results
[i
*4 + 1])
1114 pipe_resource_reference((struct pipe_resource
**)&buffer
, NULL
);
1117 ctx
->backend_mask
= mask
;
1122 /* fallback to old method - set num_backends lower bits to 1 */
1123 ctx
->backend_mask
= (~((uint32_t)0))>>(32-num_backends
);
1127 #define XFULL(name_, query_type_, type_, result_type_, group_id_) \
1130 .query_type = R600_QUERY_##query_type_, \
1131 .type = PIPE_DRIVER_QUERY_TYPE_##type_, \
1132 .result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_##result_type_, \
1133 .group_id = group_id_ \
1136 #define X(name_, query_type_, type_, result_type_) \
1137 XFULL(name_, query_type_, type_, result_type_, ~(unsigned)0)
1139 #define XG(group_, name_, query_type_, type_, result_type_) \
1140 XFULL(name_, query_type_, type_, result_type_, R600_QUERY_GROUP_##group_)
1142 static struct pipe_driver_query_info r600_driver_query_list
[] = {
1143 X("num-compilations", NUM_COMPILATIONS
, UINT64
, CUMULATIVE
),
1144 X("num-shaders-created", NUM_SHADERS_CREATED
, UINT64
, CUMULATIVE
),
1145 X("draw-calls", DRAW_CALLS
, UINT64
, CUMULATIVE
),
1146 X("requested-VRAM", REQUESTED_VRAM
, BYTES
, AVERAGE
),
1147 X("requested-GTT", REQUESTED_GTT
, BYTES
, AVERAGE
),
1148 X("buffer-wait-time", BUFFER_WAIT_TIME
, MICROSECONDS
, CUMULATIVE
),
1149 X("num-cs-flushes", NUM_CS_FLUSHES
, UINT64
, CUMULATIVE
),
1150 X("num-bytes-moved", NUM_BYTES_MOVED
, BYTES
, CUMULATIVE
),
1151 X("VRAM-usage", VRAM_USAGE
, BYTES
, AVERAGE
),
1152 X("GTT-usage", GTT_USAGE
, BYTES
, AVERAGE
),
1154 /* GPIN queries are for the benefit of old versions of GPUPerfStudio,
1155 * which use it as a fallback path to detect the GPU type.
1157 * Note: The names of these queries are significant for GPUPerfStudio
1158 * (and possibly their order as well). */
1159 XG(GPIN
, "GPIN_000", GPIN_ASIC_ID
, UINT
, AVERAGE
),
1160 XG(GPIN
, "GPIN_001", GPIN_NUM_SIMD
, UINT
, AVERAGE
),
1161 XG(GPIN
, "GPIN_002", GPIN_NUM_RB
, UINT
, AVERAGE
),
1162 XG(GPIN
, "GPIN_003", GPIN_NUM_SPI
, UINT
, AVERAGE
),
1163 XG(GPIN
, "GPIN_004", GPIN_NUM_SE
, UINT
, AVERAGE
),
1165 /* The following queries must be at the end of the list because their
1166 * availability is adjusted dynamically based on the DRM version. */
1167 X("GPU-load", GPU_LOAD
, UINT64
, AVERAGE
),
1168 X("temperature", GPU_TEMPERATURE
, UINT64
, AVERAGE
),
1169 X("shader-clock", CURRENT_GPU_SCLK
, HZ
, AVERAGE
),
1170 X("memory-clock", CURRENT_GPU_MCLK
, HZ
, AVERAGE
),
1177 static unsigned r600_get_num_queries(struct r600_common_screen
*rscreen
)
1179 if (rscreen
->info
.drm_major
== 2 && rscreen
->info
.drm_minor
>= 42)
1180 return Elements(r600_driver_query_list
);
1181 else if (rscreen
->info
.drm_major
== 3)
1182 return Elements(r600_driver_query_list
) - 3;
1184 return Elements(r600_driver_query_list
) - 4;
1187 static int r600_get_driver_query_info(struct pipe_screen
*screen
,
1189 struct pipe_driver_query_info
*info
)
1191 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
1192 unsigned num_queries
= r600_get_num_queries(rscreen
);
1195 unsigned num_perfcounters
=
1196 r600_get_perfcounter_info(rscreen
, 0, NULL
);
1198 return num_queries
+ num_perfcounters
;
1201 if (index
>= num_queries
)
1202 return r600_get_perfcounter_info(rscreen
, index
- num_queries
, info
);
1204 *info
= r600_driver_query_list
[index
];
1206 switch (info
->query_type
) {
1207 case R600_QUERY_REQUESTED_VRAM
:
1208 case R600_QUERY_VRAM_USAGE
:
1209 info
->max_value
.u64
= rscreen
->info
.vram_size
;
1211 case R600_QUERY_REQUESTED_GTT
:
1212 case R600_QUERY_GTT_USAGE
:
1213 info
->max_value
.u64
= rscreen
->info
.gart_size
;
1215 case R600_QUERY_GPU_TEMPERATURE
:
1216 info
->max_value
.u64
= 125;
1220 if (info
->group_id
!= ~(unsigned)0 && rscreen
->perfcounters
)
1221 info
->group_id
+= rscreen
->perfcounters
->num_groups
;
1226 /* Note: Unfortunately, GPUPerfStudio hardcodes the order of hardware
1227 * performance counter groups, so be careful when changing this and related
1230 static int r600_get_driver_query_group_info(struct pipe_screen
*screen
,
1232 struct pipe_driver_query_group_info
*info
)
1234 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
1235 unsigned num_pc_groups
= 0;
1237 if (rscreen
->perfcounters
)
1238 num_pc_groups
= rscreen
->perfcounters
->num_groups
;
1241 return num_pc_groups
+ R600_NUM_SW_QUERY_GROUPS
;
1243 if (index
< num_pc_groups
)
1244 return r600_get_perfcounter_group_info(rscreen
, index
, info
);
1246 index
-= num_pc_groups
;
1247 if (index
>= R600_NUM_SW_QUERY_GROUPS
)
1250 info
->name
= "GPIN";
1251 info
->max_active_queries
= 5;
1252 info
->num_queries
= 5;
1256 void r600_query_init(struct r600_common_context
*rctx
)
1258 rctx
->b
.create_query
= r600_create_query
;
1259 rctx
->b
.create_batch_query
= r600_create_batch_query
;
1260 rctx
->b
.destroy_query
= r600_destroy_query
;
1261 rctx
->b
.begin_query
= r600_begin_query
;
1262 rctx
->b
.end_query
= r600_end_query
;
1263 rctx
->b
.get_query_result
= r600_get_query_result
;
1264 rctx
->render_cond_atom
.emit
= r600_emit_query_predication
;
1266 if (((struct r600_common_screen
*)rctx
->b
.screen
)->info
.r600_num_backends
> 0)
1267 rctx
->b
.render_condition
= r600_render_condition
;
1269 LIST_INITHEAD(&rctx
->active_nontimer_queries
);
1270 LIST_INITHEAD(&rctx
->active_timer_queries
);
1273 void r600_init_screen_query_functions(struct r600_common_screen
*rscreen
)
1275 rscreen
->b
.get_driver_query_info
= r600_get_driver_query_info
;
1276 rscreen
->b
.get_driver_query_group_info
= r600_get_driver_query_group_info
;