glsl: Extract function for record comparisons.
authorGrigori Goronzy <greg@chown.ath.cx>
Tue, 26 Nov 2013 23:15:05 +0000 (00:15 +0100)
committerMatt Turner <mattst88@gmail.com>
Tue, 21 Jan 2014 22:01:09 +0000 (14:01 -0800)
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/glsl_types.cpp
src/glsl/glsl_types.h

index 12d4ac0eeba038b8e7474d355e82b8d851383428..f9bb0cfc75493cc3d7efe3c01fdae09f47ce1401 100644 (file)
@@ -449,6 +449,42 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 }
 
 
+bool
+glsl_type::record_compare(const glsl_type *b) const
+{
+   if (this->length != b->length)
+      return false;
+
+   if (this->interface_packing != b->interface_packing)
+      return false;
+
+   for (unsigned i = 0; i < this->length; i++) {
+      if (this->fields.structure[i].type != b->fields.structure[i].type)
+        return false;
+      if (strcmp(this->fields.structure[i].name,
+                b->fields.structure[i].name) != 0)
+        return false;
+      if (this->fields.structure[i].row_major
+         != b->fields.structure[i].row_major)
+        return false;
+      if (this->fields.structure[i].location
+          != b->fields.structure[i].location)
+         return false;
+      if (this->fields.structure[i].interpolation
+          != b->fields.structure[i].interpolation)
+         return false;
+      if (this->fields.structure[i].centroid
+          != b->fields.structure[i].centroid)
+         return false;
+      if (this->fields.structure[i].sample
+          != b->fields.structure[i].sample)
+         return false;
+   }
+
+   return true;
+}
+
+
 int
 glsl_type::record_key_compare(const void *a, const void *b)
 {
@@ -461,36 +497,7 @@ glsl_type::record_key_compare(const void *a, const void *b)
    if (strcmp(key1->name, key2->name) != 0)
       return 1;
 
-   if (key1->length != key2->length)
-      return 1;
-
-   if (key1->interface_packing != key2->interface_packing)
-      return 1;
-
-   for (unsigned i = 0; i < key1->length; i++) {
-      if (key1->fields.structure[i].type != key2->fields.structure[i].type)
-        return 1;
-      if (strcmp(key1->fields.structure[i].name,
-                key2->fields.structure[i].name) != 0)
-        return 1;
-      if (key1->fields.structure[i].row_major
-         != key2->fields.structure[i].row_major)
-        return 1;
-      if (key1->fields.structure[i].location
-          != key2->fields.structure[i].location)
-         return 1;
-      if (key1->fields.structure[i].interpolation
-          != key2->fields.structure[i].interpolation)
-         return 1;
-      if (key1->fields.structure[i].centroid
-          != key2->fields.structure[i].centroid)
-         return 1;
-      if (key1->fields.structure[i].sample
-          != key2->fields.structure[i].sample)
-         return 1;
-   }
-
-   return 0;
+   return !key1->record_compare(key2);
 }
 
 
index fb7c9288d3fa3dea007cd44697f211a095e78a76..f88758a9af055400e89662c06a3f2442e803cffa 100644 (file)
@@ -542,6 +542,13 @@ struct glsl_type {
     */
    int sampler_coordinate_components() const;
 
+   /**
+    * Compare a record type against another record type.
+    *
+    * This is useful for matching record types declared across shader stages.
+    */
+   bool record_compare(const glsl_type *b) const;
+
 private:
    /**
     * ralloc context for all glsl_type allocations