panfrost: Upload shader descriptors at CSO create
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 21 Aug 2020 18:16:18 +0000 (14:16 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 25 Aug 2020 15:05:38 +0000 (17:05 +0200)
Now that we've fixed all the implicit state dependencies, these don't
change after the variant is created.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6440>

src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h

index 21c1810de7532fdf6e570c991affe84ca4eb0e1f..236acd77046569e3e79298d9815abd843c91e27a 100644 (file)
@@ -35,6 +35,7 @@
 #include "midgard/midgard_compile.h"
 #include "bifrost/bifrost_compile.h"
 #include "util/u_dynarray.h"
+#include "util/u_upload_mgr.h"
 
 #include "tgsi/tgsi_dump.h"
 
@@ -98,6 +99,24 @@ pan_pack_bifrost_props(struct panfrost_shader_state *state,
         }
 }
 
+static void
+pan_upload_shader_descriptor(struct panfrost_context *ctx,
+                        struct panfrost_shader_state *state)
+{
+        const struct panfrost_device *dev = pan_device(ctx->base.screen);
+        struct mali_shader_meta meta;
+
+        memset(&meta, 0, sizeof(meta));
+        memcpy(&meta.shader, &state->shader, sizeof(state->shader));
+        memcpy(&meta.midgard_props, &state->properties, sizeof(state->properties));
+
+        if (dev->quirks & IS_BIFROST)
+                memcpy(&meta.bifrost_preload, &state->preload, sizeof(state->preload));
+
+        u_upload_data(ctx->state_uploader, 0, sizeof(meta), sizeof(meta),
+                        &meta, &state->upload.offset, &state->upload.rsrc);
+}
+
 static unsigned
 pan_format_from_nir_base(nir_alu_type base)
 {
@@ -361,6 +380,9 @@ panfrost_shader_compile(struct panfrost_context *ctx,
         else
                 pan_pack_midgard_props(state, stage);
 
+        if (stage != MESA_SHADER_FRAGMENT)
+                pan_upload_shader_descriptor(ctx, state);
+
         /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against
          * a NULL context */
         ralloc_free(s);
index 3002e551f6b83c2e34bed01be3544c489c2c10db..bcf0d199bd45f1ba6f768977d3a3463d467225a9 100644 (file)
@@ -486,10 +486,15 @@ panfrost_delete_shader_state(
         for (unsigned i = 0; i < cso->variant_count; ++i) {
                 struct panfrost_shader_state *shader_state = &cso->variants[i];
                 panfrost_bo_unreference(shader_state->bo);
+
+                if (shader_state->upload.rsrc)
+                        pipe_resource_reference(&shader_state->upload.rsrc, NULL);
+
                 shader_state->bo = NULL;
         }
         free(cso->variants);
 
+
         free(so);
 }
 
index d490f4aca564755937c3ac1b1173fe78b4aa612c..b7314c59e5f82efa4ccf8f89397695d23ca5ecf5 100644 (file)
@@ -188,6 +188,15 @@ struct panfrost_rasterizer {
 struct panfrost_shader_state {
         /* Compiled, mapped descriptor, ready for the hardware */
         bool compiled;
+
+        /* Uploaded shader descriptor (TODO: maybe stuff the packed unuploaded
+         * bits in a union to save some memory?) */
+
+        struct {
+                struct pipe_resource *rsrc;
+                uint32_t offset;
+        } upload;
+
         struct mali_shader_packed shader;
         struct mali_midgard_properties_packed properties;
         struct mali_preload_packed preload;