panfrost: Move sampler/tex descs emission helpers to pan_cmdstream.c
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 5 Mar 2020 17:43:13 +0000 (18:43 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Tue, 10 Mar 2020 11:47:34 +0000 (12:47 +0100)
Move panfrost_upload_texture_descriptors() and
panfrost_upload_sampler_descriptors() to pan_cmdstream.c where other
cmdstream related helpers live. While at it, change their prototype
and name to make it consistent with the other helpers and prepare
things for ctx->payloads[] removal.

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_context.c

index 8d9f35539538221737698c0f233ac7dd14a53e1c..467884cdd0bb93c5847c73d140af8e4666bb9710 100644 (file)
@@ -977,3 +977,71 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch,
         vtp->postfix.shared_memory = panfrost_upload_transient(batch, &shared,
                                                                sizeof(shared));
 }
+
+static mali_ptr
+panfrost_get_tex_desc(struct panfrost_batch *batch,
+                      enum pipe_shader_type st,
+                      struct panfrost_sampler_view *view)
+{
+        if (!view)
+                return (mali_ptr) 0;
+
+        struct pipe_sampler_view *pview = &view->base;
+        struct panfrost_resource *rsrc = pan_resource(pview->texture);
+
+        /* Add the BO to the job so it's retained until the job is done. */
+
+        panfrost_batch_add_bo(batch, rsrc->bo,
+                              PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
+                              panfrost_bo_access_for_stage(st));
+
+        panfrost_batch_add_bo(batch, view->bo,
+                              PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
+                              panfrost_bo_access_for_stage(st));
+
+        return view->bo->gpu;
+}
+
+void
+panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
+                                  enum pipe_shader_type stage,
+                                  struct midgard_payload_vertex_tiler *vtp)
+{
+        struct panfrost_context *ctx = batch->ctx;
+
+        if (!ctx->sampler_view_count[stage])
+                return;
+
+        uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+
+         for (int i = 0; i < ctx->sampler_view_count[stage]; ++i)
+                trampolines[i] = panfrost_get_tex_desc(batch, stage,
+                                                       ctx->sampler_views[stage][i]);
+
+         vtp->postfix.texture_trampoline = panfrost_upload_transient(batch,
+                                                                     trampolines,
+                                                                     sizeof(uint64_t) *
+                                                                     ctx->sampler_view_count[stage]);
+}
+
+void
+panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
+                                  enum pipe_shader_type stage,
+                                  struct midgard_payload_vertex_tiler *vtp)
+{
+        struct panfrost_context *ctx = batch->ctx;
+
+        if (!ctx->sampler_count[stage])
+                return;
+
+        size_t desc_size = sizeof(struct mali_sampler_descriptor);
+        size_t transfer_size = desc_size * ctx->sampler_count[stage];
+        struct panfrost_transfer transfer = panfrost_allocate_transient(batch,
+                                                                        transfer_size);
+        struct mali_sampler_descriptor *desc = (struct mali_sampler_descriptor *)transfer.cpu;
+
+        for (int i = 0; i < ctx->sampler_count[stage]; ++i)
+                desc[i] = ctx->samplers[stage][i]->hw;
+
+        vtp->postfix.sampler_descriptor = transfer.gpu;
+}
index b493f91fa27107b539f21e66344b7eec5f11da6c..aa77b8b28e1ac358f452ded108ee844b045727fd 100644 (file)
@@ -66,4 +66,14 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch,
                             const struct pipe_grid_info *info,
                             struct midgard_payload_vertex_tiler *vtp);
 
+void
+panfrost_emit_texture_descriptors(struct panfrost_batch *batch,
+                                  enum pipe_shader_type stage,
+                                  struct midgard_payload_vertex_tiler *vtp);
+
+void
+panfrost_emit_sampler_descriptors(struct panfrost_batch *batch,
+                                  enum pipe_shader_type stage,
+                                  struct midgard_payload_vertex_tiler *vtp);
+
 #endif /* __PAN_CMDSTREAM_H__ */
index 05a821807b34b4dac4bd855514b344bc4de56786..ba844cb1ca089a1751529ee35cf5716c20c2cb70 100644 (file)
@@ -262,82 +262,6 @@ panfrost_stage_attributes(struct panfrost_context *ctx)
         ctx->payloads[PIPE_SHADER_VERTEX].postfix.attribute_meta = transfer.gpu;
 }
 
-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) {
-                mali_ptr upload = 0;
-
-                if (ctx->sampler_count[t]) {
-                        size_t transfer_size = desc_size * ctx->sampler_count[t];
-
-                        struct panfrost_transfer transfer =
-                                panfrost_allocate_transient(batch, transfer_size);
-
-                        struct mali_sampler_descriptor *desc =
-                                (struct mali_sampler_descriptor *) transfer.cpu;
-
-                        for (int i = 0; i < ctx->sampler_count[t]; ++i)
-                                desc[i] = ctx->samplers[t][i]->hw;
-
-                        upload = transfer.gpu;
-                }
-
-                ctx->payloads[t].postfix.sampler_descriptor = upload;
-        }
-}
-
-static mali_ptr
-panfrost_upload_tex(
-        struct panfrost_context *ctx,
-        enum pipe_shader_type st,
-        struct panfrost_sampler_view *view)
-{
-        if (!view)
-                return (mali_ptr) 0;
-
-        struct pipe_sampler_view *pview = &view->base;
-        struct panfrost_resource *rsrc = pan_resource(pview->texture);
-
-        /* Add the BO to the job so it's retained until the job is done. */
-        struct panfrost_batch *batch = panfrost_get_batch_for_fbo(ctx);
-
-        panfrost_batch_add_bo(batch, rsrc->bo,
-                              PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
-                              panfrost_bo_access_for_stage(st));
-
-        panfrost_batch_add_bo(batch, view->bo,
-                              PAN_BO_ACCESS_SHARED | PAN_BO_ACCESS_READ |
-                              panfrost_bo_access_for_stage(st));
-
-        return view->bo->gpu;
-}
-
-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;
-
-                if (ctx->sampler_view_count[t]) {
-                        uint64_t trampolines[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-
-                        for (int i = 0; i < ctx->sampler_view_count[t]; ++i)
-                                trampolines[i] =
-                                        panfrost_upload_tex(ctx, t, ctx->sampler_views[t][i]);
-
-                        trampoline = panfrost_upload_transient(batch, trampolines, sizeof(uint64_t) * ctx->sampler_view_count[t]);
-                }
-
-                ctx->payloads[t].postfix.texture_trampoline = trampoline;
-        }
-}
-
 /* Compute number of UBOs active (more specifically, compute the highest UBO
  * number addressable -- if there are gaps, include them in the count anyway).
  * We always include UBO #0 in the count, since we *need* uniforms enabled for
@@ -382,11 +306,11 @@ panfrost_emit_for_draw(struct panfrost_context *ctx)
         if (ctx->vertex)
                 panfrost_stage_attributes(ctx);
 
-        panfrost_upload_sampler_descriptors(ctx);
-        panfrost_upload_texture_descriptors(ctx);
-
-        for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i)
+        for (int i = 0; i <= PIPE_SHADER_FRAGMENT; ++i) {
+                panfrost_emit_sampler_descriptors(batch, i, &ctx->payloads[i]);
+                panfrost_emit_texture_descriptors(batch, i, &ctx->payloads[i]);
                 panfrost_emit_const_buf(batch, i, &ctx->payloads[i]);
+        }
 
         /* TODO: Upload the viewport somewhere more appropriate */