Commit 9085c8db by Alexis Hetu Committed by Alexis Hétu

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/3311Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 8e851c1a
...@@ -74,10 +74,26 @@ enum TBasicType : unsigned char ...@@ -74,10 +74,26 @@ enum TBasicType : unsigned char
EbtGSamplerCube, // non type: represents samplerCube, isamplerCube, and usamplerCube EbtGSamplerCube, // non type: represents samplerCube, isamplerCube, and usamplerCube
EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray, and usampler2DArray EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray, and usampler2DArray
EbtStruct, EbtStruct,
EbtInterfaceBlock,
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
EbtInvariant // used as a type when qualifying a previously declared variable as being invariant 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) inline const char *getBasicString(TBasicType type)
{ {
switch(type) switch(type)
...@@ -96,11 +112,218 @@ inline const char *getBasicString(TBasicType type) ...@@ -96,11 +112,218 @@ inline const char *getBasicString(TBasicType type)
} }
} }
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) inline bool IsSampler(TBasicType type)
{ {
return type > EbtGuardSamplerBegin && type < EbtGuardSamplerEnd; 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 // 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 // or written, and by the machine dependent translator to know which registers
...@@ -164,16 +387,20 @@ struct TLayoutQualifier ...@@ -164,16 +387,20 @@ struct TLayoutQualifier
TLayoutQualifier layoutQualifier; TLayoutQualifier layoutQualifier;
layoutQualifier.location = -1; layoutQualifier.location = -1;
layoutQualifier.matrixPacking = EmpUnspecified;
layoutQualifier.blockStorage = EbsUnspecified;
return layoutQualifier; return layoutQualifier;
} }
bool isEmpty() const bool isEmpty() const
{ {
return location == -1; return location == -1 && matrixPacking == EmpUnspecified && blockStorage == EbsUnspecified;
} }
int location; int location;
TLayoutMatrixPacking matrixPacking;
TLayoutBlockStorage blockStorage;
}; };
// //
......
...@@ -212,7 +212,7 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn ...@@ -212,7 +212,7 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn
case EOpBitwiseOr: case EOpBitwiseOr:
case EOpBitwiseXor: case EOpBitwiseXor:
case EOpBitwiseAnd: case EOpBitwiseAnd:
if ((left->getBasicType() != EbtInt && left->getBasicType() != EbtUInt) || left->isMatrix() || left->isArray()) { if (!IsInteger(left->getBasicType()) || left->isMatrix() || left->isArray()) {
return 0; return 0;
} }
break; break;
...@@ -333,7 +333,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode, ...@@ -333,7 +333,7 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermNode* childNode,
switch (op) { switch (op) {
case EOpBitwiseNot: 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; return 0;
} }
break; break;
...@@ -719,7 +719,7 @@ bool TIntermUnary::promote(TInfoSink&) ...@@ -719,7 +719,7 @@ bool TIntermUnary::promote(TInfoSink&)
return false; return false;
break; break;
case EOpBitwiseNot: case EOpBitwiseNot:
if(operand->getBasicType() != EbtInt && operand->getBasicType() != EbtUInt) if (!IsInteger(operand->getBasicType()))
return false; return false;
break; break;
case EOpNegative: case EOpNegative:
......
...@@ -152,7 +152,7 @@ public: ...@@ -152,7 +152,7 @@ public:
bool isScalar() const { return primarySize == 1 && !isMatrix() && !structure; } bool isScalar() const { return primarySize == 1 && !isMatrix() && !structure; }
bool isRegister() const { return !isMatrix() && !structure && !array; } // Fits in a 4-element register bool isRegister() const { return !isMatrix() && !structure && !array; } // Fits in a 4-element register
bool isStruct() const { return structure != 0; } 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; } TTypeList* getStruct() const { return structure; }
void setStruct(TTypeList* s) { structure = s; computeDeepestStructNesting(); } void setStruct(TTypeList* s) { structure = s; computeDeepestStructNesting(); }
......
...@@ -273,7 +273,7 @@ bool ValidateLimitations::validateForLoopInit(TIntermLoop* node, ...@@ -273,7 +273,7 @@ bool ValidateLimitations::validateForLoopInit(TIntermLoop* node,
} }
// The loop index has type int or float. // The loop index has type int or float.
TBasicType type = symbol->getBasicType(); TBasicType type = symbol->getBasicType();
if ((type != EbtInt) && (type != EbtUInt) && (type != EbtFloat)) { if (!IsInteger(type) && (type != EbtFloat)) {
error(symbol->getLine(), error(symbol->getLine(),
"Invalid type for loop index", getBasicString(type)); "Invalid type for loop index", getBasicString(type));
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment