virgl: clean up virgl_res_needs_readback
authorChia-I Wu <olvaffe@gmail.com>
Fri, 10 May 2019 03:40:41 +0000 (20:40 -0700)
committerChia-I Wu <olvaffe@gmail.com>
Wed, 15 May 2019 20:51:28 +0000 (20:51 +0000)
Add comments and follow the coding style of virgl_res_needs_flush.

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

index 83918f85216d48bb1191853a0bd54bdb9cd0c2de..52197b8017532b395c22fdbe4cf2c44690d84efb 100644 (file)
@@ -79,16 +79,27 @@ bool virgl_res_needs_flush(struct virgl_context *vctx,
    return true;
 }
 
+/* We need to read back from the host storage to make sure the guest storage
+ * is up-to-date.  But there are cases where the readback can be skipped:
+ *
+ *  - the content can be discarded
+ *  - the host storage is read-only
+ *
+ * Note that PIPE_TRANSFER_WRITE without discard bits requires readback.
+ * PIPE_TRANSFER_READ becomes irrelevant.  PIPE_TRANSFER_UNSYNCHRONIZED and
+ * PIPE_TRANSFER_FLUSH_EXPLICIT are also irrelevant.
+ */
 bool virgl_res_needs_readback(struct virgl_context *vctx,
                               struct virgl_resource *res,
                               unsigned usage, unsigned level)
 {
-   bool readback = true;
+   if (usage & PIPE_TRANSFER_DISCARD_RANGE)
+      return false;
+
    if (res->clean_mask & (1 << level))
-      readback = false;
-   else if (usage & PIPE_TRANSFER_DISCARD_RANGE)
-      readback = false;
-   return readback;
+      return false;
+
+   return true;
 }
 
 static struct pipe_resource *virgl_resource_create(struct pipe_screen *screen,