llvmpipe: Fix incorrect sizeof.
[mesa.git] / src / gallium / drivers / r600 / r600_query.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 *
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
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
13 * Software.
14 *
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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include "r600_pipe.h"
24 #include "r600d.h"
25 #include "util/u_memory.h"
26
27 static bool r600_is_timer_query(unsigned type)
28 {
29 return type == PIPE_QUERY_TIME_ELAPSED ||
30 type == PIPE_QUERY_TIMESTAMP ||
31 type == PIPE_QUERY_TIMESTAMP_DISJOINT;
32 }
33
34 static bool r600_query_needs_begin(unsigned type)
35 {
36 return type != PIPE_QUERY_GPU_FINISHED &&
37 type != PIPE_QUERY_TIMESTAMP;
38 }
39
40 static struct r600_resource *r600_new_query_buffer(struct r600_context *ctx, unsigned type)
41 {
42 unsigned j, i, num_results, buf_size = 4096;
43 uint32_t *results;
44 /* Queries are normally read by the CPU after
45 * being written by the gpu, hence staging is probably a good
46 * usage pattern.
47 */
48 struct r600_resource *buf = (struct r600_resource*)
49 pipe_buffer_create(&ctx->screen->screen, PIPE_BIND_CUSTOM,
50 PIPE_USAGE_STAGING, buf_size);
51
52 switch (type) {
53 case PIPE_QUERY_OCCLUSION_COUNTER:
54 case PIPE_QUERY_OCCLUSION_PREDICATE:
55 results = ctx->ws->buffer_map(buf->cs_buf, ctx->cs, PIPE_TRANSFER_WRITE);
56 memset(results, 0, buf_size);
57
58 /* Set top bits for unused backends. */
59 num_results = buf_size / (16 * ctx->max_db);
60 for (j = 0; j < num_results; j++) {
61 for (i = 0; i < ctx->max_db; i++) {
62 if (!(ctx->backend_mask & (1<<i))) {
63 results[(i * 4)+1] = 0x80000000;
64 results[(i * 4)+3] = 0x80000000;
65 }
66 }
67 results += 4 * ctx->max_db;
68 }
69 ctx->ws->buffer_unmap(buf->cs_buf);
70 break;
71 case PIPE_QUERY_TIME_ELAPSED:
72 case PIPE_QUERY_TIMESTAMP:
73 break;
74 case PIPE_QUERY_PRIMITIVES_EMITTED:
75 case PIPE_QUERY_PRIMITIVES_GENERATED:
76 case PIPE_QUERY_SO_STATISTICS:
77 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
78 results = ctx->ws->buffer_map(buf->cs_buf, ctx->cs, PIPE_TRANSFER_WRITE);
79 memset(results, 0, buf_size);
80 ctx->ws->buffer_unmap(buf->cs_buf);
81 break;
82 default:
83 assert(0);
84 }
85 return buf;
86 }
87
88 static void r600_update_occlusion_query_state(struct r600_context *rctx,
89 unsigned type, int diff)
90 {
91 if (type == PIPE_QUERY_OCCLUSION_COUNTER ||
92 type == PIPE_QUERY_OCCLUSION_PREDICATE) {
93 bool enable;
94
95 rctx->num_occlusion_queries += diff;
96 assert(rctx->num_occlusion_queries >= 0);
97
98 enable = rctx->num_occlusion_queries != 0;
99
100 if (rctx->db_misc_state.occlusion_query_enabled != enable) {
101 rctx->db_misc_state.occlusion_query_enabled = enable;
102 rctx->db_misc_state.atom.dirty = true;
103 }
104 }
105 }
106
107 static void r600_emit_query_begin(struct r600_context *ctx, struct r600_query *query)
108 {
109 struct radeon_winsys_cs *cs = ctx->cs;
110 uint64_t va;
111
112 r600_update_occlusion_query_state(ctx, query->type, 1);
113 r600_need_cs_space(ctx, query->num_cs_dw * 2, TRUE);
114
115 /* Get a new query buffer if needed. */
116 if (query->buffer.results_end + query->result_size > query->buffer.buf->b.b.width0) {
117 struct r600_query_buffer *qbuf = MALLOC_STRUCT(r600_query_buffer);
118 *qbuf = query->buffer;
119 query->buffer.buf = r600_new_query_buffer(ctx, query->type);
120 query->buffer.results_end = 0;
121 query->buffer.previous = qbuf;
122 }
123
124 /* emit begin query */
125 va = r600_resource_va(&ctx->screen->screen, (void*)query->buffer.buf);
126 va += query->buffer.results_end;
127
128 switch (query->type) {
129 case PIPE_QUERY_OCCLUSION_COUNTER:
130 case PIPE_QUERY_OCCLUSION_PREDICATE:
131 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE, 2, 0);
132 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1);
133 cs->buf[cs->cdw++] = va;
134 cs->buf[cs->cdw++] = (va >> 32UL) & 0xFF;
135 break;
136 case PIPE_QUERY_PRIMITIVES_EMITTED:
137 case PIPE_QUERY_PRIMITIVES_GENERATED:
138 case PIPE_QUERY_SO_STATISTICS:
139 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
140 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE, 2, 0);
141 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_SAMPLE_STREAMOUTSTATS) | EVENT_INDEX(3);
142 cs->buf[cs->cdw++] = va;
143 cs->buf[cs->cdw++] = (va >> 32UL) & 0xFF;
144 break;
145 case PIPE_QUERY_TIME_ELAPSED:
146 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE_EOP, 4, 0);
147 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5);
148 cs->buf[cs->cdw++] = va;
149 cs->buf[cs->cdw++] = (3 << 29) | ((va >> 32UL) & 0xFF);
150 cs->buf[cs->cdw++] = 0;
151 cs->buf[cs->cdw++] = 0;
152 break;
153 default:
154 assert(0);
155 }
156 cs->buf[cs->cdw++] = PKT3(PKT3_NOP, 0, 0);
157 cs->buf[cs->cdw++] = r600_context_bo_reloc(ctx, query->buffer.buf, RADEON_USAGE_WRITE);
158
159 if (r600_is_timer_query(query->type)) {
160 ctx->num_cs_dw_timer_queries_suspend += query->num_cs_dw;
161 } else {
162 ctx->num_cs_dw_nontimer_queries_suspend += query->num_cs_dw;
163 }
164 }
165
166 static void r600_emit_query_end(struct r600_context *ctx, struct r600_query *query)
167 {
168 struct radeon_winsys_cs *cs = ctx->cs;
169 uint64_t va;
170
171 /* The queries which need begin already called this in begin_query. */
172 if (!r600_query_needs_begin(query->type)) {
173 r600_need_cs_space(ctx, query->num_cs_dw, FALSE);
174 }
175
176 va = r600_resource_va(&ctx->screen->screen, (void*)query->buffer.buf);
177 /* emit end query */
178 switch (query->type) {
179 case PIPE_QUERY_OCCLUSION_COUNTER:
180 case PIPE_QUERY_OCCLUSION_PREDICATE:
181 va += query->buffer.results_end + 8;
182 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE, 2, 0);
183 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_ZPASS_DONE) | EVENT_INDEX(1);
184 cs->buf[cs->cdw++] = va;
185 cs->buf[cs->cdw++] = (va >> 32UL) & 0xFF;
186 break;
187 case PIPE_QUERY_PRIMITIVES_EMITTED:
188 case PIPE_QUERY_PRIMITIVES_GENERATED:
189 case PIPE_QUERY_SO_STATISTICS:
190 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
191 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE, 2, 0);
192 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_SAMPLE_STREAMOUTSTATS) | EVENT_INDEX(3);
193 cs->buf[cs->cdw++] = query->buffer.results_end + query->result_size/2;
194 cs->buf[cs->cdw++] = 0;
195 break;
196 case PIPE_QUERY_TIME_ELAPSED:
197 va += query->buffer.results_end + query->result_size/2;
198 /* fall through */
199 case PIPE_QUERY_TIMESTAMP:
200 cs->buf[cs->cdw++] = PKT3(PKT3_EVENT_WRITE_EOP, 4, 0);
201 cs->buf[cs->cdw++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5);
202 cs->buf[cs->cdw++] = va;
203 cs->buf[cs->cdw++] = (3 << 29) | ((va >> 32UL) & 0xFF);
204 cs->buf[cs->cdw++] = 0;
205 cs->buf[cs->cdw++] = 0;
206 break;
207 default:
208 assert(0);
209 }
210 cs->buf[cs->cdw++] = PKT3(PKT3_NOP, 0, 0);
211 cs->buf[cs->cdw++] = r600_context_bo_reloc(ctx, query->buffer.buf, RADEON_USAGE_WRITE);
212
213 query->buffer.results_end += query->result_size;
214
215 if (r600_query_needs_begin(query->type)) {
216 if (r600_is_timer_query(query->type)) {
217 ctx->num_cs_dw_timer_queries_suspend -= query->num_cs_dw;
218 } else {
219 ctx->num_cs_dw_nontimer_queries_suspend -= query->num_cs_dw;
220 }
221 }
222
223 r600_update_occlusion_query_state(ctx, query->type, -1);
224 }
225
226 static void r600_emit_query_predication(struct r600_context *ctx, struct r600_query *query,
227 int operation, bool flag_wait)
228 {
229 struct radeon_winsys_cs *cs = ctx->cs;
230
231 if (operation == PREDICATION_OP_CLEAR) {
232 r600_need_cs_space(ctx, 3, FALSE);
233
234 cs->buf[cs->cdw++] = PKT3(PKT3_SET_PREDICATION, 1, 0);
235 cs->buf[cs->cdw++] = 0;
236 cs->buf[cs->cdw++] = PRED_OP(PREDICATION_OP_CLEAR);
237 } else {
238 struct r600_query_buffer *qbuf;
239 unsigned count;
240 uint32_t op;
241
242 /* Find how many results there are. */
243 count = 0;
244 for (qbuf = &query->buffer; qbuf; qbuf = qbuf->previous) {
245 count += qbuf->results_end / query->result_size;
246 }
247
248 r600_need_cs_space(ctx, 5 * count, TRUE);
249
250 op = PRED_OP(operation) | PREDICATION_DRAW_VISIBLE |
251 (flag_wait ? PREDICATION_HINT_WAIT : PREDICATION_HINT_NOWAIT_DRAW);
252
253 /* emit predicate packets for all data blocks */
254 for (qbuf = &query->buffer; qbuf; qbuf = qbuf->previous) {
255 unsigned results_base = 0;
256 uint64_t va = r600_resource_va(&ctx->screen->screen, &qbuf->buf->b.b);
257
258 while (results_base < qbuf->results_end) {
259 cs->buf[cs->cdw++] = PKT3(PKT3_SET_PREDICATION, 1, 0);
260 cs->buf[cs->cdw++] = (va + results_base) & 0xFFFFFFFFUL;
261 cs->buf[cs->cdw++] = op | (((va + results_base) >> 32UL) & 0xFF);
262 cs->buf[cs->cdw++] = PKT3(PKT3_NOP, 0, 0);
263 cs->buf[cs->cdw++] = r600_context_bo_reloc(ctx, qbuf->buf, RADEON_USAGE_READ);
264 results_base += query->result_size;
265
266 /* set CONTINUE bit for all packets except the first */
267 op |= PREDICATION_CONTINUE;
268 }
269 } while (qbuf);
270 }
271 }
272
273 static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned query_type)
274 {
275 struct r600_context *rctx = (struct r600_context *)ctx;
276
277 struct r600_query *query;
278
279 query = CALLOC_STRUCT(r600_query);
280 if (query == NULL)
281 return NULL;
282
283 query->type = query_type;
284
285 switch (query_type) {
286 case PIPE_QUERY_OCCLUSION_COUNTER:
287 case PIPE_QUERY_OCCLUSION_PREDICATE:
288 query->result_size = 16 * rctx->max_db;
289 query->num_cs_dw = 6;
290 break;
291 case PIPE_QUERY_TIME_ELAPSED:
292 query->result_size = 16;
293 query->num_cs_dw = 8;
294 break;
295 case PIPE_QUERY_TIMESTAMP:
296 query->result_size = 8;
297 query->num_cs_dw = 8;
298 break;
299 case PIPE_QUERY_PRIMITIVES_EMITTED:
300 case PIPE_QUERY_PRIMITIVES_GENERATED:
301 case PIPE_QUERY_SO_STATISTICS:
302 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
303 /* NumPrimitivesWritten, PrimitiveStorageNeeded. */
304 query->result_size = 32;
305 query->num_cs_dw = 6;
306 break;
307 default:
308 assert(0);
309 FREE(query);
310 return NULL;
311 }
312
313 query->buffer.buf = r600_new_query_buffer(rctx, query_type);
314 if (!query->buffer.buf) {
315 FREE(query);
316 return NULL;
317 }
318 return (struct pipe_query*)query;
319 }
320
321 static void r600_destroy_query(struct pipe_context *ctx, struct pipe_query *query)
322 {
323 struct r600_query *rquery = (struct r600_query*)query;
324 struct r600_query_buffer *prev = rquery->buffer.previous;
325
326 /* Release all query buffers. */
327 while (prev) {
328 struct r600_query_buffer *qbuf = prev;
329 prev = prev->previous;
330 pipe_resource_reference((struct pipe_resource**)&qbuf->buf, NULL);
331 FREE(qbuf);
332 }
333
334 pipe_resource_reference((struct pipe_resource**)&rquery->buffer.buf, NULL);
335 FREE(query);
336 }
337
338 static void r600_begin_query(struct pipe_context *ctx, struct pipe_query *query)
339 {
340 struct r600_context *rctx = (struct r600_context *)ctx;
341 struct r600_query *rquery = (struct r600_query *)query;
342 struct r600_query_buffer *prev = rquery->buffer.previous;
343
344 if (!r600_query_needs_begin(rquery->type)) {
345 assert(0);
346 return;
347 }
348
349 /* Discard the old query buffers. */
350 while (prev) {
351 struct r600_query_buffer *qbuf = prev;
352 prev = prev->previous;
353 pipe_resource_reference((struct pipe_resource**)&qbuf->buf, NULL);
354 FREE(qbuf);
355 }
356
357 /* Obtain a new buffer if the current one can't be mapped without a stall. */
358 if (rctx->ws->cs_is_buffer_referenced(rctx->cs, rquery->buffer.buf->cs_buf, RADEON_USAGE_READWRITE) ||
359 rctx->ws->buffer_is_busy(rquery->buffer.buf->buf, RADEON_USAGE_READWRITE)) {
360 pipe_resource_reference((struct pipe_resource**)&rquery->buffer.buf, NULL);
361 rquery->buffer.buf = r600_new_query_buffer(rctx, rquery->type);
362 }
363
364 rquery->buffer.results_end = 0;
365 rquery->buffer.previous = NULL;
366
367 r600_emit_query_begin(rctx, rquery);
368
369 if (r600_is_timer_query(rquery->type)) {
370 LIST_ADDTAIL(&rquery->list, &rctx->active_timer_queries);
371 } else {
372 LIST_ADDTAIL(&rquery->list, &rctx->active_nontimer_queries);
373 }
374 }
375
376 static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query)
377 {
378 struct r600_context *rctx = (struct r600_context *)ctx;
379 struct r600_query *rquery = (struct r600_query *)query;
380
381 r600_emit_query_end(rctx, rquery);
382
383 if (r600_query_needs_begin(rquery->type)) {
384 LIST_DELINIT(&rquery->list);
385 }
386 }
387
388 static unsigned r600_query_read_result(char *map, unsigned start_index, unsigned end_index,
389 bool test_status_bit)
390 {
391 uint32_t *current_result = (uint32_t*)map;
392 uint64_t start, end;
393
394 start = (uint64_t)current_result[start_index] |
395 (uint64_t)current_result[start_index+1] << 32;
396 end = (uint64_t)current_result[end_index] |
397 (uint64_t)current_result[end_index+1] << 32;
398
399 if (!test_status_bit ||
400 ((start & 0x8000000000000000UL) && (end & 0x8000000000000000UL))) {
401 return end - start;
402 }
403 return 0;
404 }
405
406 static boolean r600_get_query_buffer_result(struct r600_context *ctx,
407 struct r600_query *query,
408 struct r600_query_buffer *qbuf,
409 boolean wait,
410 union pipe_query_result *result)
411 {
412 unsigned results_base = 0;
413 char *map;
414
415 map = ctx->ws->buffer_map(qbuf->buf->cs_buf, ctx->cs,
416 PIPE_TRANSFER_READ |
417 (wait ? 0 : PIPE_TRANSFER_DONTBLOCK));
418 if (!map)
419 return FALSE;
420
421 /* count all results across all data blocks */
422 switch (query->type) {
423 case PIPE_QUERY_OCCLUSION_COUNTER:
424 while (results_base != qbuf->results_end) {
425 result->u64 +=
426 r600_query_read_result(map + results_base, 0, 2, true);
427 results_base += 16;
428 }
429 break;
430 case PIPE_QUERY_OCCLUSION_PREDICATE:
431 while (results_base != qbuf->results_end) {
432 result->b = result->b ||
433 r600_query_read_result(map + results_base, 0, 2, true) != 0;
434 results_base += 16;
435 }
436 break;
437 case PIPE_QUERY_TIME_ELAPSED:
438 while (results_base != qbuf->results_end) {
439 result->u64 +=
440 r600_query_read_result(map + results_base, 0, 2, false);
441 results_base += query->result_size;
442 }
443 break;
444 case PIPE_QUERY_TIMESTAMP:
445 {
446 uint32_t *current_result = (uint32_t*)map;
447 result->u64 = (uint64_t)current_result[0] |
448 (uint64_t)current_result[1] << 32;
449 break;
450 }
451 case PIPE_QUERY_PRIMITIVES_EMITTED:
452 /* SAMPLE_STREAMOUTSTATS stores this structure:
453 * {
454 * u64 NumPrimitivesWritten;
455 * u64 PrimitiveStorageNeeded;
456 * }
457 * We only need NumPrimitivesWritten here. */
458 while (results_base != qbuf->results_end) {
459 result->u64 +=
460 r600_query_read_result(map + results_base, 2, 6, true);
461 results_base += query->result_size;
462 }
463 break;
464 case PIPE_QUERY_PRIMITIVES_GENERATED:
465 /* Here we read PrimitiveStorageNeeded. */
466 while (results_base != qbuf->results_end) {
467 result->u64 +=
468 r600_query_read_result(map + results_base, 0, 4, true);
469 results_base += query->result_size;
470 }
471 break;
472 case PIPE_QUERY_SO_STATISTICS:
473 while (results_base != qbuf->results_end) {
474 result->so_statistics.num_primitives_written +=
475 r600_query_read_result(map + results_base, 2, 6, true);
476 result->so_statistics.primitives_storage_needed +=
477 r600_query_read_result(map + results_base, 0, 4, true);
478 results_base += query->result_size;
479 }
480 break;
481 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
482 while (results_base != qbuf->results_end) {
483 result->b = result->b ||
484 r600_query_read_result(map + results_base, 2, 6, true) !=
485 r600_query_read_result(map + results_base, 0, 4, true);
486 results_base += query->result_size;
487 }
488 break;
489 default:
490 assert(0);
491 }
492
493 ctx->ws->buffer_unmap(qbuf->buf->cs_buf);
494 return TRUE;
495 }
496
497 static boolean r600_get_query_result(struct pipe_context *ctx,
498 struct pipe_query *query,
499 boolean wait, union pipe_query_result *result)
500 {
501 struct r600_context *rctx = (struct r600_context *)ctx;
502 struct r600_query *rquery = (struct r600_query *)query;
503 struct r600_query_buffer *qbuf;
504
505 util_query_clear_result(result, rquery->type);
506
507 for (qbuf = &rquery->buffer; qbuf; qbuf = qbuf->previous) {
508 if (!r600_get_query_buffer_result(rctx, rquery, qbuf, wait, result)) {
509 return FALSE;
510 }
511 }
512
513 /* Convert the time to expected units. */
514 if (rquery->type == PIPE_QUERY_TIME_ELAPSED ||
515 rquery->type == PIPE_QUERY_TIMESTAMP) {
516 result->u64 = (1000000 * result->u64) / rctx->screen->info.r600_clock_crystal_freq;
517 }
518 return TRUE;
519 }
520
521 static void r600_render_condition(struct pipe_context *ctx,
522 struct pipe_query *query,
523 uint mode)
524 {
525 struct r600_context *rctx = (struct r600_context *)ctx;
526 struct r600_query *rquery = (struct r600_query *)query;
527 bool wait_flag = false;
528
529 rctx->current_render_cond = query;
530 rctx->current_render_cond_mode = mode;
531
532 if (query == NULL) {
533 if (rctx->predicate_drawing) {
534 rctx->predicate_drawing = false;
535 r600_emit_query_predication(rctx, NULL, PREDICATION_OP_CLEAR, false);
536 }
537 return;
538 }
539
540 if (mode == PIPE_RENDER_COND_WAIT ||
541 mode == PIPE_RENDER_COND_BY_REGION_WAIT) {
542 wait_flag = true;
543 }
544
545 rctx->predicate_drawing = true;
546
547 switch (rquery->type) {
548 case PIPE_QUERY_OCCLUSION_COUNTER:
549 case PIPE_QUERY_OCCLUSION_PREDICATE:
550 r600_emit_query_predication(rctx, rquery, PREDICATION_OP_ZPASS, wait_flag);
551 break;
552 case PIPE_QUERY_PRIMITIVES_EMITTED:
553 case PIPE_QUERY_PRIMITIVES_GENERATED:
554 case PIPE_QUERY_SO_STATISTICS:
555 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
556 r600_emit_query_predication(rctx, rquery, PREDICATION_OP_PRIMCOUNT, wait_flag);
557 break;
558 default:
559 assert(0);
560 }
561 }
562
563 void r600_suspend_nontimer_queries(struct r600_context *ctx)
564 {
565 struct r600_query *query;
566
567 LIST_FOR_EACH_ENTRY(query, &ctx->active_nontimer_queries, list) {
568 r600_emit_query_end(ctx, query);
569 }
570 assert(ctx->num_cs_dw_nontimer_queries_suspend == 0);
571 }
572
573 void r600_resume_nontimer_queries(struct r600_context *ctx)
574 {
575 struct r600_query *query;
576
577 assert(ctx->num_cs_dw_nontimer_queries_suspend == 0);
578
579 LIST_FOR_EACH_ENTRY(query, &ctx->active_nontimer_queries, list) {
580 r600_emit_query_begin(ctx, query);
581 }
582 }
583
584 void r600_suspend_timer_queries(struct r600_context *ctx)
585 {
586 struct r600_query *query;
587
588 LIST_FOR_EACH_ENTRY(query, &ctx->active_timer_queries, list) {
589 r600_emit_query_end(ctx, query);
590 }
591
592 assert(ctx->num_cs_dw_timer_queries_suspend == 0);
593 }
594
595 void r600_resume_timer_queries(struct r600_context *ctx)
596 {
597 struct r600_query *query;
598
599 assert(ctx->num_cs_dw_timer_queries_suspend == 0);
600
601 LIST_FOR_EACH_ENTRY(query, &ctx->active_timer_queries, list) {
602 r600_emit_query_begin(ctx, query);
603 }
604 }
605
606 void r600_init_query_functions(struct r600_context *rctx)
607 {
608 rctx->context.create_query = r600_create_query;
609 rctx->context.destroy_query = r600_destroy_query;
610 rctx->context.begin_query = r600_begin_query;
611 rctx->context.end_query = r600_end_query;
612 rctx->context.get_query_result = r600_get_query_result;
613
614 if (rctx->screen->info.r600_num_backends > 0)
615 rctx->context.render_condition = r600_render_condition;
616 }