From 41c9bf884ff266e9c2286002446ed2297838086f Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Wed, 27 Nov 2013 00:15:05 +0100 Subject: [PATCH] glsl: Extract function for record comparisons. Reviewed-by: Matt Turner --- src/glsl/glsl_types.cpp | 67 +++++++++++++++++++++++------------------ src/glsl/glsl_types.h | 7 +++++ 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp index 12d4ac0eeba..f9bb0cfc754 100644 --- a/src/glsl/glsl_types.cpp +++ b/src/glsl/glsl_types.cpp @@ -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); } diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h index fb7c9288d3f..f88758a9af0 100644 --- a/src/glsl/glsl_types.h +++ b/src/glsl/glsl_types.h @@ -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 -- 2.30.2