• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Nouveau Project
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  * 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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  * Authors: Christoph Bumiller
23  */
24 
25 #define NV50_PUSH_EXPLICIT_SPACE_CHECKING
26 
27 #include "nv50/nv50_context.h"
28 #include "nv50/nv50_query.h"
29 #include "nv50/nv50_query_hw.h"
30 #include "nv50/nv50_query_hw_metric.h"
31 #include "nv50/nv50_query_hw_sm.h"
32 
33 static struct pipe_query *
nv50_create_query(struct pipe_context * pipe,unsigned type,unsigned index)34 nv50_create_query(struct pipe_context *pipe, unsigned type, unsigned index)
35 {
36    struct nv50_context *nv50 = nv50_context(pipe);
37    struct nv50_query *q;
38 
39    q = nv50_hw_create_query(nv50, type, index);
40    return (struct pipe_query *)q;
41 }
42 
43 static void
nv50_destroy_query(struct pipe_context * pipe,struct pipe_query * pq)44 nv50_destroy_query(struct pipe_context *pipe, struct pipe_query *pq)
45 {
46    struct nv50_query *q = nv50_query(pq);
47    q->funcs->destroy_query(nv50_context(pipe), q);
48 }
49 
50 static boolean
nv50_begin_query(struct pipe_context * pipe,struct pipe_query * pq)51 nv50_begin_query(struct pipe_context *pipe, struct pipe_query *pq)
52 {
53    struct nv50_query *q = nv50_query(pq);
54    return q->funcs->begin_query(nv50_context(pipe), q);
55 }
56 
57 static bool
nv50_end_query(struct pipe_context * pipe,struct pipe_query * pq)58 nv50_end_query(struct pipe_context *pipe, struct pipe_query *pq)
59 {
60    struct nv50_query *q = nv50_query(pq);
61    q->funcs->end_query(nv50_context(pipe), q);
62    return true;
63 }
64 
65 static boolean
nv50_get_query_result(struct pipe_context * pipe,struct pipe_query * pq,boolean wait,union pipe_query_result * result)66 nv50_get_query_result(struct pipe_context *pipe, struct pipe_query *pq,
67                       boolean wait, union pipe_query_result *result)
68 {
69    struct nv50_query *q = nv50_query(pq);
70    return q->funcs->get_query_result(nv50_context(pipe), q, wait, result);
71 }
72 
73 static void
nv50_render_condition(struct pipe_context * pipe,struct pipe_query * pq,boolean condition,enum pipe_render_cond_flag mode)74 nv50_render_condition(struct pipe_context *pipe,
75                       struct pipe_query *pq,
76                       boolean condition, enum pipe_render_cond_flag mode)
77 {
78    struct nv50_context *nv50 = nv50_context(pipe);
79    struct nouveau_pushbuf *push = nv50->base.pushbuf;
80    struct nv50_query *q = nv50_query(pq);
81    struct nv50_hw_query *hq = nv50_hw_query(q);
82    uint32_t cond;
83    bool wait =
84       mode != PIPE_RENDER_COND_NO_WAIT &&
85       mode != PIPE_RENDER_COND_BY_REGION_NO_WAIT;
86 
87    if (!pq) {
88       cond = NV50_3D_COND_MODE_ALWAYS;
89    }
90    else {
91       /* NOTE: comparison of 2 queries only works if both have completed */
92       switch (q->type) {
93       case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
94          cond = condition ? NV50_3D_COND_MODE_EQUAL :
95                             NV50_3D_COND_MODE_NOT_EQUAL;
96          wait = true;
97          break;
98       case PIPE_QUERY_OCCLUSION_COUNTER:
99       case PIPE_QUERY_OCCLUSION_PREDICATE:
100       case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
101          if (likely(!condition)) {
102             if (unlikely(hq->nesting))
103                cond = wait ? NV50_3D_COND_MODE_NOT_EQUAL :
104                              NV50_3D_COND_MODE_ALWAYS;
105             else
106                cond = NV50_3D_COND_MODE_RES_NON_ZERO;
107          } else {
108             cond = wait ? NV50_3D_COND_MODE_EQUAL : NV50_3D_COND_MODE_ALWAYS;
109          }
110          break;
111       default:
112          assert(!"render condition query not a predicate");
113          cond = NV50_3D_COND_MODE_ALWAYS;
114          break;
115       }
116    }
117 
118    nv50->cond_query = pq;
119    nv50->cond_cond = condition;
120    nv50->cond_condmode = cond;
121    nv50->cond_mode = mode;
122 
123    if (!pq) {
124       PUSH_SPACE(push, 2);
125       BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
126       PUSH_DATA (push, cond);
127       return;
128    }
129 
130    PUSH_SPACE(push, 9);
131 
132    if (wait) {
133       BEGIN_NV04(push, SUBC_3D(NV50_GRAPH_SERIALIZE), 1);
134       PUSH_DATA (push, 0);
135    }
136 
137    PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
138    BEGIN_NV04(push, NV50_3D(COND_ADDRESS_HIGH), 3);
139    PUSH_DATAh(push, hq->bo->offset + hq->offset);
140    PUSH_DATA (push, hq->bo->offset + hq->offset);
141    PUSH_DATA (push, cond);
142 
143    BEGIN_NV04(push, NV50_2D(COND_ADDRESS_HIGH), 2);
144    PUSH_DATAh(push, hq->bo->offset + hq->offset);
145    PUSH_DATA (push, hq->bo->offset + hq->offset);
146 }
147 
148 static void
nv50_set_active_query_state(struct pipe_context * pipe,boolean enable)149 nv50_set_active_query_state(struct pipe_context *pipe, boolean enable)
150 {
151 }
152 
153 void
nv50_init_query_functions(struct nv50_context * nv50)154 nv50_init_query_functions(struct nv50_context *nv50)
155 {
156    struct pipe_context *pipe = &nv50->base.pipe;
157 
158    pipe->create_query = nv50_create_query;
159    pipe->destroy_query = nv50_destroy_query;
160    pipe->begin_query = nv50_begin_query;
161    pipe->end_query = nv50_end_query;
162    pipe->get_query_result = nv50_get_query_result;
163    pipe->set_active_query_state = nv50_set_active_query_state;
164    pipe->render_condition = nv50_render_condition;
165    nv50->cond_condmode = NV50_3D_COND_MODE_ALWAYS;
166 }
167 
168 int
nv50_screen_get_driver_query_info(struct pipe_screen * pscreen,unsigned id,struct pipe_driver_query_info * info)169 nv50_screen_get_driver_query_info(struct pipe_screen *pscreen,
170                                   unsigned id,
171                                   struct pipe_driver_query_info *info)
172 {
173    struct nv50_screen *screen = nv50_screen(pscreen);
174    int num_hw_queries = 0;
175 
176    num_hw_queries = nv50_hw_get_driver_query_info(screen, 0, NULL);
177 
178    if (!info)
179       return num_hw_queries;
180 
181    /* Init default values. */
182    info->name = "this_is_not_the_query_you_are_looking_for";
183    info->query_type = 0xdeadd01d;
184    info->max_value.u64 = 0;
185    info->type = PIPE_DRIVER_QUERY_TYPE_UINT64;
186    info->group_id = -1;
187    info->flags = 0;
188 
189    return nv50_hw_get_driver_query_info(screen, id, info);
190 }
191 
192 int
nv50_screen_get_driver_query_group_info(struct pipe_screen * pscreen,unsigned id,struct pipe_driver_query_group_info * info)193 nv50_screen_get_driver_query_group_info(struct pipe_screen *pscreen,
194                                         unsigned id,
195                                         struct pipe_driver_query_group_info *info)
196 {
197    struct nv50_screen *screen = nv50_screen(pscreen);
198    int count = 0;
199 
200    if (screen->compute)
201       if (screen->base.class_3d >= NV84_3D_CLASS)
202          count += 2;
203 
204    if (!info)
205       return count;
206 
207    if (id == NV50_HW_SM_QUERY_GROUP) {
208       if (screen->compute) {
209          if (screen->base.class_3d >= NV84_3D_CLASS) {
210             info->name = "MP counters";
211 
212             /* Expose the maximum number of hardware counters available,
213              * although some queries use more than one counter. Expect failures
214              * in that case but as performance counters are for developers,
215              * this should not have a real impact. */
216             info->max_active_queries = 4;
217             info->num_queries = NV50_HW_SM_QUERY_COUNT;
218             return 1;
219          }
220       }
221    } else
222    if (id == NV50_HW_METRIC_QUERY_GROUP) {
223       if (screen->compute) {
224          if (screen->base.class_3d >= NV84_3D_CLASS) {
225             info->name = "Performance metrics";
226             info->max_active_queries = 2; /* A metric uses at least 2 queries */
227             info->num_queries = NV50_HW_METRIC_QUERY_COUNT;
228             return 1;
229          }
230       }
231    }
232 
233    /* user asked for info about non-existing query group */
234    info->name = "this_is_not_the_query_group_you_are_looking_for";
235    info->max_active_queries = 0;
236    info->num_queries = 0;
237    return 0;
238 }
239