Add a 'CheckQuery()' driver callback to mesa to check query completion.
Make pipe_query an opaque type.
Rework softpipe queries, support overlapping occlusion queries.
/* query objects */
driver->NewQueryObject = _mesa_new_query_object;
+ driver->DeleteQuery = _mesa_delete_query;
driver->BeginQuery = _mesa_begin_query;
driver->EndQuery = _mesa_end_query;
driver->WaitQuery = _mesa_wait_query;
*/
/*@{*/
struct gl_query_object * (*NewQueryObject)(GLcontext *ctx, GLuint id);
+ void (*DeleteQuery)(GLcontext *ctx, struct gl_query_object *q);
void (*BeginQuery)(GLcontext *ctx, struct gl_query_object *q);
void (*EndQuery)(GLcontext *ctx, struct gl_query_object *q);
+ void (*CheckQuery)(GLcontext *ctx, struct gl_query_object *q);
void (*WaitQuery)(GLcontext *ctx, struct gl_query_object *q);
/*@}*/
* Not removed from hash table here.
* XXX maybe add Delete() method to gl_query_object class and call that instead
*/
-static void
-delete_query_object(struct gl_query_object *q)
+void
+_mesa_delete_query(struct gl_query_object *q)
{
_mesa_free(q);
}
if (q) {
ASSERT(!q->Active); /* should be caught earlier */
_mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
- delete_query_object(q);
+ ctx->Driver.DeleteQuery(ctx, q);
}
}
}
}
break;
case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
*params = q->Ready;
break;
default:
}
break;
case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
*params = q->Ready;
break;
default:
*params = q->Result;
break;
case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
*params = q->Ready;
break;
default:
*params = q->Result;
break;
case GL_QUERY_RESULT_AVAILABLE_ARB:
+ if (!q->Ready)
+ ctx->Driver.CheckQuery( ctx, q );
*params = q->Ready;
break;
default:
delete_queryobj_cb(GLuint id, void *data, void *userData)
{
struct gl_query_object *q= (struct gl_query_object *) data;
- (void) userData;
- delete_query_object(q);
+ GLcontext *ctx = (GLcontext *)userData;
+ ctx->Driver.DeleteQuery(ctx, q);
}
extern void
_mesa_free_query_data(GLcontext *ctx);
+extern void
+_mesa_delete_query(struct gl_query_object *q);
+
extern void
_mesa_begin_query(GLcontext *ctx, struct gl_query_object *q);
-static void
-i915_begin_query(struct pipe_context *pipe, struct pipe_query_object *q)
-{
- /* should never be called */
- assert(0);
-}
-
-
-static void
-i915_end_query(struct pipe_context *pipe, struct pipe_query_object *q)
-{
- /* should never be called */
- assert(0);
-}
-
static boolean
i915_draw_elements( struct pipe_context *pipe,
i915->pipe.clear = i915_clear;
- i915->pipe.begin_query = i915_begin_query;
- i915->pipe.end_query = i915_end_query;
i915->pipe.draw_arrays = i915_draw_arrays;
i915->pipe.draw_elements = i915_draw_elements;
#define PIPE_CONTEXT_H
#include "p_state.h"
+#include <stdint.h>
struct pipe_state_cache;
+/* Opaque driver handles:
+ */
+struct pipe_query;
/**
* Gallium rendering context. Basically:
/**
* Query objects
*/
- void (*begin_query)(struct pipe_context *pipe, struct pipe_query_object *q);
- void (*end_query)(struct pipe_context *pipe, struct pipe_query_object *q);
- void (*wait_query)(struct pipe_context *pipe, struct pipe_query_object *q);
+ struct pipe_query *(*create_query)( struct pipe_context *pipe,
+ unsigned query_type );
+
+ void (*destroy_query)(struct pipe_context *pipe,
+ struct pipe_query *q);
+
+ void (*begin_query)(struct pipe_context *pipe, struct pipe_query *q);
+ void (*end_query)(struct pipe_context *pipe, struct pipe_query *q);
+
+ boolean (*get_query_result)(struct pipe_context *pipe,
+ struct pipe_query *q,
+ boolean wait,
+ uint64_t *result);
/*
* State functions
-/**
- * Hardware queries (occlusion, transform feedback, timing, etc)
- */
-struct pipe_query_object {
- uint type:3; /**< PIPE_QUERY_x */
- uint ready:1; /**< is result ready? */
- uint64 count;
-};
-
-
#endif
DRIVER_SOURCES = \
sp_clear.c \
sp_flush.c \
+ sp_query.c \
sp_context.c \
sp_draw_arrays.c \
sp_prim_setup.c \
#include "sp_tile_cache.h"
#include "sp_texture.h"
#include "sp_winsys.h"
+#include "sp_query.h"
}
-static void
-softpipe_begin_query(struct pipe_context *pipe, struct pipe_query_object *q)
-{
- struct softpipe_context *softpipe = softpipe_context( pipe );
- assert(q->type < PIPE_QUERY_TYPES);
- assert(!softpipe->queries[q->type]);
- softpipe->queries[q->type] = q;
-}
-
-
-static void
-softpipe_end_query(struct pipe_context *pipe, struct pipe_query_object *q)
-{
- struct softpipe_context *softpipe = softpipe_context( pipe );
- assert(q->type < PIPE_QUERY_TYPES);
- assert(softpipe->queries[q->type]);
- q->ready = 1; /* software rendering is synchronous */
- softpipe->queries[q->type] = NULL;
-}
-
-
-static void
-softpipe_wait_query(struct pipe_context *pipe, struct pipe_query_object *q)
-{
- /* Should never get here since we indicated that the result was
- * ready in softpipe_end_query().
- */
- assert(0);
-}
-
-
static const char *softpipe_get_name( struct pipe_context *pipe )
{
return "softpipe";
softpipe->pipe.clear = softpipe_clear;
softpipe->pipe.flush = softpipe_flush;
- softpipe->pipe.begin_query = softpipe_begin_query;
- softpipe->pipe.end_query = softpipe_end_query;
- softpipe->pipe.wait_query = softpipe_wait_query;
+ softpipe_init_query_funcs( softpipe );
/* textures */
softpipe->pipe.texture_create = softpipe_texture_create;
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
unsigned dirty;
- /*
- * Active queries
+ /* Counter for occlusion queries. Note this supports overlapping
+ * queries.
*/
- struct pipe_query_object *queries[PIPE_QUERY_TYPES];
+ uint64_t occlusion_count;
/*
* Mapped vertex buffers
#include "sp_surface.h"
#include "sp_quad.h"
+static unsigned count_bits( unsigned val )
+{
+ unsigned i;
+
+ for (i = 0; val ; val >>= 1)
+ i += (val & 1);
+
+ return i;
+}
static void
occlusion_count_quad(struct quad_stage *qs, struct quad_header *quad)
{
struct softpipe_context *softpipe = qs->softpipe;
- struct pipe_query_object *occ
- = softpipe->queries[PIPE_QUERY_OCCLUSION_COUNTER];
- occ->count += (quad->mask ) & 1;
- occ->count += (quad->mask >> 1) & 1;
- occ->count += (quad->mask >> 2) & 1;
- occ->count += (quad->mask >> 3) & 1;
+ softpipe->occlusion_count += count_bits(quad->mask);
qs->next->run(qs->next, quad);
}
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Author:
+ * Keith Whitwell <keith@tungstengraphics.com>
+ */
+
+#include "pipe/draw/draw_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_util.h"
+#include "sp_context.h"
+#include "sp_query.h"
+
+struct softpipe_query {
+ uint64_t start;
+ uint64_t end;
+};
+
+
+static struct softpipe_query *softpipe_query( struct pipe_query *p )
+{
+ return (struct softpipe_query *)p;
+}
+
+static struct pipe_query *
+softpipe_create_query(struct pipe_context *pipe,
+ unsigned type)
+{
+ assert(type == PIPE_QUERY_OCCLUSION_COUNTER);
+ return (struct pipe_query *)CALLOC_STRUCT( softpipe_query );
+}
+
+
+static void
+softpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
+{
+ FREE(q);
+}
+
+
+static void
+softpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
+{
+ struct softpipe_context *softpipe = softpipe_context( pipe );
+ struct softpipe_query *sq = softpipe_query(q);
+
+ sq->start = softpipe->occlusion_count;
+}
+
+
+static void
+softpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
+{
+ struct softpipe_context *softpipe = softpipe_context( pipe );
+ struct softpipe_query *sq = softpipe_query(q);
+
+ sq->end = softpipe->occlusion_count;
+}
+
+
+static boolean
+softpipe_get_query_result(struct pipe_context *pipe,
+ struct pipe_query *q,
+ boolean wait,
+ uint64_t *result )
+{
+ struct softpipe_query *sq = softpipe_query(q);
+ *result = sq->end - sq->start;
+ return TRUE;
+}
+
+
+void softpipe_init_query_funcs(struct softpipe_context *softpipe )
+{
+ softpipe->pipe.create_query = softpipe_create_query;
+ softpipe->pipe.destroy_query = softpipe_destroy_query;
+ softpipe->pipe.begin_query = softpipe_begin_query;
+ softpipe->pipe.end_query = softpipe_end_query;
+ softpipe->pipe.get_query_result = softpipe_get_query_result;
+}
+
+
--- /dev/null
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Author:
+ * Keith Whitwell
+ */
+
+#ifndef SP_QUERY_H
+#define SP_QUERY_H
+
+struct softpipe_context;
+extern void softpipe_init_query_funcs(struct softpipe_context * );
+
+
+#endif /* SP_QUERY_H */
struct st_query_object
{
struct gl_query_object base;
- struct pipe_query_object pq;
+ struct pipe_query *pq;
};
if (stq) {
stq->base.Id = id;
stq->base.Ready = GL_TRUE;
+ stq->pq = NULL;
return &stq->base;
}
return NULL;
}
+
+static void
+st_DeleteQuery(GLcontext *ctx, struct gl_query_object *q)
+{
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct st_query_object *stq = st_query_object(q);
+
+ if (stq->pq) {
+ pipe->destroy_query(pipe, stq->pq);
+ stq->pq = NULL;
+ }
+
+ FREE(stq);
+}
+
/**
* Do glReadPixels by getting rows from the framebuffer surface with
* get_tile(). Convert to requested format/type with Mesa image routines.
struct pipe_context *pipe = ctx->st->pipe;
struct st_query_object *stq = st_query_object(q);
- stq->pq.count = 0;
-
switch (q->Target) {
case GL_SAMPLES_PASSED_ARB:
- stq->pq.type = PIPE_QUERY_OCCLUSION_COUNTER;
- break;
- case GL_PRIMITIVES_GENERATED_NV:
- /* someday */
- stq->pq.type = PIPE_QUERY_PRIMITIVES_GENERATED;
- break;
- case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV:
- /* someday */
- stq->pq.type = PIPE_QUERY_PRIMITIVES_EMITTED;
+ if (!stq->pq)
+ stq->pq = pipe->create_query( pipe, PIPE_QUERY_OCCLUSION_COUNTER );
break;
default:
assert(0);
+ return;
}
- pipe->begin_query(pipe, &stq->pq);
+ pipe->begin_query(pipe, stq->pq);
}
struct pipe_context *pipe = ctx->st->pipe;
struct st_query_object *stq = st_query_object(q);
- pipe->end_query(pipe, &stq->pq);
- stq->base.Ready = stq->pq.ready;
- if (stq->base.Ready)
- stq->base.Result = stq->pq.count;
+ pipe->end_query(pipe, stq->pq);
}
/* this function should only be called if we don't have a ready result */
assert(!stq->base.Ready);
- pipe->wait_query(pipe, &stq->pq);
+ while (!stq->base.Ready &&
+ !pipe->get_query_result(pipe,
+ stq->pq,
+ TRUE,
+ &q->Result))
+ {
+ /* nothing */
+ }
+
q->Ready = GL_TRUE;
- q->Result = stq->pq.count;
}
+static void
+st_CheckQuery(GLcontext *ctx, struct gl_query_object *q)
+{
+ struct pipe_context *pipe = ctx->st->pipe;
+ struct st_query_object *stq = st_query_object(q);
+
+ if (!q->Ready) {
+ q->Ready = pipe->get_query_result(pipe,
+ stq->pq,
+ FALSE,
+ &q->Result);
+ }
+}
+
+
+
void st_init_query_functions(struct dd_function_table *functions)
{
functions->NewQueryObject = st_NewQueryObject;
+ functions->DeleteQuery = st_DeleteQuery;
functions->BeginQuery = st_BeginQuery;
functions->EndQuery = st_EndQuery;
functions->WaitQuery = st_WaitQuery;
+ functions->CheckQuery = st_CheckQuery;
}