MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / sameStructType

Method sameStructType

glslang/Include/Types.h:2787–2870  ·  view source on GitHub ↗

Do two structure types match? They could be declared independently, in different places, but still might satisfy the definition of matching. From the spec: "Structures must have the same name, sequence of type names, and type definitions, and member names to be considered the same type. This rule applies recursively for nested or embedded types." If type mismatch in structure, return member ind

Source from the content-addressed store, hash-verified

2785 // block and the index of the unmatched member. Otherwise return {-1,-1}.
2786 //
2787 bool sameStructType(const TType& right, int* lpidx = nullptr, int* rpidx = nullptr) const
2788 {
2789 // Initialize error to general type mismatch.
2790 if (lpidx != nullptr) {
2791 *lpidx = -1;
2792 *rpidx = -1;
2793 }
2794
2795 // Most commonly, they are both nullptr, or the same pointer to the same actual structure
2796 // TODO: Why return true when neither types are structures?
2797 if ((!isStruct() && !right.isStruct()) ||
2798 (isStruct() && right.isStruct() && structure == right.structure))
2799 return true;
2800
2801 if (!isStruct() || !right.isStruct())
2802 return false;
2803
2804 // Structure names have to match
2805 if (*typeName != *right.typeName)
2806 return false;
2807
2808 // There are inconsistencies with how gl_PerVertex is setup. For now ignore those as errors if they
2809 // are known inconsistencies.
2810 bool isGLPerVertex = *typeName == "gl_PerVertex";
2811
2812 // Both being nullptr was caught above, now they both have to be structures of the same number of elements
2813 if (lpidx == nullptr &&
2814 (structure->size() != right.structure->size() && !isGLPerVertex)) {
2815 return false;
2816 }
2817
2818 // Compare the names and types of all the members, which have to match
2819 for (size_t li = 0, ri = 0; li < structure->size() || ri < right.structure->size(); ++li, ++ri) {
2820 if (lpidx != nullptr) {
2821 *lpidx = static_cast<int>(li);
2822 *rpidx = static_cast<int>(ri);
2823 }
2824 if (li < structure->size() && ri < right.structure->size()) {
2825 if ((*structure)[li].type->getFieldName() == (*right.structure)[ri].type->getFieldName()) {
2826 if (*(*structure)[li].type != *(*right.structure)[ri].type)
2827 return false;
2828 } else {
2829 // Skip hidden members
2830 if ((*structure)[li].type->hiddenMember()) {
2831 ri--;
2832 continue;
2833 } else if ((*right.structure)[ri].type->hiddenMember()) {
2834 li--;
2835 continue;
2836 }
2837 // If one of the members is something that's inconsistently declared, skip over it
2838 // for now.
2839 if (isGLPerVertex) {
2840 if (isInconsistentGLPerVertexMember((*structure)[li].type->getFieldName())) {
2841 ri--;
2842 continue;
2843 } else if (isInconsistentGLPerVertexMember((*right.structure)[ri].type->getFieldName())) {
2844 li--;

Callers 1

mergeErrorCheckMethod · 0.80

Calls 3

hiddenMemberMethod · 0.80
isStructMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected