+ st_flush_bitmap_cache(st_context(ctx));
+
+ if ((q->Target == GL_TIMESTAMP ||
+ q->Target == GL_TIME_ELAPSED) &&
+ !stq->pq) {
+ stq->pq = pipe->create_query(pipe, PIPE_QUERY_TIMESTAMP);
+ stq->type = PIPE_QUERY_TIMESTAMP;
+ }
+
+ if (stq->pq)
+ pipe->end_query(pipe, stq->pq);
+}
+
+
+static boolean
+get_query_result(struct pipe_context *pipe,
+ struct st_query_object *stq,
+ boolean wait)
+{
+ if (!stq->pq) {
+ /* Only needed in case we failed to allocate the gallium query earlier.
+ * Return TRUE so we don't spin on this forever.
+ */
+ return TRUE;
+ }
+
+ if (!pipe->get_query_result(pipe,
+ stq->pq,
+ wait,
+ (void *)&stq->base.Result)) {
+ return FALSE;
+ }
+
+ if (stq->base.Target == GL_TIME_ELAPSED &&
+ stq->type == PIPE_QUERY_TIMESTAMP) {
+ /* Calculate the elapsed time from the two timestamp queries */
+ GLuint64EXT Result0 = 0;
+ assert(stq->pq_begin);
+ pipe->get_query_result(pipe, stq->pq_begin, TRUE, (void *)&Result0);
+ stq->base.Result -= Result0;
+ } else {
+ assert(!stq->pq_begin);
+ }
+
+ return TRUE;