virgl: when creating / freeing transfers, pass slab pool directly
authorGurchetan Singh <gurchetansingh@chromium.org>
Fri, 4 Jan 2019 00:20:47 +0000 (16:20 -0800)
committerGert Wollny <gert.wollny@collabora.com>
Fri, 15 Feb 2019 10:19:04 +0000 (11:19 +0100)
This will allow us to destroy transfers w/o having a pointer
to the context.

Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
src/gallium/drivers/virgl/virgl_buffer.c
src/gallium/drivers/virgl/virgl_resource.c
src/gallium/drivers/virgl/virgl_resource.h
src/gallium/drivers/virgl/virgl_texture.c

index 3c732c90132ad3cb0d7320096f9a6873821ea26f..e46c9f504fd378984154c9bec6cf59b03690178a 100644 (file)
@@ -50,8 +50,8 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
    if (doflushwait)
       ctx->flush(ctx, NULL, 0);
 
-   trans = virgl_resource_create_transfer(ctx, resource, &vbuf->metadata, level,
-                                          usage, box);
+   trans = virgl_resource_create_transfer(&vctx->transfer_pool, resource,
+                                          &vbuf->metadata, level, usage, box);
 
    readback = virgl_res_needs_readback(vctx, vbuf, usage, 0);
    if (readback)
@@ -66,6 +66,7 @@ static void *virgl_buffer_transfer_map(struct pipe_context *ctx,
 
    ptr = vs->vws->resource_map(vs->vws, vbuf->hw_res);
    if (!ptr) {
+      virgl_resource_destroy_transfer(&vctx->transfer_pool, trans);
       return NULL;
    }
 
@@ -100,7 +101,7 @@ static void virgl_buffer_transfer_unmap(struct pipe_context *ctx,
    }
 
 out:
-   virgl_resource_destroy_transfer(vctx, trans);
+   virgl_resource_destroy_transfer(&vctx->transfer_pool, trans);
 }
 
 static void virgl_buffer_transfer_flush_region(struct pipe_context *ctx,
index 40f70be803647a20b04d7b4696354e7e058527e5..e9ccf66f8d04fdd44bc909c9e21c16f0baf9e913 100644 (file)
@@ -192,7 +192,7 @@ void virgl_resource_layout(struct pipe_resource *pt,
 }
 
 struct virgl_transfer *
-virgl_resource_create_transfer(struct pipe_context *ctx,
+virgl_resource_create_transfer(struct slab_child_pool *pool,
                                struct pipe_resource *pres,
                                const struct virgl_resource_metadata *metadata,
                                unsigned level, unsigned usage,
@@ -200,7 +200,6 @@ virgl_resource_create_transfer(struct pipe_context *ctx,
 {
    struct virgl_transfer *trans;
    enum pipe_format format = pres->format;
-   struct virgl_context *vctx = virgl_context(ctx);
    const unsigned blocksy = box->y / util_format_get_blockheight(format);
    const unsigned blocksx = box->x / util_format_get_blockwidth(format);
 
@@ -223,7 +222,7 @@ virgl_resource_create_transfer(struct pipe_context *ctx,
    offset += blocksy * metadata->stride[level];
    offset += blocksx * util_format_get_blocksize(format);
 
-   trans = slab_alloc(&vctx->transfer_pool);
+   trans = slab_alloc(pool);
    if (!trans)
       return NULL;
 
@@ -248,11 +247,11 @@ virgl_resource_create_transfer(struct pipe_context *ctx,
    return trans;
 }
 
-void virgl_resource_destroy_transfer(struct virgl_context *vctx,
+void virgl_resource_destroy_transfer(struct slab_child_pool *pool,
                                      struct virgl_transfer *trans)
 {
    util_range_destroy(&trans->range);
-   slab_free(&vctx->transfer_pool, trans);
+   slab_free(pool, trans);
 }
 
 void virgl_resource_destroy(struct pipe_screen *screen,
index 4aa2e71ecee6609edfbab3e89d83e3ead7c88263..3a017ef23557cd26dfbac642bff536fd7fbe99e4 100644 (file)
@@ -122,13 +122,13 @@ void virgl_resource_layout(struct pipe_resource *pt,
                            struct virgl_resource_metadata *metadata);
 
 struct virgl_transfer *
-virgl_resource_create_transfer(struct pipe_context *ctx,
+virgl_resource_create_transfer(struct slab_child_pool *pool,
                                struct pipe_resource *pres,
                                const struct virgl_resource_metadata *metadata,
                                unsigned level, unsigned usage,
                                const struct pipe_box *box);
 
-void virgl_resource_destroy_transfer(struct virgl_context *vctx,
+void virgl_resource_destroy_transfer(struct slab_child_pool *pool,
                                      struct virgl_transfer *trans);
 
 void virgl_resource_destroy(struct pipe_screen *screen,
index 9a402056e7a7f67a038cec9bdb68de8f98b11eac..ac937ec36d15f5bccd36e73cc45374e51492cfc9 100644 (file)
@@ -114,8 +114,8 @@ static void *virgl_texture_transfer_map(struct pipe_context *ctx,
    if (doflushwait)
       ctx->flush(ctx, NULL, 0);
 
-   trans = virgl_resource_create_transfer(ctx, resource, &vtex->metadata,
-                                          level, usage, box);
+   trans = virgl_resource_create_transfer(&vctx->transfer_pool, resource,
+                                          &vtex->metadata, level, usage, box);
 
    if (resource->nr_samples > 1) {
       struct pipe_resource tmp_resource;
@@ -147,7 +147,7 @@ static void *virgl_texture_transfer_map(struct pipe_context *ctx,
 
    ptr = vs->vws->resource_map(vs->vws, hw_res);
    if (!ptr) {
-      slab_free(&vctx->transfer_pool, trans);
+      virgl_resource_destroy_transfer(&vctx->transfer_pool, trans);
       return NULL;
    }
 
@@ -177,7 +177,7 @@ static void virgl_texture_transfer_unmap(struct pipe_context *ctx,
    if (trans->resolve_tmp)
       pipe_resource_reference((struct pipe_resource **)&trans->resolve_tmp, NULL);
 
-   virgl_resource_destroy_transfer(vctx, trans);
+   virgl_resource_destroy_transfer(&vctx->transfer_pool, trans);
 }
 
 static const struct u_resource_vtbl virgl_texture_vtbl =