Commit 49a8887b by Nicolas Capens Committed by Shannon Woods

Initialize the symbol table without invoking the parser.

TRAC #23359 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens
parent bd10cf55
...@@ -27,66 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec) ...@@ -27,66 +27,6 @@ bool isWebGLBasedSpec(ShShaderSpec spec)
} }
namespace { namespace {
bool InitializeBuiltIns(const TBuiltInStrings &builtInStrings, TInfoSink &infoSink, TParseContext &parseContext)
{
for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i)
{
const char* builtInShaders = i->c_str();
int builtInLengths = static_cast<int>(i->size());
if (builtInLengths <= 0)
continue;
if (PaParseStrings(1, &builtInShaders, &builtInLengths, &parseContext) != 0)
{
infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
return false;
}
}
return true;
}
bool InitializeSymbolTable(
const TBuiltIns &builtIns,
ShShaderType type, ShShaderSpec spec, const ShBuiltInResources& resources,
TInfoSink& infoSink, TSymbolTable& symbolTable)
{
TIntermediate intermediate(infoSink);
TExtensionBehavior extBehavior;
InitExtensionBehavior(resources, extBehavior);
// The builtins deliberately don't specify precisions for the function
// arguments and return types. For that reason we don't try to check them.
TParseContext parseContext(symbolTable, extBehavior, intermediate, type, spec, 0, false, NULL, infoSink);
parseContext.fragmentPrecisionHigh = resources.FragmentPrecisionHigh == 1;
GlobalParseContext = &parseContext;
assert(symbolTable.isEmpty());
//
// Parse the built-ins into the symbol table levels corresponding to each shader version (cf. ESymbolLevel).
//
// Common built-ins
symbolTable.push();
if (!InitializeBuiltIns(builtIns.getCommonBuiltIns(), infoSink, parseContext))
return false;
// GLSL ES 1.0 built-ins
symbolTable.push();
if (!InitializeBuiltIns(builtIns.getEssl1BuiltIns(), infoSink, parseContext))
return false;
// GLSL ES 3.0 built-ins
symbolTable.push();
if (!InitializeBuiltIns(builtIns.getEssl3BuiltIns(), infoSink, parseContext))
return false;
IdentifyBuiltIns(type, spec, resources, symbolTable);
return true;
}
class TScopedPoolAllocator { class TScopedPoolAllocator {
public: public:
TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop) TScopedPoolAllocator(TPoolAllocator* allocator, bool pushPop)
...@@ -258,14 +198,44 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -258,14 +198,44 @@ bool TCompiler::compile(const char* const shaderStrings[],
return success; return success;
} }
bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources& resources) bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
{ {
compileResources = resources; compileResources = resources;
TBuiltIns builtIns; assert(symbolTable.isEmpty());
builtIns.initialize(shaderType, shaderSpec, resources, extensionBehavior); symbolTable.push(); // COMMON_BUILTINS
symbolTable.push(); // ESSL1_BUILTINS
symbolTable.push(); // ESSL3_BUILTINS
TPublicType integer;
integer.type = EbtInt;
integer.primarySize = 1;
integer.secondarySize = 1;
integer.array = false;
TPublicType floatingPoint;
floatingPoint.type = EbtFloat;
floatingPoint.primarySize = 1;
floatingPoint.secondarySize = 1;
floatingPoint.array = false;
switch(shaderType)
{
case SH_FRAGMENT_SHADER:
symbolTable.setDefaultPrecision(integer, EbpMedium);
break;
case SH_VERTEX_SHADER:
symbolTable.setDefaultPrecision(integer, EbpHigh);
symbolTable.setDefaultPrecision(floatingPoint, EbpHigh);
break;
default: assert(false && "Language not supported");
}
InsertBuiltInFunctions(shaderType, shaderSpec, resources, extensionBehavior, symbolTable);
return InitializeSymbolTable(builtIns, shaderType, shaderSpec, resources, infoSink, symbolTable); IdentifyBuiltIns(shaderType, shaderSpec, resources, symbolTable);
return true;
} }
void TCompiler::clearResults() void TCompiler::clearResults()
......
...@@ -11,24 +11,8 @@ ...@@ -11,24 +11,8 @@
#include "compiler/ShHandle.h" #include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h" #include "compiler/SymbolTable.h"
typedef TVector<TString> TBuiltInStrings; void InsertBuiltInFunctions(ShShaderType type, ShShaderSpec spec, const ShBuiltInResources &resources,
const TExtensionBehavior &extensionBehavior, TSymbolTable &table);
class TBuiltIns {
public:
POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
void initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
const TExtensionBehavior& extensionBehavior);
const TBuiltInStrings &getCommonBuiltIns() const { return commonBuiltIns; }
const TBuiltInStrings &getEssl1BuiltIns() const { return essl1BuiltIns; }
const TBuiltInStrings &getEssl3BuiltIns() const { return essl3BuiltIns; }
protected:
TBuiltInStrings commonBuiltIns;
TBuiltInStrings essl1BuiltIns;
TBuiltInStrings essl3BuiltIns;
};
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec, void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources, const ShBuiltInResources& resources,
......
...@@ -283,6 +283,35 @@ public: ...@@ -283,6 +283,35 @@ public:
return table[level]->insert(symbol); return table[level]->insert(symbol);
} }
bool insertConstInt(ESymbolLevel level, const char *name, int value)
{
TVariable *constant = new TVariable(NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value);
return insert(level, *constant);
}
bool insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name, TType *ptype1, const char *pname1, TType *ptype2 = 0, const char *pname2 = 0, TType *ptype3 = 0, const char *pname3 = 0)
{
TFunction *function = new TFunction(NewPoolTString(name), *rvalue);
TParameter param1 = {NewPoolTString(pname1), ptype1};
function->addParameter(param1);
if(pname2)
{
TParameter param2 = {NewPoolTString(pname2), ptype2};
function->addParameter(param2);
}
if(pname3)
{
TParameter param3 = {NewPoolTString(pname3), ptype3};
function->addParameter(param3);
}
return insert(level, *function);
}
TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false); TSymbol *find(const TString &name, int shaderVersion, bool *builtIn = false, bool *sameScope = false);
TSymbol *findBuiltIn(const TString &name, int shaderVersion); TSymbol *findBuiltIn(const TString &name, int shaderVersion);
......
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