Commit 140152e7 by Olli Etuaho Committed by Commit Bot

Statically allocate built-in function symbols

A script gen_builtin_symbols.py now generates code for initializing built-in function symbols. The TFunction objects are initialized at C++ compile time. The source file used for the functions is in a format that's similar to how functions are given out in the GLSL spec, so it is easy to maintain. The function symbols are still inserted to the symbol table levels same as before. Getting rid of inserting the symbols at runtime is intended to be done as follow-up. This speeds up angle_unittests on Linux in release mode by a bit less than half, and in debug mode by more than half. BUG=angleproject:2267 TEST=angle_unittests Change-Id: I11c9de98c74d28e7e8cdf024516e2f6ee30ca33e Reviewed-on: https://chromium-review.googlesource.com/924155 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent d05f964b
......@@ -147,6 +147,15 @@ generators = {
],
'script': 'src/libANGLE/renderer/vulkan/gen_vk_mandatory_format_support_table.py',
},
'ESSL static builtins': {
'inputs': [
'src/compiler/translator/builtin_function_declarations.txt',
],
'outputs': [
'src/compiler/translator/SymbolTable_autogen.cpp',
],
'script': 'src/compiler/translator/gen_builtin_symbols.py',
},
}
root_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
......
......@@ -150,12 +150,12 @@
'compiler/translator/SimplifyLoopConditions.h',
'compiler/translator/SplitSequenceOperator.cpp',
'compiler/translator/SplitSequenceOperator.h',
'compiler/translator/StaticType.cpp',
'compiler/translator/StaticType.h',
'compiler/translator/Symbol.cpp',
'compiler/translator/Symbol.h',
'compiler/translator/SymbolTable.cpp',
'compiler/translator/SymbolTable.h',
'compiler/translator/SymbolTable_autogen.cpp',
'compiler/translator/SymbolUniqueId.cpp',
'compiler/translator/SymbolUniqueId.h',
'compiler/translator/Types.cpp',
......
......@@ -57,16 +57,8 @@ enum TBasicType
EbtInt,
EbtUInt,
EbtBool,
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
EbtYuvCscStandardEXT, // Only valid if EXT_YUV_target exists.
EbtGuardSamplerBegin, // non type: see implementation of IsSampler()
EbtSampler2D,
EbtSampler3D,
......@@ -90,12 +82,6 @@ enum TBasicType
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
EbtGSampler2DMS, // non type: represents sampler2DMS, isampler2DMS, and usampler2DMS
// images
EbtGuardImageBegin,
......@@ -113,13 +99,6 @@ enum TBasicType
EbtUImageCube,
EbtGuardImageEnd,
EbtGuardGImageBegin,
EbtGImage2D, // non type: represents image2D, uimage2D, iimage2D
EbtGImage3D, // non type: represents image3D, uimage3D, iimage3D
EbtGImage2DArray, // non type: represents image2DArray, uimage2DArray, iimage2DArray
EbtGImageCube, // non type: represents imageCube, uimageCube, iimageCube
EbtGuardGImageEnd,
EbtStruct,
EbtInterfaceBlock,
EbtAddress, // should be deprecated??
......@@ -233,11 +212,6 @@ inline bool IsImage(TBasicType type)
return type > EbtGuardImageBegin && type < EbtGuardImageEnd;
}
inline bool IsGImage(TBasicType type)
{
return type > EbtGuardGImageBegin && type < EbtGuardGImageEnd;
}
inline bool IsAtomicCounter(TBasicType type)
{
return type == EbtAtomicCounter;
......
//
// 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
......@@ -213,12 +213,6 @@ constexpr const TType *GetForVec(TQualifier qualifier, unsigned char size)
}
}
const TType *GetForFloatImage(TBasicType basicType);
const TType *GetForIntImage(TBasicType basicType);
const TType *GetForUintImage(TBasicType basicType);
} // namespace StaticType
} // namespace sh
......
......@@ -145,31 +145,6 @@ TFunction::TFunction(TSymbolTable *symbolTable,
ASSERT(name != nullptr || symbolType == SymbolType::AngleInternal);
}
TFunction::TFunction(TSymbolTable *symbolTable,
const ImmutableString &name,
TExtension extension,
TConstParameter *parameters,
size_t paramCount,
const TType *retType,
TOperator op,
bool knownToNotHaveSideEffects)
: TSymbol(symbolTable, name, SymbolType::BuiltIn, extension),
mParametersVector(nullptr),
mParameters(parameters),
mParamCount(paramCount),
returnType(retType),
mMangledName(""),
mOp(op),
defined(false),
mHasPrototypeDeclaration(false),
mKnownToNotHaveSideEffects(knownToNotHaveSideEffects)
{
ASSERT(name != nullptr);
ASSERT(op != EOpNull);
ASSERT(paramCount == 0 || parameters != nullptr);
mMangledName = buildMangledName();
}
void TFunction::addParameter(const TConstParameter &p)
{
ASSERT(mParametersVector);
......
......@@ -205,16 +205,6 @@ class TFunction : public TSymbol
const TType *retType,
bool knownToNotHaveSideEffects);
// Built-in function
TFunction(TSymbolTable *symbolTable,
const ImmutableString &name,
TExtension extension,
TConstParameter *parameters,
size_t paramCount,
const TType *retType,
TOperator op,
bool knownToNotHaveSideEffects);
bool isFunction() const override { return true; }
void addParameter(const TConstParameter &p);
......@@ -246,7 +236,7 @@ class TFunction : public TSymbol
bool isMain() const;
bool isImageFunction() const;
private:
// Note: Only to be used for static built-in functions!
constexpr TFunction(const TSymbolUniqueId &id,
const ImmutableString &name,
TExtension extension,
......@@ -269,6 +259,7 @@ class TFunction : public TSymbol
{
}
private:
ImmutableString buildMangledName() const;
typedef TVector<TConstParameter> TParamVector;
......
......@@ -163,78 +163,6 @@ class TSymbolTable : angle::NonCopyable
const ImmutableString &name,
const std::array<int, 3> &values);
// Note that for inserted built-in functions the const char *name needs to remain valid for the
// lifetime of the SymbolTable. SymbolTable does not allocate a copy of it.
void insertBuiltIn(ESymbolLevel level,
TOperator op,
TExtension ext,
const TType *rvalue,
const char *name,
const TType *ptype1,
const TType *ptype2 = 0,
const TType *ptype3 = 0,
const TType *ptype4 = 0,
const TType *ptype5 = 0);
void insertBuiltIn(ESymbolLevel level,
const TType *rvalue,
const char *name,
const TType *ptype1,
const TType *ptype2 = 0,
const TType *ptype3 = 0,
const TType *ptype4 = 0,
const TType *ptype5 = 0)
{
insertUnmangledBuiltIn(name, TExtension::UNDEFINED, level);
insertBuiltIn(level, EOpCallBuiltInFunction, TExtension::UNDEFINED, rvalue, name, ptype1,
ptype2, ptype3, ptype4, ptype5);
}
void insertBuiltIn(ESymbolLevel level,
TExtension ext,
const TType *rvalue,
const char *name,
const TType *ptype1,
const TType *ptype2 = 0,
const TType *ptype3 = 0,
const TType *ptype4 = 0,
const TType *ptype5 = 0)
{
insertUnmangledBuiltIn(name, ext, level);
insertBuiltIn(level, EOpCallBuiltInFunction, ext, rvalue, name, ptype1, ptype2, ptype3,
ptype4, ptype5);
}
void insertBuiltInOp(ESymbolLevel level,
TOperator op,
const TType *rvalue,
const TType *ptype1,
const TType *ptype2 = 0,
const TType *ptype3 = 0,
const TType *ptype4 = 0,
const TType *ptype5 = 0);
void insertBuiltInOp(ESymbolLevel level,
TOperator op,
TExtension ext,
const TType *rvalue,
const TType *ptype1,
const TType *ptype2 = 0,
const TType *ptype3 = 0,
const TType *ptype4 = 0,
const TType *ptype5 = 0);
void insertBuiltInFunctionNoParameters(ESymbolLevel level,
TOperator op,
const TType *rvalue,
const char *name);
void insertBuiltInFunctionNoParametersExt(ESymbolLevel level,
TExtension ext,
TOperator op,
const TType *rvalue,
const char *name);
TVariable *insertVariable(ESymbolLevel level,
const ImmutableString &name,
const TType *type,
......@@ -246,18 +174,20 @@ class TSymbolTable : angle::NonCopyable
// Used to insert unmangled functions to check redeclaration of built-ins in ESSL 3.00 and
// above.
void insertUnmangledBuiltIn(const char *name, TExtension ext, ESymbolLevel level);
void insertUnmangledBuiltIn(const ImmutableString &name, TExtension ext, ESymbolLevel level);
bool hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level);
void initSamplerDefaultPrecision(TBasicType samplerType);
void initializeBuiltInFunctions(sh::GLenum type);
void initializeBuiltInVariables(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void markBuiltInInitializationFinished();
void insertBuiltInFunctions(sh::GLenum shaderType);
void insertBuiltInFunctionUnmangledNames(sh::GLenum shaderType);
std::vector<std::unique_ptr<TSymbolTableBuiltInLevel>> mBuiltInTable;
std::vector<std::unique_ptr<TSymbolTableLevel>> mTable;
......@@ -268,6 +198,8 @@ class TSymbolTable : angle::NonCopyable
int mUniqueIdCounter;
static const int kLastStaticBuiltInId;
// -1 before built-in init has finished, one past the last built-in id afterwards.
// TODO(oetuaho): Make this a compile-time constant once the symbol table is initialized at
// compile time. http://anglebug.com/1432
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -20,7 +20,6 @@ class TSymbolUniqueId
{
public:
POOL_ALLOCATOR_NEW_DELETE();
explicit TSymbolUniqueId(TSymbolTable *symbolTable);
explicit TSymbolUniqueId(const TSymbol &symbol);
constexpr TSymbolUniqueId(const TSymbolUniqueId &) = default;
TSymbolUniqueId &operator=(const TSymbolUniqueId &);
......@@ -29,6 +28,10 @@ class TSymbolUniqueId
int get() const;
private:
friend class TSymbolTable;
explicit TSymbolUniqueId(TSymbolTable *symbolTable);
friend class BuiltInId;
constexpr TSymbolUniqueId(int staticId) : mId(staticId) {}
int mId;
......
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