2 * Copyright 2011 Christoph Bumiller
3 * Copyright 2015 Samuel Pitoiset
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
24 #define NVC0_PUSH_EXPLICIT_SPACE_CHECKING
26 #include "nvc0/nvc0_context.h"
27 #include "nvc0/nvc0_query_hw.h"
28 #include "nvc0/nvc0_query_hw_metric.h"
29 #include "nvc0/nvc0_query_hw_sm.h"
31 #define NVC0_HW_QUERY_ALLOC_SPACE 256
34 nvc0_hw_query_allocate(struct nvc0_context
*nvc0
, struct nvc0_query
*q
,
37 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
38 struct nvc0_screen
*screen
= nvc0
->screen
;
42 nouveau_bo_ref(NULL
, &hq
->bo
);
44 if (hq
->state
== NVC0_HW_QUERY_STATE_READY
)
45 nouveau_mm_free(hq
->mm
);
47 nouveau_fence_work(screen
->base
.fence
.current
,
48 nouveau_mm_free_work
, hq
->mm
);
52 hq
->mm
= nouveau_mm_allocate(screen
->base
.mm_GART
, size
, &hq
->bo
,
56 hq
->offset
= hq
->base_offset
;
58 ret
= nouveau_bo_map(hq
->bo
, 0, screen
->base
.client
);
60 nvc0_hw_query_allocate(nvc0
, q
, 0);
63 hq
->data
= (uint32_t *)((uint8_t *)hq
->bo
->map
+ hq
->base_offset
);
69 nvc0_hw_query_get(struct nouveau_pushbuf
*push
, struct nvc0_query
*q
,
70 unsigned offset
, uint32_t get
)
72 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
77 PUSH_REFN (push
, hq
->bo
, NOUVEAU_BO_GART
| NOUVEAU_BO_WR
);
78 BEGIN_NVC0(push
, NVC0_3D(QUERY_ADDRESS_HIGH
), 4);
79 PUSH_DATAh(push
, hq
->bo
->offset
+ offset
);
80 PUSH_DATA (push
, hq
->bo
->offset
+ offset
);
81 PUSH_DATA (push
, hq
->sequence
);
82 PUSH_DATA (push
, get
);
86 nvc0_hw_query_rotate(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
88 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
90 hq
->offset
+= hq
->rotate
;
91 hq
->data
+= hq
->rotate
/ sizeof(*hq
->data
);
92 if (hq
->offset
- hq
->base_offset
== NVC0_HW_QUERY_ALLOC_SPACE
)
93 nvc0_hw_query_allocate(nvc0
, q
, NVC0_HW_QUERY_ALLOC_SPACE
);
97 nvc0_hw_query_update(struct nouveau_client
*cli
, struct nvc0_query
*q
)
99 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
102 if (nouveau_fence_signalled(hq
->fence
))
103 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
105 if (hq
->data
[0] == hq
->sequence
)
106 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
111 nvc0_hw_destroy_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
113 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
115 if (hq
->funcs
&& hq
->funcs
->destroy_query
) {
116 hq
->funcs
->destroy_query(nvc0
, hq
);
120 nvc0_hw_query_allocate(nvc0
, q
, 0);
121 nouveau_fence_ref(NULL
, &hq
->fence
);
126 nvc0_hw_begin_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
128 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
129 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
132 if (hq
->funcs
&& hq
->funcs
->begin_query
)
133 return hq
->funcs
->begin_query(nvc0
, hq
);
135 /* For occlusion queries we have to change the storage, because a previous
136 * query might set the initial render conition to false even *after* we re-
137 * initialized it to true.
140 nvc0_hw_query_rotate(nvc0
, q
);
142 /* XXX: can we do this with the GPU, and sync with respect to a previous
145 hq
->data
[0] = hq
->sequence
; /* initialize sequence */
146 hq
->data
[1] = 1; /* initial render condition = true */
147 hq
->data
[4] = hq
->sequence
+ 1; /* for comparison COND_MODE */
153 case PIPE_QUERY_OCCLUSION_COUNTER
:
154 case PIPE_QUERY_OCCLUSION_PREDICATE
:
155 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
156 if (nvc0
->screen
->num_occlusion_queries_active
++) {
157 nvc0_hw_query_get(push
, q
, 0x10, 0x0100f002);
160 BEGIN_NVC0(push
, NVC0_3D(COUNTER_RESET
), 1);
161 PUSH_DATA (push
, NVC0_3D_COUNTER_RESET_SAMPLECNT
);
162 IMMED_NVC0(push
, NVC0_3D(SAMPLECNT_ENABLE
), 1);
163 /* Given that the counter is reset, the contents at 0x10 are
164 * equivalent to doing the query -- we would get hq->sequence as the
165 * payload and 0 as the reported value. This is already set up above
166 * as in the hq->rotate case.
170 case PIPE_QUERY_PRIMITIVES_GENERATED
:
171 nvc0_hw_query_get(push
, q
, 0x10, 0x09005002 | (q
->index
<< 5));
173 case PIPE_QUERY_PRIMITIVES_EMITTED
:
174 nvc0_hw_query_get(push
, q
, 0x10, 0x05805002 | (q
->index
<< 5));
176 case PIPE_QUERY_SO_STATISTICS
:
177 nvc0_hw_query_get(push
, q
, 0x20, 0x05805002 | (q
->index
<< 5));
178 nvc0_hw_query_get(push
, q
, 0x30, 0x06805002 | (q
->index
<< 5));
180 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
181 nvc0_hw_query_get(push
, q
, 0x10, 0x03005002 | (q
->index
<< 5));
183 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
184 /* XXX: This get actually writes the number of overflowed streams */
185 nvc0_hw_query_get(push
, q
, 0x10, 0x0f005002);
187 case PIPE_QUERY_TIME_ELAPSED
:
188 nvc0_hw_query_get(push
, q
, 0x10, 0x00005002);
190 case PIPE_QUERY_PIPELINE_STATISTICS
:
191 nvc0_hw_query_get(push
, q
, 0xc0 + 0x00, 0x00801002); /* VFETCH, VERTICES */
192 nvc0_hw_query_get(push
, q
, 0xc0 + 0x10, 0x01801002); /* VFETCH, PRIMS */
193 nvc0_hw_query_get(push
, q
, 0xc0 + 0x20, 0x02802002); /* VP, LAUNCHES */
194 nvc0_hw_query_get(push
, q
, 0xc0 + 0x30, 0x03806002); /* GP, LAUNCHES */
195 nvc0_hw_query_get(push
, q
, 0xc0 + 0x40, 0x04806002); /* GP, PRIMS_OUT */
196 nvc0_hw_query_get(push
, q
, 0xc0 + 0x50, 0x07804002); /* RAST, PRIMS_IN */
197 nvc0_hw_query_get(push
, q
, 0xc0 + 0x60, 0x08804002); /* RAST, PRIMS_OUT */
198 nvc0_hw_query_get(push
, q
, 0xc0 + 0x70, 0x0980a002); /* ROP, PIXELS */
199 nvc0_hw_query_get(push
, q
, 0xc0 + 0x80, 0x0d808002); /* TCP, LAUNCHES */
200 nvc0_hw_query_get(push
, q
, 0xc0 + 0x90, 0x0e809002); /* TEP, LAUNCHES */
201 ((uint64_t *)hq
->data
)[(12 + 10) * 2] = 0;
206 hq
->state
= NVC0_HW_QUERY_STATE_ACTIVE
;
211 nvc0_hw_end_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
213 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
214 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
216 if (hq
->funcs
&& hq
->funcs
->end_query
) {
217 hq
->funcs
->end_query(nvc0
, hq
);
221 if (hq
->state
!= NVC0_HW_QUERY_STATE_ACTIVE
) {
222 /* some queries don't require 'begin' to be called (e.g. GPU_FINISHED) */
224 nvc0_hw_query_rotate(nvc0
, q
);
227 hq
->state
= NVC0_HW_QUERY_STATE_ENDED
;
230 case PIPE_QUERY_OCCLUSION_COUNTER
:
231 case PIPE_QUERY_OCCLUSION_PREDICATE
:
232 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
233 nvc0_hw_query_get(push
, q
, 0, 0x0100f002);
234 if (--nvc0
->screen
->num_occlusion_queries_active
== 0) {
236 IMMED_NVC0(push
, NVC0_3D(SAMPLECNT_ENABLE
), 0);
239 case PIPE_QUERY_PRIMITIVES_GENERATED
:
240 nvc0_hw_query_get(push
, q
, 0, 0x09005002 | (q
->index
<< 5));
242 case PIPE_QUERY_PRIMITIVES_EMITTED
:
243 nvc0_hw_query_get(push
, q
, 0, 0x05805002 | (q
->index
<< 5));
245 case PIPE_QUERY_SO_STATISTICS
:
246 nvc0_hw_query_get(push
, q
, 0x00, 0x05805002 | (q
->index
<< 5));
247 nvc0_hw_query_get(push
, q
, 0x10, 0x06805002 | (q
->index
<< 5));
249 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
250 nvc0_hw_query_get(push
, q
, 0x00, 0x03005002 | (q
->index
<< 5));
252 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
253 /* XXX: This get actually writes the number of overflowed streams */
254 nvc0_hw_query_get(push
, q
, 0x00, 0x0f005002);
256 case PIPE_QUERY_TIMESTAMP
:
257 case PIPE_QUERY_TIME_ELAPSED
:
258 nvc0_hw_query_get(push
, q
, 0, 0x00005002);
260 case PIPE_QUERY_GPU_FINISHED
:
261 nvc0_hw_query_get(push
, q
, 0, 0x1000f010);
263 case PIPE_QUERY_PIPELINE_STATISTICS
:
264 nvc0_hw_query_get(push
, q
, 0x00, 0x00801002); /* VFETCH, VERTICES */
265 nvc0_hw_query_get(push
, q
, 0x10, 0x01801002); /* VFETCH, PRIMS */
266 nvc0_hw_query_get(push
, q
, 0x20, 0x02802002); /* VP, LAUNCHES */
267 nvc0_hw_query_get(push
, q
, 0x30, 0x03806002); /* GP, LAUNCHES */
268 nvc0_hw_query_get(push
, q
, 0x40, 0x04806002); /* GP, PRIMS_OUT */
269 nvc0_hw_query_get(push
, q
, 0x50, 0x07804002); /* RAST, PRIMS_IN */
270 nvc0_hw_query_get(push
, q
, 0x60, 0x08804002); /* RAST, PRIMS_OUT */
271 nvc0_hw_query_get(push
, q
, 0x70, 0x0980a002); /* ROP, PIXELS */
272 nvc0_hw_query_get(push
, q
, 0x80, 0x0d808002); /* TCP, LAUNCHES */
273 nvc0_hw_query_get(push
, q
, 0x90, 0x0e809002); /* TEP, LAUNCHES */
274 ((uint64_t *)hq
->data
)[10 * 2] = 0;
276 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
277 /* This query is not issued on GPU because disjoint is forced to false */
278 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
280 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
281 /* indexed by TFB buffer instead of by vertex stream */
282 nvc0_hw_query_get(push
, q
, 0x00, 0x0d005002 | (q
->index
<< 5));
288 nouveau_fence_ref(nvc0
->screen
->base
.fence
.current
, &hq
->fence
);
292 nvc0_hw_get_query_result(struct nvc0_context
*nvc0
, struct nvc0_query
*q
,
293 boolean wait
, union pipe_query_result
*result
)
295 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
296 uint64_t *res64
= (uint64_t*)result
;
297 uint32_t *res32
= (uint32_t*)result
;
298 uint8_t *res8
= (uint8_t*)result
;
299 uint64_t *data64
= (uint64_t *)hq
->data
;
302 if (hq
->funcs
&& hq
->funcs
->get_query_result
)
303 return hq
->funcs
->get_query_result(nvc0
, hq
, wait
, result
);
305 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
306 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
308 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
) {
310 if (hq
->state
!= NVC0_HW_QUERY_STATE_FLUSHED
) {
311 hq
->state
= NVC0_HW_QUERY_STATE_FLUSHED
;
312 /* flush for silly apps that spin on GL_QUERY_RESULT_AVAILABLE */
313 PUSH_KICK(nvc0
->base
.pushbuf
);
317 if (nouveau_bo_wait(hq
->bo
, NOUVEAU_BO_RD
, nvc0
->screen
->base
.client
))
319 NOUVEAU_DRV_STAT(&nvc0
->screen
->base
, query_sync_count
, 1);
321 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
324 case PIPE_QUERY_GPU_FINISHED
:
327 case PIPE_QUERY_OCCLUSION_COUNTER
: /* u32 sequence, u32 count, u64 time */
328 res64
[0] = hq
->data
[1] - hq
->data
[5];
330 case PIPE_QUERY_OCCLUSION_PREDICATE
:
331 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
332 res8
[0] = hq
->data
[1] != hq
->data
[5];
334 case PIPE_QUERY_PRIMITIVES_GENERATED
: /* u64 count, u64 time */
335 case PIPE_QUERY_PRIMITIVES_EMITTED
: /* u64 count, u64 time */
336 res64
[0] = data64
[0] - data64
[2];
338 case PIPE_QUERY_SO_STATISTICS
:
339 res64
[0] = data64
[0] - data64
[4];
340 res64
[1] = data64
[2] - data64
[6];
342 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
343 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
344 res8
[0] = data64
[0] != data64
[2];
346 case PIPE_QUERY_TIMESTAMP
:
347 res64
[0] = data64
[1];
349 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
350 res64
[0] = 1000000000;
353 case PIPE_QUERY_TIME_ELAPSED
:
354 res64
[0] = data64
[1] - data64
[3];
356 case PIPE_QUERY_PIPELINE_STATISTICS
:
357 for (i
= 0; i
< 10; ++i
)
358 res64
[i
] = data64
[i
* 2] - data64
[24 + i
* 2];
359 result
->pipeline_statistics
.cs_invocations
= 0;
361 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
362 res32
[0] = hq
->data
[1];
365 assert(0); /* can't happen, we don't create queries with invalid type */
373 nvc0_hw_get_query_result_resource(struct nvc0_context
*nvc0
,
374 struct nvc0_query
*q
,
376 enum pipe_query_value_type result_type
,
378 struct pipe_resource
*resource
,
381 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
382 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
383 struct nv04_resource
*buf
= nv04_resource(resource
);
384 unsigned qoffset
= 0, stride
;
386 assert(!hq
->funcs
|| !hq
->funcs
->get_query_result
);
389 /* TODO: Use a macro to write the availability of the query */
390 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
391 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
392 uint32_t ready
[2] = {hq
->state
== NVC0_HW_QUERY_STATE_READY
};
393 nvc0
->base
.push_cb(&nvc0
->base
, buf
, offset
,
394 result_type
>= PIPE_QUERY_TYPE_I64
? 2 : 1,
397 util_range_add(&buf
->valid_buffer_range
, offset
,
398 offset
+ (result_type
>= PIPE_QUERY_TYPE_I64
? 8 : 4));
400 nvc0_resource_validate(buf
, NOUVEAU_BO_WR
);
405 /* If the fence guarding this query has not been emitted, that makes a lot
406 * of the following logic more complicated.
408 if (hq
->is64bit
&& hq
->fence
->state
< NOUVEAU_FENCE_STATE_EMITTED
)
409 nouveau_fence_emit(hq
->fence
);
411 /* We either need to compute a 32- or 64-bit difference between 2 values,
412 * and then store the result as either a 32- or 64-bit value. As such let's
413 * treat all inputs as 64-bit (and just push an extra 0 for the 32-bit
414 * ones), and have one macro that clamps result to i32, u32, or just
415 * outputs the difference (no need to worry about 64-bit clamping).
417 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
418 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
420 if (wait
&& hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
421 nvc0_hw_query_fifo_wait(nvc0
, q
);
423 nouveau_pushbuf_space(push
, 32, 2, 0);
424 PUSH_REFN (push
, hq
->bo
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
425 PUSH_REFN (push
, buf
->bo
, buf
->domain
| NOUVEAU_BO_WR
);
426 BEGIN_1IC0(push
, NVC0_3D(MACRO_QUERY_BUFFER_WRITE
), 9);
428 case PIPE_QUERY_OCCLUSION_PREDICATE
:
429 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
: /* XXX what if 64-bit? */
430 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
431 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
432 PUSH_DATA(push
, 0x00000001);
435 if (result_type
== PIPE_QUERY_TYPE_I32
)
436 PUSH_DATA(push
, 0x7fffffff);
437 else if (result_type
== PIPE_QUERY_TYPE_U32
)
438 PUSH_DATA(push
, 0xffffffff);
440 PUSH_DATA(push
, 0x00000000);
445 case PIPE_QUERY_SO_STATISTICS
:
448 case PIPE_QUERY_PIPELINE_STATISTICS
:
451 case PIPE_QUERY_TIME_ELAPSED
:
452 case PIPE_QUERY_TIMESTAMP
:
461 if (hq
->is64bit
|| qoffset
) {
462 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ qoffset
+ 16 * index
,
463 8 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
464 if (q
->type
== PIPE_QUERY_TIMESTAMP
) {
468 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ qoffset
+
469 16 * (index
+ stride
),
470 8 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
473 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ 4,
474 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
476 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ 16 + 4,
477 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
481 if (wait
|| hq
->state
== NVC0_HW_QUERY_STATE_READY
) {
484 } else if (hq
->is64bit
) {
485 PUSH_DATA(push
, hq
->fence
->sequence
);
486 nouveau_pushbuf_data(push
, nvc0
->screen
->fence
.bo
, 0,
487 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
489 PUSH_DATA(push
, hq
->sequence
);
490 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
,
491 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
493 PUSH_DATAh(push
, buf
->address
+ offset
);
494 PUSH_DATA (push
, buf
->address
+ offset
);
496 util_range_add(&buf
->valid_buffer_range
, offset
,
497 offset
+ (result_type
>= PIPE_QUERY_TYPE_I64
? 8 : 4));
499 nvc0_resource_validate(buf
, NOUVEAU_BO_WR
);
502 static const struct nvc0_query_funcs hw_query_funcs
= {
503 .destroy_query
= nvc0_hw_destroy_query
,
504 .begin_query
= nvc0_hw_begin_query
,
505 .end_query
= nvc0_hw_end_query
,
506 .get_query_result
= nvc0_hw_get_query_result
,
507 .get_query_result_resource
= nvc0_hw_get_query_result_resource
,
511 nvc0_hw_create_query(struct nvc0_context
*nvc0
, unsigned type
, unsigned index
)
513 struct nvc0_hw_query
*hq
;
514 struct nvc0_query
*q
;
515 unsigned space
= NVC0_HW_QUERY_ALLOC_SPACE
;
517 hq
= nvc0_hw_sm_create_query(nvc0
, type
);
519 hq
->base
.funcs
= &hw_query_funcs
;
520 return (struct nvc0_query
*)hq
;
523 hq
= nvc0_hw_metric_create_query(nvc0
, type
);
525 hq
->base
.funcs
= &hw_query_funcs
;
526 return (struct nvc0_query
*)hq
;
529 hq
= CALLOC_STRUCT(nvc0_hw_query
);
534 q
->funcs
= &hw_query_funcs
;
539 case PIPE_QUERY_OCCLUSION_COUNTER
:
540 case PIPE_QUERY_OCCLUSION_PREDICATE
:
541 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
543 space
= NVC0_HW_QUERY_ALLOC_SPACE
;
545 case PIPE_QUERY_PIPELINE_STATISTICS
:
549 case PIPE_QUERY_SO_STATISTICS
:
553 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
554 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
555 case PIPE_QUERY_PRIMITIVES_GENERATED
:
556 case PIPE_QUERY_PRIMITIVES_EMITTED
:
560 case PIPE_QUERY_TIME_ELAPSED
:
561 case PIPE_QUERY_TIMESTAMP
:
562 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
563 case PIPE_QUERY_GPU_FINISHED
:
566 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
570 debug_printf("invalid query type: %u\n", type
);
575 if (!nvc0_hw_query_allocate(nvc0
, q
, space
)) {
581 /* we advance before query_begin ! */
582 hq
->offset
-= hq
->rotate
;
583 hq
->data
-= hq
->rotate
/ sizeof(*hq
->data
);
586 hq
->data
[0] = 0; /* initialize sequence */
592 nvc0_hw_get_driver_query_info(struct nvc0_screen
*screen
, unsigned id
,
593 struct pipe_driver_query_info
*info
)
595 int num_hw_sm_queries
= 0, num_hw_metric_queries
= 0;
597 num_hw_sm_queries
= nvc0_hw_sm_get_driver_query_info(screen
, 0, NULL
);
598 num_hw_metric_queries
=
599 nvc0_hw_metric_get_driver_query_info(screen
, 0, NULL
);
602 return num_hw_sm_queries
+ num_hw_metric_queries
;
604 if (id
< num_hw_sm_queries
)
605 return nvc0_hw_sm_get_driver_query_info(screen
, id
, info
);
607 return nvc0_hw_metric_get_driver_query_info(screen
,
608 id
- num_hw_sm_queries
, info
);
612 nvc0_hw_query_pushbuf_submit(struct nouveau_pushbuf
*push
,
613 struct nvc0_query
*q
, unsigned result_offset
)
615 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
617 PUSH_REFN(push
, hq
->bo
, NOUVEAU_BO_RD
| NOUVEAU_BO_GART
);
618 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ result_offset
, 4 |
619 NVC0_IB_ENTRY_1_NO_PREFETCH
);
623 nvc0_hw_query_fifo_wait(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
625 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
626 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
627 unsigned offset
= hq
->offset
;
629 /* ensure the query's fence has been emitted */
630 if (hq
->is64bit
&& hq
->fence
->state
< NOUVEAU_FENCE_STATE_EMITTED
)
631 nouveau_fence_emit(hq
->fence
);
634 PUSH_REFN (push
, hq
->bo
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
635 BEGIN_NVC0(push
, SUBC_3D(NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH
), 4);
637 PUSH_DATAh(push
, nvc0
->screen
->fence
.bo
->offset
);
638 PUSH_DATA (push
, nvc0
->screen
->fence
.bo
->offset
);
639 PUSH_DATA (push
, hq
->fence
->sequence
);
641 PUSH_DATAh(push
, hq
->bo
->offset
+ offset
);
642 PUSH_DATA (push
, hq
->bo
->offset
+ offset
);
643 PUSH_DATA (push
, hq
->sequence
);
645 PUSH_DATA (push
, (1 << 12) |
646 NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL
);