2 * Copyright © 2014 Broadcom
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 (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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Gallium query object support.
27 * The HW has native support for occlusion queries, with the query result
28 * being loaded and stored by the TLB unit. From a SW perspective, we have to
29 * be careful to make sure that the jobs that need to be tracking queries are
30 * bracketed by the start and end of counting, even across FBO transitions.
32 * For the transform feedback PRIMITIVES_GENERATED/WRITTEN queries, we have to
33 * do the calculations in software at draw time.
36 #include "v3d_context.h"
37 #include "broadcom/cle/v3d_packet_v33_pack.h"
41 enum pipe_query_type type
;
47 static struct pipe_query
*
48 v3d_create_query(struct pipe_context
*pctx
, unsigned query_type
, unsigned index
)
50 struct v3d_query
*q
= calloc(1, sizeof(*q
));
54 /* Note that struct pipe_query isn't actually defined anywhere. */
55 return (struct pipe_query
*)q
;
59 v3d_destroy_query(struct pipe_context
*pctx
, struct pipe_query
*query
)
61 struct v3d_query
*q
= (struct v3d_query
*)query
;
63 v3d_bo_unreference(&q
->bo
);
68 v3d_begin_query(struct pipe_context
*pctx
, struct pipe_query
*query
)
70 struct v3d_context
*v3d
= v3d_context(pctx
);
71 struct v3d_query
*q
= (struct v3d_query
*)query
;
74 case PIPE_QUERY_PRIMITIVES_GENERATED
:
75 q
->start
= v3d
->prims_generated
;
77 case PIPE_QUERY_PRIMITIVES_EMITTED
:
78 q
->start
= v3d
->tf_prims_generated
;
80 case PIPE_QUERY_OCCLUSION_COUNTER
:
81 case PIPE_QUERY_OCCLUSION_PREDICATE
:
82 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
83 q
->bo
= v3d_bo_alloc(v3d
->screen
, 4096, "query");
84 uint32_t *map
= v3d_bo_map(q
->bo
);
87 v3d
->current_oq
= q
->bo
;
88 v3d
->dirty
|= VC5_DIRTY_OQ
;
91 unreachable("unsupported query type");
98 v3d_end_query(struct pipe_context
*pctx
, struct pipe_query
*query
)
100 struct v3d_context
*v3d
= v3d_context(pctx
);
101 struct v3d_query
*q
= (struct v3d_query
*)query
;
104 case PIPE_QUERY_PRIMITIVES_GENERATED
:
105 q
->end
= v3d
->prims_generated
;
107 case PIPE_QUERY_PRIMITIVES_EMITTED
:
108 q
->end
= v3d
->tf_prims_generated
;
110 case PIPE_QUERY_OCCLUSION_COUNTER
:
111 case PIPE_QUERY_OCCLUSION_PREDICATE
:
112 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
113 v3d
->current_oq
= NULL
;
114 v3d
->dirty
|= VC5_DIRTY_OQ
;
117 unreachable("unsupported query type");
124 v3d_get_query_result(struct pipe_context
*pctx
, struct pipe_query
*query
,
125 bool wait
, union pipe_query_result
*vresult
)
127 struct v3d_context
*v3d
= v3d_context(pctx
);
128 struct v3d_query
*q
= (struct v3d_query
*)query
;
132 v3d_flush_jobs_using_bo(v3d
, q
->bo
);
135 if (!v3d_bo_wait(q
->bo
, 0, "query"))
138 if (!v3d_bo_wait(q
->bo
, ~0ull, "query"))
142 /* XXX: Sum up per-core values. */
143 uint32_t *map
= v3d_bo_map(q
->bo
);
146 v3d_bo_unreference(&q
->bo
);
150 case PIPE_QUERY_OCCLUSION_COUNTER
:
151 vresult
->u64
= result
;
153 case PIPE_QUERY_OCCLUSION_PREDICATE
:
154 case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE
:
155 vresult
->b
= result
!= 0;
157 case PIPE_QUERY_PRIMITIVES_GENERATED
:
158 case PIPE_QUERY_PRIMITIVES_EMITTED
:
159 vresult
->u64
= q
->end
- q
->start
;
162 unreachable("unsupported query type");
169 v3d_set_active_query_state(struct pipe_context
*pctx
, bool enable
)
171 struct v3d_context
*v3d
= v3d_context(pctx
);
173 v3d
->active_queries
= enable
;
174 v3d
->dirty
|= VC5_DIRTY_OQ
;
175 v3d
->dirty
|= VC5_DIRTY_STREAMOUT
;
179 v3d_query_init(struct pipe_context
*pctx
)
181 pctx
->create_query
= v3d_create_query
;
182 pctx
->destroy_query
= v3d_destroy_query
;
183 pctx
->begin_query
= v3d_begin_query
;
184 pctx
->end_query
= v3d_end_query
;
185 pctx
->get_query_result
= v3d_get_query_result
;
186 pctx
->set_active_query_state
= v3d_set_active_query_state
;