Skip to content
Snippets Groups Projects
Commit c9739941 authored by Boris Brezillon's avatar Boris Brezillon Committed by Marge Bot
Browse files

panfrost: Let compile_blend_shader() allocate the blend shader object


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: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: default avatarAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <mesa/mesa!7066>
parent dbc33e88
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -162,24 +159,11 @@ panfrost_bind_blend_state(struct pipe_context *pipe,
ctx->blend = (struct panfrost_blend_state *) cso;
}
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);
}
......
......@@ -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;
}
......@@ -31,11 +31,10 @@
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment