panfrost: Derive UBO count from shader_info
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 21 Aug 2020 14:42:59 +0000 (10:42 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 25 Aug 2020 15:05:37 +0000 (17:05 +0200)
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 <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6440>

src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_cmdstream.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h

index 0d181945c9fedabf45283adc7f4da2e2ba42a881..05bf5fa948d00172d35d5cb2e29c24a7eff77e09 100644 (file)
@@ -294,6 +294,7 @@ panfrost_shader_compile(struct panfrost_context *ctx,
         /* Needed for linkage */
         state->attribute_count = attribute_count;
         state->varying_count = varying_count;
         /* 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 */
 
         /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against
          * a NULL context */
index 9a79846d5a0f9342d44b54b2cde5807fb3ac4352..40df89b06432163248b76777fd2123784b9cd027 100644 (file)
@@ -323,7 +323,7 @@ panfrost_emit_compute_shader(struct panfrost_context *ctx,
 
                 pan_pack(&prop, BIFROST_PROPERTIES, cfg) {
                         cfg.unknown = 0x800000; /* XXX */
 
                 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 */
                 }
 
                 /* 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) {
                 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;
                         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 */
 
                 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;
                 }
 
                         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) {
                         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;
                         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
         }
 
         /* 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 =
 
         size_t sz = MALI_UNIFORM_BUFFER_LENGTH * ubo_count;
         struct panfrost_transfer ubos =
index fa4fd00d1a92057d4e216d891f78c3e5f1c56816..2fbb19c7d257457269be40210fccb8cfaf50d848 100644 (file)
@@ -145,18 +145,6 @@ panfrost_writes_point_size(struct panfrost_context *ctx)
         return vs->writes_point_size && ctx->active_prim == PIPE_PRIM_POINTS;
 }
 
         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
 /* The entire frame is in memory -- send it off to the kernel! */
 
 void
index 794978c81811dae9e4fcb17b66efdd0ee7788658..be1745491f5722156acb6197dbe01e4ce0fbc6e0 100644 (file)
@@ -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];
 
         /* 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;
         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);
 
                         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,
 void
 panfrost_create_sampler_view_bo(struct panfrost_sampler_view *so,
                                 struct pipe_context *pctx,