panfrost: Add the panfrost_batch_create_bo() helper
authorBoris Brezillon <boris.brezillon@collabora.com>
Sat, 14 Sep 2019 15:57:06 +0000 (17:57 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Wed, 18 Sep 2019 08:37:31 +0000 (10:37 +0200)
This helper automates the panfrost_bo_create()+panfrost_batch_add_bo()+
panfrost_bo_unreference() sequence that's done for all per-batch BOs.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/pan_allocate.c
src/gallium/drivers/panfrost/pan_blend_cso.c
src/gallium/drivers/panfrost/pan_job.c
src/gallium/drivers/panfrost/pan_job.h

index 7938196e3e4f321329a4feb4e4deecb302ea5e7a..3076c23ab1cc771050f44c63dd0cebb631dabf64 100644 (file)
@@ -42,8 +42,6 @@
 struct panfrost_transfer
 panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz)
 {
-        struct panfrost_screen *screen = pan_screen(batch->ctx->base.screen);
-
         /* Pad the size */
         sz = ALIGN_POT(sz, ALIGNMENT);
 
@@ -66,12 +64,7 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz)
                                TRANSIENT_SLAB_SIZE : ALIGN_POT(sz, 4096);
 
                 /* We can't reuse the current BO, but we can create a new one. */
-                bo = panfrost_bo_create(screen, bo_sz, 0);
-                panfrost_batch_add_bo(batch, bo);
-
-                /* Creating a BO adds a reference, and then the job adds a
-                 * second one. So we need to pop back one reference */
-                panfrost_bo_unreference(bo);
+                bo = panfrost_batch_create_bo(batch, bo_sz, 0);
 
                 if (sz < TRANSIENT_SLAB_SIZE) {
                         batch->transient_bo = bo;
index 90a1e2956a532a0159ed9e7f59108708a42ddab7..6bd6ff71cdc72cf961c9bc833ec6de27092a253b 100644 (file)
@@ -227,7 +227,6 @@ panfrost_blend_constant(float *out, float *in, unsigned mask)
 struct panfrost_blend_final
 panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
 {
-        struct panfrost_screen *screen = pan_screen(ctx->base.screen);
         struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
 
         /* Grab the format, falling back gracefully if called invalidly (which
@@ -273,13 +272,10 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
         final.shader.first_tag = shader->first_tag;
 
         /* Upload the shader */
-        final.shader.bo = panfrost_bo_create(screen, shader->size, PAN_BO_EXECUTE);
+        final.shader.bo = panfrost_batch_create_bo(batch, shader->size,
+                                                   PAN_BO_EXECUTE);
         memcpy(final.shader.bo->cpu, shader->buffer, shader->size);
 
-        /* Pass BO ownership to job */
-        panfrost_batch_add_bo(batch, final.shader.bo);
-        panfrost_bo_unreference(final.shader.bo);
-
         if (shader->patch_index) {
                 /* We have to specialize the blend shader to use constants, so
                  * patch in the current constants */
index 4ffc990a5334ce581fe6f8878446087bfce1751b..cc0db3e440a1be11f8a8c475879607a6ccdce565 100644 (file)
@@ -144,6 +144,25 @@ panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo)
         _mesa_set_add(batch->bos, bo);
 }
 
+struct panfrost_bo *
+panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
+                         uint32_t create_flags)
+{
+        struct panfrost_bo *bo;
+
+        bo = panfrost_bo_create(pan_screen(batch->ctx->base.screen), size,
+                                create_flags);
+        panfrost_batch_add_bo(batch, bo);
+
+        /* panfrost_batch_add_bo() has retained a reference and
+         * panfrost_bo_create() initialize the refcnt to 1, so let's
+         * unreference the BO here so it gets released when the batch is
+         * destroyed (unless it's retained by someone else in the meantime).
+         */
+        panfrost_bo_unreference(bo);
+        return bo;
+}
+
 /* Returns the polygon list's GPU address if available, or otherwise allocates
  * the polygon list.  It's perfectly fast to use allocate/free BO directly,
  * since we'll hit the BO cache and this is one-per-batch anyway. */
@@ -154,19 +173,10 @@ panfrost_batch_get_polygon_list(struct panfrost_batch *batch, unsigned size)
         if (batch->polygon_list) {
                 assert(batch->polygon_list->size >= size);
         } else {
-                struct panfrost_screen *screen = pan_screen(batch->ctx->base.screen);
-
                 /* Create the BO as invisible, as there's no reason to map */
 
-                batch->polygon_list = panfrost_bo_create(screen, size,
-                                                         PAN_BO_INVISIBLE);
-                panfrost_batch_add_bo(batch, batch->polygon_list);
-
-                /* A BO reference has been retained by panfrost_batch_add_bo(),
-                 * so we need to unreference it here if we want the BO to be
-                 * automatically released when the batch is destroyed.
-                 */
-                panfrost_bo_unreference(&screen->base, batch->polygon_list);
+                batch->polygon_list = panfrost_batch_create_bo(batch, size,
+                                                              PAN_BO_INVISIBLE);
         }
 
         return batch->polygon_list->gpu;
index b0580ea2d47003a7a1a6c46c46d915567129b8a0..b1351b902bd27b1abeb87f2cef60f67e11755d53 100644 (file)
@@ -124,6 +124,10 @@ panfrost_batch_init(struct panfrost_context *ctx);
 void
 panfrost_batch_add_bo(struct panfrost_batch *batch, struct panfrost_bo *bo);
 
+struct panfrost_bo *
+panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
+                         uint32_t create_flags);
+
 void
 panfrost_batch_submit(struct panfrost_batch *batch);