panfrost: Pass a batch to panfrost_{allocate,upload}_transient()
authorBoris Brezillon <boris.brezillon@collabora.com>
Sun, 1 Sep 2019 08:15:23 +0000 (10:15 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 13 Sep 2019 14:25:06 +0000 (16:25 +0200)
We need that if we want to upload transient buffers to a batch that's
not currently bound to the context, which in turn will be needed if we
want to relax the batch serialization we have right now (only flush
batches when we need to: on a flush request, or when one batch depends
on the result of other batches).

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/gallium/drivers/panfrost/pan_allocate.c
src/gallium/drivers/panfrost/pan_allocate.h
src/gallium/drivers/panfrost/pan_compute.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_fragment.c
src/gallium/drivers/panfrost/pan_instancing.c
src/gallium/drivers/panfrost/pan_mfbd.c
src/gallium/drivers/panfrost/pan_scoreboard.c
src/gallium/drivers/panfrost/pan_sfbd.c
src/gallium/drivers/panfrost/pan_varyings.c

index a22b1a5a88d601c8c744043a8dab2018c3cc4503..44af631d355f43ba2cfd3b0da0f528a04177d94d 100644 (file)
  * into the pool and copy there */
 
 struct panfrost_transfer
-panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz)
+panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz)
 {
-        struct panfrost_screen *screen = pan_screen(ctx->base.screen);
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+        struct panfrost_screen *screen = pan_screen(batch->ctx->base.screen);
 
         /* Pad the size */
         sz = ALIGN_POT(sz, ALIGNMENT);
@@ -89,9 +88,10 @@ panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz)
 }
 
 mali_ptr
-panfrost_upload_transient(struct panfrost_context *ctx, const void *data, size_t sz)
+panfrost_upload_transient(struct panfrost_batch *batch, const void *data,
+                          size_t sz)
 {
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sz);
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sz);
         memcpy(transfer.cpu, data, sz);
         return transfer.gpu;
 }
index c0aff62df4a175a42d042439be038d7b9dbc2f21..a80eadaffce86d97d0646479ba9794fa0b08dbc5 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "util/list.h"
 
-struct panfrost_context;
+struct panfrost_batch;
 
 /* Represents a fat pointer for GPU-mapped memory, returned from the transient
  * allocator and not used for much else */
@@ -64,9 +64,10 @@ struct panfrost_bo {
 };
 
 struct panfrost_transfer
-panfrost_allocate_transient(struct panfrost_context *ctx, size_t sz);
+panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz);
 
 mali_ptr
-panfrost_upload_transient(struct panfrost_context *ctx, const void *data, size_t sz);
+panfrost_upload_transient(struct panfrost_batch *batch, const void *data,
+                          size_t sz);
 
 #endif /* __PAN_ALLOCATE_H__ */
