Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / drivers / softpipe / sp_query.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /* Author:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "draw/draw_context.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_memory.h"
35 #include "sp_context.h"
36 #include "sp_query.h"
37 #include "sp_state.h"
38
39 struct softpipe_query {
40 uint64_t start;
41 uint64_t end;
42 };
43
44
45 static struct softpipe_query *softpipe_query( struct pipe_query *p )
46 {
47 return (struct softpipe_query *)p;
48 }
49
50 static struct pipe_query *
51 softpipe_create_query(struct pipe_context *pipe,
52 unsigned type)
53 {
54 assert(type == PIPE_QUERY_OCCLUSION_COUNTER);
55 return (struct pipe_query *)CALLOC_STRUCT( softpipe_query );
56 }
57
58
59 static void
60 softpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
61 {
62 FREE(q);
63 }
64
65
66 static void
67 softpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
68 {
69 struct softpipe_context *softpipe = softpipe_context( pipe );
70 struct softpipe_query *sq = softpipe_query(q);
71
72 sq->start = softpipe->occlusion_count;
73 softpipe->active_query_count++;
74 softpipe->dirty |= SP_NEW_QUERY;
75 }
76
77
78 static void
79 softpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
80 {
81 struct softpipe_context *softpipe = softpipe_context( pipe );
82 struct softpipe_query *sq = softpipe_query(q);
83
84 softpipe->active_query_count--;
85 sq->end = softpipe->occlusion_count;
86 softpipe->dirty |= SP_NEW_QUERY;
87 }
88
89
90 static boolean
91 softpipe_get_query_result(struct pipe_context *pipe,
92 struct pipe_query *q,
93 boolean wait,
94 uint64_t *result )
95 {
96 struct softpipe_query *sq = softpipe_query(q);
97 *result = sq->end - sq->start;
98 return TRUE;
99 }
100
101
102 void softpipe_init_query_funcs(struct softpipe_context *softpipe )
103 {
104 softpipe->pipe.create_query = softpipe_create_query;
105 softpipe->pipe.destroy_query = softpipe_destroy_query;
106 softpipe->pipe.begin_query = softpipe_begin_query;
107 softpipe->pipe.end_query = softpipe_end_query;
108 softpipe->pipe.get_query_result = softpipe_get_query_result;
109 }
110
111