Commit 614dd0f5 by Kai Ninomiya Committed by Commit Bot

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: 's avatarJamie Madill <jmadill@chromium.org>
parent ded7923b
......@@ -29,8 +29,6 @@
'compiler/translator/BuiltInFunctionEmulator.h',
'compiler/translator/BreakVariableAliasingInInnerLoops.cpp',
'compiler/translator/BreakVariableAliasingInInnerLoops.h',
'compiler/translator/Cache.cpp',
'compiler/translator/Cache.h',
'compiler/translator/CallDAG.cpp',
'compiler/translator/CallDAG.h',
'compiler/translator/ClampPointSize.cpp',
......@@ -142,6 +140,8 @@
'compiler/translator/SimplifyLoopConditions.h',
'compiler/translator/SplitSequenceOperator.cpp',
'compiler/translator/SplitSequenceOperator.h',
'compiler/translator/StaticType.cpp',
'compiler/translator/StaticType.h',
'compiler/translator/SymbolTable.cpp',
'compiler/translator/SymbolTable.h',
'compiler/translator/SymbolUniqueId.cpp',
......
......@@ -129,58 +129,95 @@ enum TBasicType
EbtLast
};
inline TBasicType convertGImageToFloatImage(TBasicType type)
constexpr const char *GetBasicMangledName(TBasicType t)
{
switch (type)
{
case EbtGImage2D:
return EbtImage2D;
case EbtGImage3D:
return EbtImage3D;
case EbtGImage2DArray:
return EbtImage2DArray;
case EbtGImageCube:
return EbtImageCube;
default:
UNREACHABLE();
}
return EbtLast;
}
inline TBasicType convertGImageToIntImage(TBasicType type)
{
switch (type)
{
case EbtGImage2D:
return EbtIImage2D;
case EbtGImage3D:
return EbtIImage3D;
case EbtGImage2DArray:
return EbtIImage2DArray;
case EbtGImageCube:
return EbtIImageCube;
default:
UNREACHABLE();
}
return EbtLast;
}
inline TBasicType convertGImageToUnsignedImage(TBasicType type)
{
switch (type)
switch (t)
{
case EbtGImage2D:
return EbtUImage2D;
case EbtGImage3D:
return EbtUImage3D;
case EbtGImage2DArray:
return EbtUImage2DArray;
case EbtGImageCube:
return EbtUImageCube;
case EbtFloat:
return "f";
case EbtInt:
return "i";
case EbtUInt:
return "u";
case EbtBool:
return "b";
case EbtYuvCscStandardEXT:
return "ycs";
case EbtSampler2D:
return "s2";
case EbtSampler3D:
return "s3";
case EbtSamplerCube:
return "sC";
case EbtSampler2DArray:
return "s2a";
case EbtSamplerExternalOES:
return "sext";
case EbtSamplerExternal2DY2YEXT:
return "sext2y2y";
case EbtSampler2DRect:
return "s2r";
case EbtSampler2DMS:
return "s2ms";
case EbtISampler2D:
return "is2";
case EbtISampler3D:
return "is3";
case EbtISamplerCube:
return "isC";
case EbtISampler2DArray:
return "is2a";
case EbtISampler2DMS:
return "is2ms";
case EbtUSampler2D:
return "us2";
case EbtUSampler3D:
return "us3";
case EbtUSamplerCube:
return "usC";
case EbtUSampler2DArray:
return "us2a";
case EbtUSampler2DMS:
return "us2ms";
case EbtSampler2DShadow:
return "s2s";
case EbtSamplerCubeShadow:
return "sCs";
case EbtSampler2DArrayShadow:
return "s2as";
case EbtImage2D:
return "im2";
case EbtIImage2D:
return "iim2";
case EbtUImage2D:
return "uim2";
case EbtImage3D:
return "im3";
case EbtIImage3D:
return "iim3";
case EbtUImage3D:
return "uim3";
case EbtImage2DArray:
return "im2a";
case EbtIImage2DArray:
return "iim2a";
case EbtUImage2DArray:
return "uim2a";
case EbtImageCube:
return "imc";
case EbtIImageCube:
return "iimc";
case EbtUImageCube:
return "uimc";
case EbtAtomicCounter:
return "ac";
case EbtStruct:
case EbtInterfaceBlock:
return nullptr;
default:
UNREACHABLE();
// EbtVoid, EbtAddress and non types
return "";
}
return EbtLast;
}
const char *getBasicString(TBasicType t);
......
......@@ -6,9 +6,9 @@
#include "compiler/translator/BuiltInFunctionEmulator.h"
#include "angle_gl.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/IntermTraverse.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/StaticType.h"
namespace sh
{
......@@ -286,19 +286,19 @@ void BuiltInFunctionEmulator::WriteEmulatedFunctionName(TInfoSinkBase &out, cons
FunctionId::FunctionId()
: mOp(EOpNull),
mParam1(TCache::getType(EbtVoid)),
mParam2(TCache::getType(EbtVoid)),
mParam3(TCache::getType(EbtVoid)),
mParam4(TCache::getType(EbtVoid))
mParam1(StaticType::GetBasic<EbtVoid>()),
mParam2(StaticType::GetBasic<EbtVoid>()),
mParam3(StaticType::GetBasic<EbtVoid>()),
mParam4(StaticType::GetBasic<EbtVoid>())
{
}
FunctionId::FunctionId(TOperator op, const TType *param)
: mOp(op),
mParam1(param),
mParam2(TCache::getType(EbtVoid)),
mParam3(TCache::getType(EbtVoid)),
mParam4(TCache::getType(EbtVoid))
mParam2(StaticType::GetBasic<EbtVoid>()),
mParam3(StaticType::GetBasic<EbtVoid>()),
mParam4(StaticType::GetBasic<EbtVoid>())
{
}
......@@ -306,13 +306,17 @@ FunctionId::FunctionId(TOperator op, const TType *param1, const TType *param2)
: mOp(op),
mParam1(param1),
mParam2(param2),
mParam3(TCache::getType(EbtVoid)),
mParam4(TCache::getType(EbtVoid))
mParam3(StaticType::GetBasic<EbtVoid>()),
mParam4(StaticType::GetBasic<EbtVoid>())
{
}
FunctionId::FunctionId(TOperator op, const TType *param1, const TType *param2, const TType *param3)
: mOp(op), mParam1(param1), mParam2(param2), mParam3(param3), mParam4(TCache::getType(EbtVoid))
: mOp(op),
mParam1(param1),
mParam2(param2),
mParam3(param3),
mParam4(StaticType::GetBasic<EbtVoid>())
{
}
......
......@@ -4,11 +4,11 @@
// found in the LICENSE file.
//
#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
#include "angle_gl.h"
#include "compiler/translator/BuiltInFunctionEmulator.h"
#include "compiler/translator/BuiltInFunctionEmulatorGLSL.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/VersionGLSL.h"
namespace sh
......@@ -19,7 +19,7 @@ void InitBuiltInAbsFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *e
{
if (shaderType == GL_VERTEX_SHADER)
{
const TType *int1 = TCache::getType(EbtInt);
const TType *int1 = StaticType::GetBasic<EbtInt>();
emu->addEmulatedFunction(EOpAbs, int1, "int abs_emu(int x) { return x * sign(x); }");
}
}
......@@ -31,10 +31,10 @@ void InitBuiltInIsnanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator
if (targetGLSLVersion < GLSL_VERSION_130)
return;
const TType *float1 = TCache::getType(EbtFloat);
const TType *float2 = TCache::getType(EbtFloat, 2);
const TType *float3 = TCache::getType(EbtFloat, 3);
const TType *float4 = TCache::getType(EbtFloat, 4);
const TType *float1 = StaticType::GetBasic<EbtFloat>();
const TType *float2 = StaticType::GetBasic<EbtFloat, 2>();
const TType *float3 = StaticType::GetBasic<EbtFloat, 3>();
const TType *float4 = StaticType::GetBasic<EbtFloat, 4>();
// !(x > 0.0 || x < 0.0 || x == 0.0) will be optimized and always equal to false.
emu->addEmulatedFunction(
......@@ -77,7 +77,7 @@ void InitBuiltInIsnanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator
void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *emu)
{
const TType *float1 = TCache::getType(EbtFloat);
const TType *float1 = StaticType::GetBasic<EbtFloat>();
auto floatFuncId = emu->addEmulatedFunction(
EOpAtan, float1, float1,
"emu_precision float atan_emu(emu_precision float y, emu_precision "
......@@ -88,9 +88,16 @@ void InitBuiltInAtanFunctionEmulatorForGLSLWorkarounds(BuiltInFunctionEmulator *
" else if (x < 0.0 && y < 0.0) return atan(y / x) - 3.14159265;\n"
" else return 1.57079632 * sign(y);\n"
"}\n");
static const std::array<const TType *, 5> floatVecs = {
nullptr,
nullptr,
StaticType::GetBasic<EbtFloat, 2>(),
StaticType::GetBasic<EbtFloat, 3>(),
StaticType::GetBasic<EbtFloat, 4>(),
};
for (int dim = 2; dim <= 4; ++dim)
{
const TType *floatVec = TCache::getType(EbtFloat, static_cast<unsigned char>(dim));
const TType *floatVec = floatVecs[dim];
std::stringstream ss;
ss << "emu_precision vec" << dim << " atan_emu(emu_precision vec" << dim
<< " y, emu_precision vec" << dim << " x)\n"
......@@ -120,8 +127,8 @@ void InitBuiltInFunctionEmulatorForGLSLMissingFunctions(BuiltInFunctionEmulator
// Emulate packUnorm2x16 and unpackUnorm2x16 (GLSL 4.10)
if (targetGLSLVersion < GLSL_VERSION_410)
{
const TType *float2 = TCache::getType(EbtFloat, 2);
const TType *uint1 = TCache::getType(EbtUInt);
const TType *float2 = StaticType::GetBasic<EbtFloat, 2>();
const TType *uint1 = StaticType::GetBasic<EbtUInt>();
// clang-format off
emu->addEmulatedFunction(EOpPackUnorm2x16, float2,
......@@ -146,8 +153,8 @@ void InitBuiltInFunctionEmulatorForGLSLMissingFunctions(BuiltInFunctionEmulator
// by using floatBitsToInt, floatBitsToUint, intBitsToFloat, and uintBitsToFloat (GLSL 3.30).
if (targetGLSLVersion >= GLSL_VERSION_330 && targetGLSLVersion < GLSL_VERSION_420)
{
const TType *float2 = TCache::getType(EbtFloat, 2);
const TType *uint1 = TCache::getType(EbtUInt);
const TType *float2 = StaticType::GetBasic<EbtFloat, 2>();
const TType *uint1 = StaticType::GetBasic<EbtUInt>();
// clang-format off
emu->addEmulatedFunction(EOpPackSnorm2x16, float2,
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Cache.cpp: Implements a cache for various commonly created objects.
#include <limits>
#include "common/angleutils.h"
#include "common/debug.h"
#include "compiler/translator/Cache.h"
namespace sh
{
namespace
{
class TScopedAllocator : angle::NonCopyable
{
public:
TScopedAllocator(TPoolAllocator *allocator) : mPreviousAllocator(GetGlobalPoolAllocator())
{
SetGlobalPoolAllocator(allocator);
}
~TScopedAllocator() { SetGlobalPoolAllocator(mPreviousAllocator); }
private:
TPoolAllocator *mPreviousAllocator;
};
} // namespace
TCache::TypeKey::TypeKey(TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize)
{
static_assert(sizeof(components) <= sizeof(value), "TypeKey::value is too small");
const size_t MaxEnumValue = std::numeric_limits<EnumComponentType>::max();
// TODO: change to static_assert() once we deprecate MSVC 2013 support
ASSERT(MaxEnumValue >= EbtLast && MaxEnumValue >= EbpLast && MaxEnumValue >= EvqLast &&
"TypeKey::EnumComponentType is too small");
value = 0;
components.basicType = static_cast<EnumComponentType>(basicType);
components.precision = static_cast<EnumComponentType>(precision);
components.qualifier = static_cast<EnumComponentType>(qualifier);
components.primarySize = primarySize;
components.secondarySize = secondarySize;
}
TCache *TCache::sCache = nullptr;
TCache::TCache()
{
}
void TCache::initialize()
{
if (sCache == nullptr)
{
sCache = new TCache();
}
}
void TCache::destroy()
{
SafeDelete(sCache);
}
const TType *TCache::getType(TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize)
{
TypeKey key(basicType, precision, qualifier, primarySize, secondarySize);
auto it = sCache->mTypes.find(key);
if (it != sCache->mTypes.end())
{
return it->second;
}
TScopedAllocator scopedAllocator(&sCache->mAllocator);
TType *type = new TType(basicType, precision, qualifier, primarySize, secondarySize);
type->realize();
sCache->mTypes.insert(std::make_pair(key, type));
return type;
}
} // namespace sh
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Cache.h: Implements a cache for various commonly created objects.
#ifndef COMPILER_TRANSLATOR_CACHE_H_
#define COMPILER_TRANSLATOR_CACHE_H_
#include <stdint.h>
#include <string.h>
#include <map>
#include "compiler/translator/Types.h"
#include "compiler/translator/PoolAlloc.h"
namespace sh
{
class TCache
{
public:
static void initialize();
static void destroy();
static const TType *getType(TBasicType basicType, TPrecision precision)
{
return getType(basicType, precision, EvqTemporary, 1, 1);
}
static const TType *getType(TBasicType basicType,
unsigned char primarySize = 1,
unsigned char secondarySize = 1)
{
return getType(basicType, EbpUndefined, EvqGlobal, primarySize, secondarySize);
}
static const TType *getType(TBasicType basicType,
TQualifier qualifier,
unsigned char primarySize = 1,
unsigned char secondarySize = 1)
{
return getType(basicType, EbpUndefined, qualifier, primarySize, secondarySize);
}
static const TType *getType(TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize);
private:
TCache();
union TypeKey {
TypeKey(TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize);
typedef uint8_t EnumComponentType;
struct
{
EnumComponentType basicType;
EnumComponentType precision;
EnumComponentType qualifier;
unsigned char primarySize;
unsigned char secondarySize;
} components;
uint64_t value;
bool operator<(const TypeKey &other) const { return value < other.value; }
};
typedef std::map<TypeKey, const TType *> TypeMap;
TypeMap mTypes;
TPoolAllocator mAllocator;
static TCache *sCache;
};
} // namespace sh
#endif // COMPILER_TRANSLATOR_CACHE_H_
......@@ -11,7 +11,6 @@
#include "angle_gl.h"
#include "common/utilities.h"
#include "compiler/translator/AddAndTrueToLoopCondition.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/CallDAG.h"
#include "compiler/translator/ClampPointSize.h"
#include "compiler/translator/CollectVariables.h"
......
......@@ -4,7 +4,6 @@
// found in the LICENSE file.
//
#include "compiler/translator/Cache.h"
#include "compiler/translator/InitializeDll.h"
#include "compiler/translator/InitializeGlobals.h"
......@@ -23,15 +22,12 @@ bool InitProcess()
return false;
}
TCache::initialize();
return true;
}
void DetachProcess()
{
FreePoolIndex();
TCache::destroy();
}
} // namespace sh
......@@ -11,9 +11,9 @@
#include "common/mathutil.h"
#include "compiler/preprocessor/SourceLocation.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/Declarator.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/StaticType.h"
#include "compiler/translator/ValidateGlobalInitializer.h"
#include "compiler/translator/ValidateSwitch.h"
#include "compiler/translator/glslang.h"
......@@ -3457,7 +3457,7 @@ TFunction *TParseContext::parseFunctionHeader(const TPublicType &type,
TFunction *TParseContext::addNonConstructorFunc(const TString *name, const TSourceLoc &loc)
{
const TType *returnType = TCache::getType(EbtVoid, EbpUndefined);
const TType *returnType = StaticType::GetQualified<EbtVoid, EvqTemporary>();
return new TFunction(&symbolTable, name, returnType);
}
......
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Compile-time instances of many common TType values. These are looked up
// (statically or dynamically) through the methods defined in the namespace.
//
#include "compiler/translator/StaticType.h"
namespace sh
{
namespace StaticType
{
const TType *GetForFloatImage(TBasicType basicType)
{
switch (basicType)
{
case EbtGImage2D:
return Get<EbtImage2D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage3D:
return Get<EbtImage3D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage2DArray:
return Get<EbtImage2DArray, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImageCube:
return Get<EbtImageCube, EbpUndefined, EvqGlobal, 1, 1>();
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
const TType *GetForIntImage(TBasicType basicType)
{
switch (basicType)
{
case EbtGImage2D:
return Get<EbtIImage2D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage3D:
return Get<EbtIImage3D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage2DArray:
return Get<EbtIImage2DArray, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImageCube:
return Get<EbtIImageCube, EbpUndefined, EvqGlobal, 1, 1>();
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
const TType *GetForUintImage(TBasicType basicType)
{
switch (basicType)
{
case EbtGImage2D:
return Get<EbtUImage2D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage3D:
return Get<EbtUImage3D, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImage2DArray:
return Get<EbtUImage2DArray, EbpUndefined, EvqGlobal, 1, 1>();
case EbtGImageCube:
return Get<EbtUImageCube, EbpUndefined, EvqGlobal, 1, 1>();
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
} // namespace StaticType
} // namespace sh
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Compile-time instances of many common TType values. These are looked up
// (statically or dynamically) through the methods defined in the namespace.
//
#ifndef COMPILER_TRANSLATOR_STATIC_TYPE_H_
#define COMPILER_TRANSLATOR_STATIC_TYPE_H_
#include "compiler/translator/Types.h"
namespace sh
{
namespace StaticType
{
namespace Helpers
{
//
// Generation and static allocation of type mangled name values.
//
// Size of the maximum possible constexpr-generated mangled name.
// If this value is too small, the compiler will produce errors.
static constexpr size_t kStaticMangledNameMaxLength = 10;
// Type which holds the mangled names for constexpr-generated TTypes.
// This simple struct is needed so that a char array can be returned by value.
struct StaticMangledName
{
// If this array is too small, the compiler will produce errors.
char name[kStaticMangledNameMaxLength + 1] = {};
};
// Generates a mangled name for a TType given its parameters.
constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize)
{
StaticMangledName name = {};
// When this function is executed constexpr (should be always),
// name.name[at] is guaranteed by the compiler to never go out of bounds.
size_t at = 0;
bool isMatrix = primarySize > 1 && secondarySize > 1;
bool isVector = primarySize > 1 && secondarySize == 1;
if (isMatrix)
{
name.name[at++] = 'm';
}
else if (isVector)
{
name.name[at++] = 'v';
}
{
const char *basicMangledName = GetBasicMangledName(basicType);
for (size_t i = 0; basicMangledName[i] != '\0'; ++i)
{
name.name[at++] = basicMangledName[i];
}
}
name.name[at++] = '0' + primarySize;
if (isMatrix)
{
name.name[at++] = 'x';
name.name[at++] = '0' + secondarySize;
}
name.name[at++] = ';';
name.name[at] = '\0';
return name;
}
// This "variable" contains the mangled names for every constexpr-generated TType.
// If kMangledNameInstance<B, P, Q, PS, SS> is used anywhere (specifally
// in kInstance, below), this is where the appropriate type will be stored.
template <TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize>
static constexpr StaticMangledName kMangledNameInstance =
BuildStaticMangledName(basicType, precision, qualifier, primarySize, secondarySize);
//
// Generation and static allocation of TType values.
//
// This "variable" contains every constexpr-generated TType.
// If kInstance<B, P, Q, PS, SS> is used anywhere (specifally
// in Get, below), this is where the appropriate type will be stored.
template <TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize>
static constexpr TType kInstance =
TType(basicType,
precision,
qualifier,
primarySize,
secondarySize,
kMangledNameInstance<basicType, precision, qualifier, primarySize, secondarySize>.name);
} // namespace Helpers
//
// Fully-qualified type lookup.
//
template <TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char primarySize,
unsigned char secondarySize>
constexpr const TType *Get()
{
static_assert(1 <= primarySize && primarySize <= 4, "primarySize out of bounds");
static_assert(1 <= secondarySize && secondarySize <= 4, "secondarySize out of bounds");
return &Helpers::kInstance<basicType, precision, qualifier, primarySize, secondarySize>;
}
//
// Overloads
//
template <TBasicType basicType, unsigned char primarySize = 1, unsigned char secondarySize = 1>
constexpr const TType *GetBasic()
{
return Get<basicType, EbpUndefined, EvqGlobal, primarySize, secondarySize>();
}
template <TBasicType basicType,
TQualifier qualifier,
unsigned char primarySize = 1,
unsigned char secondarySize = 1>
const TType *GetQualified()
{
return Get<basicType, EbpUndefined, qualifier, primarySize, secondarySize>();
}
// Dynamic lookup methods (convert runtime values to template args)
namespace Helpers
{
// Helper which takes secondarySize statically but primarySize dynamically.
template <TBasicType basicType,
TPrecision precision,
TQualifier qualifier,
unsigned char secondarySize>
const TType *GetForVecMatHelper(unsigned char primarySize)
{
static_assert(basicType == EbtFloat || basicType == EbtInt || basicType == EbtUInt ||
basicType == EbtBool,
"unsupported basicType");
switch (primarySize)
{
case 1:
return Get<basicType, precision, qualifier, 1, secondarySize>();
case 2:
return Get<basicType, precision, qualifier, 2, secondarySize>();
case 3:
return Get<basicType, precision, qualifier, 3, secondarySize>();
case 4:
return Get<basicType, precision, qualifier, 4, secondarySize>();
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
} // namespace Helpers
template <TBasicType basicType,
TPrecision precision = EbpUndefined,
TQualifier qualifier = EvqGlobal>
const TType *GetForVecMat(unsigned char primarySize, unsigned char secondarySize = 1)
{
static_assert(basicType == EbtFloat || basicType == EbtInt || basicType == EbtUInt ||
basicType == EbtBool,
"unsupported basicType");
switch (secondarySize)
{
case 1:
return Helpers::GetForVecMatHelper<basicType, precision, qualifier, 1>(primarySize);
case 2:
return Helpers::GetForVecMatHelper<basicType, precision, qualifier, 2>(primarySize);
case 3:
return Helpers::GetForVecMatHelper<basicType, precision, qualifier, 3>(primarySize);
case 4:
return Helpers::GetForVecMatHelper<basicType, precision, qualifier, 4>(primarySize);
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
template <TBasicType basicType, TPrecision precision = EbpUndefined>
const TType *GetForVec(TQualifier qualifier, unsigned char size)
{
switch (qualifier)
{
case EvqGlobal:
return Helpers::GetForVecMatHelper<basicType, precision, EvqGlobal, 1>(size);
case EvqOut:
return Helpers::GetForVecMatHelper<basicType, precision, EvqOut, 1>(size);
default:
UNREACHABLE();
return GetBasic<EbtVoid>();
}
}
const TType *GetForFloatImage(TBasicType basicType);
const TType *GetForIntImage(TBasicType basicType);
const TType *GetForUintImage(TBasicType basicType);
} // namespace StaticType
} // namespace sh
#endif // COMPILER_TRANSLATOR_STATIC_TYPE_H_
......@@ -463,138 +463,30 @@ const char *TType::buildMangledName() const
else if (isVector())
mangledName += 'v';
switch (type)
const char *basicMangledName = GetBasicMangledName(type);
if (basicMangledName != nullptr)
{
case EbtFloat:
mangledName += 'f';
break;
case EbtInt:
mangledName += 'i';
break;
case EbtUInt:
mangledName += 'u';
break;
case EbtBool:
mangledName += 'b';
break;
case EbtYuvCscStandardEXT:
mangledName += "ycs";
break;
case EbtSampler2D:
mangledName += "s2";
break;
case EbtSampler3D:
mangledName += "s3";
break;
case EbtSamplerCube:
mangledName += "sC";
break;
case EbtSampler2DArray:
mangledName += "s2a";
break;
case EbtSamplerExternalOES:
mangledName += "sext";
break;
case EbtSamplerExternal2DY2YEXT:
mangledName += "sext2y2y";
break;
case EbtSampler2DRect:
mangledName += "s2r";
break;
case EbtSampler2DMS:
mangledName += "s2ms";
break;
case EbtISampler2D:
mangledName += "is2";
break;
case EbtISampler3D:
mangledName += "is3";
break;
case EbtISamplerCube:
mangledName += "isC";
break;
case EbtISampler2DArray:
mangledName += "is2a";
break;
case EbtISampler2DMS:
mangledName += "is2ms";
break;
case EbtUSampler2D:
mangledName += "us2";
break;
case EbtUSampler3D:
mangledName += "us3";
break;
case EbtUSamplerCube:
mangledName += "usC";
break;
case EbtUSampler2DArray:
mangledName += "us2a";
break;
case EbtUSampler2DMS:
mangledName += "us2ms";
break;
case EbtSampler2DShadow:
mangledName += "s2s";
break;
case EbtSamplerCubeShadow:
mangledName += "sCs";
break;
case EbtSampler2DArrayShadow:
mangledName += "s2as";
break;
case EbtImage2D:
mangledName += "im2";
break;
case EbtIImage2D:
mangledName += "iim2";
break;
case EbtUImage2D:
mangledName += "uim2";
break;
case EbtImage3D:
mangledName += "im3";
break;
case EbtIImage3D:
mangledName += "iim3";
break;
case EbtUImage3D:
mangledName += "uim3";
break;
case EbtImage2DArray:
mangledName += "im2a";
break;
case EbtIImage2DArray:
mangledName += "iim2a";
break;
case EbtUImage2DArray:
mangledName += "uim2a";
break;
case EbtImageCube:
mangledName += "imc";
break;
case EbtIImageCube:
mangledName += "iimc";
break;
case EbtUImageCube:
mangledName += "uimc";
break;
case EbtAtomicCounter:
mangledName += "ac";
break;
case EbtStruct:
mangledName += "struct-";
mangledName += mStructure->name();
mangledName += mStructure->mangledFieldList();
break;
case EbtInterfaceBlock:
mangledName += "iblock-";
mangledName += mInterfaceBlock->name();
mangledName += mInterfaceBlock->mangledFieldList();
break;
default:
// EbtVoid, EbtAddress and non types
break;
mangledName += basicMangledName;
}
else
{
ASSERT(type == EbtStruct || type == EbtInterfaceBlock);
switch (type)
{
case EbtStruct:
mangledName += "struct-";
mangledName += mStructure->name();
mangledName += mStructure->mangledFieldList();
break;
case EbtInterfaceBlock:
mangledName += "iblock-";
mangledName += mInterfaceBlock->name();
mangledName += mInterfaceBlock->mangledFieldList();
break;
default:
UNREACHABLE();
break;
}
}
if (isMatrix())
......
......@@ -126,6 +126,45 @@ class TType
TType(const TType &t);
TType &operator=(const TType &t);
constexpr TType(TBasicType t,
TPrecision p,
TQualifier q,
unsigned char ps,
unsigned char ss,
const char *mangledName)
: type(t),
precision(p),
qualifier(q),
invariant(false),
memoryQualifier(TMemoryQualifier::Create()),
layoutQualifier(TLayoutQualifier::Create()),
primarySize(ps),
secondarySize(ss),
mArraySizes(nullptr),
mInterfaceBlock(nullptr),
mStructure(nullptr),
mIsStructSpecifier(false),
mMangledName(mangledName)
{
}
constexpr TType(TType &&t)
: type(t.type),
precision(t.precision),
qualifier(t.qualifier),
invariant(t.invariant),
memoryQualifier(t.memoryQualifier),
layoutQualifier(t.layoutQualifier),
primarySize(t.primarySize),
secondarySize(t.secondarySize),
mArraySizes(t.mArraySizes),
mInterfaceBlock(t.mInterfaceBlock),
mStructure(t.mStructure),
mIsStructSpecifier(t.mIsStructSpecifier),
mMangledName(t.mMangledName)
{
}
TBasicType getBasicType() const { return type; }
void setBasicType(TBasicType t);
......
......@@ -39,7 +39,6 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
#endif
#include "angle_gl.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/Declarator.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/ParseContext.h"
......
......@@ -89,7 +89,6 @@
#endif
#include "angle_gl.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/Declarator.h"
#include "compiler/translator/SymbolTable.h"
#include "compiler/translator/ParseContext.h"
......
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