From 5393d734a85da28a7466ae840d205bbb172de4b9 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 21 Aug 2020 10:42:59 -0400 Subject: [PATCH] panfrost: Derive UBO count from shader_info Rather than checking against the bound constant buffers. Like with num_textures, this eliminates a dependency of the shader descriptor on the context, which matters especially for vertex/compute shaders. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Tomeu Vizoso Part-of: --- src/gallium/drivers/panfrost/pan_assemble.c | 1 + src/gallium/drivers/panfrost/pan_cmdstream.c | 14 +++++++------- src/gallium/drivers/panfrost/pan_context.c | 12 ------------ src/gallium/drivers/panfrost/pan_context.h | 5 +---- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index 0d181945c9f..05bf5fa948d 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -294,6 +294,7 @@ panfrost_shader_compile(struct panfrost_context *ctx, /* Needed for linkage */ state->attribute_count = attribute_count; state->varying_count = varying_count; + state->ubo_count = s->info.num_ubos + 1; /* off-by-one for uniforms */ /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against * a NULL context */ diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 9a79846d5a0..40df89b0643 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -323,7 +323,7 @@ panfrost_emit_compute_shader(struct panfrost_context *ctx, pan_pack(&prop, BIFROST_PROPERTIES, cfg) { cfg.unknown = 0x800000; /* XXX */ - cfg.uniform_buffer_count = panfrost_ubo_count(ctx, st); + cfg.uniform_buffer_count = ss->ubo_count; } /* TODO: True compute shaders */ @@ -339,7 +339,7 @@ panfrost_emit_compute_shader(struct panfrost_context *ctx, struct mali_midgard_properties_packed prop; pan_pack(&prop, MIDGARD_PROPERTIES, cfg) { - cfg.uniform_buffer_count = panfrost_ubo_count(ctx, st); + cfg.uniform_buffer_count = ss->ubo_count; cfg.uniform_count = ss->uniform_count; cfg.work_register_count = ss->work_reg_count; cfg.writes_globals = ss->writes_global; @@ -590,7 +590,7 @@ panfrost_emit_frag_shader(struct panfrost_context *ctx, pan_pack(&prop, BIFROST_PROPERTIES, cfg) { cfg.unknown = 0x950020; /* XXX */ - cfg.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT); + cfg.uniform_buffer_count = fs->ubo_count; cfg.early_z_enable = !fs->can_discard && !fs->writes_depth && no_blend; } @@ -622,7 +622,7 @@ panfrost_emit_frag_shader(struct panfrost_context *ctx, has_blend_shader |= blend[c].is_shader; pan_pack(&prop, MIDGARD_PROPERTIES, cfg) { - cfg.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT); + cfg.uniform_buffer_count = fs->ubo_count; cfg.uniform_count = fs->uniform_count; cfg.work_register_count = fs->work_reg_count; cfg.writes_globals = fs->writes_global; @@ -1130,10 +1130,10 @@ panfrost_emit_const_buf(struct panfrost_batch *batch, } /* Next up, attach UBOs. UBO #0 is the uniforms we just - * uploaded */ + * uploaded, so it's always included. The count is the highest UBO + * addressable -- gaps are included. */ - unsigned ubo_count = panfrost_ubo_count(ctx, stage); - assert(ubo_count >= 1); + unsigned ubo_count = 32 - __builtin_clz(buf->enabled_mask | 1); size_t sz = MALI_UNIFORM_BUFFER_LENGTH * ubo_count; struct panfrost_transfer ubos = diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index fa4fd00d1a9..2fbb19c7d25 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -145,18 +145,6 @@ panfrost_writes_point_size(struct panfrost_context *ctx) return vs->writes_point_size && ctx->active_prim == PIPE_PRIM_POINTS; } -/* Compute number of UBOs active (more specifically, compute the highest UBO - * number addressable -- if there are gaps, include them in the count anyway). - * We always include UBO #0 in the count, since we *need* uniforms enabled for - * sysvals. */ - -unsigned -panfrost_ubo_count(struct panfrost_context *ctx, enum pipe_shader_type stage) -{ - unsigned mask = ctx->constant_buffer[stage].enabled_mask | 1; - return 32 - __builtin_clz(mask); -} - /* The entire frame is in memory -- send it off to the kernel! */ void diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 794978c8181..be1745491f5 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -206,7 +206,7 @@ struct panfrost_shader_state { /* For Bifrost - output type for each RT */ enum bifrost_shader_type blend_types[BIFROST_MAX_RENDER_TARGET_COUNT]; - unsigned attribute_count, varying_count; + unsigned attribute_count, varying_count, ubo_count; enum mali_format varyings[PIPE_MAX_ATTRIBS]; gl_varying_slot varyings_loc[PIPE_MAX_ATTRIBS]; struct pipe_stream_output_info stream_output; @@ -337,9 +337,6 @@ panfrost_shader_compile(struct panfrost_context *ctx, struct panfrost_shader_state *state, uint64_t *outputs_written); -unsigned -panfrost_ubo_count(struct panfrost_context *ctx, enum pipe_shader_type stage); - void panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so, struct pipe_context *pctx, -- 2.30.2