panfrost: Pack vertex properties when compiling
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 21 Aug 2020 16:34:24 +0000 (12:34 -0400)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 25 Aug 2020 15:05:37 +0000 (17:05 +0200)
They only depend on shader properties so we can do all this work at CSO
create time, reducing draw-time overhead.

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.h

index 05bf5fa948d00172d35d5cb2e29c24a7eff77e09..f84bf5db9fc546238493aad35935d6fb16d09341 100644 (file)
 
 #include "tgsi/tgsi_dump.h"
 
+static void
+pan_pack_midgard_props(struct panfrost_shader_state *state,
+                gl_shader_stage stage)
+{
+        pan_pack(&state->properties, MIDGARD_PROPERTIES, cfg) {
+                cfg.uniform_buffer_count = state->ubo_count;
+                cfg.uniform_count = state->uniform_count;
+                cfg.work_register_count = state->work_reg_count;
+                cfg.writes_globals = state->writes_global;
+                cfg.suppress_inf_nan = true; /* XXX */
+        }
+}
+
+static void
+pan_pack_bifrost_props(struct panfrost_shader_state *state,
+                gl_shader_stage stage)
+{
+        switch (stage) {
+        case MESA_SHADER_VERTEX:
+                pan_pack(&state->properties, BIFROST_PROPERTIES, cfg) {
+                        cfg.unknown = 0x800000; /* XXX */
+                        cfg.uniform_buffer_count = state->ubo_count;
+                }
+
+                pan_pack(&state->preload, PRELOAD_VERTEX, cfg) {
+                        cfg.uniform_count = state->uniform_count;
+                        cfg.vertex_id = true;
+                        cfg.instance_id = true;
+                }
+
+                break;
+        case MESA_SHADER_FRAGMENT:
+                /* TODO */
+                break;
+        default:
+                unreachable("TODO");
+        }
+}
+
 static unsigned
 pan_format_from_nir_base(nir_alu_type base)
 {
@@ -282,6 +321,11 @@ 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 */
+
         /* Prepare the descriptors at compile-time */
         pan_pack(&state->shader, SHADER, cfg) {
                 cfg.shader = shader;
@@ -291,10 +335,10 @@ panfrost_shader_compile(struct panfrost_context *ctx,
                 cfg.sampler_count = cfg.texture_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 */
+        if (dev->quirks & IS_BIFROST)
+                pan_pack_bifrost_props(state, stage);
+        else
+                pan_pack_midgard_props(state, stage);
 
         /* In both clone and tgsi_to_nir paths, the shader is ralloc'd against
          * a NULL context */
index 40df89b06432163248b76777fd2123784b9cd027..2a3cb4dd90179813ad760365fb2c3ceac79cd8bc 100644 (file)
@@ -316,38 +316,10 @@ panfrost_emit_compute_shader(struct panfrost_context *ctx,
 
         memset(meta, 0, sizeof(*meta));
         memcpy(&meta->shader, &ss->shader, sizeof(ss->shader));
+        memcpy(&meta->midgard_props, &ss->properties, sizeof(ss->properties));
 
-        if (dev->quirks & IS_BIFROST) {
-                struct mali_bifrost_properties_packed prop;
-                struct mali_preload_vertex_packed preload;
-
-                pan_pack(&prop, BIFROST_PROPERTIES, cfg) {
-                        cfg.unknown = 0x800000; /* XXX */
-                        cfg.uniform_buffer_count = ss->ubo_count;
-                }
-
-                /* TODO: True compute shaders */
-                pan_pack(&preload, PRELOAD_VERTEX, cfg) {
-                        cfg.uniform_count = ss->uniform_count;
-                        cfg.vertex_id = true;
-                        cfg.instance_id = true;
-                }
-
-                memcpy(&meta->bifrost_props, &prop, sizeof(prop));
-                memcpy(&meta->bifrost_preload, &preload, sizeof(preload));
-        } else {
-                struct mali_midgard_properties_packed prop;
-
-                pan_pack(&prop, MIDGARD_PROPERTIES, cfg) {
-                        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.suppress_inf_nan = true; /* XXX */
-                }
-
-                memcpy(&meta->midgard_props, &prop, sizeof(prop));
-        }
+        if (dev->quirks & IS_BIFROST)
+                memcpy(&meta->bifrost_preload, &ss->preload, sizeof(ss->preload));
 }
 
 static unsigned
index be1745491f5722156acb6197dbe01e4ce0fbc6e0..ef37cb57a32d5e1c8e6b699608c6d99a9a483830 100644 (file)
@@ -184,6 +184,8 @@ struct panfrost_shader_state {
         /* Compiled, mapped descriptor, ready for the hardware */
         bool compiled;
         struct mali_shader_packed shader;
+        struct mali_midgard_properties_packed properties;
+        struct mali_preload_packed preload;
 
         /* Non-descript information */
         unsigned uniform_count;