Commit f3cc4aef by Nicolas Capens

Use generic types to compact the symbol table initialization.

Just like in the spec text, use symbolic types that represent multiple concrete types. The few signatures that get generated more than once are only added to the symbol table once because it ignores duplicates. BUG=angle:926 Change-Id: I216f03d22502b724dbefc87c5a021d6021c3a434 Reviewed-on: https://chromium-review.googlesource.com/251620Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarNicolas Capens <capn@chromium.org>
parent e6d14cc3
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#ifndef COMPILER_TRANSLATOR_BASETYPES_H_ #ifndef COMPILER_TRANSLATOR_BASETYPES_H_
#define COMPILER_TRANSLATOR_BASETYPES_H_ #define COMPILER_TRANSLATOR_BASETYPES_H_
#include <assert.h> #include "compiler/translator/compilerdebug.h"
// //
// Precision qualifiers // Precision qualifiers
...@@ -42,7 +42,15 @@ enum TBasicType ...@@ -42,7 +42,15 @@ enum TBasicType
EbtInt, EbtInt,
EbtUInt, EbtUInt,
EbtBool, 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() EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler2D, EbtSampler2D,
EbtSampler3D, EbtSampler3D,
...@@ -62,10 +70,10 @@ enum TBasicType ...@@ -62,10 +70,10 @@ enum TBasicType
EbtSamplerCubeShadow, EbtSamplerCubeShadow,
EbtSampler2DArrayShadow, EbtSampler2DArrayShadow,
EbtGuardSamplerEnd, // non type: see implementation of IsSampler() EbtGuardSamplerEnd, // non type: see implementation of IsSampler()
EbtGSampler2D, // non type: represents sampler2D, isampler2D and usampler2D EbtGSampler2D, // non type: represents sampler2D, isampler2D, and usampler2D
EbtGSampler3D, // non type: represents sampler3D, isampler3D and usampler3D EbtGSampler3D, // non type: represents sampler3D, isampler3D, and usampler3D
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, EbtInterfaceBlock,
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
...@@ -411,7 +419,7 @@ inline const char* getQualifierString(TQualifier q) ...@@ -411,7 +419,7 @@ inline const char* getQualifierString(TQualifier q)
case EvqFlatIn: return "flat in"; break; case EvqFlatIn: return "flat in"; break;
case EvqLastFragColor: return "LastFragColor"; break; case EvqLastFragColor: return "LastFragColor"; break;
case EvqLastFragData: return "LastFragData"; break; case EvqLastFragData: return "LastFragData"; break;
default: return "unknown qualifier"; default: UNREACHABLE(); return "unknown qualifier";
} }
} }
...@@ -422,7 +430,7 @@ inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq) ...@@ -422,7 +430,7 @@ inline const char* getMatrixPackingString(TLayoutMatrixPacking mpq)
case EmpUnspecified: return "mp_unspecified"; case EmpUnspecified: return "mp_unspecified";
case EmpRowMajor: return "row_major"; case EmpRowMajor: return "row_major";
case EmpColumnMajor: return "column_major"; case EmpColumnMajor: return "column_major";
default: return "unknown matrix packing"; default: UNREACHABLE(); return "unknown matrix packing";
} }
} }
...@@ -434,7 +442,7 @@ inline const char* getBlockStorageString(TLayoutBlockStorage bsq) ...@@ -434,7 +442,7 @@ inline const char* getBlockStorageString(TLayoutBlockStorage bsq)
case EbsShared: return "shared"; case EbsShared: return "shared";
case EbsPacked: return "packed"; case EbsPacked: return "packed";
case EbsStd140: return "std140"; case EbsStd140: return "std140";
default: return "unknown block storage"; default: UNREACHABLE(); return "unknown block storage";
} }
} }
...@@ -448,7 +456,7 @@ inline const char* getInterpolationString(TQualifier q) ...@@ -448,7 +456,7 @@ inline const char* getInterpolationString(TQualifier q)
case EvqSmoothIn: return "smooth"; break; case EvqSmoothIn: return "smooth"; break;
case EvqCentroidIn: return "centroid"; break; case EvqCentroidIn: return "centroid"; break;
case EvqFlatIn: return "flat"; break; case EvqFlatIn: return "flat"; break;
default: return "unknown interpolation"; default: UNREACHABLE(); return "unknown interpolation";
} }
} }
......
...@@ -142,68 +142,148 @@ TSymbolTable::~TSymbolTable() ...@@ -142,68 +142,148 @@ TSymbolTable::~TSymbolTable()
pop(); pop();
} }
void TSymbolTable::insertBuiltIn( bool IsGenType(const TType *type)
ESymbolLevel level, TType *rvalue, const char *name, {
TType *ptype1, TType *ptype2, TType *ptype3, TType *ptype4, TType *ptype5) if (type)
{
TBasicType basicType = type->getBasicType();
return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || basicType == EbtGenBType;
}
return false;
}
bool IsVecType(const TType *type)
{
if (type)
{
TBasicType basicType = type->getBasicType();
return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || basicType == EbtBVec;
}
return false;
}
TType *SpecificType(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;
}
}
TType *VectorType(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;
}
}
void TSymbolTable::insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name, TType *ptype1, TType *ptype2, TType *ptype3, TType *ptype4, TType *ptype5)
{ {
if (ptype1->getBasicType() == EbtGSampler2D) if (ptype1->getBasicType() == EbtGSampler2D)
{ {
bool gvec4 = (rvalue->getBasicType() == EbtGVec4); bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5);
new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5);
new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5);
return;
} }
if (ptype1->getBasicType() == EbtGSampler3D) else if (ptype1->getBasicType() == EbtGSampler3D)
{ {
bool gvec4 = (rvalue->getBasicType() == EbtGVec4); bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5);
new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5);
new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5);
return;
} }
if (ptype1->getBasicType() == EbtGSamplerCube) else if (ptype1->getBasicType() == EbtGSamplerCube)
{ {
bool gvec4 = (rvalue->getBasicType() == EbtGVec4); bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5);
new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5);
new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5);
return;
} }
if (ptype1->getBasicType() == EbtGSampler2DArray) else if (ptype1->getBasicType() == EbtGSampler2DArray)
{ {
bool gvec4 = (rvalue->getBasicType() == EbtGVec4); bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtFloat, 4) : rvalue, name, new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5);
new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5);
new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name,
new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5);
return;
} }
else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3))
{
ASSERT(!ptype4 && !ptype5);
insertBuiltIn(level, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1));
insertBuiltIn(level, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2));
insertBuiltIn(level, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3));
insertBuiltIn(level, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4));
}
else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3))
{
ASSERT(!ptype4 && !ptype5);
insertBuiltIn(level, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2));
insertBuiltIn(level, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3));
insertBuiltIn(level, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4));
}
else
{
TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
TFunction *function = new TFunction(NewPoolTString(name), *rvalue); TParameter param1 = {0, ptype1};
function->addParameter(param1);
TType *types[] = {ptype1, ptype2, ptype3, ptype4, ptype5}; if (ptype2)
for (size_t ii = 0; ii < sizeof(types) / sizeof(types[0]); ++ii)
{
if (types[ii])
{ {
TParameter param = {NULL, types[ii]}; TParameter param2 = {0, ptype2};
function->addParameter(param); function->addParameter(param2);
}
if (ptype3)
{
TParameter param3 = {0, ptype3};
function->addParameter(param3);
}
if (ptype4)
{
TParameter param4 = {0, ptype4};
function->addParameter(param4);
}
if (ptype5)
{
TParameter param5 = {0, ptype5};
function->addParameter(param5);
} }
}
insert(level, function); insert(level, function);
}
} }
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const
......
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