+ vs->vws->resource_wait(vs->vws, query->buf->hw_res);
+ else if (vs->vws->resource_is_busy(vs->vws, query->buf->hw_res))
+ return false;
+
+ host_state = vs->vws->resource_map(vs->vws, query->buf->hw_res);
+
+ /* The resouce is idle and the result should be available at this point,
+ * unless we are dealing with an older host. In that case,
+ * VIRGL_CCMD_GET_QUERY_RESULT is not fenced, the buffer is not
+ * coherent, and transfers are unsynchronized. We have to repeatedly
+ * transfer until we get the result back.
+ */
+ while (host_state->query_state != VIRGL_QUERY_STATE_DONE) {
+ debug_printf("VIRGL: get_query_result is forced blocking\n");
+
+ if (transfer) {
+ pipe_buffer_unmap(ctx, transfer);
+ if (!wait)
+ return false;
+ }
+
+ host_state = pipe_buffer_map(ctx, &query->buf->u.b,
+ PIPE_TRANSFER_READ, &transfer);
+ }
+
+ if (query->result_size == 8)
+ query->result = host_state->result;