Generalize "main" to a settable entry point name.

This commit is contained in:
John Kessenich
2016-03-12 18:17:47 -07:00
parent 6cc7674b6d
commit 4d65ee31a6
8 changed files with 38 additions and 8 deletions

View File

@@ -590,8 +590,8 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(const glslang::TIntermediate* gls
builder.setSource(TranslateSourceLanguage(glslangIntermediate->getProfile()), glslangIntermediate->getVersion());
stdBuiltins = builder.import("GLSL.std.450");
builder.setMemoryModel(spv::AddressingModelLogical, spv::MemoryModelGLSL450);
shaderEntry = builder.makeMain();
entryPoint = builder.addEntryPoint(executionModel, shaderEntry, "main");
shaderEntry = builder.makeEntrypoint(glslangIntermediate->getEntryPoint().c_str());
entryPoint = builder.addEntryPoint(executionModel, shaderEntry, glslangIntermediate->getEntryPoint().c_str());
// Add the source extensions
const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions();
@@ -2082,7 +2082,9 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& /*structTy
bool TGlslangToSpvTraverser::isShaderEntrypoint(const glslang::TIntermAggregate* node)
{
return node->getName() == "main(";
// have to ignore mangling and just look at the base name
int firstOpen = node->getName().find('(');
return node->getName().compare(0, firstOpen, glslangIntermediate->getEntryPoint()) == 0;
}
// Make all the functions, skeletally, without actually visiting their bodies.

View File

@@ -893,7 +893,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
}
// Comments in header
Function* Builder::makeMain()
Function* Builder::makeEntrypoint(const char* entryPoint)
{
assert(! mainFunction);
@@ -901,7 +901,7 @@ Function* Builder::makeMain()
std::vector<Id> params;
std::vector<Decoration> precisions;
mainFunction = makeFunctionEntry(NoPrecision, makeVoidType(), "main", params, precisions, &entry);
mainFunction = makeFunctionEntry(NoPrecision, makeVoidType(), entryPoint, params, precisions, &entry);
return mainFunction;
}

View File

@@ -205,9 +205,9 @@ public:
void setBuildPoint(Block* bp) { buildPoint = bp; }
Block* getBuildPoint() const { return buildPoint; }
// Make the main function. The returned pointer is only valid
// Make the entry-point function. The returned pointer is only valid
// for the lifetime of this builder.
Function* makeMain();
Function* makeEntrypoint(const char*);
// Make a shader-style function, and create its entry block if entry is non-zero.
// Return the function, pass back the entry.