[Mesa-dev] [PATCH 09/12] virgl: make virgl_buffers use resource helpers

Gurchetan Singh gurchetansingh at chromium.org
Fri Dec 7 01:19:30 UTC 2018


We reuse the helpers we created.
---
 src/gallium/drivers/virgl/virgl_buffer.c   | 28 +++++++---------------
 src/gallium/drivers/virgl/virgl_resource.h |  1 +
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/src/gallium/drivers/virgl/virgl_buffer.c b/src/gallium/drivers/virgl/virgl_buffer.c
index d810e9e986..d5d728735e 100644
--- a/src/gallium/drivers/virgl/virgl_buffer.c
+++ b/src/gallium/drivers/virgl/virgl_buffer.c
@@ -51,7 +51,6 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
    struct virgl_transfer *trans;
    void *ptr;
    bool readback;
-   uint32_t offset;
    bool doflushwait = false;
 
    if ((usage & PIPE_TRANSFER_READ) && (vbuf->on_list == TRUE))
@@ -62,22 +61,13 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
    if (doflushwait)
       ctx->flush(ctx, NULL, 0);
 
-   trans = slab_alloc(&vctx->transfer_pool);
-   if (!trans)
-      return NULL;
-
-   trans->base.resource = resource;
-   trans->base.level = level;
-   trans->base.usage = usage;
-   trans->base.box = *box;
-   trans->base.stride = 0;
-   trans->base.layer_stride = 0;
-
-   offset = box->x;
+   trans = virgl_resource_create_transfer(ctx, resource, &vbuf->metadata, level,
+                                          usage, box);
 
    readback = virgl_res_needs_readback(vctx, &vbuf->base, usage);
    if (readback)
-      vs->vws->transfer_get(vs->vws, vbuf->base.hw_res, box, trans->base.stride, trans->base.layer_stride, offset, level);
+      vs->vws->transfer_get(vs->vws, vbuf->base.hw_res, box, trans->base.stride,
+                            trans->base.layer_stride, trans->offset, level);
 
    if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED))
       doflushwait = true;
@@ -90,9 +80,7 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
       return NULL;
    }
 
-   trans->offset = offset;
    *transfer = &trans->base;
-
    return ptr + trans->offset;
 }
 
@@ -150,7 +138,6 @@ struct pipe_resource *virgl_buffer_create(struct virgl_screen *vs,
                                           const struct pipe_resource *template)
 {
    struct virgl_buffer *buf;
-   uint32_t size;
    uint32_t vbind;
    buf = CALLOC_STRUCT(virgl_buffer);
    buf->base.clean = TRUE;
@@ -159,11 +146,14 @@ struct pipe_resource *virgl_buffer_create(struct virgl_screen *vs,
    buf->base.u.vtbl = &virgl_buffer_vtbl;
    pipe_reference_init(&buf->base.u.b.reference, 1);
    util_range_init(&buf->valid_buffer_range);
+   virgl_resource_layout(&buf->base.u.b, &buf->metadata);
 
    vbind = pipe_to_virgl_bind(template->bind);
-   size = template->width0;
 
-   buf->base.hw_res = vs->vws->resource_create(vs->vws, template->target, template->format, vbind, template->width0, 1, 1, 1, 0, 0, size);
+   buf->base.hw_res = vs->vws->resource_create(vs->vws, template->target,
+                                               template->format, vbind,
+                                               template->width0, 1, 1, 1, 0, 0,
+                                               buf->metadata.total_size);
 
    util_range_set_empty(&buf->valid_buffer_range);
    return &buf->base.u.b;
diff --git a/src/gallium/drivers/virgl/virgl_resource.h b/src/gallium/drivers/virgl/virgl_resource.h
index 82016741ec..fa985494a7 100644
--- a/src/gallium/drivers/virgl/virgl_resource.h
+++ b/src/gallium/drivers/virgl/virgl_resource.h
@@ -65,6 +65,7 @@ struct virgl_buffer {
     * the unsynchronized map flag and expect the driver to figure it out.
     */
    struct util_range valid_buffer_range;
+   struct virgl_resource_metadata metadata;
 };
 
 struct virgl_texture {
-- 
2.18.1



More information about the mesa-dev mailing list