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 */
205 hq
->state
= NVC0_HW_QUERY_STATE_ACTIVE
;
210 nvc0_hw_end_query(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
212 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
213 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
215 if (hq
->funcs
&& hq
->funcs
->end_query
) {
216 hq
->funcs
->end_query(nvc0
, hq
);
220 if (hq
->state
!= NVC0_HW_QUERY_STATE_ACTIVE
) {
221 /* some queries don't require 'begin' to be called (e.g. GPU_FINISHED) */
223 nvc0_hw_query_rotate(nvc0
, q
);
226 hq
->state
= NVC0_HW_QUERY_STATE_ENDED
;
229 case PIPE_QUERY_OCCLUSION_COUNTER
:
230 case PIPE_QUERY_OCCLUSION_PREDICATE
:
231 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
232 nvc0_hw_query_get(push
, q
, 0, 0x0100f002);
233 if (--nvc0
->screen
->num_occlusion_queries_active
== 0) {
235 IMMED_NVC0(push
, NVC0_3D(SAMPLECNT_ENABLE
), 0);
238 case PIPE_QUERY_PRIMITIVES_GENERATED
:
239 nvc0_hw_query_get(push
, q
, 0, 0x09005002 | (q
->index
<< 5));
241 case PIPE_QUERY_PRIMITIVES_EMITTED
:
242 nvc0_hw_query_get(push
, q
, 0, 0x05805002 | (q
->index
<< 5));
244 case PIPE_QUERY_SO_STATISTICS
:
245 nvc0_hw_query_get(push
, q
, 0x00, 0x05805002 | (q
->index
<< 5));
246 nvc0_hw_query_get(push
, q
, 0x10, 0x06805002 | (q
->index
<< 5));
248 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
249 nvc0_hw_query_get(push
, q
, 0x00, 0x03005002 | (q
->index
<< 5));
251 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
252 /* XXX: This get actually writes the number of overflowed streams */
253 nvc0_hw_query_get(push
, q
, 0x00, 0x0f005002);
255 case PIPE_QUERY_TIMESTAMP
:
256 case PIPE_QUERY_TIME_ELAPSED
:
257 nvc0_hw_query_get(push
, q
, 0, 0x00005002);
259 case PIPE_QUERY_GPU_FINISHED
:
260 nvc0_hw_query_get(push
, q
, 0, 0x1000f010);
262 case PIPE_QUERY_PIPELINE_STATISTICS
:
263 nvc0_hw_query_get(push
, q
, 0x00, 0x00801002); /* VFETCH, VERTICES */
264 nvc0_hw_query_get(push
, q
, 0x10, 0x01801002); /* VFETCH, PRIMS */
265 nvc0_hw_query_get(push
, q
, 0x20, 0x02802002); /* VP, LAUNCHES */
266 nvc0_hw_query_get(push
, q
, 0x30, 0x03806002); /* GP, LAUNCHES */
267 nvc0_hw_query_get(push
, q
, 0x40, 0x04806002); /* GP, PRIMS_OUT */
268 nvc0_hw_query_get(push
, q
, 0x50, 0x07804002); /* RAST, PRIMS_IN */
269 nvc0_hw_query_get(push
, q
, 0x60, 0x08804002); /* RAST, PRIMS_OUT */
270 nvc0_hw_query_get(push
, q
, 0x70, 0x0980a002); /* ROP, PIXELS */
271 nvc0_hw_query_get(push
, q
, 0x80, 0x0d808002); /* TCP, LAUNCHES */
272 nvc0_hw_query_get(push
, q
, 0x90, 0x0e809002); /* TEP, LAUNCHES */
274 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
275 /* This query is not issued on GPU because disjoint is forced to false */
276 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
278 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
279 /* indexed by TFB buffer instead of by vertex stream */
280 nvc0_hw_query_get(push
, q
, 0x00, 0x0d005002 | (q
->index
<< 5));
286 nouveau_fence_ref(nvc0
->screen
->base
.fence
.current
, &hq
->fence
);
290 nvc0_hw_get_query_result(struct nvc0_context
*nvc0
, struct nvc0_query
*q
,
291 boolean wait
, union pipe_query_result
*result
)
293 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
294 uint64_t *res64
= (uint64_t*)result
;
295 uint32_t *res32
= (uint32_t*)result
;
296 uint8_t *res8
= (uint8_t*)result
;
297 uint64_t *data64
= (uint64_t *)hq
->data
;
300 if (hq
->funcs
&& hq
->funcs
->get_query_result
)
301 return hq
->funcs
->get_query_result(nvc0
, hq
, wait
, result
);
303 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
304 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
306 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
) {
308 if (hq
->state
!= NVC0_HW_QUERY_STATE_FLUSHED
) {
309 hq
->state
= NVC0_HW_QUERY_STATE_FLUSHED
;
310 /* flush for silly apps that spin on GL_QUERY_RESULT_AVAILABLE */
311 PUSH_KICK(nvc0
->base
.pushbuf
);
315 if (nouveau_bo_wait(hq
->bo
, NOUVEAU_BO_RD
, nvc0
->screen
->base
.client
))
317 NOUVEAU_DRV_STAT(&nvc0
->screen
->base
, query_sync_count
, 1);
319 hq
->state
= NVC0_HW_QUERY_STATE_READY
;
322 case PIPE_QUERY_GPU_FINISHED
:
325 case PIPE_QUERY_OCCLUSION_COUNTER
: /* u32 sequence, u32 count, u64 time */
326 res64
[0] = hq
->data
[1] - hq
->data
[5];
328 case PIPE_QUERY_OCCLUSION_PREDICATE
:
329 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
330 res8
[0] = hq
->data
[1] != hq
->data
[5];
332 case PIPE_QUERY_PRIMITIVES_GENERATED
: /* u64 count, u64 time */
333 case PIPE_QUERY_PRIMITIVES_EMITTED
: /* u64 count, u64 time */
334 res64
[0] = data64
[0] - data64
[2];
336 case PIPE_QUERY_SO_STATISTICS
:
337 res64
[0] = data64
[0] - data64
[4];
338 res64
[1] = data64
[2] - data64
[6];
340 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
341 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
342 res8
[0] = data64
[0] != data64
[2];
344 case PIPE_QUERY_TIMESTAMP
:
345 res64
[0] = data64
[1];
347 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
348 res64
[0] = 1000000000;
351 case PIPE_QUERY_TIME_ELAPSED
:
352 res64
[0] = data64
[1] - data64
[3];
354 case PIPE_QUERY_PIPELINE_STATISTICS
:
355 for (i
= 0; i
< 10; ++i
)
356 res64
[i
] = data64
[i
* 2] - data64
[24 + i
* 2];
357 result
->pipeline_statistics
.cs_invocations
= 0;
359 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
360 res32
[0] = hq
->data
[1];
363 assert(0); /* can't happen, we don't create queries with invalid type */
371 nvc0_hw_get_query_result_resource(struct nvc0_context
*nvc0
,
372 struct nvc0_query
*q
,
374 enum pipe_query_value_type result_type
,
376 struct pipe_resource
*resource
,
379 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
380 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
381 struct nv04_resource
*buf
= nv04_resource(resource
);
382 unsigned qoffset
= 0, stride
;
384 assert(!hq
->funcs
|| !hq
->funcs
->get_query_result
);
387 /* TODO: Use a macro to write the availability of the query */
388 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
389 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
390 uint32_t ready
[2] = {hq
->state
== NVC0_HW_QUERY_STATE_READY
};
391 nvc0
->base
.push_cb(&nvc0
->base
, buf
, offset
,
392 result_type
>= PIPE_QUERY_TYPE_I64
? 2 : 1,
395 util_range_add(&buf
->valid_buffer_range
, offset
,
396 offset
+ (result_type
>= PIPE_QUERY_TYPE_I64
? 8 : 4));
398 nvc0_resource_validate(buf
, NOUVEAU_BO_WR
);
403 /* If the fence guarding this query has not been emitted, that makes a lot
404 * of the following logic more complicated.
406 if (hq
->is64bit
&& hq
->fence
->state
< NOUVEAU_FENCE_STATE_EMITTED
)
407 nouveau_fence_emit(hq
->fence
);
409 /* We either need to compute a 32- or 64-bit difference between 2 values,
410 * and then store the result as either a 32- or 64-bit value. As such let's
411 * treat all inputs as 64-bit (and just push an extra 0 for the 32-bit
412 * ones), and have one macro that clamps result to i32, u32, or just
413 * outputs the difference (no need to worry about 64-bit clamping).
415 if (hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
416 nvc0_hw_query_update(nvc0
->screen
->base
.client
, q
);
418 if (wait
&& hq
->state
!= NVC0_HW_QUERY_STATE_READY
)
419 nvc0_hw_query_fifo_wait(nvc0
, q
);
421 nouveau_pushbuf_space(push
, 32, 2, 0);
422 PUSH_REFN (push
, hq
->bo
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
423 PUSH_REFN (push
, buf
->bo
, buf
->domain
| NOUVEAU_BO_WR
);
424 BEGIN_1IC0(push
, NVC0_3D(MACRO_QUERY_BUFFER_WRITE
), 9);
426 case PIPE_QUERY_OCCLUSION_PREDICATE
:
427 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
: /* XXX what if 64-bit? */
428 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
429 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
430 PUSH_DATA(push
, 0x00000001);
433 if (result_type
== PIPE_QUERY_TYPE_I32
)
434 PUSH_DATA(push
, 0x7fffffff);
435 else if (result_type
== PIPE_QUERY_TYPE_U32
)
436 PUSH_DATA(push
, 0xffffffff);
438 PUSH_DATA(push
, 0x00000000);
443 case PIPE_QUERY_SO_STATISTICS
:
446 case PIPE_QUERY_PIPELINE_STATISTICS
:
449 case PIPE_QUERY_TIME_ELAPSED
:
450 case PIPE_QUERY_TIMESTAMP
:
459 if (hq
->is64bit
|| qoffset
) {
460 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ qoffset
+ 16 * index
,
461 8 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
462 if (q
->type
== PIPE_QUERY_TIMESTAMP
) {
466 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ qoffset
+
467 16 * (index
+ stride
),
468 8 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
471 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ 4,
472 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
474 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ 16 + 4,
475 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
479 if (wait
|| hq
->state
== NVC0_HW_QUERY_STATE_READY
) {
482 } else if (hq
->is64bit
) {
483 PUSH_DATA(push
, hq
->fence
->sequence
);
484 nouveau_pushbuf_data(push
, nvc0
->screen
->fence
.bo
, 0,
485 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
487 PUSH_DATA(push
, hq
->sequence
);
488 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
,
489 4 | NVC0_IB_ENTRY_1_NO_PREFETCH
);
491 PUSH_DATAh(push
, buf
->address
+ offset
);
492 PUSH_DATA (push
, buf
->address
+ offset
);
494 util_range_add(&buf
->valid_buffer_range
, offset
,
495 offset
+ (result_type
>= PIPE_QUERY_TYPE_I64
? 8 : 4));
497 nvc0_resource_validate(buf
, NOUVEAU_BO_WR
);
500 static const struct nvc0_query_funcs hw_query_funcs
= {
501 .destroy_query
= nvc0_hw_destroy_query
,
502 .begin_query
= nvc0_hw_begin_query
,
503 .end_query
= nvc0_hw_end_query
,
504 .get_query_result
= nvc0_hw_get_query_result
,
505 .get_query_result_resource
= nvc0_hw_get_query_result_resource
,
509 nvc0_hw_create_query(struct nvc0_context
*nvc0
, unsigned type
, unsigned index
)
511 struct nvc0_hw_query
*hq
;
512 struct nvc0_query
*q
;
513 unsigned space
= NVC0_HW_QUERY_ALLOC_SPACE
;
515 hq
= nvc0_hw_sm_create_query(nvc0
, type
);
517 hq
->base
.funcs
= &hw_query_funcs
;
518 return (struct nvc0_query
*)hq
;
521 hq
= nvc0_hw_metric_create_query(nvc0
, type
);
523 hq
->base
.funcs
= &hw_query_funcs
;
524 return (struct nvc0_query
*)hq
;
527 hq
= CALLOC_STRUCT(nvc0_hw_query
);
532 q
->funcs
= &hw_query_funcs
;
537 case PIPE_QUERY_OCCLUSION_COUNTER
:
538 case PIPE_QUERY_OCCLUSION_PREDICATE
:
539 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
541 space
= NVC0_HW_QUERY_ALLOC_SPACE
;
543 case PIPE_QUERY_PIPELINE_STATISTICS
:
547 case PIPE_QUERY_SO_STATISTICS
:
551 case PIPE_QUERY_SO_OVERFLOW_PREDICATE
:
552 case PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE
:
553 case PIPE_QUERY_PRIMITIVES_GENERATED
:
554 case PIPE_QUERY_PRIMITIVES_EMITTED
:
558 case PIPE_QUERY_TIME_ELAPSED
:
559 case PIPE_QUERY_TIMESTAMP
:
560 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
561 case PIPE_QUERY_GPU_FINISHED
:
564 case NVC0_HW_QUERY_TFB_BUFFER_OFFSET
:
568 debug_printf("invalid query type: %u\n", type
);
573 if (!nvc0_hw_query_allocate(nvc0
, q
, space
)) {
579 /* we advance before query_begin ! */
580 hq
->offset
-= hq
->rotate
;
581 hq
->data
-= hq
->rotate
/ sizeof(*hq
->data
);
584 hq
->data
[0] = 0; /* initialize sequence */
590 nvc0_hw_get_driver_query_info(struct nvc0_screen
*screen
, unsigned id
,
591 struct pipe_driver_query_info
*info
)
593 int num_hw_sm_queries
= 0, num_hw_metric_queries
= 0;
595 num_hw_sm_queries
= nvc0_hw_sm_get_driver_query_info(screen
, 0, NULL
);
596 num_hw_metric_queries
=
597 nvc0_hw_metric_get_driver_query_info(screen
, 0, NULL
);
600 return num_hw_sm_queries
+ num_hw_metric_queries
;
602 if (id
< num_hw_sm_queries
)
603 return nvc0_hw_sm_get_driver_query_info(screen
, id
, info
);
605 return nvc0_hw_metric_get_driver_query_info(screen
,
606 id
- num_hw_sm_queries
, info
);
610 nvc0_hw_query_pushbuf_submit(struct nouveau_pushbuf
*push
,
611 struct nvc0_query
*q
, unsigned result_offset
)
613 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
615 PUSH_REFN(push
, hq
->bo
, NOUVEAU_BO_RD
| NOUVEAU_BO_GART
);
616 nouveau_pushbuf_data(push
, hq
->bo
, hq
->offset
+ result_offset
, 4 |
617 NVC0_IB_ENTRY_1_NO_PREFETCH
);
621 nvc0_hw_query_fifo_wait(struct nvc0_context
*nvc0
, struct nvc0_query
*q
)
623 struct nouveau_pushbuf
*push
= nvc0
->base
.pushbuf
;
624 struct nvc0_hw_query
*hq
= nvc0_hw_query(q
);
625 unsigned offset
= hq
->offset
;
627 /* ensure the query's fence has been emitted */
628 if (hq
->is64bit
&& hq
->fence
->state
< NOUVEAU_FENCE_STATE_EMITTED
)
629 nouveau_fence_emit(hq
->fence
);
632 PUSH_REFN (push
, hq
->bo
, NOUVEAU_BO_GART
| NOUVEAU_BO_RD
);
633 BEGIN_NVC0(push
, SUBC_3D(NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH
), 4);
635 PUSH_DATAh(push
, nvc0
->screen
->fence
.bo
->offset
);
636 PUSH_DATA (push
, nvc0
->screen
->fence
.bo
->offset
);
637 PUSH_DATA (push
, hq
->fence
->sequence
);
639 PUSH_DATAh(push
, hq
->bo
->offset
+ offset
);
640 PUSH_DATA (push
, hq
->bo
->offset
+ offset
);
641 PUSH_DATA (push
, hq
->sequence
);
643 PUSH_DATA (push
, (1 << 12) |
644 NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL
);