2 * Copyright 2011 Nouveau Project
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Christoph Bumiller
25 #define NV50_PUSH_EXPLICIT_SPACE_CHECKING
27 #include "nv50/nv50_context.h"
28 #include "nv50/nv50_query.h"
29 #include "nv50/nv50_query_hw.h"
31 static struct pipe_query *
32 nv50_create_query(struct pipe_context *pipe, unsigned type, unsigned index)
34 struct nv50_context *nv50 = nv50_context(pipe);
37 q = nv50_hw_create_query(nv50, type, index);
38 return (struct pipe_query *)q;
42 nv50_destroy_query(struct pipe_context *pipe, struct pipe_query *pq)
44 struct nv50_query *q = nv50_query(pq);
45 q->funcs->destroy_query(nv50_context(pipe), q);
49 nv50_begin_query(struct pipe_context *pipe, struct pipe_query *pq)
51 struct nv50_query *q = nv50_query(pq);
52 return q->funcs->begin_query(nv50_context(pipe), q);
56 nv50_end_query(struct pipe_context *pipe, struct pipe_query *pq)
58 struct nv50_query *q = nv50_query(pq);
59 q->funcs->end_query(nv50_context(pipe), q);
63 nv50_get_query_result(struct pipe_context *pipe, struct pipe_query *pq,
64 boolean wait, union pipe_query_result *result)
66 struct nv50_query *q = nv50_query(pq);
67 return q->funcs->get_query_result(nv50_context(pipe), q, wait, result);
71 nv50_render_condition(struct pipe_context *pipe,
72 struct pipe_query *pq,
73 boolean condition, uint mode)
75 struct nv50_context *nv50 = nv50_context(pipe);
76 struct nouveau_pushbuf *push = nv50->base.pushbuf;
77 struct nv50_query *q = nv50_query(pq);
78 struct nv50_hw_query *hq = nv50_hw_query(q);
81 mode != PIPE_RENDER_COND_NO_WAIT &&
82 mode != PIPE_RENDER_COND_BY_REGION_NO_WAIT;
85 cond = NV50_3D_COND_MODE_ALWAYS;
88 /* NOTE: comparison of 2 queries only works if both have completed */
90 case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
91 cond = condition ? NV50_3D_COND_MODE_EQUAL :
92 NV50_3D_COND_MODE_NOT_EQUAL;
95 case PIPE_QUERY_OCCLUSION_COUNTER:
96 case PIPE_QUERY_OCCLUSION_PREDICATE:
97 if (likely(!condition)) {
98 if (unlikely(hq->nesting))
99 cond = wait ? NV50_3D_COND_MODE_NOT_EQUAL :
100 NV50_3D_COND_MODE_ALWAYS;
102 cond = NV50_3D_COND_MODE_RES_NON_ZERO;
104 cond = wait ? NV50_3D_COND_MODE_EQUAL : NV50_3D_COND_MODE_ALWAYS;
108 assert(!"render condition query not a predicate");
109 cond = NV50_3D_COND_MODE_ALWAYS;
114 nv50->cond_query = pq;
115 nv50->cond_cond = condition;
116 nv50->cond_condmode = cond;
117 nv50->cond_mode = mode;
121 BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
122 PUSH_DATA (push, cond);
129 BEGIN_NV04(push, SUBC_3D(NV50_GRAPH_SERIALIZE), 1);
133 PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
134 BEGIN_NV04(push, NV50_3D(COND_ADDRESS_HIGH), 3);
135 PUSH_DATAh(push, hq->bo->offset + hq->offset);
136 PUSH_DATA (push, hq->bo->offset + hq->offset);
137 PUSH_DATA (push, cond);
139 BEGIN_NV04(push, NV50_2D(COND_ADDRESS_HIGH), 2);
140 PUSH_DATAh(push, hq->bo->offset + hq->offset);
141 PUSH_DATA (push, hq->bo->offset + hq->offset);
145 nv50_init_query_functions(struct nv50_context *nv50)
147 struct pipe_context *pipe = &nv50->base.pipe;
149 pipe->create_query = nv50_create_query;
150 pipe->destroy_query = nv50_destroy_query;
151 pipe->begin_query = nv50_begin_query;
152 pipe->end_query = nv50_end_query;
153 pipe->get_query_result = nv50_get_query_result;
154 pipe->render_condition = nv50_render_condition;
158 nv50_screen_get_driver_query_info(struct pipe_screen *pscreen,
160 struct pipe_driver_query_info *info)
162 struct nv50_screen *screen = nv50_screen(pscreen);
163 int num_hw_queries = 0;
165 num_hw_queries = nv50_hw_get_driver_query_info(screen, 0, NULL);
168 return num_hw_queries;
170 /* Init default values. */
171 info->name = "this_is_not_the_query_you_are_looking_for";
172 info->query_type = 0xdeadd01d;
173 info->max_value.u64 = 0;
174 info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;
177 return nv50_hw_get_driver_query_info(screen, id, info);