Commit 01971113 by Dmitry Skiba Committed by Jamie Madill

Cache TTypes.

*re-land with build fix for Win/Release* This change saves us ~70KiB per compiler with just ~3KiB of cache. BUG=492725 Change-Id: I4382c55b2480f70b00c5d117fcb7e0c51d0dfbb4 Reviewed-on: https://chromium-review.googlesource.com/284735Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarDmitry Skiba <dskiba@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@chromium.org>
parent 53b76107
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
'compiler/translator/BuiltInFunctionEmulator.h', 'compiler/translator/BuiltInFunctionEmulator.h',
'compiler/translator/BuiltInFunctionEmulatorGLSL.cpp', 'compiler/translator/BuiltInFunctionEmulatorGLSL.cpp',
'compiler/translator/BuiltInFunctionEmulatorGLSL.h', 'compiler/translator/BuiltInFunctionEmulatorGLSL.h',
'compiler/translator/Cache.cpp',
'compiler/translator/Cache.h',
'compiler/translator/CallDAG.cpp', 'compiler/translator/CallDAG.cpp',
'compiler/translator/CallDAG.h', 'compiler/translator/CallDAG.h',
'compiler/translator/CodeGen.cpp', 'compiler/translator/CodeGen.cpp',
......
...@@ -18,7 +18,10 @@ enum TPrecision ...@@ -18,7 +18,10 @@ enum TPrecision
EbpUndefined, EbpUndefined,
EbpLow, EbpLow,
EbpMedium, EbpMedium,
EbpHigh EbpHigh,
// end of list
EbpLast
}; };
inline const char* getPrecisionString(TPrecision p) inline const char* getPrecisionString(TPrecision p)
...@@ -77,6 +80,9 @@ enum TBasicType ...@@ -77,6 +80,9 @@ enum TBasicType
EbtStruct, EbtStruct,
EbtInterfaceBlock, EbtInterfaceBlock,
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
// end of list
EbtLast
}; };
const char* getBasicString(TBasicType t); const char* getBasicString(TBasicType t);
......
//
// 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
{
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();
UNUSED_ASSERTION_VARIABLE(MaxEnumValue);
// 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;
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;
}
//
// 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"
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;
};
#endif // COMPILER_TRANSLATOR_CACHE_H_
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "compiler/translator/Cache.h"
#include "compiler/translator/Compiler.h" #include "compiler/translator/Compiler.h"
#include "compiler/translator/CallDAG.h" #include "compiler/translator/CallDAG.h"
#include "compiler/translator/ForLoopUnroll.h" #include "compiler/translator/ForLoopUnroll.h"
......
...@@ -11,25 +11,26 @@ ...@@ -11,25 +11,26 @@
// //
#include "compiler/translator/Initialize.h" #include "compiler/translator/Initialize.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
#include "angle_gl.h" #include "angle_gl.h"
void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable) void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInResources &resources, TSymbolTable &symbolTable)
{ {
TType *float1 = new TType(EbtFloat); const TType *float1 = TCache::getType(EbtFloat);
TType *float2 = new TType(EbtFloat, 2); const TType *float2 = TCache::getType(EbtFloat, 2);
TType *float3 = new TType(EbtFloat, 3); const TType *float3 = TCache::getType(EbtFloat, 3);
TType *float4 = new TType(EbtFloat, 4); const TType *float4 = TCache::getType(EbtFloat, 4);
TType *int1 = new TType(EbtInt); const TType *int1 = TCache::getType(EbtInt);
TType *int2 = new TType(EbtInt, 2); const TType *int2 = TCache::getType(EbtInt, 2);
TType *int3 = new TType(EbtInt, 3); const TType *int3 = TCache::getType(EbtInt, 3);
TType *uint1 = new TType(EbtUInt); const TType *uint1 = TCache::getType(EbtUInt);
TType *bool1 = new TType(EbtBool); const TType *bool1 = TCache::getType(EbtBool);
TType *genType = new TType(EbtGenType); const TType *genType = TCache::getType(EbtGenType);
TType *genIType = new TType(EbtGenIType); const TType *genIType = TCache::getType(EbtGenIType);
TType *genUType = new TType(EbtGenUType); const TType *genUType = TCache::getType(EbtGenUType);
TType *genBType = new TType(EbtGenBType); const TType *genBType = TCache::getType(EbtGenBType);
// //
// Angle and Trigonometric Functions. // Angle and Trigonometric Functions.
...@@ -102,14 +103,10 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -102,14 +103,10 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", genType, genType, genType);
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpSmoothStep, genType, "smoothstep", float1, float1, genType);
TType *outFloat1 = new TType(EbtFloat); const TType *outFloat1 = TCache::getType(EbtFloat, EvqOut);
TType *outFloat2 = new TType(EbtFloat, 2); const TType *outFloat2 = TCache::getType(EbtFloat, EvqOut, 2);
TType *outFloat3 = new TType(EbtFloat, 3); const TType *outFloat3 = TCache::getType(EbtFloat, EvqOut, 3);
TType *outFloat4 = new TType(EbtFloat, 4); const TType *outFloat4 = TCache::getType(EbtFloat, EvqOut, 4);
outFloat1->setQualifier(EvqOut);
outFloat2->setQualifier(EvqOut);
outFloat3->setQualifier(EvqOut);
outFloat4->setQualifier(EvqOut);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float1, "modf", float1, outFloat1);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpModf, float2, "modf", float2, outFloat2);
...@@ -142,15 +139,15 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -142,15 +139,15 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpReflect, genType, "reflect", genType, genType);
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpRefract, genType, "refract", genType, genType, float1);
TType *mat2 = new TType(EbtFloat, 2, 2); const TType *mat2 = TCache::getType(EbtFloat, 2, 2);
TType *mat3 = new TType(EbtFloat, 3, 3); const TType *mat3 = TCache::getType(EbtFloat, 3, 3);
TType *mat4 = new TType(EbtFloat, 4, 4); const TType *mat4 = TCache::getType(EbtFloat, 4, 4);
TType *mat2x3 = new TType(EbtFloat, 2, 3); const TType *mat2x3 = TCache::getType(EbtFloat, 2, 3);
TType *mat3x2 = new TType(EbtFloat, 3, 2); const TType *mat3x2 = TCache::getType(EbtFloat, 3, 2);
TType *mat2x4 = new TType(EbtFloat, 2, 4); const TType *mat2x4 = TCache::getType(EbtFloat, 2, 4);
TType *mat4x2 = new TType(EbtFloat, 4, 2); const TType *mat4x2 = TCache::getType(EbtFloat, 4, 2);
TType *mat3x4 = new TType(EbtFloat, 3, 4); const TType *mat3x4 = TCache::getType(EbtFloat, 3, 4);
TType *mat4x3 = new TType(EbtFloat, 4, 3); const TType *mat4x3 = TCache::getType(EbtFloat, 4, 3);
// //
// Matrix Functions. // Matrix Functions.
...@@ -193,10 +190,10 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -193,10 +190,10 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat3, "inverse", mat3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, EOpInverse, mat4, "inverse", mat4);
TType *vec = new TType(EbtVec); const TType *vec = TCache::getType(EbtVec);
TType *ivec = new TType(EbtIVec); const TType *ivec = TCache::getType(EbtIVec);
TType *uvec = new TType(EbtUVec); const TType *uvec = TCache::getType(EbtUVec);
TType *bvec = new TType(EbtBVec); const TType *bvec = TCache::getType(EbtBVec);
// //
// Vector relational functions. // Vector relational functions.
...@@ -225,8 +222,8 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -225,8 +222,8 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpAll, bool1, "all", bvec);
symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec); symbolTable.insertBuiltIn(COMMON_BUILTINS, EOpVectorLogicalNot, bvec, "not", bvec);
TType *sampler2D = new TType(EbtSampler2D); const TType *sampler2D = TCache::getType(EbtSampler2D);
TType *samplerCube = new TType(EbtSamplerCube); const TType *samplerCube = TCache::getType(EbtSamplerCube);
// //
// Texture Functions for GLSL ES 1.0 // Texture Functions for GLSL ES 1.0
...@@ -238,7 +235,7 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -238,7 +235,7 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
if (resources.OES_EGL_image_external) if (resources.OES_EGL_image_external)
{ {
TType *samplerExternalOES = new TType(EbtSamplerExternalOES); const TType *samplerExternalOES = TCache::getType(EbtSamplerExternalOES);
symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2D", samplerExternalOES, float2);
symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DProj", samplerExternalOES, float3);
...@@ -247,7 +244,7 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -247,7 +244,7 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
if (resources.ARB_texture_rectangle) if (resources.ARB_texture_rectangle)
{ {
TType *sampler2DRect = new TType(EbtSampler2DRect); const TType *sampler2DRect = TCache::getType(EbtSampler2DRect);
symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRect", sampler2DRect, float2);
symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "texture2DRectProj", sampler2DRect, float3);
...@@ -296,12 +293,12 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -296,12 +293,12 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1); symbolTable.insertBuiltIn(ESSL1_BUILTINS, float4, "textureCubeLod", samplerCube, float3, float1);
} }
TType *gvec4 = new TType(EbtGVec4); const TType *gvec4 = TCache::getType(EbtGVec4);
TType *gsampler2D = new TType(EbtGSampler2D); const TType *gsampler2D = TCache::getType(EbtGSampler2D);
TType *gsamplerCube = new TType(EbtGSamplerCube); const TType *gsamplerCube = TCache::getType(EbtGSamplerCube);
TType *gsampler3D = new TType(EbtGSampler3D); const TType *gsampler3D = TCache::getType(EbtGSampler3D);
TType *gsampler2DArray = new TType(EbtGSampler2DArray); const TType *gsampler2DArray = TCache::getType(EbtGSampler2DArray);
// //
// Texture Functions for GLSL ES 3.0 // Texture Functions for GLSL ES 3.0
...@@ -329,9 +326,9 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR ...@@ -329,9 +326,9 @@ void InsertBuiltInFunctions(sh::GLenum type, ShShaderSpec spec, const ShBuiltInR
symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1); symbolTable.insertBuiltIn(ESSL3_BUILTINS, gvec4, "textureProj", gsampler3D, float4, float1);
} }
TType *sampler2DShadow = new TType(EbtSampler2DShadow); const TType *sampler2DShadow = TCache::getType(EbtSampler2DShadow);
TType *samplerCubeShadow = new TType(EbtSamplerCubeShadow); const TType *samplerCubeShadow = TCache::getType(EbtSamplerCubeShadow);
TType *sampler2DArrayShadow = new TType(EbtSampler2DArrayShadow); const TType *sampler2DArrayShadow = TCache::getType(EbtSampler2DArrayShadow);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", sampler2DShadow, float3);
symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4); symbolTable.insertBuiltIn(ESSL3_BUILTINS, float1, "texture", samplerCubeShadow, float4);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "compiler/translator/Cache.h"
#include "compiler/translator/InitializeDll.h" #include "compiler/translator/InitializeDll.h"
#include "compiler/translator/InitializeGlobals.h" #include "compiler/translator/InitializeGlobals.h"
#include "compiler/translator/InitializeParseContext.h" #include "compiler/translator/InitializeParseContext.h"
...@@ -24,6 +25,8 @@ bool InitProcess() ...@@ -24,6 +25,8 @@ bool InitProcess()
return false; return false;
} }
TCache::initialize();
return true; return true;
} }
...@@ -31,4 +34,5 @@ void DetachProcess() ...@@ -31,4 +34,5 @@ void DetachProcess()
{ {
FreeParseContextIndex(); FreeParseContextIndex();
FreePoolIndex(); FreePoolIndex();
TCache::destroy();
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <stdio.h> #include <stdio.h>
#include "compiler/preprocessor/SourceLocation.h" #include "compiler/preprocessor/SourceLocation.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/glslang.h" #include "compiler/translator/glslang.h"
#include "compiler/translator/ValidateSwitch.h" #include "compiler/translator/ValidateSwitch.h"
#include "compiler/translator/ValidateGlobalInitializer.h" #include "compiler/translator/ValidateGlobalInitializer.h"
......
...@@ -247,18 +247,13 @@ public: ...@@ -247,18 +247,13 @@ public:
pointer address(reference x) const { return &x; } pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; } const_pointer address(const_reference x) const { return &x; }
pool_allocator() : allocator(GetGlobalPoolAllocator()) { } pool_allocator() { }
pool_allocator(TPoolAllocator& a) : allocator(&a) { }
pool_allocator(const pool_allocator<T>& p) : allocator(p.allocator) { }
template <class Other>
pool_allocator<T>& operator=(const pool_allocator<Other>& p) {
allocator = p.allocator;
return *this;
}
template<class Other> template<class Other>
pool_allocator(const pool_allocator<Other>& p) : allocator(&p.getAllocator()) { } pool_allocator(const pool_allocator<Other>& p) { }
template <class Other>
pool_allocator<T>& operator=(const pool_allocator<Other>& p) { return *this; }
#if defined(__SUNPRO_CC) && !defined(_RWSTD_ALLOCATOR) #if defined(__SUNPRO_CC) && !defined(_RWSTD_ALLOCATOR)
// libCStd on some platforms have a different allocate/deallocate interface. // libCStd on some platforms have a different allocate/deallocate interface.
...@@ -284,17 +279,13 @@ public: ...@@ -284,17 +279,13 @@ public:
void construct(pointer p, const T& val) { new ((void *)p) T(val); } void construct(pointer p, const T& val) { new ((void *)p) T(val); }
void destroy(pointer p) { p->T::~T(); } void destroy(pointer p) { p->T::~T(); }
bool operator==(const pool_allocator& rhs) const { return &getAllocator() == &rhs.getAllocator(); } bool operator==(const pool_allocator& rhs) const { return true; }
bool operator!=(const pool_allocator& rhs) const { return &getAllocator() != &rhs.getAllocator(); } bool operator!=(const pool_allocator& rhs) const { return false; }
size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); } size_type max_size() const { return static_cast<size_type>(-1) / sizeof(T); }
size_type max_size(int size) const { return static_cast<size_type>(-1) / size; } size_type max_size(int size) const { return static_cast<size_type>(-1) / size; }
void setAllocator(TPoolAllocator* a) { allocator = a; } TPoolAllocator& getAllocator() const { return *GetGlobalPoolAllocator(); }
TPoolAllocator& getAllocator() const { return *allocator; }
protected:
TPoolAllocator* allocator;
}; };
#endif // COMPILER_TRANSLATOR_POOLALLOC_H_ #endif // COMPILER_TRANSLATOR_POOLALLOC_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#endif #endif
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/Cache.h"
#include <stdio.h> #include <stdio.h>
#include <algorithm> #include <algorithm>
...@@ -164,10 +165,10 @@ const TType *SpecificType(const TType *type, int size) ...@@ -164,10 +165,10 @@ const TType *SpecificType(const TType *type, int size)
switch(type->getBasicType()) switch(type->getBasicType())
{ {
case EbtGenType: return new TType(EbtFloat, static_cast<unsigned char>(size)); case EbtGenType: return TCache::getType(EbtFloat, static_cast<unsigned char>(size));
case EbtGenIType: return new TType(EbtInt, static_cast<unsigned char>(size)); case EbtGenIType: return TCache::getType(EbtInt, static_cast<unsigned char>(size));
case EbtGenUType: return new TType(EbtUInt, static_cast<unsigned char>(size)); case EbtGenUType: return TCache::getType(EbtUInt, static_cast<unsigned char>(size));
case EbtGenBType: return new TType(EbtBool, static_cast<unsigned char>(size)); case EbtGenBType: return TCache::getType(EbtBool, static_cast<unsigned char>(size));
default: return type; default: return type;
} }
} }
...@@ -185,10 +186,10 @@ const TType *VectorType(const TType *type, int size) ...@@ -185,10 +186,10 @@ const TType *VectorType(const TType *type, int size)
switch(type->getBasicType()) switch(type->getBasicType())
{ {
case EbtVec: return new TType(EbtFloat, static_cast<unsigned char>(size)); case EbtVec: return TCache::getType(EbtFloat, static_cast<unsigned char>(size));
case EbtIVec: return new TType(EbtInt, static_cast<unsigned char>(size)); case EbtIVec: return TCache::getType(EbtInt, static_cast<unsigned char>(size));
case EbtUVec: return new TType(EbtUInt, static_cast<unsigned char>(size)); case EbtUVec: return TCache::getType(EbtUInt, static_cast<unsigned char>(size));
case EbtBVec: return new TType(EbtBool, static_cast<unsigned char>(size)); case EbtBVec: return TCache::getType(EbtBool, static_cast<unsigned char>(size));
default: return type; default: return type;
} }
} }
...@@ -199,30 +200,30 @@ void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *e ...@@ -199,30 +200,30 @@ void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *e
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, new TType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5);
} }
else 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, new TType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5);
} }
else 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, new TType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5);
} }
else 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, new TType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtInt, 4) : rvalue, name, new TType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5);
insertBuiltIn(level, gvec4 ? new TType(EbtUInt, 4) : rvalue, name, new TType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5);
} }
else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3))
{ {
......
...@@ -142,7 +142,8 @@ TString TType::buildMangledName() const ...@@ -142,7 +142,8 @@ TString TType::buildMangledName() const
mangledName += interfaceBlock->mangledName(); mangledName += interfaceBlock->mangledName();
break; break;
default: default:
UNREACHABLE(); // EbtVoid, EbtAddress and non types
break;
} }
if (isMatrix()) if (isMatrix())
......
...@@ -491,10 +491,15 @@ class TType ...@@ -491,10 +491,15 @@ class TType
return structure ? structure->containsSamplers() : false; return structure ? structure->containsSamplers() : false;
} }
// Initializes all lazily-initialized members.
void realize()
{
getMangledName();
}
protected: protected:
TString buildMangledName() const; TString buildMangledName() const;
size_t getStructSize() const; size_t getStructSize() const;
void computeDeepestStructNesting();
TBasicType type; TBasicType type;
TPrecision precision; TPrecision precision;
......
...@@ -37,6 +37,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -37,6 +37,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
#endif #endif
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
...@@ -369,14 +370,14 @@ function_identifier ...@@ -369,14 +370,14 @@ function_identifier
| IDENTIFIER { | IDENTIFIER {
if (context->reservedErrorCheck(@1, *$1.string)) if (context->reservedErrorCheck(@1, *$1.string))
context->recover(); context->recover();
const TType *type = new TType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction($1.string, type); TFunction *function = new TFunction($1.string, type);
$$ = function; $$ = function;
} }
| FIELD_SELECTION { | FIELD_SELECTION {
if (context->reservedErrorCheck(@1, *$1.string)) if (context->reservedErrorCheck(@1, *$1.string))
context->recover(); context->recover();
const TType *type = new TType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction($1.string, type); TFunction *function = new TFunction($1.string, type);
$$ = function; $$ = function;
} }
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
#endif #endif
#include "angle_gl.h" #include "angle_gl.h"
#include "compiler/translator/Cache.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
#include "compiler/translator/ParseContext.h" #include "compiler/translator/ParseContext.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
...@@ -2603,7 +2604,7 @@ yyreduce: ...@@ -2603,7 +2604,7 @@ yyreduce:
{ {
if (context->reservedErrorCheck((yylsp[0]), *(yyvsp[0].lex).string)) if (context->reservedErrorCheck((yylsp[0]), *(yyvsp[0].lex).string))
context->recover(); context->recover();
const TType *type = new TType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction((yyvsp[0].lex).string, type); TFunction *function = new TFunction((yyvsp[0].lex).string, type);
(yyval.interm.function) = function; (yyval.interm.function) = function;
} }
...@@ -2615,7 +2616,7 @@ yyreduce: ...@@ -2615,7 +2616,7 @@ yyreduce:
{ {
if (context->reservedErrorCheck((yylsp[0]), *(yyvsp[0].lex).string)) if (context->reservedErrorCheck((yylsp[0]), *(yyvsp[0].lex).string))
context->recover(); context->recover();
const TType *type = new TType(EbtVoid, EbpUndefined); const TType *type = TCache::getType(EbtVoid, EbpUndefined);
TFunction *function = new TFunction((yyvsp[0].lex).string, type); TFunction *function = new TFunction((yyvsp[0].lex).string, type);
(yyval.interm.function) = function; (yyval.interm.function) = 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