Commit df98cc26 by John Kessenich

Add amend ability for anonymous blocks, so they can grow between function bodies.

parent 16738a36
float4 a;
float b;
void f1()
{
a * b;
}
float3 c;
void f2()
{
a.x + b + c.x;
}
void f3()
{
c;
}
int d;
void f4()
{
d * a;
}
int e;
\ No newline at end of file
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1527" #define GLSLANG_REVISION "Overload400-PrecQual.1528"
#define GLSLANG_DATE "29-Sep-2016" #define GLSLANG_DATE "29-Sep-2016"
...@@ -196,7 +196,7 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp ...@@ -196,7 +196,7 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp
TType blockType(new TTypeList, blockName, blockQualifier); TType blockType(new TTypeList, blockName, blockQualifier);
TString* instanceName = NewPoolTString(""); TString* instanceName = NewPoolTString("");
globalUniformBlock = new TVariable(instanceName, blockType, true); globalUniformBlock = new TVariable(instanceName, blockType, true);
globalUniformBlockAdded = false; firstNewMember = 0;
} }
// add the requested member as a member to the block // add the requested member as a member to the block
...@@ -205,7 +205,6 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp ...@@ -205,7 +205,6 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp
type->setFieldName(memberName); type->setFieldName(memberName);
TTypeLoc typeLoc = {type, loc}; TTypeLoc typeLoc = {type, loc};
globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc); globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc);
globalUniformBlockChanged = true;
} }
// //
...@@ -218,17 +217,25 @@ bool TParseContextBase::insertGlobalUniformBlock() ...@@ -218,17 +217,25 @@ bool TParseContextBase::insertGlobalUniformBlock()
if (globalUniformBlock == nullptr) if (globalUniformBlock == nullptr)
return true; return true;
if (globalUniformBlockAdded) int numMembers = globalUniformBlock->getType().getStruct()->size();
return ! globalUniformBlockChanged; bool inserted;
if (firstNewMember == 0) {
globalUniformBlockChanged = false; // This is the first request; we need a normal symbol table insert
globalUniformBlockAdded = symbolTable.insert(*globalUniformBlock); inserted = symbolTable.insert(*globalUniformBlock);
if (globalUniformBlockAdded) { if (inserted)
intermediate.addSymbolLinkageNode(linkage, *globalUniformBlock); intermediate.addSymbolLinkageNode(linkage, *globalUniformBlock);
} else if (firstNewMember <= numMembers) {
// This is a follow-on request; we need to amend the first insert
inserted = symbolTable.amend(*globalUniformBlock, firstNewMember);
}
if (inserted) {
finalizeGlobalUniformBlockLayout(*globalUniformBlock); finalizeGlobalUniformBlockLayout(*globalUniformBlock);
firstNewMember = numMembers;
} }
return globalUniformBlockAdded; return inserted;
} }
} // end namespace glslang } // end namespace glslang
...@@ -158,8 +158,7 @@ protected: ...@@ -158,8 +158,7 @@ protected:
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL) // Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
bool globalUniformBlockAdded; // true once inserted into the symbol table int firstNewMember; // the index of the first member not yet inserted into the symbol table
bool globalUniformBlockChanged; // true if members have changed
// override this to set the language-specific name // override this to set the language-specific name
virtual const char* getGlobalUniformBlockName() { return ""; } virtual const char* getGlobalUniformBlockName() { return ""; }
virtual void finalizeGlobalUniformBlockLayout(TVariable&) { } virtual void finalizeGlobalUniformBlockLayout(TVariable&) { }
......
...@@ -147,7 +147,8 @@ public: ...@@ -147,7 +147,8 @@ public:
TVariable(const TString *name, const TType& t, bool uT = false ) TVariable(const TString *name, const TType& t, bool uT = false )
: TSymbol(name), : TSymbol(name),
userType(uT), userType(uT),
constSubtree(nullptr) { type.shallowCopy(t); } constSubtree(nullptr),
anonId(-1) { type.shallowCopy(t); }
virtual TVariable* clone() const; virtual TVariable* clone() const;
virtual ~TVariable() { } virtual ~TVariable() { }
...@@ -161,6 +162,8 @@ public: ...@@ -161,6 +162,8 @@ public:
virtual void setConstArray(const TConstUnionArray& array) { constArray = array; } virtual void setConstArray(const TConstUnionArray& array) { constArray = array; }
virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; } virtual void setConstSubtree(TIntermTyped* subtree) { constSubtree = subtree; }
virtual TIntermTyped* getConstSubtree() const { return constSubtree; } virtual TIntermTyped* getConstSubtree() const { return constSubtree; }
virtual void setAnonId(int i) { anonId = i; }
virtual int getAnonId() const { return anonId; }
virtual void dump(TInfoSink &infoSink) const; virtual void dump(TInfoSink &infoSink) const;
...@@ -178,6 +181,7 @@ protected: ...@@ -178,6 +181,7 @@ protected:
// constant, or neither, but never both. // constant, or neither, but never both.
TConstUnionArray constArray; // for compile-time constant value TConstUnionArray constArray; // for compile-time constant value
TIntermTyped* constSubtree; // for specialization constant computation TIntermTyped* constSubtree; // for specialization constant computation
int anonId; // the ID used for anonymous blocks: TODO: see if uniqueId could serve a dual purpose
}; };
// //
...@@ -305,27 +309,16 @@ public: ...@@ -305,27 +309,16 @@ public:
// //
// returning true means symbol was added to the table with no semantic errors // returning true means symbol was added to the table with no semantic errors
// //
tInsertResult result;
const TString& name = symbol.getName(); const TString& name = symbol.getName();
if (name == "") { if (name == "") {
symbol.getAsVariable()->setAnonId(anonId++);
// An empty name means an anonymous container, exposing its members to the external scope. // An empty name means an anonymous container, exposing its members to the external scope.
// Give it a name and insert its members in the symbol table, pointing to the container. // Give it a name and insert its members in the symbol table, pointing to the container.
char buf[20]; char buf[20];
snprintf(buf, 20, "%s%d", AnonymousPrefix, anonId); snprintf(buf, 20, "%s%d", AnonymousPrefix, symbol.getAsVariable()->getAnonId());
symbol.changeName(NewPoolTString(buf)); symbol.changeName(NewPoolTString(buf));
bool isOkay = true; return insertAnonymousMembers(symbol, 0);
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
for (unsigned int m = 0; m < types.size(); ++m) {
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), anonId);
result = level.insert(tLevelPair(member->getMangledName(), member));
if (! result.second)
isOkay = false;
}
++anonId;
return isOkay;
} else { } else {
// Check for redefinition errors: // Check for redefinition errors:
// - STL itself will tell us if there is a direct name collision, with name mangling, at this level // - STL itself will tell us if there is a direct name collision, with name mangling, at this level
...@@ -340,12 +333,33 @@ public: ...@@ -340,12 +333,33 @@ public:
level.insert(tLevelPair(insertName, &symbol)); level.insert(tLevelPair(insertName, &symbol));
return true; return true;
} else { } else
result = level.insert(tLevelPair(insertName, &symbol)); return level.insert(tLevelPair(insertName, &symbol)).second;
}
}
return result.second; // Add more members to an already inserted aggregate object
bool amend(TSymbol& symbol, int firstNewMember)
{
// See insert() for comments on basic explanation of insert.
// This operates similarly, but more simply.
// Only supporting amend of anonymous blocks so far.
if (IsAnonymous(symbol.getName()))
return insertAnonymousMembers(symbol, firstNewMember);
else
return false;
} }
bool insertAnonymousMembers(TSymbol& symbol, int firstMember)
{
const TTypeList& types = *symbol.getAsVariable()->getType().getStruct();
for (unsigned int m = firstMember; m < types.size(); ++m) {
TAnonMember* member = new TAnonMember(&types[m].type->getFieldName(), m, *symbol.getAsVariable(), symbol.getAsVariable()->getAnonId());
if (! level.insert(tLevelPair(member->getMangledName(), member)).second)
return false;
} }
return true;
} }
TSymbol* find(const TString& name) const TSymbol* find(const TString& name) const
...@@ -546,6 +560,14 @@ public: ...@@ -546,6 +560,14 @@ public:
return table[currentLevel()]->insert(symbol, separateNameSpaces); return table[currentLevel()]->insert(symbol, separateNameSpaces);
} }
// Add more members to an already inserted aggregate object
bool amend(TSymbol& symbol, int firstNewMember)
{
// See insert() for comments on basic explanation of insert.
// This operates similarly, but more simply.
return table[currentLevel()]->amend(symbol, firstNewMember);
}
// //
// To allocate an internal temporary, which will need to be uniquely // To allocate an internal temporary, which will need to be uniquely
// identified by the consumer of the AST, but never need to // identified by the consumer of the AST, but never need to
......
...@@ -80,6 +80,7 @@ TEST_P(HlslCompileAndFlattenTest, FromFile) ...@@ -80,6 +80,7 @@ TEST_P(HlslCompileAndFlattenTest, FromFile)
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
ToSpirv, HlslCompileTest, ToSpirv, HlslCompileTest,
::testing::ValuesIn(std::vector<FileNameEntryPointPair>{ ::testing::ValuesIn(std::vector<FileNameEntryPointPair>{
{"hlsl.amend.frag", "f1"},
{"hlsl.array.frag", "PixelShaderFunction"}, {"hlsl.array.frag", "PixelShaderFunction"},
{"hlsl.array.implicit-size.frag", "PixelShaderFunction"}, {"hlsl.array.implicit-size.frag", "PixelShaderFunction"},
{"hlsl.assoc.frag", "PixelShaderFunction"}, {"hlsl.assoc.frag", "PixelShaderFunction"},
......
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