summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/virgl/virgl_buffer.c
diff options
context:
space:
mode:
authorAlexandros Frantzis <[email protected]>2019-06-22 01:18:27 +0300
committerChia-I Wu <[email protected]>2019-07-03 09:59:55 -0700
commite5be4351c2f5cc7a639dc2727e0b38f56b4a2263 (patch)
tree4560150f342c23c0514bc1365c0f649e8ad694f5 /src/gallium/drivers/virgl/virgl_buffer.c
parent243db4980c77e9d55b016ea79c4ddf075101bde0 (diff)
virgl: Clear the valid buffer range when possible
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 <[email protected]> Reviewed-by: Chia-I Wu <[email protected]>
Diffstat (limited to 'src/gallium/drivers/virgl/virgl_buffer.c')
-rw-r--r--src/gallium/drivers/virgl/virgl_buffer.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/gallium/drivers/virgl/virgl_buffer.c b/src/gallium/drivers/virgl/virgl_buffer.c
index fb97ce15aae..b0684bcbf57 100644
--- a/src/gallium/drivers/virgl/virgl_buffer.c
+++ b/src/gallium/drivers/virgl/virgl_buffer.c
@@ -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);