panfrost: Let compile_blend_shader() allocate the blend shader object
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 8 Oct 2020 08:52:30 +0000 (10:52 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 9 Oct 2020 14:16:41 +0000 (14:16 +0000)
This way we avoid an extra copy in panfrost_get_blend_shader().
Note that the allocation is attached to the blend state object
which simplifies the delete_blend_state() path.

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/7066>

src/gallium/drivers/panfrost/pan_blend_cso.c
src/gallium/drivers/panfrost/pan_blend_shaders.c
src/gallium/drivers/panfrost/pan_blend_shaders.h

index a334199..4f5a835 100644 (file)
@@ -88,10 +88,7 @@ panfrost_get_blend_shader(
 
         /* Cache miss. Build one instead, cache it, and go */
 
-        struct panfrost_blend_shader generated =
-                panfrost_compile_blend_shader(ctx, blend, fmt, rt);
-
-        shader = mem_dup(&generated, sizeof(generated));
+        shader = panfrost_compile_blend_shader(ctx, blend, fmt, rt);
         _mesa_hash_table_u64_insert(shaders, key, shader);
         return  shader;
 }
@@ -163,23 +160,10 @@ panfrost_bind_blend_state(struct pipe_context *pipe,
 }
 
 static void
-panfrost_delete_blend_shader(struct hash_entry *entry)
-{
-        struct panfrost_blend_shader *shader = (struct panfrost_blend_shader *)entry->data;
-        free(shader->buffer);
-        free(shader);
-}
-
-static void
 panfrost_delete_blend_state(struct pipe_context *pipe,
                             void *cso)
 {
         struct panfrost_blend_state *blend = (struct panfrost_blend_state *) cso;
-
-        for (unsigned c = 0; c < PIPE_MAX_COLOR_BUFS; ++c) {
-                struct panfrost_blend_rt *rt = &blend->rt[c];
-                _mesa_hash_table_u64_clear(rt->shaders, panfrost_delete_blend_shader);
-        }
         ralloc_free(blend);
 }
 
index bfaf474..d8b5c2a 100644 (file)
@@ -129,17 +129,16 @@ nir_iclamp(nir_builder *b, nir_ssa_def *v, int32_t lo, int32_t hi)
         return nir_imin(b, nir_imax(b, v, nir_imm_int(b, lo)), nir_imm_int(b, hi));
 }
 
-struct panfrost_blend_shader
-panfrost_compile_blend_shader(
-        struct panfrost_context *ctx,
-        struct panfrost_blend_state *state,
-        enum pipe_format format,
-        unsigned rt)
+struct panfrost_blend_shader *
+panfrost_compile_blend_shader(struct panfrost_context *ctx,
+                              struct panfrost_blend_state *state,
+                              enum pipe_format format,
+                              unsigned rt)
 {
         struct panfrost_device *dev = pan_device(ctx->base.screen);
-        struct panfrost_blend_shader res;
+        struct panfrost_blend_shader *res = ralloc(state, struct panfrost_blend_shader);
 
-        res.ctx = ctx;
+        res->ctx = ctx;
 
         /* Build the shader */
 
@@ -224,11 +223,13 @@ panfrost_compile_blend_shader(
         midgard_compile_shader_nir(shader, &program, &inputs);
 
         /* Allow us to patch later */
-        res.patch_index = program.blend_patch_offset;
-        res.first_tag = program.first_tag;
-        res.size = program.compiled.size;
-        res.buffer = program.compiled.data;
-        res.work_count = program.work_register_count;
+        res->patch_index = program.blend_patch_offset;
+        res->first_tag = program.first_tag;
+        res->size = program.compiled.size;
+        res->buffer = ralloc_size(res, res->size);
+        memcpy(res->buffer, program.compiled.data, res->size);
+        util_dynarray_fini(&program.compiled);
+        res->work_count = program.work_register_count;
 
         return res;
 }
index 40185cd..1fcae66 100644 (file)
 #include "pan_context.h"
 #include "pan_blend.h"
 
-struct panfrost_blend_shader
-panfrost_compile_blend_shader(
-        struct panfrost_context *ctx,
-        struct panfrost_blend_state *state,
-        enum pipe_format format,
-        unsigned rt);
+struct panfrost_blend_shader *
+panfrost_compile_blend_shader(struct panfrost_context *ctx,
+                              struct panfrost_blend_state *state,
+                              enum pipe_format format,
+                              unsigned rt);
 
 #endif