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
;
48 static struct softpipe_query
*softpipe_query( struct pipe_query
*p
)
50 return (struct softpipe_query
*)p
;
53 static struct pipe_query
*
54 softpipe_create_query(struct pipe_context
*pipe
,
57 struct softpipe_query
* sq
;
59 assert(type
== PIPE_QUERY_OCCLUSION_COUNTER
||
60 type
== PIPE_QUERY_TIME_ELAPSED
||
61 type
== PIPE_QUERY_SO_STATISTICS
||
62 type
== PIPE_QUERY_GPU_FINISHED
);
63 sq
= CALLOC_STRUCT( softpipe_query
);
66 return (struct pipe_query
*)sq
;
71 softpipe_destroy_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
78 softpipe_begin_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
80 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
81 struct softpipe_query
*sq
= softpipe_query(q
);
84 case PIPE_QUERY_OCCLUSION_COUNTER
:
85 sq
->start
= softpipe
->occlusion_count
;
87 case PIPE_QUERY_TIME_ELAPSED
:
88 sq
->start
= 1000*os_time_get();
90 case PIPE_QUERY_SO_STATISTICS
:
91 sq
->so
.num_primitives_written
= 0;
92 sq
->so
.primitives_storage_needed
= 0;
94 case PIPE_QUERY_GPU_FINISHED
:
100 softpipe
->active_query_count
++;
101 softpipe
->dirty
|= SP_NEW_QUERY
;
106 softpipe_end_query(struct pipe_context
*pipe
, struct pipe_query
*q
)
108 struct softpipe_context
*softpipe
= softpipe_context( pipe
);
109 struct softpipe_query
*sq
= softpipe_query(q
);
111 softpipe
->active_query_count
--;
113 case PIPE_QUERY_OCCLUSION_COUNTER
:
114 sq
->end
= softpipe
->occlusion_count
;
116 case PIPE_QUERY_TIME_ELAPSED
:
117 sq
->end
= 1000*os_time_get();
119 case PIPE_QUERY_SO_STATISTICS
:
120 sq
->so
.num_primitives_written
=
121 softpipe
->so_stats
.num_primitives_written
;
122 sq
->so
.primitives_storage_needed
=
123 softpipe
->so_stats
.primitives_storage_needed
;
125 case PIPE_QUERY_GPU_FINISHED
:
131 softpipe
->dirty
|= SP_NEW_QUERY
;
136 softpipe_get_query_result(struct pipe_context
*pipe
,
137 struct pipe_query
*q
,
141 struct softpipe_query
*sq
= softpipe_query(q
);
142 uint64_t *result
= (uint64_t*)vresult
;
145 case PIPE_QUERY_SO_STATISTICS
:
146 memcpy(vresult
, &sq
->so
,
147 sizeof(struct pipe_query_data_so_statistics
));
149 case PIPE_QUERY_GPU_FINISHED
:
153 *result
= sq
->end
- sq
->start
;
161 * Called by rendering function to check rendering is conditional.
162 * \return TRUE if we should render, FALSE if we should skip rendering
165 softpipe_check_render_cond(struct softpipe_context
*sp
)
167 struct pipe_context
*pipe
= &sp
->pipe
;
171 if (!sp
->render_cond_query
) {
172 return TRUE
; /* no query predicate, draw normally */
175 wait
= (sp
->render_cond_mode
== PIPE_RENDER_COND_WAIT
||
176 sp
->render_cond_mode
== PIPE_RENDER_COND_BY_REGION_WAIT
);
178 b
= pipe
->get_query_result(pipe
, sp
->render_cond_query
, wait
, &result
);
186 void softpipe_init_query_funcs(struct softpipe_context
*softpipe
)
188 softpipe
->pipe
.create_query
= softpipe_create_query
;
189 softpipe
->pipe
.destroy_query
= softpipe_destroy_query
;
190 softpipe
->pipe
.begin_query
= softpipe_begin_query
;
191 softpipe
->pipe
.end_query
= softpipe_end_query
;
192 softpipe
->pipe
.get_query_result
= softpipe_get_query_result
;