From b28f4bb67ce385b8e87c8d2c4d29195fe557547c Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 5 Mar 2020 10:46:39 +0100 Subject: [PATCH] panfrost: Add an helper to retrieve the currently active shader state Doing that improves readability and helps avoiding code duplication. Signed-off-by: Boris Brezillon Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_context.c | 18 +++++++----------- src/gallium/drivers/panfrost/pan_context.h | 12 ++++++++++++ src/gallium/drivers/panfrost/pan_varyings.c | 4 ++-- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index cc958469eda..83067e30446 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -357,7 +357,7 @@ bool panfrost_writes_point_size(struct panfrost_context *ctx) { assert(ctx->shader[PIPE_SHADER_VERTEX]); - struct panfrost_shader_state *vs = &ctx->shader[PIPE_SHADER_VERTEX]->variants[ctx->shader[PIPE_SHADER_VERTEX]->active_variant]; + struct panfrost_shader_state *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); return vs->writes_point_size && ctx->payloads[PIPE_SHADER_FRAGMENT].prefix.draw_mode == MALI_POINTS; } @@ -719,15 +719,13 @@ static void panfrost_patch_shader_state(struct panfrost_context *ctx, enum pipe_shader_type stage) { - struct panfrost_shader_variants *all = ctx->shader[stage]; + struct panfrost_shader_state *ss = panfrost_get_shader_state(ctx, stage); - if (!all) { + if (!ss) { ctx->payloads[stage].postfix.shader = 0; return; } - struct panfrost_shader_state *ss = &all->variants[all->active_variant]; - ss->tripipe->texture_count = ctx->sampler_view_count[stage]; ss->tripipe->sampler_count = ctx->sampler_count[stage]; @@ -804,7 +802,7 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data) } if (ctx->shader[PIPE_SHADER_FRAGMENT]) { - struct panfrost_shader_state *variant = &ctx->shader[PIPE_SHADER_FRAGMENT]->variants[ctx->shader[PIPE_SHADER_FRAGMENT]->active_variant]; + struct panfrost_shader_state *variant = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); panfrost_patch_shader_state(ctx, PIPE_SHADER_FRAGMENT); @@ -1160,12 +1158,11 @@ panfrost_queue_draw(struct panfrost_context *ctx) } for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) { - struct panfrost_shader_variants *all = ctx->shader[i]; + struct panfrost_shader_state *ss = panfrost_get_shader_state(ctx, i); - if (!all) + if (!ss) continue; - struct panfrost_shader_state *ss = &all->variants[all->active_variant]; batch->stack_size = MAX2(batch->stack_size, ss->stack_size); } } @@ -1553,8 +1550,7 @@ panfrost_bind_rasterizer_state( /* Point sprites are emulated */ - struct panfrost_shader_state *variant = - ctx->shader[PIPE_SHADER_FRAGMENT] ? &ctx->shader[PIPE_SHADER_FRAGMENT]->variants[ctx->shader[PIPE_SHADER_FRAGMENT]->active_variant] : NULL; + struct panfrost_shader_state *variant = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); if (ctx->rasterizer->base.sprite_coord_enable || (variant && variant->point_sprite_mask)) ctx->base.bind_fs_state(&ctx->base, ctx->shader[PIPE_SHADER_FRAGMENT]); diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 1e3639d5016..5fe8aebe960 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -272,6 +272,18 @@ pan_context(struct pipe_context *pcontext) return (struct panfrost_context *) pcontext; } +static inline struct panfrost_shader_state * +panfrost_get_shader_state(struct panfrost_context *ctx, + enum pipe_shader_type st) +{ + struct panfrost_shader_variants *all = ctx->shader[st]; + + if (!all) + return NULL; + + return &all->variants[all->active_variant]; +} + struct pipe_context * panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags); diff --git a/src/gallium/drivers/panfrost/pan_varyings.c b/src/gallium/drivers/panfrost/pan_varyings.c index 63425491ab0..9945944b982 100644 --- a/src/gallium/drivers/panfrost/pan_varyings.c +++ b/src/gallium/drivers/panfrost/pan_varyings.c @@ -180,8 +180,8 @@ panfrost_emit_varying_descriptor( { /* Load the shaders */ - struct panfrost_shader_state *vs = &ctx->shader[PIPE_SHADER_VERTEX]->variants[ctx->shader[PIPE_SHADER_VERTEX]->active_variant]; - struct panfrost_shader_state *fs = &ctx->shader[PIPE_SHADER_FRAGMENT]->variants[ctx->shader[PIPE_SHADER_FRAGMENT]->active_variant]; + struct panfrost_shader_state *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_shader_state *fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); unsigned int num_gen_varyings = 0; /* Allocate the varying descriptor */ -- 2.30.2