Commit 99a05762 by John Kessenich

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

parent c0275796
...@@ -246,7 +246,7 @@ protected: ...@@ -246,7 +246,7 @@ protected:
class TSymbolTableLevel { class TSymbolTableLevel {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator()) POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSymbolTableLevel() : defaultPrecision (0), anonId(0) { } TSymbolTableLevel() : defaultPrecision(0), anonId(0) { }
~TSymbolTableLevel(); ~TSymbolTableLevel();
bool insert(TSymbol& symbol) bool insert(TSymbol& symbol)
...@@ -365,21 +365,12 @@ protected: ...@@ -365,21 +365,12 @@ protected:
class TSymbolTable { class TSymbolTable {
public: 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. // 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() ~TSymbolTable()
{ {
// don't deallocate levels passed in from elsewhere // don't deallocate levels passed in from elsewhere
...@@ -388,18 +379,28 @@ public: ...@@ -388,18 +379,28 @@ public:
} }
// //
// When the symbol table is initialized with the built-ins, there should // While level adopting is generic, the methods below enact a the following
// 'push' calls, so that built-in shared across all compiles are at level 0 // convention for levels:
// built-ins specific to a compile are at level 1 and the shader // 0: common built-ins shared across all stages, all compiles, only one copy for all symbol tables
// globals are at level 2. // 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
// TODO: compile-time memory: have an even earlier level for all built-ins // 3: user-shader globals
// common to all stages. Currently, each stage has copy.
// //
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 isEmpty() { return table.size() == 0; }
bool atBuiltInLevel() { return atSharedBuiltInLevel() || atDynamicBuiltInLevel(); } bool atBuiltInLevel() { return atSharedBuiltInLevel() || atDynamicBuiltInLevel(); }
bool atSharedBuiltInLevel() { return table.size() == 1; } bool atSharedBuiltInLevel() { return table.size() <= 2; }
bool atGlobalLevel() { return table.size() <= 3; } bool atDynamicBuiltInLevel() { return table.size() == 3; }
bool atGlobalLevel() { return table.size() <= 4; }
void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; } void setNoBuiltInRedeclarations() { noBuiltInRedeclarations = true; }
void push() void push()
...@@ -450,8 +451,16 @@ public: ...@@ -450,8 +451,16 @@ public:
return symbol; return symbol;
} }
TSymbolTableLevel* getGlobalLevel() { assert(table.size() >= 3); return table[2]; } void relateToOperator(const char* name, TOperator op)
void relateToOperator(const char* name, TOperator op) { table[0]->relateToOperator(name, op); } {
for (unsigned int level = 0; level < table.size(); ++level) {
if (atSharedBuiltInLevel())
table[level]->relateToOperator(name, op);
else
break;
}
}
int getMaxSymbolId() { return uniqueId; } int getMaxSymbolId() { return uniqueId; }
void dump(TInfoSink &infoSink) const; void dump(TInfoSink &infoSink) const;
void copyTable(const TSymbolTable& copyOf); void copyTable(const TSymbolTable& copyOf);
...@@ -459,10 +468,10 @@ public: ...@@ -459,10 +468,10 @@ public:
void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); } void setPreviousDefaultPrecisions(TPrecisionQualifier *p) { table[currentLevel()]->setPreviousDefaultPrecisions(p); }
protected: protected:
TSymbolTable(TSymbolTable&);
TSymbolTable& operator=(TSymbolTableLevel&); TSymbolTable& operator=(TSymbolTableLevel&);
int currentLevel() const { return static_cast<int>(table.size()) - 1; } int currentLevel() const { return static_cast<int>(table.size()) - 1; }
bool atDynamicBuiltInLevel() { return table.size() == 2; }
std::vector<TSymbolTableLevel*> table; std::vector<TSymbolTableLevel*> table;
int uniqueId; // for unique identification in code generation int uniqueId; // for unique identification in code generation
......
...@@ -1098,7 +1098,7 @@ declaration ...@@ -1098,7 +1098,7 @@ declaration
| PRECISION precision_qualifier type_specifier SEMICOLON { | PRECISION precision_qualifier type_specifier SEMICOLON {
parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement"); parseContext.profileRequires($1.loc, ENoProfile, 130, 0, "precision statement");
// lazy setting of the previous scope's defaults, only takes on first one in a particular scope // lazy setting of the previous scope's defaults, has effect only the first time it is called in a particular scope
parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]); parseContext.symbolTable.setPreviousDefaultPrecisions(&parseContext.defaultPrecision[0]);
parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision); parseContext.setDefaultPrecision($1.loc, $3, $2.qualifier.precision);
......
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