Adding base type changes related to Uniform Blocks This cl should be a NOOP. It simply adds some basic functionality in BaseTypes.h that will be useful in eventually enabling Uniform Blocks in the parser. Change-Id: I0c2b3200e0ae95ddce86367663081c2aef751308 Reviewed-on: https://swiftshader-review.googlesource.com/3311 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/OpenGL/compiler/BaseTypes.h b/src/OpenGL/compiler/BaseTypes.h index 7e25c40..93d598c 100644 --- a/src/OpenGL/compiler/BaseTypes.h +++ b/src/OpenGL/compiler/BaseTypes.h
@@ -74,10 +74,26 @@ EbtGSamplerCube, // non type: represents samplerCube, isamplerCube, and usamplerCube EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray, and usampler2DArray EbtStruct, + EbtInterfaceBlock, EbtAddress, // should be deprecated?? EbtInvariant // used as a type when qualifying a previously declared variable as being invariant }; +enum TLayoutMatrixPacking +{ + EmpUnspecified, + EmpRowMajor, + EmpColumnMajor +}; + +enum TLayoutBlockStorage +{ + EbsUnspecified, + EbsShared, + EbsPacked, + EbsStd140 +}; + inline const char *getBasicString(TBasicType type) { switch(type) @@ -96,11 +112,218 @@ } } +inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq) +{ + switch(mpq) + { + case EmpUnspecified: return "mp_unspecified"; + case EmpRowMajor: return "row_major"; + case EmpColumnMajor: return "column_major"; + default: UNREACHABLE(); return "unknown matrix packing"; + } +} + +inline const char* getBlockStorageString(TLayoutBlockStorage bsq) +{ + switch(bsq) + { + case EbsUnspecified: return "bs_unspecified"; + case EbsShared: return "shared"; + case EbsPacked: return "packed"; + case EbsStd140: return "std140"; + default: UNREACHABLE(); return "unknown block storage"; + } +} + inline bool IsSampler(TBasicType type) { return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd; } +inline bool IsIntegerSampler(TBasicType type) +{ + switch(type) + { + case EbtISampler2D: + case EbtISampler3D: + case EbtISamplerCube: + case EbtISampler2DArray: + case EbtUSampler2D: + case EbtUSampler3D: + case EbtUSamplerCube: + case EbtUSampler2DArray: + return true; + case EbtSampler2D: + case EbtSampler3D: + case EbtSamplerCube: + case EbtSamplerExternalOES: + case EbtSampler2DArray: + case EbtSampler2DShadow: + case EbtSamplerCubeShadow: + case EbtSampler2DArrayShadow: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsSampler2D(TBasicType type) +{ + switch(type) + { + case EbtSampler2D: + case EbtISampler2D: + case EbtUSampler2D: + case EbtSampler2DArray: + case EbtISampler2DArray: + case EbtUSampler2DArray: + case EbtSamplerExternalOES: + case EbtSampler2DShadow: + case EbtSampler2DArrayShadow: + return true; + case EbtSampler3D: + case EbtISampler3D: + case EbtUSampler3D: + case EbtISamplerCube: + case EbtUSamplerCube: + case EbtSamplerCube: + case EbtSamplerCubeShadow: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsSamplerCube(TBasicType type) +{ + switch(type) + { + case EbtSamplerCube: + case EbtISamplerCube: + case EbtUSamplerCube: + case EbtSamplerCubeShadow: + return true; + case EbtSampler2D: + case EbtSampler3D: + case EbtSamplerExternalOES: + case EbtSampler2DArray: + case EbtISampler2D: + case EbtISampler3D: + case EbtISampler2DArray: + case EbtUSampler2D: + case EbtUSampler3D: + case EbtUSampler2DArray: + case EbtSampler2DShadow: + case EbtSampler2DArrayShadow: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsSampler3D(TBasicType type) +{ + switch(type) + { + case EbtSampler3D: + case EbtISampler3D: + case EbtUSampler3D: + return true; + case EbtSampler2D: + case EbtSamplerCube: + case EbtSamplerExternalOES: + case EbtSampler2DArray: + case EbtISampler2D: + case EbtISamplerCube: + case EbtISampler2DArray: + case EbtUSampler2D: + case EbtUSamplerCube: + case EbtUSampler2DArray: + case EbtSampler2DShadow: + case EbtSamplerCubeShadow: + case EbtSampler2DArrayShadow: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsSamplerArray(TBasicType type) +{ + switch(type) + { + case EbtSampler2DArray: + case EbtISampler2DArray: + case EbtUSampler2DArray: + case EbtSampler2DArrayShadow: + return true; + case EbtSampler2D: + case EbtISampler2D: + case EbtUSampler2D: + case EbtSamplerExternalOES: + case EbtSampler3D: + case EbtISampler3D: + case EbtUSampler3D: + case EbtISamplerCube: + case EbtUSamplerCube: + case EbtSamplerCube: + case EbtSampler2DShadow: + case EbtSamplerCubeShadow: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsShadowSampler(TBasicType type) +{ + switch(type) + { + case EbtSampler2DShadow: + case EbtSamplerCubeShadow: + case EbtSampler2DArrayShadow: + return true; + case EbtISampler2D: + case EbtISampler3D: + case EbtISamplerCube: + case EbtISampler2DArray: + case EbtUSampler2D: + case EbtUSampler3D: + case EbtUSamplerCube: + case EbtUSampler2DArray: + case EbtSampler2D: + case EbtSampler3D: + case EbtSamplerCube: + case EbtSamplerExternalOES: + case EbtSampler2DArray: + return false; + default: + assert(!IsSampler(type)); + } + + return false; +} + +inline bool IsInteger(TBasicType type) +{ + return type == EbtInt || type == EbtUInt; +} + +inline bool SupportsPrecision(TBasicType type) +{ + return type == EbtFloat || type == EbtInt || type == EbtUInt || IsSampler(type); +} + // // Qualifiers and built-ins. These are mainly used to see what can be read // or written, and by the machine dependent translator to know which registers @@ -164,16 +387,20 @@ TLayoutQualifier layoutQualifier; layoutQualifier.location = -1; + layoutQualifier.matrixPacking = EmpUnspecified; + layoutQualifier.blockStorage = EbsUnspecified; return layoutQualifier; } bool isEmpty() const { - return location == -1; + return location == -1 && matrixPacking == EmpUnspecified && blockStorage == EbsUnspecified; } int location; + TLayoutMatrixPacking matrixPacking; + TLayoutBlockStorage blockStorage; }; //
diff --git a/src/OpenGL/compiler/Intermediate.cpp b/src/OpenGL/compiler/Intermediate.cpp index b1d2526..779565b 100644 --- a/src/OpenGL/compiler/Intermediate.cpp +++ b/src/OpenGL/compiler/Intermediate.cpp
@@ -212,7 +212,7 @@ case EOpBitwiseOr: case EOpBitwiseXor: case EOpBitwiseAnd: - if ((left->getBasicType() != EbtInt && left->getBasicType() != EbtUInt) || left->isMatrix() || left->isArray()) { + if (!IsInteger(left->getBasicType()) || left->isMatrix() || left->isArray()) { return 0; } break; @@ -333,7 +333,7 @@ switch (op) { case EOpBitwiseNot: - if ((child->getType().getBasicType() != EbtInt && child->getType().getBasicType() != EbtUInt) || child->getType().isMatrix() || child->getType().isArray()) { + if (!IsInteger(child->getType().getBasicType()) || child->getType().isMatrix() || child->getType().isArray()) { return 0; } break; @@ -719,7 +719,7 @@ return false; break; case EOpBitwiseNot: - if(operand->getBasicType() != EbtInt && operand->getBasicType() != EbtUInt) + if (!IsInteger(operand->getBasicType())) return false; break; case EOpNegative:
diff --git a/src/OpenGL/compiler/Types.h b/src/OpenGL/compiler/Types.h index be5d61f..de16d51 100644 --- a/src/OpenGL/compiler/Types.h +++ b/src/OpenGL/compiler/Types.h
@@ -152,7 +152,7 @@ bool isScalar() const { return primarySize == 1 && !isMatrix() && !structure; } bool isRegister() const { return !isMatrix() && !structure && !array; } // Fits in a 4-element register bool isStruct() const { return structure != 0; } - bool isScalarInt() const { return isScalar() && (type == EbtInt || type == EbtUInt); } + bool isScalarInt() const { return isScalar() && IsInteger(type); } TTypeList* getStruct() const { return structure; } void setStruct(TTypeList* s) { structure = s; computeDeepestStructNesting(); }
diff --git a/src/OpenGL/compiler/ValidateLimitations.cpp b/src/OpenGL/compiler/ValidateLimitations.cpp index 80ff727..269028c 100644 --- a/src/OpenGL/compiler/ValidateLimitations.cpp +++ b/src/OpenGL/compiler/ValidateLimitations.cpp
@@ -273,7 +273,7 @@ } // The loop index has type int or float. TBasicType type = symbol->getBasicType(); - if ((type != EbtInt) && (type != EbtUInt) && (type != EbtFloat)) { + if (!IsInteger(type) && (type != EbtFloat)) { error(symbol->getLine(), "Invalid type for loop index", getBasicString(type)); return false;