Commit 391bda23 by Olli Etuaho Committed by Commit Bot

Generate code for initializing built-in variables

gen_builtin_symbols.py now generates code for initializing built-in variable symbols as well. Some of the variable symbols are static, but some of them also get initialized dynamically based on values in ShBuiltInResources. The static symbols have get functions in a header file so they can be referenced from AST traversers as well without doing a lookup. BUG=angleproject:2267 TEST=angle_unittests, angle_end2end_tests Change-Id: Ida7f3aeb06d2bce0f737f1483b1bd5833aeddd2e Reviewed-on: https://chromium-review.googlesource.com/911768Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent b7d924a8
......@@ -150,8 +150,10 @@ generators = {
'ESSL static builtins': {
'inputs': [
'src/compiler/translator/builtin_function_declarations.txt',
'src/compiler/translator/builtin_variables.json',
],
'outputs': [
'src/compiler/translator/BuiltIn_autogen.h',
'src/compiler/translator/SymbolTable_autogen.cpp',
'src/tests/compiler_tests/ImmutableString_test_autogen.cpp',
],
......
......@@ -27,6 +27,7 @@
'compiler/translator/BaseTypes.h',
'compiler/translator/BuiltInFunctionEmulator.cpp',
'compiler/translator/BuiltInFunctionEmulator.h',
'compiler/translator/BuiltIn_autogen.h',
'compiler/translator/BreakVariableAliasingInInnerLoops.cpp',
'compiler/translator/BreakVariableAliasingInInnerLoops.h',
'compiler/translator/CallDAG.cpp',
......
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_builtin_symbols.py using data from builtin_variables.json and
// builtin_function_declarations.txt.
//
// Copyright 2018 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.
//
// BuiltIn_autogen.h:
// Compile-time initialized built-ins.
#ifndef COMPILER_TRANSLATOR_BUILTIN_AUTOGEN_H_
#define COMPILER_TRANSLATOR_BUILTIN_AUTOGEN_H_
namespace sh
{
class TVariable;
namespace BuiltInVariable
{
const TVariable *gl_FragColor();
const TVariable *gl_FragCoord();
const TVariable *gl_FragDepth();
const TVariable *gl_FrontFacing();
const TVariable *gl_GlobalInvocationID();
const TVariable *gl_InstanceID();
const TVariable *gl_InvocationID();
const TVariable *gl_LastFragColor();
const TVariable *gl_LastFragColorARM();
const TVariable *gl_Layer();
const TVariable *gl_LayerGS();
const TVariable *gl_LayerVS();
const TVariable *gl_LocalInvocationID();
const TVariable *gl_LocalInvocationIndex();
const TVariable *gl_NumWorkGroups();
const TVariable *gl_PointCoord();
const TVariable *gl_PointSize();
const TVariable *gl_Position();
const TVariable *gl_PrimitiveID();
const TVariable *gl_PrimitiveIDGS();
const TVariable *gl_PrimitiveIDIn();
const TVariable *gl_SecondaryFragColorEXT();
const TVariable *gl_VertexID();
const TVariable *gl_ViewID_OVR();
const TVariable *gl_ViewID_OVRESSL1();
const TVariable *gl_ViewportIndex();
const TVariable *gl_WorkGroupID();
const TVariable *gl_WorkGroupSize();
} // namespace BuiltInVariable
} // namespace sh
#endif // COMPILER_TRANSLATOR_BUILTIN_AUTOGEN_H_
......@@ -10,6 +10,7 @@
#include "compiler/translator/ClampFragDepth.h"
#include "compiler/translator/BuiltIn_autogen.h"
#include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/ImmutableString.h"
#include "compiler/translator/IntermNode_util.h"
......@@ -27,8 +28,7 @@ void ClampFragDepth(TIntermBlock *root, TSymbolTable *symbolTable)
return;
}
TIntermSymbol *fragDepthNode =
ReferenceBuiltInVariable(ImmutableString("gl_FragDepth"), *symbolTable, 300);
TIntermSymbol *fragDepthNode = new TIntermSymbol(BuiltInVariable::gl_FragDepth());
TIntermTyped *minFragDepthNode = CreateZeroNode(TType(EbtFloat, EbpHigh, EvqConst));
......
......@@ -8,6 +8,7 @@
#include "compiler/translator/ClampPointSize.h"
#include "compiler/translator/BuiltIn_autogen.h"
#include "compiler/translator/FindSymbolNode.h"
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/RunAtTheEndOfShader.h"
......@@ -24,8 +25,7 @@ void ClampPointSize(TIntermBlock *root, float maxPointSize, TSymbolTable *symbol
return;
}
TIntermSymbol *pointSizeNode =
ReferenceBuiltInVariable(ImmutableString("gl_PointSize"), *symbolTable, 100);
TIntermSymbol *pointSizeNode = new TIntermSymbol(BuiltInVariable::gl_PointSize());
TConstantUnion *maxPointSizeConstant = new TConstantUnion();
maxPointSizeConstant->setFConst(maxPointSize);
......
......@@ -9,6 +9,7 @@
#include "compiler/translator/DeclareAndInitBuiltinsForInstancedMultiview.h"
#include "compiler/translator/BuiltIn_autogen.h"
#include "compiler/translator/FindMain.h"
#include "compiler/translator/InitializeVariables.h"
#include "compiler/translator/IntermNode_util.h"
......@@ -24,20 +25,11 @@ namespace sh
namespace
{
constexpr const ImmutableString kGlLayerString("gl_Layer");
constexpr const ImmutableString kGlViewportIndexString("gl_ViewportIndex");
constexpr const ImmutableString kGlViewIdOVRString("gl_ViewID_OVR");
constexpr const ImmutableString kGlInstanceIdString("gl_InstanceID");
constexpr const ImmutableString kViewIDVariableName("ViewID_OVR");
constexpr const ImmutableString kInstanceIDVariableName("InstanceID");
constexpr const ImmutableString kMultiviewBaseViewLayerIndexVariableName(
"multiviewBaseViewLayerIndex");
TIntermSymbol *CreateGLInstanceIDSymbol(const TSymbolTable &symbolTable)
{
return ReferenceBuiltInVariable(kGlInstanceIdString, symbolTable, 300);
}
// Adds the InstanceID and ViewID_OVR initializers to the end of the initializers' sequence.
void InitializeViewIDAndInstanceID(const TVariable *viewID,
const TVariable *instanceID,
......@@ -53,7 +45,7 @@ void InitializeViewIDAndInstanceID(const TVariable *viewID,
// Create a uint(gl_InstanceID) node.
TIntermSequence *glInstanceIDSymbolCastArguments = new TIntermSequence();
glInstanceIDSymbolCastArguments->push_back(CreateGLInstanceIDSymbol(symbolTable));
glInstanceIDSymbolCastArguments->push_back(new TIntermSymbol(BuiltInVariable::gl_InstanceID()));
TIntermAggregate *glInstanceIDAsUint = TIntermAggregate::CreateConstructor(
TType(EbtUInt, EbpHigh, EvqTemporary), glInstanceIDSymbolCastArguments);
......@@ -105,8 +97,7 @@ void SelectViewIndexInVertexShader(const TVariable *viewID,
TType(EbtInt, EbpHigh, EvqTemporary), viewIDSymbolCastArguments);
// Create a gl_ViewportIndex node.
TIntermSymbol *viewportIndexSymbol =
ReferenceBuiltInVariable(kGlViewportIndexString, symbolTable, 0);
TIntermSymbol *viewportIndexSymbol = new TIntermSymbol(BuiltInVariable::gl_ViewportIndex());
// Create a { gl_ViewportIndex = int(ViewID_OVR) } node.
TIntermBlock *viewportIndexInitializerInBlock = new TIntermBlock();
......@@ -114,7 +105,7 @@ void SelectViewIndexInVertexShader(const TVariable *viewID,
new TIntermBinary(EOpAssign, viewportIndexSymbol, viewIDAsInt));
// Create a gl_Layer node.
TIntermSymbol *layerSymbol = ReferenceBuiltInVariable(kGlLayerString, symbolTable, 0);
TIntermSymbol *layerSymbol = new TIntermSymbol(BuiltInVariable::gl_LayerVS());
// Create an int(ViewID_OVR) + multiviewBaseViewLayerIndex node
TIntermBinary *sumOfViewIDAndBaseViewIndex = new TIntermBinary(
......@@ -155,10 +146,7 @@ void DeclareAndInitBuiltinsForInstancedMultiview(TIntermBlock *root,
new TType(EbtUInt, EbpHigh, viewIDQualifier), SymbolType::AngleInternal);
DeclareGlobalVariable(root, viewID);
ReplaceVariable(
root,
static_cast<const TVariable *>(symbolTable->findBuiltIn(kGlViewIdOVRString, 300, true)),
viewID);
ReplaceVariable(root, BuiltInVariable::gl_ViewID_OVR(), viewID);
if (shaderType == GL_VERTEX_SHADER)
{
// Replacing gl_InstanceID with InstanceID should happen before adding the initializers of
......@@ -168,10 +156,7 @@ void DeclareAndInitBuiltinsForInstancedMultiview(TIntermBlock *root,
new TVariable(symbolTable, kInstanceIDVariableName, instanceIDVariableType,
SymbolType::AngleInternal);
DeclareGlobalVariable(root, instanceID);
ReplaceVariable(root,
static_cast<const TVariable *>(
symbolTable->findBuiltIn(kGlInstanceIdString, 300, true)),
instanceID);
ReplaceVariable(root, BuiltInVariable::gl_InstanceID(), instanceID);
TIntermSequence *initializers = new TIntermSequence();
InitializeViewIDAndInstanceID(viewID, instanceID, numberOfViews, *symbolTable,
......@@ -207,4 +192,4 @@ void DeclareAndInitBuiltinsForInstancedMultiview(TIntermBlock *root,
}
}
} // namespace sh
\ No newline at end of file
} // namespace sh
......@@ -82,6 +82,14 @@ TStructure::TStructure(TSymbolTable *symbolTable,
{
}
TStructure::TStructure(const TSymbolUniqueId &id,
const ImmutableString &name,
TExtension extension,
const TFieldList *fields)
: TSymbol(id, name, SymbolType::BuiltIn, extension), TFieldListCollection(fields)
{
}
void TStructure::createSamplerSymbols(const char *namePrefix,
const TString &apiNamePrefix,
TVector<const TVariable *> *outputSymbols,
......@@ -124,6 +132,17 @@ TInterfaceBlock::TInterfaceBlock(TSymbolTable *symbolTable,
ASSERT(name != nullptr);
}
TInterfaceBlock::TInterfaceBlock(const TSymbolUniqueId &id,
const ImmutableString &name,
TExtension extension,
const TFieldList *fields)
: TSymbol(id, name, SymbolType::BuiltIn, extension),
TFieldListCollection(fields),
mBlockStorage(EbsUnspecified),
mBinding(0)
{
}
TFunction::TFunction(TSymbolTable *symbolTable,
const ImmutableString &name,
SymbolType symbolType,
......
......@@ -89,7 +89,7 @@ class TVariable : public TSymbol
void shareConstPointer(const TConstantUnion *constArray) { unionArray = constArray; }
private:
// Note: only to be used for built-in variables with autogenerated ids!
constexpr TVariable(const TSymbolUniqueId &id,
const ImmutableString &name,
SymbolType symbolType,
......@@ -99,6 +99,7 @@ class TVariable : public TSymbol
{
}
private:
const TType *mType;
const TConstantUnion *unionArray;
};
......@@ -125,6 +126,13 @@ class TStructure : public TSymbol, public TFieldListCollection
bool atGlobalScope() const { return mAtGlobalScope; }
private:
friend class TSymbolTable;
// For creating built-in structs.
TStructure(const TSymbolUniqueId &id,
const ImmutableString &name,
TExtension extension,
const TFieldList *fields);
// TODO(zmo): Find a way to get rid of the const_cast in function
// setName(). At the moment keep this function private so only
// friend class RegenerateStructNames may call it.
......@@ -150,6 +158,13 @@ class TInterfaceBlock : public TSymbol, public TFieldListCollection
int blockBinding() const { return mBinding; }
private:
friend class TSymbolTable;
// For creating built-in interface blocks.
TInterfaceBlock(const TSymbolUniqueId &id,
const ImmutableString &name,
TExtension extension,
const TFieldList *fields);
TLayoutBlockStorage mBlockStorage;
int mBinding;
......
......@@ -30,7 +30,6 @@
// are tracked in the intermediate representation, not the symbol table.
//
#include <array>
#include <memory>
#include "common/angleutils.h"
......@@ -140,44 +139,16 @@ class TSymbolTable : angle::NonCopyable
void pushBuiltInLevel();
// The insert* entry points are used when initializing the symbol table with built-ins.
void insertVariable(ESymbolLevel level, const ImmutableString &name, const TType *type);
void insertVariableExt(ESymbolLevel level,
TExtension ext,
const ImmutableString &name,
const TType *type);
template <TPrecision precision>
void insertConstInt(ESymbolLevel level, const ImmutableString &name, int value);
template <TPrecision precision>
void insertConstIntExt(ESymbolLevel level,
TExtension ext,
const ImmutableString &name,
int value);
template <TPrecision precision>
void insertConstIvec3(ESymbolLevel level,
const ImmutableString &name,
const std::array<int, 3> &values);
TVariable *insertVariable(ESymbolLevel level,
const ImmutableString &name,
const TType *type,
SymbolType symbolType);
void insertBuiltIn(ESymbolLevel level, const TSymbol *symbol);
TFunction *findUserDefinedFunction(const ImmutableString &name) const;
void initSamplerDefaultPrecision(TBasicType samplerType);
void initializeBuiltInVariables(sh::GLenum type,
ShShaderSpec spec,
const ShBuiltInResources &resources);
void markBuiltInInitializationFinished();
void insertBuiltInFunctions(sh::GLenum shaderType);
void insertBuiltInVariables(sh::GLenum shaderType,
ShShaderSpec spec,
const ShBuiltInResources &resources);
std::vector<std::unique_ptr<TSymbolTableBuiltInLevel>> mBuiltInTable;
std::vector<std::unique_ptr<TSymbolTableLevel>> mTable;
......@@ -189,12 +160,7 @@ 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
int mUserDefinedUniqueIdsStart;
static const int kLastBuiltInId;
sh::GLenum mShaderType;
};
......
......@@ -774,11 +774,6 @@ void TType::realize()
getMangledName();
}
bool TType::isRealized() const
{
return mMangledName != nullptr;
}
void TType::invalidateMangledName()
{
mMangledName = nullptr;
......
......@@ -319,8 +319,6 @@ class TType
// Initializes all lazily-initialized members.
void realize();
bool isRealized() const;
private:
void invalidateMangledName();
const char *buildMangledName() 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