assert(type == PIPE_QUERY_OCCLUSION_COUNTER);
pq = CALLOC_STRUCT( llvmpipe_query );
- if (pq) {
- pipe_mutex_init(pq->mutex);
- }
return (struct pipe_query *) pq;
}
llvmpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
{
struct llvmpipe_query *pq = llvmpipe_query(q);
- /* query might still be in process if we never waited for the result */
- if (!pq->done) {
- llvmpipe_finish(pipe, __FUNCTION__);
+
+ /* Ideally we would refcount queries & not get destroyed until the
+ * last scene had finished with us.
+ */
+ if (pq->fence) {
+ if (!lp_fence_issued(pq->fence))
+ llvmpipe_flush(pipe, NULL, __FUNCTION__);
+
+ if (!lp_fence_signalled(pq->fence))
+ lp_fence_wait(pq->fence);
+
+ lp_fence_reference(&pq->fence, NULL);
}
- pipe_mutex_destroy(pq->mutex);
FREE(pq);
}
llvmpipe_get_query_result(struct pipe_context *pipe,
struct pipe_query *q,
boolean wait,
- void *vresult)
+ union pipe_query_result *vresult)
{
struct llvmpipe_query *pq = llvmpipe_query(q);
uint64_t *result = (uint64_t *)vresult;
+ int i;
- if (!pq->done) {
- if (wait) {
- llvmpipe_finish(pipe, __FUNCTION__);
- }
- /* this is a bit inconsequent but should be ok */
- else {
- llvmpipe_flush(pipe, 0, NULL, __FUNCTION__);
- }
+ if (!pq->fence) {
+ /* no fence because there was no scene, so results is zero */
+ *result = 0;
+ return TRUE;
}
- if (pq->done) {
- *result = pq->result;
+ if (!lp_fence_signalled(pq->fence)) {
+ if (!lp_fence_issued(pq->fence))
+ llvmpipe_flush(pipe, NULL, __FUNCTION__);
+
+ if (!wait)
+ return FALSE;
+
+ lp_fence_wait(pq->fence);
}
- return pq->done;
+ /* Sum the results from each of the threads:
+ */
+ *result = 0;
+ for (i = 0; i < LP_MAX_THREADS; i++) {
+ *result += pq->count[i];
+ }
+
+ return TRUE;
}
* flush the scene now. Real apps shouldn't re-use a query in a
* frame of rendering.
*/
- if (pq->binned) {
+ if (pq->fence && !lp_fence_issued(pq->fence)) {
llvmpipe_finish(pipe, __FUNCTION__);
}
+
+ memset(pq->count, 0, sizeof(pq->count));
lp_setup_begin_query(llvmpipe->setup, pq);
llvmpipe->active_query_count++;
llvmpipe->dirty |= LP_NEW_QUERY;
}
+boolean
+llvmpipe_check_render_cond(struct llvmpipe_context *lp)
+{
+ struct pipe_context *pipe = &lp->pipe;
+ boolean b, wait;
+ uint64_t result;
+
+ if (!lp->render_cond_query)
+ return TRUE; /* no query predicate, draw normally */
+ wait = (lp->render_cond_mode == PIPE_RENDER_COND_WAIT ||
+ lp->render_cond_mode == PIPE_RENDER_COND_BY_REGION_WAIT);
+
+ b = pipe->get_query_result(pipe, lp->render_cond_query, wait, (void*)&result);
+ if (b)
+ return result > 0;
+ else
+ return TRUE;
+}
void llvmpipe_init_query_funcs(struct llvmpipe_context *llvmpipe )
{