Replace TCache with static TType instances
Replaces TCache with (static generation + static/dynamic lookups) of
TType instances, using compile-time template and constexpr magic.
Work started by jmadill here: https://crrev.com/c/776280
With more contributions from jmadill here: https://crrev.com/c/801494
Bug: angleproject:1432
Change-Id: I07181543f8fee4b2606cdd2d0738351e83d4ce57
Reviewed-on: https://chromium-review.googlesource.com/786317
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index 39f4f54..62bd3ba 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -13,8 +13,8 @@
#include "compiler/translator/SymbolTable.h"
-#include "compiler/translator/Cache.h"
#include "compiler/translator/IntermNode.h"
+#include "compiler/translator/StaticType.h"
#include <stdio.h>
#include <algorithm>
@@ -249,7 +249,7 @@
return false;
}
-const TType *SpecificType(const TType *type, int size)
+constexpr const TType *SpecificType(const TType *type, int size)
{
ASSERT(size >= 1 && size <= 4);
@@ -263,20 +263,23 @@
switch (type->getBasicType())
{
case EbtGenType:
- return TCache::getType(EbtFloat, type->getQualifier(),
- static_cast<unsigned char>(size));
+ return StaticType::GetForVec<EbtFloat>(type->getQualifier(),
+ static_cast<unsigned char>(size));
case EbtGenIType:
- return TCache::getType(EbtInt, type->getQualifier(), static_cast<unsigned char>(size));
+ return StaticType::GetForVec<EbtInt>(type->getQualifier(),
+ static_cast<unsigned char>(size));
case EbtGenUType:
- return TCache::getType(EbtUInt, type->getQualifier(), static_cast<unsigned char>(size));
+ return StaticType::GetForVec<EbtUInt>(type->getQualifier(),
+ static_cast<unsigned char>(size));
case EbtGenBType:
- return TCache::getType(EbtBool, type->getQualifier(), static_cast<unsigned char>(size));
+ return StaticType::GetForVec<EbtBool>(type->getQualifier(),
+ static_cast<unsigned char>(size));
default:
return type;
}
}
-const TType *VectorType(const TType *type, int size)
+constexpr const TType *VectorType(const TType *type, int size)
{
ASSERT(size >= 2 && size <= 4);
@@ -290,13 +293,13 @@
switch (type->getBasicType())
{
case EbtVec:
- return TCache::getType(EbtFloat, static_cast<unsigned char>(size));
+ return StaticType::GetForVecMat<EbtFloat>(static_cast<unsigned char>(size));
case EbtIVec:
- return TCache::getType(EbtInt, static_cast<unsigned char>(size));
+ return StaticType::GetForVecMat<EbtInt>(static_cast<unsigned char>(size));
case EbtUVec:
- return TCache::getType(EbtUInt, static_cast<unsigned char>(size));
+ return StaticType::GetForVecMat<EbtUInt>(static_cast<unsigned char>(size));
case EbtBVec:
- return TCache::getType(EbtBool, static_cast<unsigned char>(size));
+ return StaticType::GetForVecMat<EbtBool>(static_cast<unsigned char>(size));
default:
return type;
}
@@ -398,70 +401,71 @@
{
insertUnmangledBuiltInName(name, level);
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name,
- TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name,
- TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name,
- TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtSampler2D>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtISampler2D>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtUSampler2D>(), ptype2, ptype3, ptype4, ptype5);
}
else if (ptype1->getBasicType() == EbtGSampler3D)
{
insertUnmangledBuiltInName(name, level);
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name,
- TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name,
- TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name,
- TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtSampler3D>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtISampler3D>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtUSampler3D>(), ptype2, ptype3, ptype4, ptype5);
}
else if (ptype1->getBasicType() == EbtGSamplerCube)
{
insertUnmangledBuiltInName(name, level);
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name,
- TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name,
- TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name,
- TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtSamplerCube>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtISamplerCube>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtUSamplerCube>(), ptype2, ptype3, ptype4, ptype5);
}
else if (ptype1->getBasicType() == EbtGSampler2DArray)
{
insertUnmangledBuiltInName(name, level);
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name,
- TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name,
- TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name,
- TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtSampler2DArray>(), ptype2, ptype3, ptype4,
+ ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtISampler2DArray>(), ptype2, ptype3, ptype4,
+ ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtUSampler2DArray>(), ptype2, ptype3, ptype4,
+ ptype5);
}
else if (ptype1->getBasicType() == EbtGSampler2DMS)
{
insertUnmangledBuiltInName(name, level);
bool gvec4 = (rvalue->getBasicType() == EbtGVec4);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name,
- TCache::getType(EbtSampler2DMS), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name,
- TCache::getType(EbtISampler2DMS), ptype2, ptype3, ptype4, ptype5);
- insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name,
- TCache::getType(EbtUSampler2DMS), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtFloat, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtSampler2DMS>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtISampler2DMS>(), ptype2, ptype3, ptype4, ptype5);
+ insertBuiltIn(level, gvec4 ? StaticType::GetBasic<EbtUInt, 4>() : rvalue, name,
+ StaticType::GetBasic<EbtUSampler2DMS>(), ptype2, ptype3, ptype4, ptype5);
}
else if (IsGImage(ptype1->getBasicType()))
{
insertUnmangledBuiltInName(name, level);
- const TType *floatType = TCache::getType(EbtFloat, 4);
- const TType *intType = TCache::getType(EbtInt, 4);
- const TType *unsignedType = TCache::getType(EbtUInt, 4);
+ const TType *floatType = StaticType::GetBasic<EbtFloat, 4>();
+ const TType *intType = StaticType::GetBasic<EbtInt, 4>();
+ const TType *unsignedType = StaticType::GetBasic<EbtUInt, 4>();
- const TType *floatImage =
- TCache::getType(convertGImageToFloatImage(ptype1->getBasicType()));
- const TType *intImage = TCache::getType(convertGImageToIntImage(ptype1->getBasicType()));
- const TType *unsignedImage =
- TCache::getType(convertGImageToUnsignedImage(ptype1->getBasicType()));
+ const TType *floatImage = StaticType::GetForFloatImage(ptype1->getBasicType());
+ const TType *intImage = StaticType::GetForIntImage(ptype1->getBasicType());
+ const TType *unsignedImage = StaticType::GetForUintImage(ptype1->getBasicType());
// GLSL ES 3.10, Revision 4, 8.12 Image Functions
if (rvalue->getBasicType() == EbtGVec4)