etnaviv: pass shader key by reference
The shader key has grown substancially since the introduction of the shadow sampler lowering to the point where passing it by value when looking for the right variant matching the current state is showing up in the CPU profiles. Pass the key by reference to get rid of this overhead. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18968>
This commit is contained in:
@@ -155,7 +155,7 @@ main(int argc, char **argv)
|
||||
shader.compiler = compiler;
|
||||
|
||||
struct util_debug_callback debug = {}; // TODO: proper debug callback
|
||||
struct etna_shader_variant *v = etna_shader_variant(&shader, key, &debug);
|
||||
struct etna_shader_variant *v = etna_shader_variant(&shader, &key, &debug);
|
||||
if (!v) {
|
||||
fprintf(stderr, "shader variant creation failed!\n");
|
||||
return 1;
|
||||
|
||||
@@ -161,7 +161,7 @@ etna_update_state_for_draw(struct etna_context *ctx, const struct pipe_draw_info
|
||||
}
|
||||
|
||||
static bool
|
||||
etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
|
||||
etna_get_vs(struct etna_context *ctx, struct etna_shader_key* const key)
|
||||
{
|
||||
const struct etna_shader_variant *old = ctx->shader.vs;
|
||||
|
||||
@@ -177,7 +177,7 @@ etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
|
||||
}
|
||||
|
||||
static bool
|
||||
etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
|
||||
etna_get_fs(struct etna_context *ctx, struct etna_shader_key* const key)
|
||||
{
|
||||
const struct etna_shader_variant *old = ctx->shader.fs;
|
||||
|
||||
@@ -189,15 +189,15 @@ etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
|
||||
if (ctx->sampler[i]->compare_mode == PIPE_TEX_COMPARE_NONE)
|
||||
continue;
|
||||
|
||||
key.has_sample_tex_compare = 1;
|
||||
key.num_texture_states = ctx->num_fragment_sampler_views;
|
||||
key->has_sample_tex_compare = 1;
|
||||
key->num_texture_states = ctx->num_fragment_sampler_views;
|
||||
|
||||
key.tex_swizzle[i].swizzle_r = ctx->sampler_view[i]->swizzle_r;
|
||||
key.tex_swizzle[i].swizzle_g = ctx->sampler_view[i]->swizzle_g;
|
||||
key.tex_swizzle[i].swizzle_b = ctx->sampler_view[i]->swizzle_b;
|
||||
key.tex_swizzle[i].swizzle_a = ctx->sampler_view[i]->swizzle_a;
|
||||
key->tex_swizzle[i].swizzle_r = ctx->sampler_view[i]->swizzle_r;
|
||||
key->tex_swizzle[i].swizzle_g = ctx->sampler_view[i]->swizzle_g;
|
||||
key->tex_swizzle[i].swizzle_b = ctx->sampler_view[i]->swizzle_b;
|
||||
key->tex_swizzle[i].swizzle_a = ctx->sampler_view[i]->swizzle_a;
|
||||
|
||||
key.tex_compare_func[i] = ctx->sampler[i]->compare_func;
|
||||
key->tex_compare_func[i] = ctx->sampler[i]->compare_func;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info,
|
||||
if (pfb->cbufs[0])
|
||||
key.frag_rb_swap = !!translate_pe_format_rb_swap(pfb->cbufs[0]->format);
|
||||
|
||||
if (!etna_get_vs(ctx, key) || !etna_get_fs(ctx, key)) {
|
||||
if (!etna_get_vs(ctx, &key) || !etna_get_fs(ctx, &key)) {
|
||||
BUG("compiled shaders are not okay");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -399,7 +399,8 @@ etna_shader_update_vertex(struct etna_context *ctx)
|
||||
}
|
||||
|
||||
static struct etna_shader_variant *
|
||||
create_variant(struct etna_shader *shader, struct etna_shader_key key)
|
||||
create_variant(struct etna_shader *shader,
|
||||
const struct etna_shader_key* const key)
|
||||
{
|
||||
struct etna_shader_variant *v = CALLOC_STRUCT(etna_shader_variant);
|
||||
int ret;
|
||||
@@ -408,7 +409,7 @@ create_variant(struct etna_shader *shader, struct etna_shader_key key)
|
||||
return NULL;
|
||||
|
||||
v->shader = shader;
|
||||
v->key = key;
|
||||
v->key = *key;
|
||||
v->id = ++shader->variant_count;
|
||||
|
||||
if (etna_disk_cache_retrieve(shader->compiler, v))
|
||||
@@ -430,15 +431,16 @@ fail:
|
||||
}
|
||||
|
||||
struct etna_shader_variant *
|
||||
etna_shader_variant(struct etna_shader *shader, struct etna_shader_key key,
|
||||
struct util_debug_callback *debug)
|
||||
etna_shader_variant(struct etna_shader *shader,
|
||||
const struct etna_shader_key* const key,
|
||||
struct util_debug_callback *debug)
|
||||
{
|
||||
struct etna_shader_variant *v;
|
||||
|
||||
assert(shader->specs->fragment_sampler_count <= ARRAY_SIZE(key.tex_swizzle));
|
||||
assert(shader->specs->fragment_sampler_count <= ARRAY_SIZE(key->tex_swizzle));
|
||||
|
||||
for (v = shader->variants; v; v = v->next)
|
||||
if (etna_shader_key_equal(&key, &v->key))
|
||||
if (etna_shader_key_equal(key, &v->key))
|
||||
return v;
|
||||
|
||||
/* compile new variant if it doesn't exist already */
|
||||
@@ -473,7 +475,7 @@ create_initial_variants_async(void *job, void *gdata, int thread_index)
|
||||
struct util_debug_callback debug = {};
|
||||
static struct etna_shader_key key;
|
||||
|
||||
etna_shader_variant(shader, key, &debug);
|
||||
etna_shader_variant(shader, &key, &debug);
|
||||
}
|
||||
|
||||
static void *
|
||||
@@ -500,7 +502,7 @@ etna_create_shader_state(struct pipe_context *pctx,
|
||||
|
||||
if (initial_variants_synchronous(ctx)) {
|
||||
struct etna_shader_key key = {};
|
||||
etna_shader_variant(shader, key, &ctx->base.debug);
|
||||
etna_shader_variant(shader, &key, &ctx->base.debug);
|
||||
} else {
|
||||
struct etna_screen *screen = ctx->screen;
|
||||
util_queue_add_job(&screen->shader_compiler_queue, shader, &shader->ready,
|
||||
|
||||
@@ -64,7 +64,8 @@ struct etna_shader_key
|
||||
};
|
||||
|
||||
static inline bool
|
||||
etna_shader_key_equal(struct etna_shader_key *a, struct etna_shader_key *b)
|
||||
etna_shader_key_equal(const struct etna_shader_key* const a,
|
||||
const struct etna_shader_key* const b)
|
||||
{
|
||||
/* slow-path if we need to check tex_{swizzle,compare_func} */
|
||||
if (unlikely(a->has_sample_tex_compare || b->has_sample_tex_compare))
|
||||
@@ -98,8 +99,9 @@ bool
|
||||
etna_shader_update_vertex(struct etna_context *ctx);
|
||||
|
||||
struct etna_shader_variant *
|
||||
etna_shader_variant(struct etna_shader *shader, struct etna_shader_key key,
|
||||
struct util_debug_callback *debug);
|
||||
etna_shader_variant(struct etna_shader *shader,
|
||||
const struct etna_shader_key* const key,
|
||||
struct util_debug_callback *debug);
|
||||
|
||||
void
|
||||
etna_shader_init(struct pipe_context *pctx);
|
||||
|
||||
Reference in New Issue
Block a user