index 51967fe481ef2e2e516e62df5fe498fd3e79852b..4639c1b03c38e90afe90a131172048c2ecfa4b63 100644 (file)
@@ -87,6 +87,9 @@ panfrost_launch_grid(struct pipe_context *pipe,
 {
         struct panfrost_context *ctx = pan_context(pipe);
 
+        /* TODO: Do we want a special compute-only batch? */
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+
         ctx->compute_grid = info;
 
         struct mali_job_descriptor_header job = {
@@ -113,7 +116,7 @@ panfrost_launch_grid(struct pipe_context *pipe,
         };
 
         payload->postfix.framebuffer =
-                panfrost_upload_transient(ctx, &compute_fbd, sizeof(compute_fbd));
+                panfrost_upload_transient(batch, &compute_fbd, sizeof(compute_fbd));
 
         /* Invoke according to the grid info */
 
@@ -123,13 +126,10 @@ panfrost_launch_grid(struct pipe_context *pipe,
 
         /* Upload the payload */
 
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sizeof(job) + sizeof(*payload));
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(job) + sizeof(*payload));
         memcpy(transfer.cpu, &job, sizeof(job));
         memcpy(transfer.cpu + sizeof(job), payload, sizeof(*payload));
 
-        /* TODO: Do we want a special compute-only batch? */
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-
         /* Queue the job */
         panfrost_scoreboard_queue_compute_job(batch, transfer);
 
index 35b36f501e2aa171c5b23fbd75b6bd9a0f8bdfe3..3f036ce4b5f3c127def8aa8e083a03cf2edf2f24 100644 (file)
@@ -167,17 +167,19 @@ panfrost_clear(
 static mali_ptr
 panfrost_attach_vt_mfbd(struct panfrost_context *ctx)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct bifrost_framebuffer mfbd = panfrost_emit_mfbd(ctx, ~0);
 
-        return panfrost_upload_transient(ctx, &mfbd, sizeof(mfbd)) | MALI_MFBD;
+        return panfrost_upload_transient(batch, &mfbd, sizeof(mfbd)) | MALI_MFBD;
 }
 
 static mali_ptr
 panfrost_attach_vt_sfbd(struct panfrost_context *ctx)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct mali_single_framebuffer sfbd = panfrost_emit_sfbd(ctx, ~0);
 
-        return panfrost_upload_transient(ctx, &sfbd, sizeof(sfbd)) | MALI_SFBD;
+        return panfrost_upload_transient(batch, &sfbd, sizeof(sfbd)) | MALI_SFBD;
 }
 
 static void
@@ -434,6 +436,7 @@ panfrost_default_shader_backend(struct panfrost_context *ctx)
 struct panfrost_transfer
 panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct mali_job_descriptor_header job = {
                 .job_type = is_tiler ? JOB_TYPE_TILER : JOB_TYPE_VERTEX,
                 .job_descriptor_size = 1,
@@ -441,7 +444,7 @@ panfrost_vertex_tiler_job(struct panfrost_context *ctx, bool is_tiler)
 
         struct midgard_payload_vertex_tiler *payload = is_tiler ? &ctx->payloads[PIPE_SHADER_FRAGMENT] : &ctx->payloads[PIPE_SHADER_VERTEX];
 
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sizeof(job) + sizeof(*payload));
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(job) + sizeof(*payload));
         memcpy(transfer.cpu, &job, sizeof(job));
         memcpy(transfer.cpu + sizeof(job), payload, sizeof(*payload));
         return transfer;
@@ -471,10 +474,11 @@ panfrost_writes_point_size(struct panfrost_context *ctx)
 static void
 panfrost_stage_attributes(struct panfrost_context *ctx)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct panfrost_vertex_state *so = ctx->vertex;
 
         size_t sz = sizeof(struct mali_attr_meta) * so->num_elements;
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sz);
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sz);
         struct mali_attr_meta *target = (struct mali_attr_meta *) transfer.cpu;
 
         /* Copy as-is for the first pass */
@@ -527,6 +531,7 @@ panfrost_stage_attributes(struct panfrost_context *ctx)
 static void
 panfrost_upload_sampler_descriptors(struct panfrost_context *ctx)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         size_t desc_size = sizeof(struct mali_sampler_descriptor);
 
         for (int t = 0; t <= PIPE_SHADER_FRAGMENT; ++t) {
@@ -536,7 +541,7 @@ panfrost_upload_sampler_descriptors(struct panfrost_context *ctx)
                         size_t transfer_size = desc_size * ctx->sampler_count[t];
 
                         struct panfrost_transfer transfer =
-                                panfrost_allocate_transient(ctx, transfer_size);
+                                panfrost_allocate_transient(batch, transfer_size);
 
                         struct mali_sampler_descriptor *desc =
                                 (struct mali_sampler_descriptor *) transfer.cpu;
@@ -626,13 +631,15 @@ panfrost_upload_tex(
                 }
         }
 
