glsl: fix cross validation for explicit locations on structs and arrays
authorTimothy Arceri <timothy.arceri@collabora.com>
Wed, 23 Dec 2015 23:33:45 +0000 (10:33 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Fri, 22 Apr 2016 10:59:57 +0000 (20:59 +1000)
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/glsl/link_varyings.cpp

index 87606be9337be934e02097cf9b18f0e0534ac4bc..c222ede9291b6b5bbe849cfb8f49592a55c4b996 100644 (file)
@@ -367,18 +367,24 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
          /* User-defined varyings with explicit locations are handled
           * differently because they do not need to have matching names.
           */
-         const unsigned idx = var->data.location - VARYING_SLOT_VAR0;
+         const glsl_type *type = get_varying_type(var, producer->Stage);
+         unsigned num_elements = type->count_attribute_slots(false);
+         unsigned idx = var->data.location - VARYING_SLOT_VAR0;
+         unsigned slot_limit = idx + num_elements;
 
-         if (explicit_locations[idx] != NULL) {
-            linker_error(prog,
+         while (idx < slot_limit) {
+            if (explicit_locations[idx] != NULL) {
+               linker_error(prog,
                          "%s shader has multiple outputs explicitly "
                          "assigned to location %d\n",
                          _mesa_shader_stage_to_string(producer->Stage),
                          idx);
-            return;
-         }
+               return;
+            }
 
-         explicit_locations[idx] = var;
+            explicit_locations[idx] = var;
+            idx++;
+         }
       }
    }
 
@@ -426,14 +432,25 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,
          ir_variable *output = NULL;
          if (input->data.explicit_location
              && input->data.location >= VARYING_SLOT_VAR0) {
-            output = explicit_locations[input->data.location - VARYING_SLOT_VAR0];
 
-            if (output == NULL) {
-               linker_error(prog,
-                            "%s shader input `%s' with explicit location "
-                            "has no matching output\n",
-                            _mesa_shader_stage_to_string(consumer->Stage),
-                            input->name);
+            const glsl_type *type = get_varying_type(input, consumer->Stage);
+            unsigned num_elements = type->count_attribute_slots(false);
+            unsigned idx = input->data.location - VARYING_SLOT_VAR0;
+            unsigned slot_limit = idx + num_elements;
+
+            while (idx < slot_limit) {
+               output = explicit_locations[idx];
+
+               if (output == NULL ||
+                   input->data.location != output->data.location) {
+                  linker_error(prog,
+                               "%s shader input `%s' with explicit location "
+                               "has no matching output\n",
+                               _mesa_shader_stage_to_string(consumer->Stage),
+                               input->name);
+                  break;
+               }
+               idx++;
             }
          } else {
             output = parameters.get_variable(input->name);