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"
29 #include "r300_emit.h"
30 #include "r300_query.h"
33 static struct pipe_query *r300_create_query(struct pipe_context *pipe,
36 struct r300_context *r300 = r300_context(pipe);
37 struct r300_screen *r300screen = r300_screen(r300->context.screen);
39 struct r300_query *q, *qptr;
41 q = CALLOC_STRUCT(r300_query);
44 assert(q->type == PIPE_QUERY_OCCLUSION_COUNTER);
48 if (r300screen->caps->family == CHIP_FAMILY_RV530)
49 query_size = r300screen->caps->num_z_pipes * sizeof(uint32_t);
51 query_size = r300screen->caps->num_frag_pipes * sizeof(uint32_t);
53 if (!is_empty_list(&r300->query_list)) {
54 qptr = last_elem(&r300->query_list);
55 q->offset = qptr->offset + query_size;
57 insert_at_tail(&r300->query_list, q);
60 if (q->offset >= 4096) {
64 return (struct pipe_query*)q;
67 static void r300_destroy_query(struct pipe_context* pipe,
68 struct pipe_query* query)
70 struct r300_query* q = (struct r300_query*)query;
76 static void r300_begin_query(struct pipe_context* pipe,
77 struct pipe_query* query)
80 struct r300_context* r300 = r300_context(pipe);
81 struct r300_query* q = (struct r300_query*)query;
83 assert(r300->query_current == NULL);
85 map = pipe->screen->buffer_map(pipe->screen, r300->oqbo,
86 PIPE_BUFFER_USAGE_CPU_WRITE);
89 pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
92 r300->query_current = q;
93 r300->dirty_state |= R300_NEW_QUERY;
96 static void r300_end_query(struct pipe_context* pipe,
97 struct pipe_query* query)
99 struct r300_context* r300 = r300_context(pipe);
101 r300_emit_query_end(r300);
102 r300->query_current = NULL;
105 static boolean r300_get_query_result(struct pipe_context* pipe,
106 struct pipe_query* query,
110 struct r300_context* r300 = r300_context(pipe);
111 struct r300_screen* r300screen = r300_screen(r300->context.screen);
112 struct r300_query *q = (struct r300_query*)query;
113 unsigned flags = PIPE_BUFFER_USAGE_CPU_READ;
116 unsigned i, num_results;
118 if (q->flushed == FALSE)
119 pipe->flush(pipe, 0, NULL);
121 flags |= PIPE_BUFFER_USAGE_DONTBLOCK;
124 map = pipe->screen->buffer_map(pipe->screen, r300->oqbo, flags);
127 map += q->offset / 4;
129 if (r300screen->caps->family == CHIP_FAMILY_RV530)
130 num_results = r300screen->caps->num_z_pipes;
132 num_results = r300screen->caps->num_frag_pipes;
134 for (i = 0; i < num_results; i++) {
136 /* Looks like our results aren't ready yet. */
138 debug_printf("r300: Despite waiting, OQ results haven't"
147 pipe->screen->buffer_unmap(pipe->screen, r300->oqbo);
150 /* Our results haven't been written yet... */
158 void r300_init_query_functions(struct r300_context* r300) {
159 r300->context.create_query = r300_create_query;
160 r300->context.destroy_query = r300_destroy_query;
161 r300->context.begin_query = r300_begin_query;
162 r300->context.end_query = r300_end_query;
163 r300->context.get_query_result = r300_get_query_result;