-        return panfrost_upload_transient(ctx, &view->hw,
+        return panfrost_upload_transient(batch, &view->hw,
                                          sizeof(struct mali_texture_descriptor));
 }
 
 static void
 panfrost_upload_texture_descriptors(struct panfrost_context *ctx)
 {
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+
         for (int t = 0; t <= PIPE_SHADER_FRAGMENT; ++t) {
                 mali_ptr trampoline = 0;
 
@@ -643,7 +650,7 @@ panfrost_upload_texture_descriptors(struct panfrost_context *ctx)
                                 trampolines[i] =
                                         panfrost_upload_tex(ctx, ctx->sampler_views[t][i]);
 
-                        trampoline = panfrost_upload_transient(ctx, trampolines, sizeof(uint64_t) * ctx->sampler_view_count[t]);
+                        trampoline = panfrost_upload_transient(batch, trampolines, sizeof(uint64_t) * ctx->sampler_view_count[t]);
                 }
 
                 ctx->payloads[t].postfix.texture_trampoline = trampoline;
@@ -789,12 +796,14 @@ panfrost_map_constant_buffer_gpu(
         struct pipe_constant_buffer *cb = &buf->cb[index];
         struct panfrost_resource *rsrc = pan_resource(cb->buffer);
 
-        if (rsrc)
+        if (rsrc) {
                 return rsrc->bo->gpu;
-        else if (cb->user_buffer)
-                return panfrost_upload_transient(ctx, cb->user_buffer, cb->buffer_size);
-        else
+       } else if (cb->user_buffer) {
+                struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+                return panfrost_upload_transient(batch, cb->user_buffer, cb->buffer_size);
+       } else {
                 unreachable("No constant buffer");
+        }
 }
 
 /* Compute number of UBOs active (more specifically, compute the highest UBO
@@ -831,9 +840,10 @@ panfrost_patch_shader_state(
          * transient uploaded */
 
         if (should_upload) {
-                return panfrost_upload_transient(ctx,
-                                ss->tripipe,
-                                sizeof(struct mali_shader_meta));
+                struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+
+                return panfrost_upload_transient(batch, ss->tripipe,
+                                                 sizeof(struct mali_shader_meta));
         }
 
         /* If we don't need an upload, don't bother */
@@ -1020,7 +1030,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                 }
 
                 size_t size = sizeof(struct mali_shader_meta) + (sizeof(struct midgard_blend_rt) * rt_count);
-                struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, size);
+                struct panfrost_transfer transfer = panfrost_allocate_transient(batch, size);
                 memcpy(transfer.cpu, &ctx->fragment_shader_core, sizeof(struct mali_shader_meta));
 
                 ctx->payloads[PIPE_SHADER_FRAGMENT].postfix._shader_upper = (transfer.gpu) >> 4;
@@ -1111,7 +1121,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                 size_t sys_size = sizeof(float) * 4 * ss->sysval_count;
                 size_t uniform_size = has_uniforms ? (buf->cb[0].buffer_size) : 0;
                 size_t size = sys_size + uniform_size;
-                struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, size);
+                struct panfrost_transfer transfer = panfrost_allocate_transient(batch, size);
 
                 /* Upload sysvals requested by the shader */
                 panfrost_upload_sysvals(ctx, transfer.cpu, ss, i);
@@ -1167,7 +1177,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                         ubos[ubo].ptr = gpu >> 2;
                 }
 
-                mali_ptr ubufs = panfrost_upload_transient(ctx, ubos, sz);
+                mali_ptr ubufs = panfrost_upload_transient(batch, ubos, sz);
                 postfix->uniforms = transfer.gpu;
                 postfix->uniform_buffers = ubufs;
 
@@ -1267,7 +1277,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
         view.clip_maxz = maxz;
 
         ctx->payloads[PIPE_SHADER_FRAGMENT].postfix.viewport =
-                panfrost_upload_transient(ctx,
+                panfrost_upload_transient(batch,
                                           &view,
                                           sizeof(struct mali_viewport));
 
@@ -1517,7 +1527,7 @@ panfrost_get_index_buffer_mapped(struct panfrost_context *ctx, const struct pipe
         } else {
                 /* Otherwise, we need to upload to transient memory */
                 const uint8_t *ibuf8 = (const uint8_t *) info->index.user;
-                return panfrost_upload_transient(ctx, ibuf8 + offset, info->count * info->index_size);
+                return panfrost_upload_transient(batch, ibuf8 + offset, info->count * info->index_size);
         }
 }
 
@@ -2577,13 +2587,14 @@ panfrost_begin_query(struct pipe_context *pipe, struct pipe_query *q)
 {
         struct panfrost_context *ctx = pan_context(pipe);
         struct panfrost_query *query = (struct panfrost_query *) q;
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
 
         switch (query->type) {
         case PIPE_QUERY_OCCLUSION_COUNTER:
         case PIPE_QUERY_OCCLUSION_PREDICATE:
         case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
                 /* Allocate a word for the query results to be stored */
-                query->transfer = panfrost_allocate_transient(ctx, sizeof(unsigned));
+                query->transfer = panfrost_allocate_transient(batch, sizeof(unsigned));
                 ctx->occlusion_query = query;
                 break;
 
index f92bf4e3522665a3ade6a5d9cb4672cc1cf57679..dc89bce1b76bdc3cf1a2e14d5331619a1867c8b8 100644 (file)
@@ -108,7 +108,7 @@ panfrost_fragment_job(struct panfrost_context *ctx, bool has_draws)
          * shared with 64-bit Bifrost systems, and accordingly there is 4-bytes
          * of zero padding in between. */
 
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sizeof(header) + sizeof(payload));
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(header) + sizeof(payload));
         memcpy(transfer.cpu, &header, sizeof(header));
         memcpy(transfer.cpu + sizeof(header), &payload, sizeof(payload));
         return transfer.gpu;
