• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-file-style: "k&r"; ttxab-width 4; indent-tabs-mode: t; -*- */
2 
3 /*
4  * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28 
29 #include "pipe/p_state.h"
30 #include "util/u_memory.h"
31 
32 #include "freedreno_query.h"
33 #include "freedreno_query_sw.h"
34 #include "freedreno_query_hw.h"
35 #include "freedreno_context.h"
36 #include "freedreno_util.h"
37 
38 /*
39  * Pipe Query interface:
40  */
41 
42 static struct pipe_query *
fd_create_query(struct pipe_context * pctx,unsigned query_type,unsigned index)43 fd_create_query(struct pipe_context *pctx, unsigned query_type, unsigned index)
44 {
45 	struct fd_context *ctx = fd_context(pctx);
46 	struct fd_query *q;
47 
48 	q = fd_sw_create_query(ctx, query_type);
49 	if (!q && ctx->create_query)
50 		q = ctx->create_query(ctx, query_type);
51 
52 	return (struct pipe_query *) q;
53 }
54 
55 static void
fd_destroy_query(struct pipe_context * pctx,struct pipe_query * pq)56 fd_destroy_query(struct pipe_context *pctx, struct pipe_query *pq)
57 {
58 	struct fd_query *q = fd_query(pq);
59 	q->funcs->destroy_query(fd_context(pctx), q);
60 }
61 
62 static boolean
fd_begin_query(struct pipe_context * pctx,struct pipe_query * pq)63 fd_begin_query(struct pipe_context *pctx, struct pipe_query *pq)
64 {
65 	struct fd_query *q = fd_query(pq);
66 	boolean ret;
67 
68 	if (q->active)
69 		return false;
70 
71 	ret = q->funcs->begin_query(fd_context(pctx), q);
72 	q->active = ret;
73 
74 	return ret;
75 }
76 
77 static bool
fd_end_query(struct pipe_context * pctx,struct pipe_query * pq)78 fd_end_query(struct pipe_context *pctx, struct pipe_query *pq)
79 {
80 	struct fd_query *q = fd_query(pq);
81 
82 	/* there are a couple special cases, which don't have
83 	 * a matching ->begin_query():
84 	 */
85 	if (skip_begin_query(q->type) && !q->active)
86 		fd_begin_query(pctx, pq);
87 
88 	if (!q->active)
89 		return false;
90 
91 	q->funcs->end_query(fd_context(pctx), q);
92 	q->active = false;
93 
94 	return true;
95 }
96 
97 static boolean
fd_get_query_result(struct pipe_context * pctx,struct pipe_query * pq,boolean wait,union pipe_query_result * result)98 fd_get_query_result(struct pipe_context *pctx, struct pipe_query *pq,
99 		boolean wait, union pipe_query_result *result)
100 {
101 	struct fd_query *q = fd_query(pq);
102 
103 	if (q->active)
104 		return false;
105 
106 	util_query_clear_result(result, q->type);
107 
108 	return q->funcs->get_query_result(fd_context(pctx), q, wait, result);
109 }
110 
111 static void
fd_render_condition(struct pipe_context * pctx,struct pipe_query * pq,boolean condition,enum pipe_render_cond_flag mode)112 fd_render_condition(struct pipe_context *pctx, struct pipe_query *pq,
113 					boolean condition, enum pipe_render_cond_flag mode)
114 {
115 	struct fd_context *ctx = fd_context(pctx);
116 	ctx->cond_query = pq;
117 	ctx->cond_cond = condition;
118 	ctx->cond_mode = mode;
119 }
120 
121 static int
fd_get_driver_query_info(struct pipe_screen * pscreen,unsigned index,struct pipe_driver_query_info * info)122 fd_get_driver_query_info(struct pipe_screen *pscreen,
123 		unsigned index, struct pipe_driver_query_info *info)
124 {
125 	struct pipe_driver_query_info list[] = {
126 			{"draw-calls", FD_QUERY_DRAW_CALLS, {0}},
127 			{"batches", FD_QUERY_BATCH_TOTAL, {0}},
128 			{"batches-sysmem", FD_QUERY_BATCH_SYSMEM, {0}},
129 			{"batches-gmem", FD_QUERY_BATCH_GMEM, {0}},
130 			{"batches-nondraw", FD_QUERY_BATCH_NONDRAW, {0}},
131 			{"restores", FD_QUERY_BATCH_RESTORE, {0}},
132 			{"prims-emitted", PIPE_QUERY_PRIMITIVES_EMITTED, {0}},
133 			{"staging", FD_QUERY_STAGING_UPLOADS, {0}},
134 			{"shadow", FD_QUERY_SHADOW_UPLOADS, {0}},
135 	};
136 
137 	if (!info)
138 		return ARRAY_SIZE(list);
139 
140 	if (index >= ARRAY_SIZE(list))
141 		return 0;
142 
143 	*info = list[index];
144 	return 1;
145 }
146 
147 static void
fd_set_active_query_state(struct pipe_context * pipe,boolean enable)148 fd_set_active_query_state(struct pipe_context *pipe, boolean enable)
149 {
150 }
151 
152 void
fd_query_screen_init(struct pipe_screen * pscreen)153 fd_query_screen_init(struct pipe_screen *pscreen)
154 {
155 	pscreen->get_driver_query_info = fd_get_driver_query_info;
156 }
157 
158 void
fd_query_context_init(struct pipe_context * pctx)159 fd_query_context_init(struct pipe_context *pctx)
160 {
161 	pctx->create_query = fd_create_query;
162 	pctx->destroy_query = fd_destroy_query;
163 	pctx->begin_query = fd_begin_query;
164 	pctx->end_query = fd_end_query;
165 	pctx->get_query_result = fd_get_query_result;
166 	pctx->set_active_query_state = fd_set_active_query_state;
167 	pctx->render_condition = fd_render_condition;
168 }
169