panfrost: Correctly size varyings
authorAlyssa Rosenzweig <alyssa@collabora.com>
Wed, 2 Jun 2021 18:52:36 +0000 (14:52 -0400)
committerMarge Bot <eric+marge@anholt.net>
Thu, 10 Jun 2021 18:06:10 +0000 (18:06 +0000)
The same slot could be specified multiple times with different
location_frac out of order, so we use two passes.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11123>

src/panfrost/lib/pan_shader.c

index f8fa8ad..4cf91c7 100644 (file)
@@ -87,13 +87,13 @@ collect_varyings(nir_shader *s, nir_variable_mode varying_mode,
 {
         *varying_count = 0;
 
+        unsigned comps[MAX_VARYING] = { 0 };
+
         nir_foreach_variable_with_modes(var, s, varying_mode) {
                 unsigned loc = var->data.driver_location;
-                unsigned sz = glsl_count_attribute_slots(var->type, FALSE);
                 const struct glsl_type *column =
                         glsl_without_array_or_matrix(var->type);
                 unsigned chan = glsl_get_components(column);
-                enum glsl_base_type base_type = glsl_get_base_type(column);
 
                 /* If we have a fractional location added, we need to increase the size
                  * so it will fit, i.e. a vec3 in YZW requires us to allocate a vec4.
@@ -101,7 +101,16 @@ collect_varyings(nir_shader *s, nir_variable_mode varying_mode,
                  * packed varyings will be aligned.
                  */
                 chan += var->data.location_frac;
-                assert(chan >= 1 && chan <= 4);
+                comps[loc] = MAX2(comps[loc], chan);
+        }
+
+        nir_foreach_variable_with_modes(var, s, varying_mode) {
+                unsigned loc = var->data.driver_location;
+                unsigned sz = glsl_count_attribute_slots(var->type, FALSE);
+                const struct glsl_type *column =
+                        glsl_without_array_or_matrix(var->type);
+                enum glsl_base_type base_type = glsl_get_base_type(column);
+                unsigned chan = comps[loc];
 
                 nir_alu_type type = nir_get_nir_type_for_glsl_base_type(base_type);