virgl: Clear the valid buffer range when possible
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Fri, 21 Jun 2019 22:18:27 +0000 (01:18 +0300)
committerChia-I Wu <olvaffe@gmail.com>
Wed, 3 Jul 2019 16:59:55 +0000 (09:59 -0700)
If we are discarding the whole resource, we don't care about previous contents,
and the resource storage is now unused, either because we have created new
resource storage, or because we have waited for the existing resource storage
to become unused, or because the transfer is unsynchronized.

In the last two cases this commit marks the storage as uninitialized, but only
if the resource is not host writable (in which case we can't clear the valid
range, since that would result in missed readbacks in future transfers).

In the first case, when the whole resource discard involves a reallocation, the
reallocation and subsequent rebinding already update the valid buffer range
appropriately.

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

index fb97ce1..b0684bc 100644 (file)
@@ -78,6 +78,27 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
       return NULL;
    }
 
+   /* For the checks below to be able to use 'usage', we assume that
+    * transfer preparation doesn't affect the usage.
+    */
+   assert(usage == trans->base.usage);
+
+   /* If we are doing a whole resource discard with a hw_res map, the buffer
+    * storage can now be considered unused and we don't care about previous
+    * contents.  We can thus mark the storage as uninitialized, but only if the
+    * buffer is not host writable (in which case we can't clear the valid
+    * range, since that would result in missed readbacks in future transfers).
+    * We only do this for VIRGL_TRANSFER_MAP_HW_RES, since for
+    * VIRGL_TRANSFER_MAP_REALLOC we already take care of the buffer range when
+    * reallocating and rebinding, and VIRGL_TRANSFER_MAP_STAGING is not
+    * currently used for whole resource discards.
+    */
+   if (map_type == VIRGL_TRANSFER_MAP_HW_RES &&
+       (usage & PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE) &&
+       (vbuf->clean_mask & 1)) {
+      util_range_set_empty(&vbuf->valid_buffer_range);
+   }
+
    if (usage & PIPE_TRANSFER_WRITE)
        util_range_add(&vbuf->valid_buffer_range, box->x, box->x + box->width);
 
index 6199257..c47a154 100644 (file)
@@ -655,6 +655,9 @@ virgl_resource_realloc(struct virgl_context *vctx, struct virgl_resource *res)
    vs->vws->resource_reference(vs->vws, &res->hw_res, NULL);
    res->hw_res = hw_res;
 
+   /* We can safely clear the range here, since it will be repopulated in the
+    * following rebind operation, according to the active buffer binds.
+    */
    util_range_set_empty(&res->valid_buffer_range);
 
    /* count toward the staging resource size limit */