etnaviv: reset indexed rendering information when not rendering indexed
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_query_sw.c
1 /*
2 * Copyright (c) 2016 Etnaviv Project
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 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
26 */
27
28 #include "os/os_time.h"
29 #include "pipe/p_state.h"
30 #include "util/u_inlines.h"
31 #include "util/u_memory.h"
32 #include "util/u_string.h"
33
34 #include "etnaviv_context.h"
35 #include "etnaviv_query_sw.h"
36
37 static void
38 etna_sw_destroy_query(struct etna_context *ctx, struct etna_query *q)
39 {
40 struct etna_sw_query *sq = etna_sw_query(q);
41
42 FREE(sq);
43 }
44
45 static uint64_t
46 read_counter(struct etna_context *ctx, int type)
47 {
48 switch (type) {
49 case PIPE_QUERY_PRIMITIVES_EMITTED:
50 return ctx->stats.prims_emitted;
51 case ETNA_QUERY_DRAW_CALLS:
52 return ctx->stats.draw_calls;
53 case ETNA_QUERY_RS_OPERATIONS:
54 return ctx->stats.rs_operations;
55 }
56
57 return 0;
58 }
59
60 static boolean
61 etna_sw_begin_query(struct etna_context *ctx, struct etna_query *q)
62 {
63 struct etna_sw_query *sq = etna_sw_query(q);
64
65 q->active = true;
66 sq->begin_value = read_counter(ctx, q->type);
67
68 return true;
69 }
70
71 static void
72 etna_sw_end_query(struct etna_context *ctx, struct etna_query *q)
73 {
74 struct etna_sw_query *sq = etna_sw_query(q);
75
76 q->active = false;
77 sq->end_value = read_counter(ctx, q->type);
78 }
79
80 static boolean
81 etna_sw_get_query_result(struct etna_context *ctx, struct etna_query *q,
82 boolean wait, union pipe_query_result *result)
83 {
84 struct etna_sw_query *sq = etna_sw_query(q);
85
86 if (q->active)
87 return false;
88
89 util_query_clear_result(result, q->type);
90 result->u64 = sq->end_value - sq->begin_value;
91
92 return true;
93 }
94
95 static const struct etna_query_funcs sw_query_funcs = {
96 .destroy_query = etna_sw_destroy_query,
97 .begin_query = etna_sw_begin_query,
98 .end_query = etna_sw_end_query,
99 .get_query_result = etna_sw_get_query_result,
100 };
101
102 struct etna_query *
103 etna_sw_create_query(struct etna_context *ctx, unsigned query_type)
104 {
105 struct etna_sw_query *sq;
106 struct etna_query *q;
107
108 switch (query_type) {
109 case PIPE_QUERY_PRIMITIVES_EMITTED:
110 case ETNA_QUERY_DRAW_CALLS:
111 case ETNA_QUERY_RS_OPERATIONS:
112 break;
113 default:
114 return NULL;
115 }
116
117 sq = CALLOC_STRUCT(etna_sw_query);
118 if (!sq)
119 return NULL;
120
121 q = &sq->base;
122 q->funcs = &sw_query_funcs;
123 q->type = query_type;
124
125 return q;
126 }