Generalize "main" to a settable entry point name.
This commit is contained in:
parent
6cc7674b6d
commit
4d65ee31a6
@ -590,8 +590,8 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(const glslang::TIntermediate* gls
|
|||||||
builder.setSource(TranslateSourceLanguage(glslangIntermediate->getProfile()), glslangIntermediate->getVersion());
|
builder.setSource(TranslateSourceLanguage(glslangIntermediate->getProfile()), glslangIntermediate->getVersion());
|
||||||
stdBuiltins = builder.import("GLSL.std.450");
|
stdBuiltins = builder.import("GLSL.std.450");
|
||||||
builder.setMemoryModel(spv::AddressingModelLogical, spv::MemoryModelGLSL450);
|
builder.setMemoryModel(spv::AddressingModelLogical, spv::MemoryModelGLSL450);
|
||||||
shaderEntry = builder.makeMain();
|
shaderEntry = builder.makeEntrypoint(glslangIntermediate->getEntryPoint().c_str());
|
||||||
entryPoint = builder.addEntryPoint(executionModel, shaderEntry, "main");
|
entryPoint = builder.addEntryPoint(executionModel, shaderEntry, glslangIntermediate->getEntryPoint().c_str());
|
||||||
|
|
||||||
// Add the source extensions
|
// Add the source extensions
|
||||||
const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions();
|
const auto& sourceExtensions = glslangIntermediate->getRequestedExtensions();
|
||||||
@ -2082,7 +2082,9 @@ void TGlslangToSpvTraverser::updateMemberOffset(const glslang::TType& /*structTy
|
|||||||
|
|
||||||
bool TGlslangToSpvTraverser::isShaderEntrypoint(const glslang::TIntermAggregate* node)
|
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.
|
// Make all the functions, skeletally, without actually visiting their bodies.
|
||||||
|
@ -893,7 +893,7 @@ void Builder::addMemberDecoration(Id id, unsigned int member, Decoration decorat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Comments in header
|
// Comments in header
|
||||||
Function* Builder::makeMain()
|
Function* Builder::makeEntrypoint(const char* entryPoint)
|
||||||
{
|
{
|
||||||
assert(! mainFunction);
|
assert(! mainFunction);
|
||||||
|
|
||||||
@ -901,7 +901,7 @@ Function* Builder::makeMain()
|
|||||||
std::vector<Id> params;
|
std::vector<Id> params;
|
||||||
std::vector<Decoration> precisions;
|
std::vector<Decoration> precisions;
|
||||||
|
|
||||||
mainFunction = makeFunctionEntry(NoPrecision, makeVoidType(), "main", params, precisions, &entry);
|
mainFunction = makeFunctionEntry(NoPrecision, makeVoidType(), entryPoint, params, precisions, &entry);
|
||||||
|
|
||||||
return mainFunction;
|
return mainFunction;
|
||||||
}
|
}
|
||||||
|
@ -205,9 +205,9 @@ public:
|
|||||||
void setBuildPoint(Block* bp) { buildPoint = bp; }
|
void setBuildPoint(Block* bp) { buildPoint = bp; }
|
||||||
Block* getBuildPoint() const { return buildPoint; }
|
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.
|
// 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.
|
// Make a shader-style function, and create its entry block if entry is non-zero.
|
||||||
// Return the function, pass back the entry.
|
// Return the function, pass back the entry.
|
||||||
|
@ -449,6 +449,7 @@ int NumWorkItems = 0;
|
|||||||
int Options = 0;
|
int Options = 0;
|
||||||
const char* ExecutableName = nullptr;
|
const char* ExecutableName = nullptr;
|
||||||
const char* binaryFileName = nullptr;
|
const char* binaryFileName = nullptr;
|
||||||
|
const char* entryPointName = nullptr;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create the default name for saving a binary if -o is not provided.
|
// Create the default name for saving a binary if -o is not provided.
|
||||||
@ -537,6 +538,16 @@ void ProcessArguments(int argc, char* argv[])
|
|||||||
case 'd':
|
case 'd':
|
||||||
Options |= EOptionDefaultDesktop;
|
Options |= EOptionDefaultDesktop;
|
||||||
break;
|
break;
|
||||||
|
case 'e':
|
||||||
|
// HLSL todo: entry point handle needs much more sophistication.
|
||||||
|
// This is okay for one compilation unit with one entry point.
|
||||||
|
entryPointName = argv[1];
|
||||||
|
if (argc > 0) {
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
} else
|
||||||
|
Error("no <entry-point> provided for -e");
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
@ -693,6 +704,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
const auto &compUnit = *it;
|
const auto &compUnit = *it;
|
||||||
glslang::TShader* shader = new glslang::TShader(compUnit.stage);
|
glslang::TShader* shader = new glslang::TShader(compUnit.stage);
|
||||||
shader->setStrings(compUnit.text, 1);
|
shader->setStrings(compUnit.text, 1);
|
||||||
|
if (entryPointName) // HLSL todo: this needs to be tracked per compUnits
|
||||||
|
shader->setEntryPoint(entryPointName);
|
||||||
shaders.push_back(shader);
|
shaders.push_back(shader);
|
||||||
|
|
||||||
const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100;
|
const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100;
|
||||||
@ -726,20 +739,24 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
// Program-level processing...
|
// Program-level processing...
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Link
|
||||||
if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages))
|
if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages))
|
||||||
LinkFailed = true;
|
LinkFailed = true;
|
||||||
|
|
||||||
|
// Report
|
||||||
if (! (Options & EOptionSuppressInfolog) &&
|
if (! (Options & EOptionSuppressInfolog) &&
|
||||||
! (Options & EOptionMemoryLeakMode)) {
|
! (Options & EOptionMemoryLeakMode)) {
|
||||||
PutsIfNonEmpty(program.getInfoLog());
|
PutsIfNonEmpty(program.getInfoLog());
|
||||||
PutsIfNonEmpty(program.getInfoDebugLog());
|
PutsIfNonEmpty(program.getInfoDebugLog());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reflect
|
||||||
if (Options & EOptionDumpReflection) {
|
if (Options & EOptionDumpReflection) {
|
||||||
program.buildReflection();
|
program.buildReflection();
|
||||||
program.dumpReflection();
|
program.dumpReflection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dump SPIR-V
|
||||||
if (Options & EOptionSpv) {
|
if (Options & EOptionSpv) {
|
||||||
if (CompileFailed || LinkFailed)
|
if (CompileFailed || LinkFailed)
|
||||||
printf("SPIR-V is not generated for failed compile or link\n");
|
printf("SPIR-V is not generated for failed compile or link\n");
|
||||||
@ -1030,6 +1047,7 @@ void usage()
|
|||||||
" creates the default configuration file (redirect to a .conf file)\n"
|
" creates the default configuration file (redirect to a .conf file)\n"
|
||||||
" -d default to desktop (#version 110) when there is no shader #version\n"
|
" -d default to desktop (#version 110) when there is no shader #version\n"
|
||||||
" (default is ES version 100)\n"
|
" (default is ES version 100)\n"
|
||||||
|
" -e specify entry-point name\n"
|
||||||
" -h print this usage message\n"
|
" -h print this usage message\n"
|
||||||
" -i intermediate tree (glslang AST) is printed out\n"
|
" -i intermediate tree (glslang AST) is printed out\n"
|
||||||
" -l link all input files together to form a single module\n"
|
" -l link all input files together to form a single module\n"
|
||||||
|
@ -975,7 +975,7 @@ TIntermAggregate* TParseContext::handleFunctionDefinition(const TSourceLoc& loc,
|
|||||||
//
|
//
|
||||||
// Raise error message if main function takes any parameters or returns anything other than void
|
// Raise error message if main function takes any parameters or returns anything other than void
|
||||||
//
|
//
|
||||||
if (function.getName() == "main") {
|
if (function.getName() == intermediate.getEntryPoint()) {
|
||||||
if (function.getParamCount() > 0)
|
if (function.getParamCount() > 0)
|
||||||
error(loc, "function cannot take any parameter(s)", function.getName().c_str(), "");
|
error(loc, "function cannot take any parameter(s)", function.getName().c_str(), "");
|
||||||
if (function.getType().getBasicType() != EbtVoid)
|
if (function.getType().getBasicType() != EbtVoid)
|
||||||
|
@ -588,6 +588,7 @@ bool ProcessDeferred(
|
|||||||
// Now we can process the full shader under proper symbols and rules.
|
// Now we can process the full shader under proper symbols and rules.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
intermediate.setEntryPoint("main");
|
||||||
TParseContext parseContext(symbolTable, intermediate, false, version, profile, spv, vulkan, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages);
|
TParseContext parseContext(symbolTable, intermediate, false, version, profile, spv, vulkan, compiler->getLanguage(), compiler->infoSink, forwardCompatible, messages);
|
||||||
glslang::TScanContext scanContext(parseContext);
|
glslang::TScanContext scanContext(parseContext);
|
||||||
TPpContext ppContext(parseContext, includer);
|
TPpContext ppContext(parseContext, includer);
|
||||||
@ -1355,6 +1356,11 @@ void TShader::setStringsWithLengthsAndNames(
|
|||||||
stringNames = names;
|
stringNames = names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TShader::setEntryPoint(const char* entryPoint)
|
||||||
|
{
|
||||||
|
intermediate->setEntryPoint(entryPoint);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Turn the shader strings into a parse tree in the TIntermediate.
|
// Turn the shader strings into a parse tree in the TIntermediate.
|
||||||
//
|
//
|
||||||
|
@ -145,6 +145,8 @@ public:
|
|||||||
void output(TInfoSink&, bool tree);
|
void output(TInfoSink&, bool tree);
|
||||||
void removeTree();
|
void removeTree();
|
||||||
|
|
||||||
|
void setEntryPoint(const char* ep) { entryPoint = ep; }
|
||||||
|
const TString& getEntryPoint() const { return entryPoint; }
|
||||||
void setVersion(int v) { version = v; }
|
void setVersion(int v) { version = v; }
|
||||||
int getVersion() const { return version; }
|
int getVersion() const { return version; }
|
||||||
void setProfile(EProfile p) { profile = p; }
|
void setProfile(EProfile p) { profile = p; }
|
||||||
@ -338,6 +340,7 @@ protected:
|
|||||||
static int getBaseAlignmentScalar(const TType&, int& size);
|
static int getBaseAlignmentScalar(const TType&, int& size);
|
||||||
|
|
||||||
const EShLanguage language;
|
const EShLanguage language;
|
||||||
|
TString entryPoint;
|
||||||
TIntermNode* treeRoot;
|
TIntermNode* treeRoot;
|
||||||
EProfile profile;
|
EProfile profile;
|
||||||
int version;
|
int version;
|
||||||
|
@ -290,6 +290,7 @@ public:
|
|||||||
void setStringsWithLengthsAndNames(
|
void setStringsWithLengthsAndNames(
|
||||||
const char* const* s, const int* l, const char* const* names, int n);
|
const char* const* s, const int* l, const char* const* names, int n);
|
||||||
void setPreamble(const char* s) { preamble = s; }
|
void setPreamble(const char* s) { preamble = s; }
|
||||||
|
void setEntryPoint(const char* entryPoint);
|
||||||
|
|
||||||
// Interface to #include handlers.
|
// Interface to #include handlers.
|
||||||
class Includer {
|
class Includer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user