Mesa (main): zink: split out zink_transfer allocation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 17 21:13:58 UTC 2021


Module: Mesa
Branch: main
Commit: b19bff17f401698e89b5a975b68fafa52f838ccb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b19bff17f401698e89b5a975b68fafa52f838ccb

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Jul 30 10:19:00 2021 -0400

zink: split out zink_transfer allocation

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12422>

---

 src/gallium/drivers/zink/zink_resource.c | 37 ++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index c18d89683df..cabac629777 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -1036,6 +1036,28 @@ unmap_resource(struct zink_screen *screen, struct zink_resource *res)
    zink_bo_unmap(screen, res->obj->bo);
 }
 
+static struct zink_transfer *
+create_transfer(struct zink_context *ctx, struct pipe_resource *pres, unsigned usage, const struct pipe_box *box)
+{
+   struct zink_transfer *trans;
+
+   if (usage & PIPE_MAP_THREAD_SAFE)
+      trans = malloc(sizeof(*trans));
+   else if (usage & TC_TRANSFER_MAP_THREADED_UNSYNC)
+      trans = slab_alloc(&ctx->transfer_pool_unsync);
+   else
+      trans = slab_alloc(&ctx->transfer_pool);
+   if (!trans)
+      return NULL;
+
+   memset(trans, 0, sizeof(*trans));
+   pipe_resource_reference(&trans->base.b.resource, pres);
+
+   trans->base.b.usage = usage;
+   trans->base.b.box = *box;
+   return trans;
+}
+
 static void *
 buffer_transfer_map(struct zink_context *ctx, struct zink_resource *res, unsigned usage,
                     const struct pipe_box *box, struct zink_transfer *trans)
@@ -1186,24 +1208,11 @@ zink_transfer_map(struct pipe_context *pctx,
    struct zink_screen *screen = zink_screen(pctx->screen);
    struct zink_resource *res = zink_resource(pres);
 
-   struct zink_transfer *trans;
-
-   if (usage & PIPE_MAP_THREAD_SAFE)
-      trans = malloc(sizeof(*trans));
-   else if (usage & TC_TRANSFER_MAP_THREADED_UNSYNC)
-      trans = slab_alloc(&ctx->transfer_pool_unsync);
-   else
-      trans = slab_alloc(&ctx->transfer_pool);
+   struct zink_transfer *trans = create_transfer(ctx, pres, usage, box);
    if (!trans)
       return NULL;
 
-   memset(trans, 0, sizeof(*trans));
-   pipe_resource_reference(&trans->base.b.resource, pres);
-
-   trans->base.b.resource = pres;
    trans->base.b.level = level;
-   trans->base.b.usage = usage;
-   trans->base.b.box = *box;
 
    void *ptr, *base;
    if (pres->target == PIPE_BUFFER) {



More information about the mesa-commit mailing list