index 44fe0a344aab69d87f995670afa2ba57923ba9c2..e7e1f1d0e12bc130e77f1020781bd9ec805bba50 100644 (file)
@@ -341,7 +341,7 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch)
         /* Upload whatever we emitted and go */
 
         ctx->payloads[PIPE_SHADER_VERTEX].postfix.attributes =
-                panfrost_upload_transient(ctx, attrs, k * sizeof(union mali_attr));
+                panfrost_upload_transient(batch, attrs, k * sizeof(union mali_attr));
 }
 
 
index 8b1831c92083392f9bc5d7c5c70ecb6415b260e7..da1827a30ca9577f6f8d200cecb67a1f6a63b95a 100644 (file)
@@ -364,8 +364,9 @@ panfrost_mfbd_upload(
                 (has_extra ? sizeof(struct bifrost_fb_extra) : 0) +
                 sizeof(struct bifrost_render_target) * 4;
 
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct panfrost_transfer m_f_trans =
-                panfrost_allocate_transient(ctx, total_sz);
+                panfrost_allocate_transient(batch, total_sz);
 
         /* Do the transfer */
 
index 776833a13aba5cc8226aed1283cc7b056ffbf232..f0771a2c5b5680cd170bd1b54e7452687b44a5ee 100644 (file)
@@ -282,7 +282,8 @@ panfrost_set_value_job(struct panfrost_context *ctx, mali_ptr polygon_list)
                 .unknown = 0x3,
         };
 
-        struct panfrost_transfer transfer = panfrost_allocate_transient(ctx, sizeof(job) + sizeof(payload));
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch, sizeof(job) + sizeof(payload));
         memcpy(transfer.cpu, &job, sizeof(job));
         memcpy(transfer.cpu + sizeof(job), &payload, sizeof(payload));
 
index f58c054c8f2454b4d95550c757128ddaef3c98ff..843e5632491b632bb59b5984a3aa111ab97330da 100644 (file)
@@ -147,5 +147,5 @@ panfrost_sfbd_fragment(struct panfrost_context *ctx, bool has_draws)
         if (batch->requirements & PAN_REQ_MSAA)
                 fb.format |= MALI_FRAMEBUFFER_MSAA_A | MALI_FRAMEBUFFER_MSAA_B;
 
-        return panfrost_upload_transient(ctx, &fb, sizeof(fb)) | MALI_SFBD;
+        return panfrost_upload_transient(batch, &fb, sizeof(fb)) | MALI_SFBD;
 }
index 12760109b7cba57df1b0350b0c985b9aadbc212e..7adfc3ec4c7d56b31e923bf8286e54ea47476b5b 100644 (file)
@@ -38,8 +38,9 @@ panfrost_emit_varyings(
         slot->size = stride * count;
         slot->shift = slot->extra_flags = 0;
 
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
         struct panfrost_transfer transfer =
-                panfrost_allocate_transient(ctx, slot->size);
+                panfrost_allocate_transient(batch, slot->size);
 
         slot->elements = transfer.gpu | MALI_ATTR_LINEAR;
 
@@ -179,7 +180,8 @@ panfrost_emit_varying_descriptor(
         size_t vs_size = sizeof(struct mali_attr_meta) * vs->tripipe->varying_count;
         size_t fs_size = sizeof(struct mali_attr_meta) * fs->tripipe->varying_count;
 
-        struct panfrost_transfer trans = panfrost_allocate_transient(ctx,
+        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
+        struct panfrost_transfer trans = panfrost_allocate_transient(batch,
                                          vs_size + fs_size);
 
         struct pipe_stream_output_info so = vs->stream_output;
@@ -398,7 +400,7 @@ panfrost_emit_varying_descriptor(
                 }
         }
 
-        mali_ptr varyings_p = panfrost_upload_transient(ctx, &varyings, idx * sizeof(union mali_attr));
+        mali_ptr varyings_p = panfrost_upload_transient(batch, &varyings, idx * sizeof(union mali_attr));
         ctx->payloads[PIPE_SHADER_VERTEX].postfix.varyings = varyings_p;
         ctx->payloads[PIPE_SHADER_FRAGMENT].postfix.varyings = varyings_p;