Commit 8fa9d23d by Nicolas Capens

Use generic types to compact the symbol table initialization.

Bug 19331817 Change-Id: I6ec0f8c6f2ef61f3d0d5adb627eab4a29dffc8ac Reviewed-on: https://swiftshader-review.googlesource.com/2380Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 7322195e
......@@ -7,6 +7,8 @@
#ifndef _BASICTYPES_INCLUDED_
#define _BASICTYPES_INCLUDED_
#include "debug.h"
//
// Precision qualifiers
//
......@@ -19,9 +21,9 @@ enum TPrecision : unsigned char
EbpHigh
};
inline const char* getPrecisionString(TPrecision p)
inline const char *getPrecisionString(TPrecision precision)
{
switch(p)
switch(precision)
{
case EbpHigh: return "highp"; break;
case EbpMedium: return "mediump"; break;
......@@ -40,7 +42,15 @@ enum TBasicType : unsigned char
EbtInt,
EbtUInt,
EbtBool,
EbtGVec4, // non type: represents vec4, ivec4 and uvec4
EbtGVec4, // non type: represents vec4, ivec4, and uvec4
EbtGenType, // non type: represents float, vec2, vec3, and vec4
EbtGenIType, // non type: represents int, ivec2, ivec3, and ivec4
EbtGenUType, // non type: represents uint, uvec2, uvec3, and uvec4
EbtGenBType, // non type: represents bool, bvec2, bvec3, and bvec4
EbtVec, // non type: represents vec2, vec3, and vec4
EbtIVec, // non type: represents ivec2, ivec3, and ivec4
EbtUVec, // non type: represents uvec2, uvec3, and uvec4
EbtBVec, // non type: represents bvec2, bvec3, and bvec4
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler2D,
EbtSampler3D,
......@@ -59,18 +69,18 @@ enum TBasicType : unsigned char
EbtSamplerCubeShadow,
EbtSampler2DArrayShadow,
EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtGSampler2D, // non type: represents sampler2D, isampler2D and usampler2D
EbtGSampler3D, // non type: represents sampler3D, isampler3D and usampler3D
EbtGSamplerCube, // non type: represents samplerCube, isamplerCube and usamplerCube
EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray and usampler2DArray
EbtGSampler2D, // non type: represents sampler2D, isampler2D, and usampler2D
EbtGSampler3D, // non type: represents sampler3D, isampler3D, and usampler3D
EbtGSamplerCube, // non type: represents samplerCube, isamplerCube, and usamplerCube
EbtGSampler2DArray, // non type: represents sampler2DArray, isampler2DArray, and usampler2DArray
EbtStruct,
EbtAddress, // should be deprecated??
EbtInvariant // used as a type when qualifying a previously declared variable as being invariant
};
inline const char* getBasicString(TBasicType t)
inline const char *getBasicString(TBasicType type)
{
switch (t)
switch(type)
{
case EbtVoid: return "void";
case EbtFloat: return "float";
......@@ -82,7 +92,7 @@ inline const char* getBasicString(TBasicType t)
case EbtSamplerExternalOES: return "samplerExternalOES";
case EbtSampler3D: return "sampler3D";
case EbtStruct: return "structure";
default: return "unknown type";
default: UNREACHABLE(); return "unknown type";
}
}
......@@ -158,9 +168,9 @@ struct TLayoutQualifier
//
// This is just for debug print out, carried along with the definitions above.
//
inline const char* getQualifierString(TQualifier q)
inline const char *getQualifierString(TQualifier qualifier)
{
switch(q)
switch(qualifier)
{
case EvqTemporary: return "Temporary"; break;
case EvqGlobal: return "Global"; break;
......@@ -183,7 +193,7 @@ inline const char* getQualifierString(TQualifier q)
case EvqFrontFacing: return "FrontFacing"; break;
case EvqFragColor: return "FragColor"; break;
case EvqFragData: return "FragData"; break;
default: return "unknown qualifier";
default: UNREACHABLE(); return "unknown qualifier";
}
}
......
......@@ -228,6 +228,70 @@ enum ESymbolLevel
GLOBAL_LEVEL
};
inline bool IsGenType(const TType *type)
{
if(type)
{
TBasicType basicType = type->getBasicType();
return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || basicType == EbtGenBType;
}
return false;
}
inline bool IsVecType(const TType *type)
{
if(type)
{
TBasicType basicType = type->getBasicType();
return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || basicType == EbtBVec;
}
return false;
}
inline TType *GenType(TType *type, int size)
{
ASSERT(size >= 1 && size <= 4);
if(!type)
{
return nullptr;
}
ASSERT(!IsVecType(type));
switch(type->getBasicType())
{
case EbtGenType: return new TType(EbtFloat, size);
case EbtGenIType: return new TType(EbtInt, size);
case EbtGenUType: return new TType(EbtUInt, size);
case EbtGenBType: return new TType(EbtBool, size);
default: return type;
}
}
inline TType *VecType(TType *type, int size)
{
ASSERT(size >= 2 && size <= 4);
if(!type)
{
return nullptr;
}
ASSERT(!IsGenType(type));
switch(type->getBasicType())
{
case EbtVec: return new TType(EbtFloat, size);
case EbtIVec: return new TType(EbtInt, size);
case EbtUVec: return new TType(EbtUInt, size);
case EbtBVec: return new TType(EbtBool, size);
default: return type;
}
}
class TSymbolTable
{
public:
......@@ -315,6 +379,29 @@ public:
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4);
return;
}
else if(IsGenType(rvalue) ||
IsGenType(ptype1) ||
IsGenType(ptype2) ||
IsGenType(ptype3) ||
IsGenType(ptype4))
{
insertBuiltIn(level, GenType(rvalue, 1), name, GenType(ptype1, 1), GenType(ptype2, 1), GenType(ptype3, 1), GenType(ptype4, 1));
insertBuiltIn(level, GenType(rvalue, 2), name, GenType(ptype1, 2), GenType(ptype2, 2), GenType(ptype3, 2), GenType(ptype4, 2));
insertBuiltIn(level, GenType(rvalue, 3), name, GenType(ptype1, 3), GenType(ptype2, 3), GenType(ptype3, 3), GenType(ptype4, 3));
insertBuiltIn(level, GenType(rvalue, 4), name, GenType(ptype1, 4), GenType(ptype2, 4), GenType(ptype3, 4), GenType(ptype4, 4));
return;
}
else if(IsVecType(rvalue) ||
IsVecType(ptype1) ||
IsVecType(ptype2) ||
IsVecType(ptype3) ||
IsVecType(ptype4))
{
insertBuiltIn(level, VecType(rvalue, 2), name, VecType(ptype1, 2), VecType(ptype2, 2), VecType(ptype3, 2), VecType(ptype4, 2));
insertBuiltIn(level, VecType(rvalue, 3), name, VecType(ptype1, 3), VecType(ptype2, 3), VecType(ptype3, 3), VecType(ptype4, 3));
insertBuiltIn(level, VecType(rvalue, 4), name, VecType(ptype1, 4), VecType(ptype2, 4), VecType(ptype3, 4), VecType(ptype4, 4));
return;
}
TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
......@@ -333,6 +420,12 @@ public:
function->addParameter(param3);
}
if(ptype4)
{
TParameter param4 = {0, ptype4};
function->addParameter(param4);
}
insert(level, *function);
}
......
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