virgl: Store the virgl_hw_res for copy transfers
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Wed, 26 Jun 2019 09:12:17 +0000 (12:12 +0300)
committerChia-I Wu <olvaffe@gmail.com>
Fri, 28 Jun 2019 04:30:02 +0000 (04:30 +0000)
Store the virgl_hw_res instead of the pipe_resource for copy transfer
sources. This prepares the codebase for a change to provide only the
virgl_hw_res for the staging buffers in upcoming commits.

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_encode.c
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_resource.h
src/gallium/drivers/virgl/virgl_texture.c
src/gallium/drivers/virgl/virgl_transfer_queue.c

index ed001722ab47ac938ff86b8c81f0ca9b10dd6129..93ccaeee99587cdaee731ffa39c2a6986f7081f1 100644 (file)
@@ -112,7 +112,7 @@ static void virgl_buffer_transfer_unmap(struct pipe_context *ctx,
          trans->offset = transfer->box.x;
       }
 
-      if (trans->copy_src_res) {
+      if (trans->copy_src_hw_res) {
          virgl_encode_copy_transfer(vctx, trans);
          /* It's now safe for other mappings to use the transfer_uploader. */
          vctx->transfer_uploader_in_use = false;
index 2975e6048cf01aede54b7c6686e988ebb7082e1f..0489f0880127504ffab5d5c327198f0b7817b50c 100644 (file)
@@ -1168,16 +1168,17 @@ void virgl_encode_copy_transfer(struct virgl_context *ctx,
                                 struct virgl_transfer *trans)
 {
    uint32_t command;
-   struct virgl_resource *copy_src_res = virgl_resource(trans->copy_src_res);
    struct virgl_screen *vs = virgl_screen(ctx->base.screen);
 
+   assert(trans->copy_src_hw_res);
+
    command = VIRGL_CMD0(VIRGL_CCMD_COPY_TRANSFER3D, 0, VIRGL_COPY_TRANSFER3D_SIZE);
    virgl_encoder_write_cmd_dword(ctx, command);
    /* Copy transfers need to explicitly specify the stride, since it may differ
     * from the image stride.
     */
    virgl_encoder_transfer3d_common(vs, ctx->cbuf, trans, virgl_transfer3d_explicit_stride);
-   virgl_encoder_emit_resource(vs, ctx->cbuf, copy_src_res);
+   vs->vws->emit_res(vs->vws, ctx->cbuf, trans->copy_src_hw_res, TRUE);
    virgl_encoder_write_dword(ctx->cbuf, trans->copy_src_offset);
    /* At the moment all copy transfers are synchronized. */
    virgl_encoder_write_dword(ctx->cbuf, 1);
index 5e372de7f15e3497a80bd72fd90f42a9557cdfa4..24f388f86ec57a244b31b311742ebade85ded0b2 100644 (file)
@@ -461,7 +461,7 @@ virgl_resource_create_transfer(struct virgl_context *vctx,
    trans->base.layer_stride = metadata->layer_stride[level];
    trans->offset = offset;
    util_range_init(&trans->range);
-   trans->copy_src_res = NULL;
+   trans->copy_src_hw_res = NULL;
    trans->copy_src_offset = 0;
 
    if (trans->base.resource->target != PIPE_TEXTURE_3D &&
@@ -481,7 +481,7 @@ void virgl_resource_destroy_transfer(struct virgl_context *vctx,
 {
    struct virgl_winsys *vws = virgl_screen(vctx->base.screen)->vws;
 
-   pipe_resource_reference(&trans->copy_src_res, NULL);
+   vws->resource_reference(vws, &trans->copy_src_hw_res, NULL);
 
    util_range_destroy(&trans->range);
    vws->resource_reference(vws, &trans->hw_res, NULL);
@@ -569,6 +569,7 @@ void *virgl_transfer_uploader_map(struct virgl_context *vctx,
                                   struct virgl_transfer *vtransfer)
 {
    struct virgl_resource *vres = virgl_resource(vtransfer->base.resource);
+   struct pipe_resource *copy_src_res = NULL;
    unsigned size;
    unsigned align_offset;
    unsigned stride;
@@ -600,8 +601,15 @@ void *virgl_transfer_uploader_map(struct virgl_context *vctx,
    u_upload_alloc(vctx->transfer_uploader, 0, size + align_offset,
                   VIRGL_MAP_BUFFER_ALIGNMENT,
                   &vtransfer->copy_src_offset,
-                  &vtransfer->copy_src_res, &map_addr);
+                  &copy_src_res, &map_addr);
    if (map_addr) {
+      struct virgl_winsys *vws = virgl_screen(vctx->base.screen)->vws;
+
+      /* Extract and reference the hw_res backing the pipe_resource. */
+      vws->resource_reference(vws, &vtransfer->copy_src_hw_res,
+                              virgl_resource(copy_src_res)->hw_res);
+      pipe_resource_reference(&copy_src_res, NULL);
+
       /* Update source offset and address to point to the requested x coordinate
        * if we have an align_offset (see above for more information). */
       vtransfer->copy_src_offset += align_offset;
index f9439a9489fb14637cbf6b2b3a564d16f3b72157..d390f1ce3cd2823e1732dc4e43b43f6b9e88197e 100644 (file)
@@ -96,7 +96,7 @@ struct virgl_transfer {
     * that the transfer source data should be taken from this
     * resource instead of the original transfer resource.
     */
-   struct pipe_resource *copy_src_res;
+   struct virgl_hw_res *copy_src_hw_res;
    /* The offset in the copy source resource to copy data from. */
    uint32_t copy_src_offset;
 };
index 3c5737c5d17cc1ce7aaba5f79f123ae27048766e..1553d41a072b1ea990541e1bd873f5559705c57e 100644 (file)
@@ -355,7 +355,7 @@ static void virgl_texture_transfer_unmap(struct pipe_context *ctx,
    }
 
    if (queue_unmap) {
-      if (trans->copy_src_res) {
+      if (trans->copy_src_hw_res) {
          virgl_encode_copy_transfer(vctx, trans);
          /* It's now safe for other mappings to use the transfer_uploader. */
          vctx->transfer_uploader_in_use = false;
index 33f8b62f4a32b2e365ac3e98ac464599a58a0c6e..970ee986cc118c6fa26c070adcccb86c64933d33 100644 (file)
@@ -289,7 +289,7 @@ int virgl_transfer_queue_unmap(struct virgl_transfer_queue *queue,
    struct list_iteration_args iter;
 
    /* We don't support copy transfers in the transfer queue. */
-   assert(!transfer->copy_src_res);
+   assert(!transfer->copy_src_hw_res);
 
    /* Attempt to merge multiple intersecting transfers into a single one. */
    if (transfer->base.resource->target == PIPE_BUFFER) {
@@ -364,7 +364,7 @@ virgl_transfer_queue_extend(struct virgl_transfer_queue *queue,
    struct list_iteration_args iter;
 
    /* We don't support extending from copy transfers. */
-   assert(!transfer->copy_src_res);
+   assert(!transfer->copy_src_hw_res);
 
    if (transfer->base.resource->target == PIPE_BUFFER) {
       memset(&iter, 0, sizeof(iter));