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
.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
.num_render_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;
417 bool old_perfect_enable
=
418 rctx
->num_perfect_occlusion_queries
!= 0;
419 bool enable
, perfect_enable
;
421 rctx
->num_occlusion_queries
+= diff
;
422 assert(rctx
->num_occlusion_queries
>= 0);
424 if (type
== PIPE_QUERY_OCCLUSION_COUNTER
) {
425 rctx
->num_perfect_occlusion_queries
+= diff
;
426 assert(rctx
->num_perfect_occlusion_queries
>= 0);
429 enable
= rctx
->num_occlusion_queries
!= 0;
430 perfect_enable
= rctx
->num_perfect_occlusion_queries
!= 0;
432 if (enable
!= old_enable
|| perfect_enable
!= old_perfect_enable
) {
433 rctx
->set_occlusion_query_state(&rctx
->b
, enable
);
438 static unsigned event_type_for_stream(struct r600_query_hw
*query
)
440 switch (query
->stream
) {
442 case 0: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS
;
443 case 1: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS1
;
444 case 2: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS2
;
445 case 3: return EVENT_TYPE_SAMPLE_STREAMOUTSTATS3
;
449 static void r600_query_hw_do_emit_start(struct r600_common_context
*ctx
,
450 struct r600_query_hw
*query
,
451 struct r600_resource
*buffer
,
454 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
456 switch (query
->b
.type
) {
457 case PIPE_QUERY_OCCLUSION_COUNTER
:
458 case PIPE_QUERY_OCCLUSION_PREDICATE
:
459 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
460 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
462 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
464 case PIPE_QUERY_PRIMITIVES_EMITTED
:
465 case PIPE_QUERY_PRIMITIVES_GENERATED
:
466 case PIPE_QUERY_SO_STATISTICS
:
467 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
468 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
469 radeon_emit(cs
, EVENT_TYPE(event_type_for_stream(query
)) | EVENT_INDEX(3));
471 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
473 case PIPE_QUERY_TIME_ELAPSED
:
474 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE_EOP
, 4, 0));
475 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT
) | EVENT_INDEX(5));
477 radeon_emit(cs
, (3 << 29) | ((va
>> 32) & 0xFFFF));
481 case PIPE_QUERY_PIPELINE_STATISTICS
:
482 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
483 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_SAMPLE_PIPELINESTAT
) | EVENT_INDEX(2));
485 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
490 r600_emit_reloc(ctx
, &ctx
->gfx
, query
->buffer
.buf
, RADEON_USAGE_WRITE
,
494 static void r600_query_hw_emit_start(struct r600_common_context
*ctx
,
495 struct r600_query_hw
*query
)
499 r600_update_occlusion_query_state(ctx
, query
->b
.type
, 1);
500 r600_update_prims_generated_query_state(ctx
, query
->b
.type
, 1);
502 ctx
->need_gfx_cs_space(&ctx
->b
, query
->num_cs_dw_begin
+ query
->num_cs_dw_end
,
505 /* Get a new query buffer if needed. */
506 if (query
->buffer
.results_end
+ query
->result_size
> query
->buffer
.buf
->b
.b
.width0
) {
507 struct r600_query_buffer
*qbuf
= MALLOC_STRUCT(r600_query_buffer
);
508 *qbuf
= query
->buffer
;
509 query
->buffer
.buf
= r600_new_query_buffer(ctx
, query
);
510 query
->buffer
.results_end
= 0;
511 query
->buffer
.previous
= qbuf
;
514 /* emit begin query */
515 va
= query
->buffer
.buf
->gpu_address
+ query
->buffer
.results_end
;
517 query
->ops
->emit_start(ctx
, query
, query
->buffer
.buf
, va
);
519 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
520 ctx
->num_cs_dw_timer_queries_suspend
+= query
->num_cs_dw_end
;
522 ctx
->num_cs_dw_nontimer_queries_suspend
+= query
->num_cs_dw_end
;
525 static void r600_query_hw_do_emit_stop(struct r600_common_context
*ctx
,
526 struct r600_query_hw
*query
,
527 struct r600_resource
*buffer
,
530 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
532 switch (query
->b
.type
) {
533 case PIPE_QUERY_OCCLUSION_COUNTER
:
534 case PIPE_QUERY_OCCLUSION_PREDICATE
:
536 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
537 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
539 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
541 case PIPE_QUERY_PRIMITIVES_EMITTED
:
542 case PIPE_QUERY_PRIMITIVES_GENERATED
:
543 case PIPE_QUERY_SO_STATISTICS
:
544 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
545 va
+= query
->result_size
/2;
546 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
547 radeon_emit(cs
, EVENT_TYPE(event_type_for_stream(query
)) | EVENT_INDEX(3));
549 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
551 case PIPE_QUERY_TIME_ELAPSED
:
552 va
+= query
->result_size
/2;
554 case PIPE_QUERY_TIMESTAMP
:
555 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE_EOP
, 4, 0));
556 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT
) | EVENT_INDEX(5));
558 radeon_emit(cs
, (3 << 29) | ((va
>> 32) & 0xFFFF));
562 case PIPE_QUERY_PIPELINE_STATISTICS
:
563 va
+= query
->result_size
/2;
564 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
565 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_SAMPLE_PIPELINESTAT
) | EVENT_INDEX(2));
567 radeon_emit(cs
, (va
>> 32) & 0xFFFF);
572 r600_emit_reloc(ctx
, &ctx
->gfx
, query
->buffer
.buf
, RADEON_USAGE_WRITE
,
576 static void r600_query_hw_emit_stop(struct r600_common_context
*ctx
,
577 struct r600_query_hw
*query
)
581 /* The queries which need begin already called this in begin_query. */
582 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
) {
583 ctx
->need_gfx_cs_space(&ctx
->b
, query
->num_cs_dw_end
, FALSE
);
587 va
= query
->buffer
.buf
->gpu_address
+ query
->buffer
.results_end
;
589 query
->ops
->emit_stop(ctx
, query
, query
->buffer
.buf
, va
);
591 query
->buffer
.results_end
+= query
->result_size
;
593 if (!(query
->flags
& R600_QUERY_HW_FLAG_NO_START
)) {
594 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
595 ctx
->num_cs_dw_timer_queries_suspend
-= query
->num_cs_dw_end
;
597 ctx
->num_cs_dw_nontimer_queries_suspend
-= query
->num_cs_dw_end
;
600 r600_update_occlusion_query_state(ctx
, query
->b
.type
, -1);
601 r600_update_prims_generated_query_state(ctx
, query
->b
.type
, -1);
604 static void r600_emit_query_predication(struct r600_common_context
*ctx
,
605 struct r600_atom
*atom
)
607 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
608 struct r600_query_hw
*query
= (struct r600_query_hw
*)ctx
->render_cond
;
609 struct r600_query_buffer
*qbuf
;
616 flag_wait
= ctx
->render_cond_mode
== PIPE_RENDER_COND_WAIT
||
617 ctx
->render_cond_mode
== PIPE_RENDER_COND_BY_REGION_WAIT
;
619 switch (query
->b
.type
) {
620 case PIPE_QUERY_OCCLUSION_COUNTER
:
621 case PIPE_QUERY_OCCLUSION_PREDICATE
:
622 op
= PRED_OP(PREDICATION_OP_ZPASS
);
624 case PIPE_QUERY_PRIMITIVES_EMITTED
:
625 case PIPE_QUERY_PRIMITIVES_GENERATED
:
626 case PIPE_QUERY_SO_STATISTICS
:
627 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
628 op
= PRED_OP(PREDICATION_OP_PRIMCOUNT
);
635 /* if true then invert, see GL_ARB_conditional_render_inverted */
636 if (ctx
->render_cond_invert
)
637 op
|= PREDICATION_DRAW_NOT_VISIBLE
; /* Draw if not visable/overflow */
639 op
|= PREDICATION_DRAW_VISIBLE
; /* Draw if visable/overflow */
641 op
|= flag_wait
? PREDICATION_HINT_WAIT
: PREDICATION_HINT_NOWAIT_DRAW
;
643 /* emit predicate packets for all data blocks */
644 for (qbuf
= &query
->buffer
; qbuf
; qbuf
= qbuf
->previous
) {
645 unsigned results_base
= 0;
646 uint64_t va
= qbuf
->buf
->gpu_address
;
648 while (results_base
< qbuf
->results_end
) {
649 radeon_emit(cs
, PKT3(PKT3_SET_PREDICATION
, 1, 0));
650 radeon_emit(cs
, va
+ results_base
);
651 radeon_emit(cs
, op
| (((va
+ results_base
) >> 32) & 0xFF));
652 r600_emit_reloc(ctx
, &ctx
->gfx
, qbuf
->buf
, RADEON_USAGE_READ
,
654 results_base
+= query
->result_size
;
656 /* set CONTINUE bit for all packets except the first */
657 op
|= PREDICATION_CONTINUE
;
662 static struct pipe_query
*r600_create_query(struct pipe_context
*ctx
, unsigned query_type
, unsigned index
)
664 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
666 if (query_type
== PIPE_QUERY_TIMESTAMP_DISJOINT
||
667 query_type
== PIPE_QUERY_GPU_FINISHED
||
668 query_type
>= PIPE_QUERY_DRIVER_SPECIFIC
)
669 return r600_query_sw_create(ctx
, query_type
);
671 return r600_query_hw_create(rctx
, query_type
, index
);
674 static void r600_destroy_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
676 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
677 struct r600_query
*rquery
= (struct r600_query
*)query
;
679 rquery
->ops
->destroy(rctx
, rquery
);
682 static boolean
r600_begin_query(struct pipe_context
*ctx
,
683 struct pipe_query
*query
)
685 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
686 struct r600_query
*rquery
= (struct r600_query
*)query
;
688 return rquery
->ops
->begin(rctx
, rquery
);
691 static void r600_query_hw_reset_buffers(struct r600_common_context
*rctx
,
692 struct r600_query_hw
*query
)
694 struct r600_query_buffer
*prev
= query
->buffer
.previous
;
696 /* Discard the old query buffers. */
698 struct r600_query_buffer
*qbuf
= prev
;
699 prev
= prev
->previous
;
700 pipe_resource_reference((struct pipe_resource
**)&qbuf
->buf
, NULL
);
704 if (query
->flags
& R600_QUERY_HW_FLAG_PREDICATE
) {
705 /* Obtain a new buffer if the current one can't be mapped without a stall. */
706 if (r600_rings_is_buffer_referenced(rctx
, query
->buffer
.buf
->buf
, RADEON_USAGE_READWRITE
) ||
707 !rctx
->ws
->buffer_wait(query
->buffer
.buf
->buf
, 0, RADEON_USAGE_READWRITE
)) {
708 pipe_resource_reference((struct pipe_resource
**)&query
->buffer
.buf
, NULL
);
709 query
->buffer
.buf
= r600_new_query_buffer(rctx
, query
);
711 query
->ops
->prepare_buffer(rctx
, query
, query
->buffer
.buf
);
715 query
->buffer
.results_end
= 0;
716 query
->buffer
.previous
= NULL
;
719 boolean
r600_query_hw_begin(struct r600_common_context
*rctx
,
720 struct r600_query
*rquery
)
722 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
724 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
) {
729 r600_query_hw_reset_buffers(rctx
, query
);
731 r600_query_hw_emit_start(rctx
, query
);
733 if (query
->flags
& R600_QUERY_HW_FLAG_TIMER
)
734 LIST_ADDTAIL(&query
->list
, &rctx
->active_timer_queries
);
736 LIST_ADDTAIL(&query
->list
, &rctx
->active_nontimer_queries
);
740 static void r600_end_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
742 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
743 struct r600_query
*rquery
= (struct r600_query
*)query
;
745 rquery
->ops
->end(rctx
, rquery
);
748 void r600_query_hw_end(struct r600_common_context
*rctx
,
749 struct r600_query
*rquery
)
751 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
753 if (query
->flags
& R600_QUERY_HW_FLAG_NO_START
)
754 r600_query_hw_reset_buffers(rctx
, query
);
756 r600_query_hw_emit_stop(rctx
, query
);
758 if (!(query
->flags
& R600_QUERY_HW_FLAG_NO_START
))
759 LIST_DELINIT(&query
->list
);
762 static unsigned r600_query_read_result(void *map
, unsigned start_index
, unsigned end_index
,
763 bool test_status_bit
)
765 uint32_t *current_result
= (uint32_t*)map
;
768 start
= (uint64_t)current_result
[start_index
] |
769 (uint64_t)current_result
[start_index
+1] << 32;
770 end
= (uint64_t)current_result
[end_index
] |
771 (uint64_t)current_result
[end_index
+1] << 32;
773 if (!test_status_bit
||
774 ((start
& 0x8000000000000000UL
) && (end
& 0x8000000000000000UL
))) {
780 static void r600_query_hw_add_result(struct r600_common_context
*ctx
,
781 struct r600_query_hw
*query
,
783 union pipe_query_result
*result
)
785 switch (query
->b
.type
) {
786 case PIPE_QUERY_OCCLUSION_COUNTER
: {
787 unsigned results_base
= 0;
788 while (results_base
!= query
->result_size
) {
790 r600_query_read_result(buffer
+ results_base
, 0, 2, true);
795 case PIPE_QUERY_OCCLUSION_PREDICATE
: {
796 unsigned results_base
= 0;
797 while (results_base
!= query
->result_size
) {
798 result
->b
= result
->b
||
799 r600_query_read_result(buffer
+ results_base
, 0, 2, true) != 0;
804 case PIPE_QUERY_TIME_ELAPSED
:
805 result
->u64
+= r600_query_read_result(buffer
, 0, 2, false);
807 case PIPE_QUERY_TIMESTAMP
:
809 uint32_t *current_result
= (uint32_t*)buffer
;
810 result
->u64
= (uint64_t)current_result
[0] |
811 (uint64_t)current_result
[1] << 32;
814 case PIPE_QUERY_PRIMITIVES_EMITTED
:
815 /* SAMPLE_STREAMOUTSTATS stores this structure:
817 * u64 NumPrimitivesWritten;
818 * u64 PrimitiveStorageNeeded;
820 * We only need NumPrimitivesWritten here. */
821 result
->u64
+= r600_query_read_result(buffer
, 2, 6, true);
823 case PIPE_QUERY_PRIMITIVES_GENERATED
:
824 /* Here we read PrimitiveStorageNeeded. */
825 result
->u64
+= r600_query_read_result(buffer
, 0, 4, true);
827 case PIPE_QUERY_SO_STATISTICS
:
828 result
->so_statistics
.num_primitives_written
+=
829 r600_query_read_result(buffer
, 2, 6, true);
830 result
->so_statistics
.primitives_storage_needed
+=
831 r600_query_read_result(buffer
, 0, 4, true);
833 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
834 result
->b
= result
->b
||
835 r600_query_read_result(buffer
, 2, 6, true) !=
836 r600_query_read_result(buffer
, 0, 4, true);
838 case PIPE_QUERY_PIPELINE_STATISTICS
:
839 if (ctx
->chip_class
>= EVERGREEN
) {
840 result
->pipeline_statistics
.ps_invocations
+=
841 r600_query_read_result(buffer
, 0, 22, false);
842 result
->pipeline_statistics
.c_primitives
+=
843 r600_query_read_result(buffer
, 2, 24, false);
844 result
->pipeline_statistics
.c_invocations
+=
845 r600_query_read_result(buffer
, 4, 26, false);
846 result
->pipeline_statistics
.vs_invocations
+=
847 r600_query_read_result(buffer
, 6, 28, false);
848 result
->pipeline_statistics
.gs_invocations
+=
849 r600_query_read_result(buffer
, 8, 30, false);
850 result
->pipeline_statistics
.gs_primitives
+=
851 r600_query_read_result(buffer
, 10, 32, false);
852 result
->pipeline_statistics
.ia_primitives
+=
853 r600_query_read_result(buffer
, 12, 34, false);
854 result
->pipeline_statistics
.ia_vertices
+=
855 r600_query_read_result(buffer
, 14, 36, false);
856 result
->pipeline_statistics
.hs_invocations
+=
857 r600_query_read_result(buffer
, 16, 38, false);
858 result
->pipeline_statistics
.ds_invocations
+=
859 r600_query_read_result(buffer
, 18, 40, false);
860 result
->pipeline_statistics
.cs_invocations
+=
861 r600_query_read_result(buffer
, 20, 42, false);
863 result
->pipeline_statistics
.ps_invocations
+=
864 r600_query_read_result(buffer
, 0, 16, false);
865 result
->pipeline_statistics
.c_primitives
+=
866 r600_query_read_result(buffer
, 2, 18, false);
867 result
->pipeline_statistics
.c_invocations
+=
868 r600_query_read_result(buffer
, 4, 20, false);
869 result
->pipeline_statistics
.vs_invocations
+=
870 r600_query_read_result(buffer
, 6, 22, false);
871 result
->pipeline_statistics
.gs_invocations
+=
872 r600_query_read_result(buffer
, 8, 24, false);
873 result
->pipeline_statistics
.gs_primitives
+=
874 r600_query_read_result(buffer
, 10, 26, false);
875 result
->pipeline_statistics
.ia_primitives
+=
876 r600_query_read_result(buffer
, 12, 28, false);
877 result
->pipeline_statistics
.ia_vertices
+=
878 r600_query_read_result(buffer
, 14, 30, false);
880 #if 0 /* for testing */
881 printf("Pipeline stats: IA verts=%llu, IA prims=%llu, VS=%llu, HS=%llu, "
882 "DS=%llu, GS=%llu, GS prims=%llu, Clipper=%llu, "
883 "Clipper prims=%llu, PS=%llu, CS=%llu\n",
884 result
->pipeline_statistics
.ia_vertices
,
885 result
->pipeline_statistics
.ia_primitives
,
886 result
->pipeline_statistics
.vs_invocations
,
887 result
->pipeline_statistics
.hs_invocations
,
888 result
->pipeline_statistics
.ds_invocations
,
889 result
->pipeline_statistics
.gs_invocations
,
890 result
->pipeline_statistics
.gs_primitives
,
891 result
->pipeline_statistics
.c_invocations
,
892 result
->pipeline_statistics
.c_primitives
,
893 result
->pipeline_statistics
.ps_invocations
,
894 result
->pipeline_statistics
.cs_invocations
);
902 static boolean
r600_get_query_result(struct pipe_context
*ctx
,
903 struct pipe_query
*query
, boolean wait
,
904 union pipe_query_result
*result
)
906 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
907 struct r600_query
*rquery
= (struct r600_query
*)query
;
909 return rquery
->ops
->get_result(rctx
, rquery
, wait
, result
);
912 static void r600_query_hw_clear_result(struct r600_query_hw
*query
,
913 union pipe_query_result
*result
)
915 util_query_clear_result(result
, query
->b
.type
);
918 boolean
r600_query_hw_get_result(struct r600_common_context
*rctx
,
919 struct r600_query
*rquery
,
920 boolean wait
, union pipe_query_result
*result
)
922 struct r600_query_hw
*query
= (struct r600_query_hw
*)rquery
;
923 struct r600_query_buffer
*qbuf
;
925 query
->ops
->clear_result(query
, result
);
927 for (qbuf
= &query
->buffer
; qbuf
; qbuf
= qbuf
->previous
) {
928 unsigned results_base
= 0;
931 map
= r600_buffer_map_sync_with_rings(rctx
, qbuf
->buf
,
933 (wait
? 0 : PIPE_TRANSFER_DONTBLOCK
));
937 while (results_base
!= qbuf
->results_end
) {
938 query
->ops
->add_result(rctx
, query
, map
+ results_base
,
940 results_base
+= query
->result_size
;
944 /* Convert the time to expected units. */
945 if (rquery
->type
== PIPE_QUERY_TIME_ELAPSED
||
946 rquery
->type
== PIPE_QUERY_TIMESTAMP
) {
947 result
->u64
= (1000000 * result
->u64
) / rctx
->screen
->info
.clock_crystal_freq
;
952 static void r600_render_condition(struct pipe_context
*ctx
,
953 struct pipe_query
*query
,
957 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
958 struct r600_query_hw
*rquery
= (struct r600_query_hw
*)query
;
959 struct r600_query_buffer
*qbuf
;
960 struct r600_atom
*atom
= &rctx
->render_cond_atom
;
962 rctx
->render_cond
= query
;
963 rctx
->render_cond_invert
= condition
;
964 rctx
->render_cond_mode
= mode
;
966 /* Compute the size of SET_PREDICATION packets. */
969 for (qbuf
= &rquery
->buffer
; qbuf
; qbuf
= qbuf
->previous
)
970 atom
->num_dw
+= (qbuf
->results_end
/ rquery
->result_size
) * 5;
973 rctx
->set_atom_dirty(rctx
, atom
, query
!= NULL
);
976 static void r600_suspend_queries(struct r600_common_context
*ctx
,
977 struct list_head
*query_list
,
978 unsigned *num_cs_dw_queries_suspend
)
980 struct r600_query_hw
*query
;
982 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
983 r600_query_hw_emit_stop(ctx
, query
);
985 assert(*num_cs_dw_queries_suspend
== 0);
988 void r600_suspend_nontimer_queries(struct r600_common_context
*ctx
)
990 r600_suspend_queries(ctx
, &ctx
->active_nontimer_queries
,
991 &ctx
->num_cs_dw_nontimer_queries_suspend
);
994 void r600_suspend_timer_queries(struct r600_common_context
*ctx
)
996 r600_suspend_queries(ctx
, &ctx
->active_timer_queries
,
997 &ctx
->num_cs_dw_timer_queries_suspend
);
1000 static unsigned r600_queries_num_cs_dw_for_resuming(struct r600_common_context
*ctx
,
1001 struct list_head
*query_list
)
1003 struct r600_query_hw
*query
;
1004 unsigned num_dw
= 0;
1006 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
1008 num_dw
+= query
->num_cs_dw_begin
+ query
->num_cs_dw_end
;
1010 /* Workaround for the fact that
1011 * num_cs_dw_nontimer_queries_suspend is incremented for every
1012 * resumed query, which raises the bar in need_cs_space for
1013 * queries about to be resumed.
1015 num_dw
+= query
->num_cs_dw_end
;
1017 /* primitives generated query */
1018 num_dw
+= ctx
->streamout
.enable_atom
.num_dw
;
1019 /* guess for ZPASS enable or PERFECT_ZPASS_COUNT enable updates */
1025 static void r600_resume_queries(struct r600_common_context
*ctx
,
1026 struct list_head
*query_list
,
1027 unsigned *num_cs_dw_queries_suspend
)
1029 struct r600_query_hw
*query
;
1030 unsigned num_cs_dw
= r600_queries_num_cs_dw_for_resuming(ctx
, query_list
);
1032 assert(*num_cs_dw_queries_suspend
== 0);
1034 /* Check CS space here. Resuming must not be interrupted by flushes. */
1035 ctx
->need_gfx_cs_space(&ctx
->b
, num_cs_dw
, TRUE
);
1037 LIST_FOR_EACH_ENTRY(query
, query_list
, list
) {
1038 r600_query_hw_emit_start(ctx
, query
);
1042 void r600_resume_nontimer_queries(struct r600_common_context
*ctx
)
1044 r600_resume_queries(ctx
, &ctx
->active_nontimer_queries
,
1045 &ctx
->num_cs_dw_nontimer_queries_suspend
);
1048 void r600_resume_timer_queries(struct r600_common_context
*ctx
)
1050 r600_resume_queries(ctx
, &ctx
->active_timer_queries
,
1051 &ctx
->num_cs_dw_timer_queries_suspend
);
1054 /* Get backends mask */
1055 void r600_query_init_backend_mask(struct r600_common_context
*ctx
)
1057 struct radeon_winsys_cs
*cs
= ctx
->gfx
.cs
;
1058 struct r600_resource
*buffer
;
1060 unsigned num_backends
= ctx
->screen
->info
.num_render_backends
;
1061 unsigned i
, mask
= 0;
1063 /* if backend_map query is supported by the kernel */
1064 if (ctx
->screen
->info
.r600_gb_backend_map_valid
) {
1065 unsigned num_tile_pipes
= ctx
->screen
->info
.num_tile_pipes
;
1066 unsigned backend_map
= ctx
->screen
->info
.r600_gb_backend_map
;
1067 unsigned item_width
, item_mask
;
1069 if (ctx
->chip_class
>= EVERGREEN
) {
1077 while (num_tile_pipes
--) {
1078 i
= backend_map
& item_mask
;
1080 backend_map
>>= item_width
;
1083 ctx
->backend_mask
= mask
;
1088 /* otherwise backup path for older kernels */
1090 /* create buffer for event data */
1091 buffer
= (struct r600_resource
*)
1092 pipe_buffer_create(ctx
->b
.screen
, PIPE_BIND_CUSTOM
,
1093 PIPE_USAGE_STAGING
, ctx
->max_db
*16);
1097 /* initialize buffer with zeroes */
1098 results
= r600_buffer_map_sync_with_rings(ctx
, buffer
, PIPE_TRANSFER_WRITE
);
1100 memset(results
, 0, ctx
->max_db
* 4 * 4);
1102 /* emit EVENT_WRITE for ZPASS_DONE */
1103 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 2, 0));
1104 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_ZPASS_DONE
) | EVENT_INDEX(1));
1105 radeon_emit(cs
, buffer
->gpu_address
);
1106 radeon_emit(cs
, buffer
->gpu_address
>> 32);
1108 r600_emit_reloc(ctx
, &ctx
->gfx
, buffer
,
1109 RADEON_USAGE_WRITE
, RADEON_PRIO_QUERY
);
1111 /* analyze results */
1112 results
= r600_buffer_map_sync_with_rings(ctx
, buffer
, PIPE_TRANSFER_READ
);
1114 for(i
= 0; i
< ctx
->max_db
; i
++) {
1115 /* at least highest bit will be set if backend is used */
1116 if (results
[i
*4 + 1])
1122 pipe_resource_reference((struct pipe_resource
**)&buffer
, NULL
);
1125 ctx
->backend_mask
= mask
;
1130 /* fallback to old method - set num_backends lower bits to 1 */
1131 ctx
->backend_mask
= (~((uint32_t)0))>>(32-num_backends
);
1135 #define XFULL(name_, query_type_, type_, result_type_, group_id_) \
1138 .query_type = R600_QUERY_##query_type_, \
1139 .type = PIPE_DRIVER_QUERY_TYPE_##type_, \
1140 .result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_##result_type_, \
1141 .group_id = group_id_ \
1144 #define X(name_, query_type_, type_, result_type_) \
1145 XFULL(name_, query_type_, type_, result_type_, ~(unsigned)0)
1147 #define XG(group_, name_, query_type_, type_, result_type_) \
1148 XFULL(name_, query_type_, type_, result_type_, R600_QUERY_GROUP_##group_)
1150 static struct pipe_driver_query_info r600_driver_query_list
[] = {
1151 X("num-compilations", NUM_COMPILATIONS
, UINT64
, CUMULATIVE
),
1152 X("num-shaders-created", NUM_SHADERS_CREATED
, UINT64
, CUMULATIVE
),
1153 X("draw-calls", DRAW_CALLS
, UINT64
, CUMULATIVE
),
1154 X("requested-VRAM", REQUESTED_VRAM
, BYTES
, AVERAGE
),
1155 X("requested-GTT", REQUESTED_GTT
, BYTES
, AVERAGE
),
1156 X("buffer-wait-time", BUFFER_WAIT_TIME
, MICROSECONDS
, CUMULATIVE
),
1157 X("num-cs-flushes", NUM_CS_FLUSHES
, UINT64
, CUMULATIVE
),
1158 X("num-bytes-moved", NUM_BYTES_MOVED
, BYTES
, CUMULATIVE
),
1159 X("VRAM-usage", VRAM_USAGE
, BYTES
, AVERAGE
),
1160 X("GTT-usage", GTT_USAGE
, BYTES
, AVERAGE
),
1162 /* GPIN queries are for the benefit of old versions of GPUPerfStudio,
1163 * which use it as a fallback path to detect the GPU type.
1165 * Note: The names of these queries are significant for GPUPerfStudio
1166 * (and possibly their order as well). */
1167 XG(GPIN
, "GPIN_000", GPIN_ASIC_ID
, UINT
, AVERAGE
),
1168 XG(GPIN
, "GPIN_001", GPIN_NUM_SIMD
, UINT
, AVERAGE
),
1169 XG(GPIN
, "GPIN_002", GPIN_NUM_RB
, UINT
, AVERAGE
),
1170 XG(GPIN
, "GPIN_003", GPIN_NUM_SPI
, UINT
, AVERAGE
),
1171 XG(GPIN
, "GPIN_004", GPIN_NUM_SE
, UINT
, AVERAGE
),
1173 /* The following queries must be at the end of the list because their
1174 * availability is adjusted dynamically based on the DRM version. */
1175 X("GPU-load", GPU_LOAD
, UINT64
, AVERAGE
),
1176 X("temperature", GPU_TEMPERATURE
, UINT64
, AVERAGE
),
1177 X("shader-clock", CURRENT_GPU_SCLK
, HZ
, AVERAGE
),
1178 X("memory-clock", CURRENT_GPU_MCLK
, HZ
, AVERAGE
),
1185 static unsigned r600_get_num_queries(struct r600_common_screen
*rscreen
)
1187 if (rscreen
->info
.drm_major
== 2 && rscreen
->info
.drm_minor
>= 42)
1188 return Elements(r600_driver_query_list
);
1189 else if (rscreen
->info
.drm_major
== 3)
1190 return Elements(r600_driver_query_list
) - 3;
1192 return Elements(r600_driver_query_list
) - 4;
1195 static int r600_get_driver_query_info(struct pipe_screen
*screen
,
1197 struct pipe_driver_query_info
*info
)
1199 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
1200 unsigned num_queries
= r600_get_num_queries(rscreen
);
1203 unsigned num_perfcounters
=
1204 r600_get_perfcounter_info(rscreen
, 0, NULL
);
1206 return num_queries
+ num_perfcounters
;
1209 if (index
>= num_queries
)
1210 return r600_get_perfcounter_info(rscreen
, index
- num_queries
, info
);
1212 *info
= r600_driver_query_list
[index
];
1214 switch (info
->query_type
) {
1215 case R600_QUERY_REQUESTED_VRAM
:
1216 case R600_QUERY_VRAM_USAGE
:
1217 info
->max_value
.u64
= rscreen
->info
.vram_size
;
1219 case R600_QUERY_REQUESTED_GTT
:
1220 case R600_QUERY_GTT_USAGE
:
1221 info
->max_value
.u64
= rscreen
->info
.gart_size
;
1223 case R600_QUERY_GPU_TEMPERATURE
:
1224 info
->max_value
.u64
= 125;
1228 if (info
->group_id
!= ~(unsigned)0 && rscreen
->perfcounters
)
1229 info
->group_id
+= rscreen
->perfcounters
->num_groups
;
1234 /* Note: Unfortunately, GPUPerfStudio hardcodes the order of hardware
1235 * performance counter groups, so be careful when changing this and related
1238 static int r600_get_driver_query_group_info(struct pipe_screen
*screen
,
1240 struct pipe_driver_query_group_info
*info
)
1242 struct r600_common_screen
*rscreen
= (struct r600_common_screen
*)screen
;
1243 unsigned num_pc_groups
= 0;
1245 if (rscreen
->perfcounters
)
1246 num_pc_groups
= rscreen
->perfcounters
->num_groups
;
1249 return num_pc_groups
+ R600_NUM_SW_QUERY_GROUPS
;
1251 if (index
< num_pc_groups
)
1252 return r600_get_perfcounter_group_info(rscreen
, index
, info
);
1254 index
-= num_pc_groups
;
1255 if (index
>= R600_NUM_SW_QUERY_GROUPS
)
1258 info
->name
= "GPIN";
1259 info
->max_active_queries
= 5;
1260 info
->num_queries
= 5;
1264 void r600_query_init(struct r600_common_context
*rctx
)
1266 rctx
->b
.create_query
= r600_create_query
;
1267 rctx
->b
.create_batch_query
= r600_create_batch_query
;
1268 rctx
->b
.destroy_query
= r600_destroy_query
;
1269 rctx
->b
.begin_query
= r600_begin_query
;
1270 rctx
->b
.end_query
= r600_end_query
;
1271 rctx
->b
.get_query_result
= r600_get_query_result
;
1272 rctx
->render_cond_atom
.emit
= r600_emit_query_predication
;
1274 if (((struct r600_common_screen
*)rctx
->b
.screen
)->info
.num_render_backends
> 0)
1275 rctx
->b
.render_condition
= r600_render_condition
;
1277 LIST_INITHEAD(&rctx
->active_nontimer_queries
);
1278 LIST_INITHEAD(&rctx
->active_timer_queries
);
1281 void r600_init_screen_query_functions(struct r600_common_screen
*rscreen
)
1283 rscreen
->b
.get_driver_query_info
= r600_get_driver_query_info
;
1284 rscreen
->b
.get_driver_query_group_info
= r600_get_driver_query_group_info
;