Share built-in symbols common to all stages for desktop (but still per profile per version).

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22662 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-08-09 20:31:43 +00:00
parent c027579631
commit 99a0576225
3 changed files with 110 additions and 77 deletions

View file

@ -246,7 +246,7 @@ protected:
class TSymbolTableLevel {
public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSymbolTableLevel() : defaultPrecision (0), anonId(0) { }
TSymbolTableLevel() : defaultPrecision(0), anonId(0) { }
~TSymbolTableLevel();
bool insert(TSymbol& symbol)
@ -365,21 +365,12 @@ protected:
class TSymbolTable {
public:
TSymbolTable() : uniqueId(0), noBuiltInRedeclarations(false), adoptedLevels(1) // TODO: memory: can we make adoptedLevels be 0 for symbol tables we don't keep?
TSymbolTable() : uniqueId(0), noBuiltInRedeclarations(false), adoptedLevels(0)
{
//
// This symbol table cannot be used until push() is called.
//
}
explicit TSymbolTable(TSymbolTable& symTable)
{
if (! symTable.isEmpty()) {
table.push_back(symTable.table[0]);
adoptedLevels = 1;
uniqueId = symTable.uniqueId;
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
} // else should only be to handle error paths
}
~TSymbolTable()
{
// don't deallocate levels passed in from elsewhere
@ -388,18 +379,28 @@ public:
}
//
// When the symbol table is initialized with the built-ins, there should
// 'push' calls, so that built-in shared across all compiles are at level 0
// built-ins specific to a compile are at level 1 and the shader
// globals are at level 2.
//
// TODO: compile-time memory: have an even earlier level for all built-ins
// common to all stages. Currently, each stage has copy.
// While level adopting is generic, the methods below enact a the following
// convention for levels:
// 0: common built-ins shared across all stages, all compiles, only one copy for all symbol tables
// 1: per-stage built-ins, shared across all compiles, but a different copy per stage
// 2: built-ins specific to a compile, like resources that are context-dependent
// 3: user-shader globals
//
void adoptLevels(TSymbolTable& symTable)
{
for (unsigned int level = 0; level < symTable.table.size(); ++level) {
table.push_back(symTable.table[level]);
++adoptedLevels;
}
uniqueId = symTable.uniqueId;
noBuiltInRedeclarations = symTable.noBuiltInRedeclarations;
}
bool isEmpty() { return table.size() == 0; }
bool atBuiltInLevel() { return atSharedBuiltInLevel() || atDynamicBuiltInLevel(); }
bool atSharedBuiltInLevel() { return table.size() == 1; }
bool atGlobalLevel() { return table.size() <= 3; }
bool atSharedBuiltInLevel() { return table.size() <= 2; }
bool atDynamicBuiltInLevel() { return table.size() == 3; }
bool atGlobalLevel() { return table.size() <= 4; }
void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; }
void push()
@ -450,8 +451,16 @@ public:
return symbol;
}
TSymbolTableLevel* getGlobalLevel() { assert(table.size() >= 3); return table[2]; }
void relateToOperator(const char* name, TOperator op) { table[0]->relateToOperator(name, op); }
void relateToOperator(const char* name, TOperator op)
{
for (unsigned int level = 0; level < table.size(); ++level) {
if (atSharedBuiltInLevel())
table[level]->relateToOperator(name, op);
else
break;
}
}
int getMaxSymbolId() { return uniqueId; }
void dump(TInfoSink &infoSink) const;
void copyTable(const TSymbolTable& copyOf);
@ -459,10 +468,10 @@ public:
void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); }
protected:
TSymbolTable(TSymbolTable&);
TSymbolTable& operator=(TSymbolTableLevel&);
int currentLevel() const { return static_cast<int>(table.size()) - 1; }
bool atDynamicBuiltInLevel() { return table.size() == 2; }
std::vector<TSymbolTableLevel*> table;
int uniqueId; // for unique identification in code generation