panfrost: Move shared mem desc emission out of panfrost_launch_grid()
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 5 Mar 2020 08:57:44 +0000 (09:57 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Tue, 10 Mar 2020 11:47:33 +0000 (12:47 +0100)
Let's move the shared memory descriptor emission to a dedicated function
living with its pairs in pan_cmdstream.c.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4083>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_cmdstream.h
src/gallium/drivers/panfrost/pan_compute.c

index 99b3f5eeb8bca202cdf0bf5677473125329c367f..7f723b699a42cf4d68a7c62f14eeccfcd264f9a7 100644 (file)
@@ -422,3 +422,33 @@ panfrost_emit_const_buf(struct panfrost_batch *batch,
 
         buf->dirty_mask = 0;
 }
+
+void
+panfrost_emit_shared_memory(struct panfrost_batch *batch,
+                            const struct pipe_grid_info *info,
+                            struct midgard_payload_vertex_tiler *vtp)
+{
+        struct panfrost_context *ctx = batch->ctx;
+        struct panfrost_shader_variants *all = ctx->shader[PIPE_SHADER_COMPUTE];
+        struct panfrost_shader_state *ss = &all->variants[all->active_variant];
+        unsigned single_size = util_next_power_of_two(MAX2(ss->shared_size,
+                                                           128));
+        unsigned shared_size = single_size * info->grid[0] * info->grid[1] *
+                               info->grid[2] * 4;
+        struct panfrost_bo *bo = panfrost_batch_get_shared_memory(batch,
+                                                                  shared_size,
+                                                                  1);
+
+        struct mali_shared_memory shared = {
+                .shared_memory = bo->gpu,
+                .shared_workgroup_count =
+                        util_logbase2_ceil(info->grid[0]) +
+                        util_logbase2_ceil(info->grid[1]) +
+                        util_logbase2_ceil(info->grid[2]),
+                .shared_unk1 = 0x2,
+                .shared_shift = util_logbase2(single_size) - 1
+        };
+
+        vtp->postfix.shared_memory = panfrost_upload_transient(batch, &shared,
+                                                               sizeof(shared));
+}
index a9efca75e506ce46c4395c413f414d96d77f2f48..8ad9a8282d752fea9fd0e42a43ebf68e88110893 100644 (file)
@@ -26,6 +26,7 @@
 #define __PAN_CMDSTREAM_H__
 
 #include "pipe/p_defines.h"
+#include "pipe/p_state.h"
 
 #include "panfrost-job.h"
 
@@ -40,4 +41,9 @@ panfrost_emit_const_buf(struct panfrost_batch *batch,
                         enum pipe_shader_type stage,
                         struct midgard_payload_vertex_tiler *vtp);
 
+void
+panfrost_emit_shared_memory(struct panfrost_batch *batch,
+                            const struct pipe_grid_info *info,
+                            struct midgard_payload_vertex_tiler *vtp);
+
 #endif /* __PAN_CMDSTREAM_H__ */
index 9747c5cdab7bae9fb764280b6b5b43c4249403b5..d344d862243a2f8f1dc4296f53399a186cb9b73f 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include "pan_context.h"
+#include "pan_cmdstream.h"
 #include "pan_bo.h"
 #include "util/u_memory.h"
 #include "nir_serialize.h"
@@ -106,8 +107,6 @@ panfrost_launch_grid(struct pipe_context *pipe,
 
         /* TODO: Stub */
         struct midgard_payload_vertex_tiler *payload = &ctx->payloads[PIPE_SHADER_COMPUTE];
-        struct panfrost_shader_variants *all = ctx->shader[PIPE_SHADER_COMPUTE];
-        struct panfrost_shader_state *ss = &all->variants[all->active_variant];
 
         /* We implement OpenCL inputs as uniforms (or a UBO -- same thing), so
          * reuse the graphics path for this by lowering to Gallium */
@@ -123,22 +122,7 @@ panfrost_launch_grid(struct pipe_context *pipe,
                 pipe->set_constant_buffer(pipe, PIPE_SHADER_COMPUTE, 0, &ubuf);
 
         panfrost_emit_for_draw(ctx, false);
-
-        unsigned single_size = util_next_power_of_two(MAX2(ss->shared_size, 128));
-        unsigned shared_size = single_size * info->grid[0] * info->grid[1] * info->grid[2] * 4;
-
-        struct mali_shared_memory shared = {
-                .shared_memory = panfrost_batch_get_shared_memory(batch, shared_size, 1)->gpu,
-                .shared_workgroup_count =
-                        util_logbase2_ceil(info->grid[0]) +
-                        util_logbase2_ceil(info->grid[1]) +
-                        util_logbase2_ceil(info->grid[2]),
-                .shared_unk1 = 0x2,
-                .shared_shift = util_logbase2(single_size) - 1
-        };
-
-        payload->postfix.shared_memory =
-                panfrost_upload_transient(batch, &shared, sizeof(shared));
+        panfrost_emit_shared_memory(batch, info, payload);
 
         /* Invoke according to the grid info */