From 7bc34fbe8441bf72e4549996b3bdf39bf3251b20 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 14 Oct 2022 15:44:48 -0400 Subject: [PATCH] panfrost: Remove uncompiled_shader->active_variant The active compiled shader (variant) is context state, it is inappropriate to stash it on the uncompiled shader. Add compiled shader pointers to the context and get rid of the active_variant mutation. Names from iris. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_blit.c | 4 +- src/gallium/drivers/panfrost/pan_cmdstream.c | 69 ++++++++++++---------------- src/gallium/drivers/panfrost/pan_context.c | 6 +-- src/gallium/drivers/panfrost/pan_context.h | 19 ++------ src/gallium/drivers/panfrost/pan_job.c | 3 +- src/gallium/drivers/panfrost/pan_shader.c | 23 ++++++---- 6 files changed, 54 insertions(+), 70 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_blit.c b/src/gallium/drivers/panfrost/pan_blit.c index 1297ea8..7f059bd 100644 --- a/src/gallium/drivers/panfrost/pan_blit.c +++ b/src/gallium/drivers/panfrost/pan_blit.c @@ -38,11 +38,11 @@ panfrost_blitter_save(struct panfrost_context *ctx, bool render_cond) util_blitter_save_vertex_buffer_slot(blitter, ctx->vertex_buffers); util_blitter_save_vertex_elements(blitter, ctx->vertex); - util_blitter_save_vertex_shader(blitter, ctx->shader[PIPE_SHADER_VERTEX]); + util_blitter_save_vertex_shader(blitter, ctx->uncompiled[PIPE_SHADER_VERTEX]); util_blitter_save_rasterizer(blitter, ctx->rasterizer); util_blitter_save_viewport(blitter, &ctx->pipe_viewport); util_blitter_save_scissor(blitter, &ctx->scissor); - util_blitter_save_fragment_shader(blitter, ctx->shader[PIPE_SHADER_FRAGMENT]); + util_blitter_save_fragment_shader(blitter, ctx->uncompiled[PIPE_SHADER_FRAGMENT]); util_blitter_save_blend(blitter, ctx->blend); util_blitter_save_depth_stencil_alpha(blitter, ctx->depth_stencil); util_blitter_save_stencil_ref(blitter, &ctx->stencil_ref); diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 1c40c5f5..a7aba40 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -402,7 +402,7 @@ panfrost_emit_blend(struct panfrost_batch *batch, void *rts, mali_ptr *blend_sha #if PAN_ARCH >= 6 const struct panfrost_device *dev = pan_device(ctx->base.screen); struct panfrost_compiled_shader *fs = - panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + ctx->prog[PIPE_SHADER_FRAGMENT]; /* Words 2 and 3: Internal blend */ if (blend_shaders[i]) { @@ -481,7 +481,7 @@ pan_allow_forward_pixel_to_kill(struct panfrost_context *ctx, struct panfrost_co static mali_ptr panfrost_emit_compute_shader_meta(struct panfrost_batch *batch, enum pipe_shader_type stage) { - struct panfrost_compiled_shader *ss = panfrost_get_shader_state(batch->ctx, stage); + struct panfrost_compiled_shader *ss = batch->ctx->prog[stage]; panfrost_batch_add_bo(batch, ss->bin.bo, PIPE_SHADER_VERTEX); panfrost_batch_add_bo(batch, ss->state.bo, PIPE_SHADER_VERTEX); @@ -526,7 +526,7 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx, { struct pipe_rasterizer_state *rast = &ctx->rasterizer->base; const struct panfrost_zsa_state *zsa = ctx->depth_stencil; - struct panfrost_compiled_shader *fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *fs = ctx->prog[PIPE_SHADER_FRAGMENT]; struct panfrost_blend_state *so = ctx->blend; bool alpha_to_coverage = ctx->blend->base.alpha_to_coverage; bool msaa = rast->multisample; @@ -661,7 +661,7 @@ panfrost_emit_frag_shader(struct panfrost_context *ctx, const struct panfrost_zsa_state *zsa = ctx->depth_stencil; const struct panfrost_rasterizer *rast = ctx->rasterizer; struct panfrost_compiled_shader *fs = - panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + ctx->prog[PIPE_SHADER_FRAGMENT]; /* We need to merge several several partial renderer state descriptors, * so stage to temporary storage rather than reading back write-combine @@ -705,7 +705,7 @@ static mali_ptr panfrost_emit_frag_shader_meta(struct panfrost_batch *batch) { struct panfrost_context *ctx = batch->ctx; - struct panfrost_compiled_shader *ss = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *ss = ctx->prog[PIPE_SHADER_FRAGMENT]; panfrost_batch_add_bo(batch, ss->bin.bo, PIPE_SHADER_FRAGMENT); @@ -821,7 +821,7 @@ panfrost_emit_depth_stencil(struct panfrost_batch *batch) struct panfrost_context *ctx = batch->ctx; const struct panfrost_zsa_state *zsa = ctx->depth_stencil; struct panfrost_rasterizer *rast = ctx->rasterizer; - struct panfrost_compiled_shader *fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *fs = ctx->prog[PIPE_SHADER_FRAGMENT]; bool back_enab = zsa->base.stencil[1].enabled; struct panfrost_ptr T = pan_pool_alloc_desc(&batch->pool.base, DEPTH_STENCIL); @@ -1324,7 +1324,7 @@ panfrost_upload_sysvals(struct panfrost_batch *batch, { unsigned buf = PAN_SYSVAL_ID(sysval); struct panfrost_compiled_shader *vs = - panfrost_get_shader_state(batch->ctx, PIPE_SHADER_VERTEX); + batch->ctx->prog[PIPE_SHADER_VERTEX]; struct pipe_stream_output_info *so = &vs->stream_output; unsigned stride = so->stride[buf] * 4; @@ -1472,14 +1472,12 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, unsigned *pushed_words) { struct panfrost_context *ctx = batch->ctx; - struct panfrost_uncompiled_shader *all = ctx->shader[stage]; + struct panfrost_constant_buffer *buf = &ctx->constant_buffer[stage]; + struct panfrost_compiled_shader *ss = ctx->prog[stage]; - if (!all) + if (!ss) return 0; - struct panfrost_constant_buffer *buf = &ctx->constant_buffer[stage]; - struct panfrost_compiled_shader *ss = &all->variants[all->active_variant]; - /* Allocate room for the sysval and the uniforms */ size_t sys_size = sizeof(float) * 4 * ss->info.sysvals.sysval_count; struct panfrost_ptr transfer = @@ -1489,7 +1487,7 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, panfrost_upload_sysvals(batch, &transfer, ss, stage); /* Next up, attach UBOs. UBO count includes gaps but no sysval UBO */ - struct panfrost_compiled_shader *shader = panfrost_get_shader_state(ctx, stage); + struct panfrost_compiled_shader *shader = ctx->prog[stage]; unsigned ubo_count = shader->info.ubo_count - (sys_size ? 1 : 0); unsigned sysval_ubo = sys_size ? ubo_count : ~0; struct panfrost_ptr ubos = { 0 }; @@ -1621,8 +1619,7 @@ panfrost_emit_shared_memory(struct panfrost_batch *batch, { struct panfrost_context *ctx = batch->ctx; struct panfrost_device *dev = pan_device(ctx->base.screen); - struct panfrost_uncompiled_shader *all = ctx->shader[PIPE_SHADER_COMPUTE]; - struct panfrost_compiled_shader *ss = &all->variants[all->active_variant]; + struct panfrost_compiled_shader *ss = ctx->prog[PIPE_SHADER_COMPUTE]; struct panfrost_ptr t = pan_pool_alloc_desc(&batch->pool.base, LOCAL_STORAGE); @@ -1970,7 +1967,7 @@ panfrost_emit_image_attribs(struct panfrost_batch *batch, enum pipe_shader_type type) { struct panfrost_context *ctx = batch->ctx; - struct panfrost_compiled_shader *shader = panfrost_get_shader_state(ctx, type); + struct panfrost_compiled_shader *shader = ctx->prog[type]; if (!shader->info.attribute_count) { *buffers = 0; @@ -2006,7 +2003,7 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch, { struct panfrost_context *ctx = batch->ctx; struct panfrost_vertex_state *so = ctx->vertex; - struct panfrost_compiled_shader *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; bool instanced = ctx->indirect_draw || ctx->instance_count > 1; uint32_t image_mask = ctx->image_mask[PIPE_SHADER_VERTEX]; unsigned nr_images = util_last_bit(image_mask); @@ -2558,12 +2555,9 @@ panfrost_emit_varying_descriptor(struct panfrost_batch *batch, mali_ptr *psiz, bool point_coord_replace) { - /* Load the shaders */ struct panfrost_context *ctx = batch->ctx; - struct panfrost_compiled_shader *vs, *fs; - - vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); - fs = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; + struct panfrost_compiled_shader *fs = ctx->prog[PIPE_SHADER_FRAGMENT]; uint16_t point_coord_mask = 0; @@ -2957,7 +2951,7 @@ panfrost_update_shader_state(struct panfrost_batch *batch, enum pipe_shader_type st) { struct panfrost_context *ctx = batch->ctx; - struct panfrost_compiled_shader *ss = panfrost_get_shader_state(ctx, st); + struct panfrost_compiled_shader *ss = ctx->prog[st]; bool frag = (st == PIPE_SHADER_FRAGMENT); unsigned dirty_3d = ctx->dirty; @@ -3113,7 +3107,7 @@ panfrost_emit_primitive(struct panfrost_context *ctx, cfg.job_task_split = 6; #else struct panfrost_compiled_shader *fs = - panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + ctx->prog[PIPE_SHADER_FRAGMENT]; cfg.allow_rotating_primitives = !(lines || fs->info.bifrost.uses_flat_shading); cfg.primitive_restart = info->primitive_restart; @@ -3274,7 +3268,7 @@ panfrost_emit_draw(void *out, #if PAN_ARCH >= 9 struct panfrost_compiled_shader *fs = - panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + ctx->prog[PIPE_SHADER_FRAGMENT]; cfg.multisample_enable = rast->multisample; cfg.sample_mask = rast->multisample ? ctx->sample_mask : 0xFFFF; @@ -3406,12 +3400,8 @@ panfrost_emit_malloc_vertex(struct panfrost_batch *batch, void *job) { struct panfrost_context *ctx = batch->ctx; - - struct panfrost_compiled_shader *vs = - panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); - - struct panfrost_compiled_shader *fs = - panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; + struct panfrost_compiled_shader *fs = ctx->prog[PIPE_SHADER_FRAGMENT]; bool fs_required = panfrost_fs_required(fs, ctx->blend, &ctx->pipe_framebuffer, @@ -3553,17 +3543,18 @@ panfrost_launch_xfb(struct panfrost_batch *batch, perf_debug_ctx(batch->ctx, "Emulating transform feedback"); - struct panfrost_compiled_shader *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_uncompiled_shader *vs_uncompiled = ctx->uncompiled[PIPE_SHADER_VERTEX]; + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; struct panfrost_uncompiled_shader v = { .variants = vs->xfb }; vs->xfb->stream_output = vs->stream_output; - struct panfrost_uncompiled_shader *saved_vs = ctx->shader[PIPE_SHADER_VERTEX]; mali_ptr saved_rsd = batch->rsd[PIPE_SHADER_VERTEX]; mali_ptr saved_ubo = batch->uniform_buffers[PIPE_SHADER_VERTEX]; mali_ptr saved_push = batch->push_uniforms[PIPE_SHADER_VERTEX]; - ctx->shader[PIPE_SHADER_VERTEX] = &v; + ctx->uncompiled[PIPE_SHADER_VERTEX] = &v; + ctx->prog[PIPE_SHADER_VERTEX] = vs->xfb; batch->rsd[PIPE_SHADER_VERTEX] = panfrost_emit_compute_shader_meta(batch, PIPE_SHADER_VERTEX); #if PAN_ARCH >= 9 @@ -3611,7 +3602,8 @@ panfrost_launch_xfb(struct panfrost_batch *batch, panfrost_add_job(&batch->pool.base, &batch->scoreboard, job_type, true, false, 0, 0, &t, false); - ctx->shader[PIPE_SHADER_VERTEX] = saved_vs; + ctx->uncompiled[PIPE_SHADER_VERTEX] = vs_uncompiled; + ctx->prog[PIPE_SHADER_VERTEX] = vs; batch->rsd[PIPE_SHADER_VERTEX] = saved_rsd; batch->uniform_buffers[PIPE_SHADER_VERTEX] = saved_ubo; batch->push_uniforms[PIPE_SHADER_VERTEX] = saved_push; @@ -3650,7 +3642,7 @@ panfrost_direct_draw(struct panfrost_batch *batch, ctx->active_prim = info->mode; ctx->drawid = drawid_offset; - struct panfrost_compiled_shader *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; bool idvs = vs->info.vs.idvs; bool secondary_shader = vs->info.vs.secondary_enable; @@ -3816,7 +3808,7 @@ panfrost_indirect_draw(struct panfrost_batch *batch, ctx->drawid = drawid_offset; ctx->indirect_draw = true; - struct panfrost_compiled_shader *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; bool idvs = vs->info.vs.idvs; bool secondary_shader = vs->info.vs.secondary_enable; @@ -4149,8 +4141,7 @@ panfrost_launch_grid(struct pipe_context *pipe, cfg.samplers = batch->samplers[PIPE_SHADER_COMPUTE]; } #else - struct panfrost_compiled_shader *cs = - &ctx->shader[PIPE_SHADER_COMPUTE]->variants[0]; + struct panfrost_compiled_shader *cs = ctx->prog[PIPE_SHADER_COMPUTE]; pan_section_pack(t.cpu, COMPUTE_JOB, PAYLOAD, cfg) { cfg.workgroup_size_x = info->block[0]; diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index 22e0790..ea51307 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -87,8 +87,8 @@ panfrost_clear( bool panfrost_writes_point_size(struct panfrost_context *ctx) { - assert(ctx->shader[PIPE_SHADER_VERTEX]); - struct panfrost_compiled_shader *vs = panfrost_get_shader_state(ctx, PIPE_SHADER_VERTEX); + struct panfrost_compiled_shader *vs = ctx->prog[PIPE_SHADER_VERTEX]; + assert(vs != NULL); return vs->info.vs.writes_point_size && ctx->active_prim == PIPE_PRIM_POINTS; } @@ -208,7 +208,7 @@ panfrost_get_blend(struct panfrost_batch *batch, unsigned rti, struct panfrost_b PIPE_SHADER_FRAGMENT, "Blend shader"); } - struct panfrost_compiled_shader *ss = panfrost_get_shader_state(ctx, PIPE_SHADER_FRAGMENT); + struct panfrost_compiled_shader *ss = ctx->prog[PIPE_SHADER_FRAGMENT]; /* Default for Midgard */ nir_alu_type col0_type = nir_type_float32; diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index e90383c..f338af6 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -185,9 +185,11 @@ struct panfrost_context { struct panfrost_constant_buffer constant_buffer[PIPE_SHADER_TYPES]; struct panfrost_rasterizer *rasterizer; - struct panfrost_uncompiled_shader *shader[PIPE_SHADER_TYPES]; struct panfrost_vertex_state *vertex; + struct panfrost_uncompiled_shader *uncompiled[PIPE_SHADER_TYPES]; + struct panfrost_compiled_shader *prog[PIPE_SHADER_TYPES]; + struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; uint32_t vb_mask; @@ -327,9 +329,6 @@ struct panfrost_uncompiled_shader { * shaders for desktop GL. */ uint32_t fixed_varying_mask; - - /* The current active variant */ - unsigned active_variant; }; /** (Vertex buffer index, divisor) tuple that will become an Attribute Buffer @@ -363,18 +362,6 @@ pan_so_target(struct pipe_stream_output_target *target) return (struct panfrost_streamout_target *)target; } -static inline struct panfrost_compiled_shader * -panfrost_get_shader_state(struct panfrost_context *ctx, - enum pipe_shader_type st) -{ - struct panfrost_uncompiled_shader *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_job.c b/src/gallium/drivers/panfrost/pan_job.c index 341dc86..4074ae2 100644 --- a/src/gallium/drivers/panfrost/pan_job.c +++ b/src/gallium/drivers/panfrost/pan_job.c @@ -873,9 +873,8 @@ panfrost_batch_adjust_stack_size(struct panfrost_batch *batch) struct panfrost_context *ctx = batch->ctx; for (unsigned i = 0; i < PIPE_SHADER_TYPES; ++i) { - struct panfrost_compiled_shader *ss; + struct panfrost_compiled_shader *ss = ctx->prog[i]; - ss = panfrost_get_shader_state(ctx, i); if (!ss) continue; diff --git a/src/gallium/drivers/panfrost/pan_shader.c b/src/gallium/drivers/panfrost/pan_shader.c index bf1fa96..e91eba5 100644 --- a/src/gallium/drivers/panfrost/pan_shader.c +++ b/src/gallium/drivers/panfrost/pan_shader.c @@ -138,7 +138,7 @@ panfrost_build_key(struct panfrost_context *ctx, struct panfrost_device *dev = pan_device(ctx->base.screen); struct pipe_framebuffer_state *fb = &ctx->pipe_framebuffer; struct pipe_rasterizer_state *rast = (void *) ctx->rasterizer; - struct panfrost_uncompiled_shader *vs = ctx->shader[MESA_SHADER_VERTEX]; + struct panfrost_uncompiled_shader *vs = ctx->uncompiled[MESA_SHADER_VERTEX]; key->fs.nr_cbufs = fb->nr_cbufs; @@ -262,7 +262,8 @@ panfrost_bind_shader_state( enum pipe_shader_type type) { struct panfrost_context *ctx = pan_context(pctx); - ctx->shader[type] = hwcso; + ctx->uncompiled[type] = hwcso; + ctx->prog[type] = NULL; ctx->dirty |= PAN_DIRTY_TLS_SIZE; ctx->dirty_shader[type] |= PAN_DIRTY_STAGE_SHADER; @@ -280,16 +281,16 @@ panfrost_update_shader_variant(struct panfrost_context *ctx, return; /* We need linking information, defer this */ - if (type == PIPE_SHADER_FRAGMENT && !ctx->shader[PIPE_SHADER_VERTEX]) + if (type == PIPE_SHADER_FRAGMENT && !ctx->uncompiled[PIPE_SHADER_VERTEX]) return; /* Also defer, happens with GALLIUM_HUD */ - if (!ctx->shader[type]) + if (!ctx->uncompiled[type]) return; /* Match the appropriate variant */ signed variant = -1; - struct panfrost_uncompiled_shader *variants = ctx->shader[type]; + struct panfrost_uncompiled_shader *variants = ctx->uncompiled[type]; simple_mtx_lock(&variants->lock); @@ -309,7 +310,7 @@ panfrost_update_shader_variant(struct panfrost_context *ctx, if (variant == -1) variant = panfrost_new_variant_locked(ctx, variants, &key); - variants->active_variant = variant; + ctx->prog[type] = &variants->variants[variant]; /* TODO: it would be more efficient to release the lock before * compiling instead of after, but that can race if thread A compiles a @@ -417,7 +418,6 @@ panfrost_create_compute_state( so->variants = v; so->variant_count = 1; - so->active_variant = 0; assert(cso->ir_type == PIPE_SHADER_IR_NIR && "TGSI kernels unsupported"); @@ -432,7 +432,14 @@ static void panfrost_bind_compute_state(struct pipe_context *pipe, void *cso) { struct panfrost_context *ctx = pan_context(pipe); - ctx->shader[PIPE_SHADER_COMPUTE] = cso; + struct panfrost_uncompiled_shader *uncompiled = cso; + + ctx->uncompiled[PIPE_SHADER_COMPUTE] = uncompiled; + + if (uncompiled) + ctx->prog[PIPE_SHADER_COMPUTE] = &uncompiled->variants[0]; + else + ctx->prog[PIPE_SHADER_COMPUTE] = NULL; } static void -- 2.7.4