Support a uniform block to hold global uniform variables.

Used initially just by HLSL, for $Global.  Could be an option
for GLSL -> Vulkan.
This commit is contained in:
John Kessenich
2016-09-27 19:13:05 -06:00
parent e82061de08
commit 6dbc0a7a33
6 changed files with 117 additions and 40 deletions

View File

@@ -2,5 +2,5 @@
// 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).
#define GLSLANG_REVISION "Overload400-PrecQual.1523"
#define GLSLANG_REVISION "Overload400-PrecQual.1524"
#define GLSLANG_DATE "27-Sep-2016"

View File

@@ -181,4 +181,54 @@ const TFunction* TParseContextBase::selectFunction(
return incumbent;
}
//
// Make the passed-in variable information become a member of the
// global uniform block. If this doesn't exist yet, make it.
//
void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName)
{
// make the global block, if not yet made
if (globalUniformBlock == nullptr) {
TString& blockName = *NewPoolTString(getGlobalUniformBlockName());
TQualifier blockQualifier;
blockQualifier.clear();
blockQualifier.storage = EvqUniform;
TType blockType(new TTypeList, blockName, blockQualifier);
TString* instanceName = NewPoolTString("");
globalUniformBlock = new TVariable(instanceName, blockType, true);
globalUniformBlockAdded = false;
}
// add the requested member as a member to the block
TType* type = new TType;
type->shallowCopy(memberType);
type->setFieldName(memberName);
TTypeLoc typeLoc = {type, loc};
globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc);
globalUniformBlockChanged = true;
}
//
// Insert into the symbol table the global uniform block created in
// growGlobalUniformBlock(). The variables added as members won't be
// found unless this is done.
//
bool TParseContextBase::insertGlobalUniformBlock()
{
if (globalUniformBlock == nullptr)
return true;
if (globalUniformBlockAdded)
return ! globalUniformBlockChanged;
globalUniformBlockChanged = false;
globalUniformBlockAdded = symbolTable.insert(*globalUniformBlock);
if (globalUniformBlockAdded) {
intermediate.addSymbolLinkageNode(linkage, *globalUniformBlock);
finalizeGlobalUniformBlockLayout(*globalUniformBlock);
}
return globalUniformBlockAdded;
}
} // end namespace glslang

View File

@@ -78,7 +78,8 @@ public:
TInfoSink& infoSink, bool forwardCompatible, EShMessages messages)
: TParseVersions(interm, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
symbolTable(symbolTable),
linkage(nullptr), scanContext(nullptr), ppContext(nullptr) { }
linkage(nullptr), scanContext(nullptr), ppContext(nullptr),
globalUniformBlock(nullptr) { }
virtual ~TParseContextBase() { }
virtual void setLimits(const TBuiltInResource&) = 0;
@@ -126,6 +127,13 @@ public:
TSymbolTable& symbolTable; // symbol table that goes with the current language, version, and profile
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
// TODO: This could perhaps get its own object, but the current design doesn't work
// yet when new uniform variables are declared between function definitions, so
// this is pending getting a fully functional design.
virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName);
virtual bool insertGlobalUniformBlock();
protected:
TParseContextBase(TParseContextBase&);
TParseContextBase& operator=(TParseContextBase&);
@@ -147,6 +155,14 @@ protected:
std::function<bool(const TType&, const TType&)>,
std::function<bool(const TType&, const TType&, const TType&)>,
/* output */ bool& tie);
// Manage the global uniform block (default uniforms in GLSL, $Global in HLSL)
TVariable* globalUniformBlock; // the actual block, inserted into the symbol table
bool globalUniformBlockAdded; // true once inserted into the symbol table
bool globalUniformBlockChanged; // true if members have changed
// override this to set the language-specific name
virtual const char* getGlobalUniformBlockName() { return ""; }
virtual void finalizeGlobalUniformBlockLayout(TVariable&) { }
};
//