r300-gallium: Clean up compile warnings and strict compile errors.
[mesa.git] / src / gallium / drivers / r300 / r300_query.c
1 /*
2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
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:
10 *
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
13 * Software.
14 *
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. */
22
23 #include "r300_query.h"
24
25 static struct pipe_query* r300_create_query(struct pipe_context* pipe,
26 unsigned query_type)
27 {
28 struct r300_query* q = CALLOC_STRUCT(r300_query);
29
30 q->type = query_type;
31 assert(q->type == PIPE_QUERY_OCCLUSION_COUNTER);
32
33 /* XXX this is to force winsys to give us a GTT buffer */
34 q->buf = pipe->screen->buffer_create(pipe->screen, 64,
35 PIPE_BUFFER_USAGE_VERTEX, 64);
36
37 return (struct pipe_query*)q;
38 }
39
40 static void r300_destroy_query(struct pipe_context* pipe,
41 struct pipe_query* query)
42 {
43 FREE(query);
44 }
45
46 static void r300_begin_query(struct pipe_context* pipe,
47 struct pipe_query* query)
48 {
49 uint32_t* map;
50 struct r300_context* r300 = r300_context(pipe);
51 struct r300_query* q = (struct r300_query*)query;
52 CS_LOCALS(r300);
53
54 map = pipe_buffer_map(pipe->screen, q->buf, PIPE_BUFFER_USAGE_CPU_WRITE);
55 *map = ~0;
56 pipe_buffer_unmap(pipe->screen, q->buf);
57
58 BEGIN_CS(2);
59 OUT_CS_REG(R300_ZB_ZPASS_DATA, 0);
60 END_CS;
61 }
62
63 static void r300_end_query(struct pipe_context* pipe,
64 struct pipe_query* query)
65 {
66 struct r300_context* r300 = r300_context(pipe);
67 struct r300_query* q = (struct r300_query*)query;
68 CS_LOCALS(r300);
69
70 BEGIN_CS(4);
71 OUT_CS_REG_SEQ(R300_ZB_ZPASS_ADDR, 1);
72 OUT_CS_RELOC(q->buf, 0, 0, RADEON_GEM_DOMAIN_GTT, 0);
73 END_CS;
74 }
75
76 static boolean r300_get_query_result(struct pipe_context* pipe,
77 struct pipe_query* query,
78 boolean wait,
79 uint64_t* result)
80 {
81 struct r300_query* q = (struct r300_query*)query;
82 uint32_t* map;
83 uint32_t temp;
84
85 if (wait) {
86 /* Well, we're expected to just sit here and spin, so let's go ahead
87 * and flush so we can be sure that the card's spinning... */
88 /* XXX double-check these params */
89 pipe->flush(pipe, 0, NULL);
90 }
91
92 map = pipe_buffer_map(pipe->screen, q->buf, PIPE_BUFFER_USAGE_CPU_READ);
93 temp = *map;
94 pipe_buffer_unmap(pipe->screen, q->buf);
95
96 if (temp < 0) {
97 /* Our results haven't been written yet... */
98 return FALSE;
99 }
100
101 *result = temp;
102 return TRUE;
103 }
104
105 void r300_init_query_functions(struct r300_context* r300) {
106 r300->context.create_query = r300_create_query;
107 r300->context.destroy_query = r300_destroy_query;
108 r300->context.begin_query = r300_begin_query;
109 r300->context.end_query = r300_end_query;
110 r300->context.get_query_result = r300_get_query_result;
111 }