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:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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&) { }
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user