2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 #include "util/u_memory.h"
24 #include "util/u_simple_list.h"
26 #include "r300_context.h"
27 #include "r300_screen.h"
28 #include "r300_emit.h"
32 static struct pipe_query
*r300_create_query(struct pipe_context
*pipe
,
35 struct r300_context
*r300
= r300_context(pipe
);
36 struct r300_screen
*r300screen
= r300
->screen
;
39 if (query_type
!= PIPE_QUERY_OCCLUSION_COUNTER
) {
43 q
= CALLOC_STRUCT(r300_query
);
49 if (r300screen
->caps
.family
== CHIP_FAMILY_RV530
)
50 q
->num_pipes
= r300screen
->info
.r300_num_z_pipes
;
52 q
->num_pipes
= r300screen
->info
.r300_num_gb_pipes
;
54 /* Open up the occlusion query buffer. */
55 q
->buf
= r300
->rws
->buffer_create(r300
->rws
, 4096, 4096,
56 PIPE_BIND_CUSTOM
, PIPE_USAGE_STAGING
);
57 q
->cs_buf
= r300
->rws
->buffer_get_cs_handle(q
->buf
);
59 return (struct pipe_query
*)q
;
62 static void r300_destroy_query(struct pipe_context
* pipe
,
63 struct pipe_query
* query
)
65 struct r300_query
* q
= r300_query(query
);
67 pb_reference(&q
->buf
, NULL
);
71 void r300_resume_query(struct r300_context
*r300
,
72 struct r300_query
*query
)
74 r300
->query_current
= query
;
75 r300_mark_atom_dirty(r300
, &r300
->query_start
);
78 static void r300_begin_query(struct pipe_context
* pipe
,
79 struct pipe_query
* query
)
81 struct r300_context
* r300
= r300_context(pipe
);
82 struct r300_query
* q
= r300_query(query
);
84 if (r300
->query_current
!= NULL
) {
85 fprintf(stderr
, "r300: begin_query: "
86 "Some other query has already been started.\n");
92 r300_resume_query(r300
, q
);
95 void r300_stop_query(struct r300_context
*r300
)
97 r300_emit_query_end(r300
);
98 r300
->query_current
= NULL
;
101 static void r300_end_query(struct pipe_context
* pipe
,
102 struct pipe_query
* query
)
104 struct r300_context
* r300
= r300_context(pipe
);
105 struct r300_query
*q
= r300_query(query
);
107 if (q
!= r300
->query_current
) {
108 fprintf(stderr
, "r300: end_query: Got invalid query.\n");
113 r300_stop_query(r300
);
116 static boolean
r300_get_query_result(struct pipe_context
* pipe
,
117 struct pipe_query
* query
,
121 struct r300_context
* r300
= r300_context(pipe
);
122 struct r300_query
*q
= r300_query(query
);
126 map
= r300
->rws
->buffer_map(q
->buf
, r300
->cs
,
128 (!wait
? PIPE_TRANSFER_DONTBLOCK
: 0));
132 /* Sum up the results. */
134 for (i
= 0; i
< q
->num_results
; i
++) {
139 r300
->rws
->buffer_unmap(q
->buf
);
141 *((uint64_t*)vresult
) = temp
;
145 static void r300_render_condition(struct pipe_context
*pipe
,
146 struct pipe_query
*query
,
149 struct r300_context
*r300
= r300_context(pipe
);
153 r300
->skip_rendering
= FALSE
;
156 wait
= mode
== PIPE_RENDER_COND_WAIT
||
157 mode
== PIPE_RENDER_COND_BY_REGION_WAIT
;
159 if (r300_get_query_result(pipe
, query
, wait
, &result
)) {
160 r300
->skip_rendering
= result
== 0;
165 void r300_init_query_functions(struct r300_context
* r300
) {
166 r300
->context
.create_query
= r300_create_query
;
167 r300
->context
.destroy_query
= r300_destroy_query
;
168 r300
->context
.begin_query
= r300_begin_query
;
169 r300
->context
.end_query
= r300_end_query
;
170 r300
->context
.get_query_result
= r300_get_query_result
;
171 r300
->context
.render_condition
= r300_render_condition
;