virgl: improve virgl_transfer_queue_is_queued
authorChia-I Wu <olvaffe@gmail.com>
Mon, 8 Jul 2019 23:34:32 +0000 (16:34 -0700)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 9 Jul 2019 21:26:55 +0000 (14:26 -0700)
Search only the pending list and return immediately on the first
hit.

When the transfer queue was introduced, the function was used to
deal with

  write transfer -> draw -> write transfer

sequence.  It was used to tell if the second transfer intersects
with the first transfer. If yes, the transfer queue avoided
reordering the second transfer to before the draw (by flushing) in
case the draw uses the transferred data.

With the recent changes to the transfer code, the function is used
to deal with

  write transfer -> readback transfer

We want to avoid reordering the readback transfer to before the
first transfer (also by flushing).

In the old code, we needed to track the compeleted transfers as well
to avoid reordering.  But in the new code, a readback transfer is
guaranteed to see the data from the completed transfers (in other
words, it cannot be reoderered to before the already completed
transfers).  We don't need to search the COMPLETED_LIST.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
src/gallium/drivers/virgl/virgl_transfer_queue.c

index a7767345f992171d5da507b1e1030e8b4eccb055..4511d2f12d2dec2283cd87793520974772a73336 100644 (file)
@@ -137,25 +137,27 @@ transfer_overlap(const struct virgl_transfer *xfer,
    return true;
 }
 
-static bool transfers_intersect(struct virgl_transfer *queued,
-                                struct virgl_transfer *current)
+static struct virgl_transfer *
+virgl_transfer_queue_find_pending(const struct virgl_transfer_queue *queue,
+                                  const struct virgl_hw_res *hw_res,
+                                  unsigned level,
+                                  const struct pipe_box *box,
+                                  bool include_touching)
 {
-   return transfer_overlap(queued, current->hw_res, current->base.level,
-         &current->base.box, true);
-}
+   struct virgl_transfer *xfer;
+   LIST_FOR_EACH_ENTRY(xfer, &queue->lists[PENDING_LIST], queue_link) {
+      if (transfer_overlap(xfer, hw_res, level, box, include_touching))
+         return xfer;
+   }
 
-static bool transfers_overlap(struct virgl_transfer *queued,
-                              struct virgl_transfer *current)
-{
-   return transfer_overlap(queued, current->hw_res, current->base.level,
-         &current->base.box, false);
+   return NULL;
 }
 
-static void set_true(UNUSED struct virgl_transfer_queue *queue,
-                     struct list_action_args *args)
+static bool transfers_intersect(struct virgl_transfer *queued,
+                                struct virgl_transfer *current)
 {
-   bool *val = args->data;
-   *val = true;
+   return transfer_overlap(queued, current->hw_res, current->base.level,
+         &current->base.box, true);
 }
 
 static void set_queued(UNUSED struct virgl_transfer_queue *queue,
@@ -392,22 +394,11 @@ int virgl_transfer_queue_clear(struct virgl_transfer_queue *queue,
 bool virgl_transfer_queue_is_queued(struct virgl_transfer_queue *queue,
                                     struct virgl_transfer *transfer)
 {
-   bool queued = false;
-   struct list_iteration_args iter;
-
-   memset(&iter, 0, sizeof(iter));
-   iter.current = transfer;
-   iter.compare = transfers_overlap;
-   iter.action = set_true;
-   iter.data = &queued;
-
-   iter.type = PENDING_LIST;
-   compare_and_perform_action(queue, &iter);
-
-   iter.type = COMPLETED_LIST;
-   compare_and_perform_action(queue, &iter);
-
-   return queued;
+   return virgl_transfer_queue_find_pending(queue,
+                                            transfer->hw_res,
+                                            transfer->base.level,
+                                            &transfer->base.box,
+                                            false);
 }
 
 struct virgl_transfer *