allow renaming of shader entry point when creating SPIR-V

Use "--source-entrypoint name" on the command line, or the
TShader::setSourceEntryPoint(char*) API.

When the name given to the above interfaces is detected in the
shader source, it will be renamed to the entry point name supplied
to the -e option or the TShader::setEntryPoint() method.
This commit is contained in:
steve-lunarg
2016-10-31 15:13:43 -06:00
parent 8ce6e2ba49
commit f1e0c87127
9 changed files with 199 additions and 10 deletions

View File

@@ -308,8 +308,13 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node)
// identifier
HlslToken idToken;
while (acceptIdentifier(idToken)) {
TString* fnName = idToken.string;
// Potentially rename shader entry point function. No-op most of the time.
parseContext.renameShaderFunction(fnName);
// function_parameters
TFunction& function = *new TFunction(idToken.string, declaredType);
TFunction& function = *new TFunction(fnName, declaredType);
if (acceptFunctionParameters(function)) {
// post_decls
acceptPostDecls(function.getWritableType().getQualifier());

View File

@@ -51,6 +51,7 @@ namespace glslang {
HlslParseContext::HlslParseContext(TSymbolTable& symbolTable, TIntermediate& interm, bool parsingBuiltins,
int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TInfoSink& infoSink,
const TString sourceEntryPointName,
bool forwardCompatible, EShMessages messages) :
TParseContextBase(symbolTable, interm, parsingBuiltins, version, profile, spvVersion, language, infoSink, forwardCompatible, messages),
contextPragma(true, false),
@@ -58,7 +59,8 @@ HlslParseContext::HlslParseContext(TSymbolTable& symbolTable, TIntermediate& int
postEntryPointReturn(false),
limits(resources.limits),
entryPointOutput(nullptr),
nextInLocation(0), nextOutLocation(0)
nextInLocation(0), nextOutLocation(0),
sourceEntryPointName(sourceEntryPointName)
{
globalUniformDefaults.clear();
globalUniformDefaults.layoutMatrix = ElmRowMajor;
@@ -5539,4 +5541,13 @@ TIntermNode* HlslParseContext::addSwitch(const TSourceLoc& loc, TIntermTyped* ex
return switchNode;
}
// Potentially rename shader entry point function
void HlslParseContext::renameShaderFunction(TString*& name) const
{
// Replace the entry point name given in the shader with the real entry point name,
// if there is a substitution.
if (name != nullptr && *name == sourceEntryPointName)
name = new TString(intermediate.getEntryPointName().c_str());
}
} // end namespace glslang

View File

@@ -47,6 +47,7 @@ class HlslParseContext : public TParseContextBase {
public:
HlslParseContext(TSymbolTable&, TIntermediate&, bool parsingBuiltins,
int version, EProfile, const SpvVersion& spvVersion, EShLanguage, TInfoSink&,
const TString sourceEntryPointName,
bool forwardCompatible = false, EShMessages messages = EShMsgDefault);
virtual ~HlslParseContext();
void initializeExtensionBehavior();
@@ -165,6 +166,9 @@ public:
bool handleOutputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
bool handleInputGeometry(const TSourceLoc&, const TLayoutGeometry& geometry);
// Potentially rename shader entry point function
void renameShaderFunction(TString*& name) const;
protected:
void inheritGlobalDefaults(TQualifier& dst) const;
TVariable* makeInternalVariable(const char* name, const TType&) const;
@@ -251,6 +255,8 @@ protected:
TMap<int, TVector<TVariable*>> flattenMap;
unsigned int nextInLocation;
unsigned int nextOutLocation;
TString sourceEntryPointName;
};
} // end namespace glslang