Always correctly terminate main. Issue #588, PR #600.

This commit is contained in:
John Kessenich
2016-11-26 13:23:20 -07:00
parent 1c573fbcfb
commit fca826212c
11 changed files with 24 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ private:
class TGlslangToSpvTraverser : public glslang::TIntermTraverser {
public:
TGlslangToSpvTraverser(const glslang::TIntermediate*, spv::SpvBuildLogger* logger);
virtual ~TGlslangToSpvTraverser();
virtual ~TGlslangToSpvTraverser() { }
bool visitAggregate(glslang::TVisit, glslang::TIntermAggregate*);
bool visitBinary(glslang::TVisit, glslang::TIntermBinary*);
@@ -111,6 +111,7 @@ public:
bool visitLoop(glslang::TVisit, glslang::TIntermLoop*);
bool visitBranch(glslang::TVisit visit, glslang::TIntermBranch*);
void finishSpv();
void dumpSpv(std::vector<unsigned int>& out);
protected:
@@ -896,27 +897,27 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(const glslang::TIntermediate* gls
default:
break;
}
}
// Finish everything and dump
void TGlslangToSpvTraverser::dumpSpv(std::vector<unsigned int>& out)
// Finish creating SPV, after the traversal is complete.
void TGlslangToSpvTraverser::finishSpv()
{
if (! mainTerminated) {
builder.setBuildPoint(shaderEntry->getLastBlock());
builder.leaveFunction();
}
// finish off the entry-point SPV instruction by adding the Input/Output <id>
for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it)
entryPoint->addIdOperand(*it);
builder.eliminateDeadDecorations();
builder.dump(out);
}
TGlslangToSpvTraverser::~TGlslangToSpvTraverser()
// Write the SPV into 'out'.
void TGlslangToSpvTraverser::dumpSpv(std::vector<unsigned int>& out)
{
if (! mainTerminated) {
spv::Block* lastMainBlock = shaderEntry->getLastBlock();
builder.setBuildPoint(lastMainBlock);
builder.leaveFunction();
}
builder.dump(out);
}
//
@@ -5120,9 +5121,8 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsign
glslang::GetThreadPoolAllocator().push();
TGlslangToSpvTraverser it(&intermediate, logger);
root->traverse(&it);
it.finishSpv();
it.dumpSpv(spirv);
glslang::GetThreadPoolAllocator().pop();