1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #include "draw/draw_context.h"
33 #include "os/os_time.h"
34 #include "pipe/p_defines.h"
35 #include "util/u_memory.h"
36 #include "sp_context.h"
40 struct softpipe_query
{
44 struct pipe_query_data_so_statistics so
;
45 unsigned num_primitives_generated
;
47 struct pipe_query_data_pipeline_statistics stats
;
51 static struct softpipe_query
*softpipe_query( struct pipe_query
*p
)
53 return (struct softpipe_query
*)p
;
56 static struct pipe_query
*
57 softpipe_create_query(struct pipe_context
*pipe
,
60 struct softpipe_query
* sq
;
62 assert(type
== PIPE_QUERY_OCCLUSION_COUNTER
||
63 type
== PIPE_QUERY_TIME_ELAPSED
||
64 type
== PIPE_QUERY_SO_STATISTICS
||
65 type
== PIPE_QUERY_PRIMITIVES_EMITTED
||
66 type
== PIPE_QUERY_PRIMITIVES_GENERATED
||
67 type
== PIPE_QUERY_PIPELINE_STATISTICS
||
68 type
== PIPE_QUERY_GPU_FINISHED
||
69 type
== PIPE_QUERY_TIMESTAMP
||
70 type
== PIPE_QUERY_TIMESTAMP_DISJOINT
);
71 sq
= CALLOC_STRUCT( softpipe_query
);
74 return (struct pipe_query
*)sq
;
79 softpipe_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
86 softpipe_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
88 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
89 struct softpipe_query
*sq
= softpipe_query(q
);
92 case PIPE_QUERY_OCCLUSION_COUNTER
:
93 sq
->start
= softpipe
->occlusion_count
;
95 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
96 case PIPE_QUERY_TIME_ELAPSED
:
97 sq
->start
= os_time_get_nano();
99 case PIPE_QUERY_SO_STATISTICS
:
100 sq
->so
.primitives_storage_needed
= 0;
101 case PIPE_QUERY_PRIMITIVES_EMITTED
:
102 sq
->so
.num_primitives_written
= 0;
103 softpipe
->so_stats
.num_primitives_written
= 0;
105 case PIPE_QUERY_PRIMITIVES_GENERATED
:
106 sq
->num_primitives_generated
= 0;
107 softpipe
->num_primitives_generated
= 0;
109 case PIPE_QUERY_TIMESTAMP
:
110 case PIPE_QUERY_GPU_FINISHED
:
112 case PIPE_QUERY_PIPELINE_STATISTICS
:
113 /* reset our cache */
114 if (softpipe
->active_statistics_queries
== 0) {
115 memset(&softpipe
->pipeline_statistics
, 0,
116 sizeof(softpipe
->pipeline_statistics
));
118 memcpy(&sq
->stats
, &softpipe
->pipeline_statistics
,
120 softpipe
->active_statistics_queries
++;
126 softpipe
->active_query_count
++;
127 softpipe
->dirty
|= SP_NEW_QUERY
;
132 softpipe_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
134 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
135 struct softpipe_query
*sq
= softpipe_query(q
);
137 softpipe
->active_query_count
--;
139 case PIPE_QUERY_OCCLUSION_COUNTER
:
140 sq
->end
= softpipe
->occlusion_count
;
142 case PIPE_QUERY_TIMESTAMP
:
145 case PIPE_QUERY_TIMESTAMP_DISJOINT
:
146 case PIPE_QUERY_TIME_ELAPSED
:
147 sq
->end
= os_time_get_nano();
149 case PIPE_QUERY_SO_STATISTICS
:
150 sq
->so
.primitives_storage_needed
=
151 softpipe
->so_stats
.primitives_storage_needed
;
152 case PIPE_QUERY_PRIMITIVES_EMITTED
:
153 sq
->so
.num_primitives_written
=
154 softpipe
->so_stats
.num_primitives_written
;
156 case PIPE_QUERY_PRIMITIVES_GENERATED
:
157 sq
->num_primitives_generated
= softpipe
->num_primitives_generated
;
159 case PIPE_QUERY_GPU_FINISHED
:
161 case PIPE_QUERY_PIPELINE_STATISTICS
:
162 sq
->stats
.ia_vertices
=
163 softpipe
->pipeline_statistics
.ia_vertices
- sq
->stats
.ia_vertices
;
164 sq
->stats
.ia_primitives
=
165 softpipe
->pipeline_statistics
.ia_primitives
- sq
->stats
.ia_primitives
;
166 sq
->stats
.vs_invocations
=
167 softpipe
->pipeline_statistics
.vs_invocations
- sq
->stats
.vs_invocations
;
168 sq
->stats
.gs_invocations
=
169 softpipe
->pipeline_statistics
.gs_invocations
- sq
->stats
.gs_invocations
;
170 sq
->stats
.gs_primitives
=
171 softpipe
->pipeline_statistics
.gs_primitives
- sq
->stats
.gs_primitives
;
172 sq
->stats
.c_invocations
=
173 softpipe
->pipeline_statistics
.c_invocations
- sq
->stats
.c_invocations
;
174 sq
->stats
.c_primitives
=
175 softpipe
->pipeline_statistics
.c_primitives
- sq
->stats
.c_primitives
;
176 sq
->stats
.ps_invocations
=
177 softpipe
->pipeline_statistics
.ps_invocations
- sq
->stats
.ps_invocations
;
179 softpipe
->active_statistics_queries
--;
185 softpipe
->dirty
|= SP_NEW_QUERY
;
190 softpipe_get_query_result(struct pipe_context
*pipe
,
191 struct pipe_query
*q
,
193 union pipe_query_result
*vresult
)
195 struct softpipe_query
*sq
= softpipe_query(q
);
196 uint64_t *result
= (uint64_t*)vresult
;
199 case PIPE_QUERY_SO_STATISTICS
:
200 memcpy(vresult
, &sq
->so
,
201 sizeof(struct pipe_query_data_so_statistics
));
203 case PIPE_QUERY_PIPELINE_STATISTICS
:
204 memcpy(vresult
, &sq
->stats
,
205 sizeof(struct pipe_query_data_pipeline_statistics
));;
207 case PIPE_QUERY_GPU_FINISHED
:
210 case PIPE_QUERY_TIMESTAMP_DISJOINT
: {
211 struct pipe_query_data_timestamp_disjoint td
;
212 /* os_get_time_nano return nanoseconds */
213 td
.frequency
= UINT64_C(1000000000);
214 td
.disjoint
= sq
->end
!= sq
->start
;
216 sizeof(struct pipe_query_data_timestamp_disjoint
));
219 case PIPE_QUERY_PRIMITIVES_EMITTED
:
220 *result
= sq
->so
.num_primitives_written
;
222 case PIPE_QUERY_PRIMITIVES_GENERATED
:
223 *result
= sq
->num_primitives_generated
;
226 *result
= sq
->end
- sq
->start
;
234 * Called by rendering function to check rendering is conditional.
235 * \return TRUE if we should render, FALSE if we should skip rendering
238 softpipe_check_render_cond(struct softpipe_context
*sp
)
240 struct pipe_context
*pipe
= &sp
->pipe
;
244 if (!sp
->render_cond_query
) {
245 return TRUE
; /* no query predicate, draw normally */
248 wait
= (sp
->render_cond_mode
== PIPE_RENDER_COND_WAIT
||
249 sp
->render_cond_mode
== PIPE_RENDER_COND_BY_REGION_WAIT
);
251 b
= pipe
->get_query_result(pipe
, sp
->render_cond_query
, wait
,
260 void softpipe_init_query_funcs(struct softpipe_context
*softpipe
)
262 softpipe
->pipe
.create_query
= softpipe_create_query
;
263 softpipe
->pipe
.destroy_query
= softpipe_destroy_query
;
264 softpipe
->pipe
.begin_query
= softpipe_begin_query
;
265 softpipe
->pipe
.end_query
= softpipe_end_query
;
266 softpipe
->pipe
.get_query_result
= softpipe_get_query_result
;