Shader: Fix SPIRV shaders terminating before function last statement

This commit is contained in:
SirLynix 2022-03-25 12:55:32 +01:00
parent 8146ec251a
commit 83deecd8f1
2 changed files with 23 additions and 4 deletions

View File

@ -138,6 +138,8 @@ namespace Nz
}; };
private: private:
void HandleStatementList(const std::vector<ShaderAst::StatementPtr>& statements);
void PushResultId(UInt32 value); void PushResultId(UInt32 value);
UInt32 PopResultId(); UInt32 PopResultId();

View File

@ -655,8 +655,7 @@ namespace Nz
} }
} }
for (auto& statementPtr : node.statements) HandleStatementList(node.statements);
statementPtr->Visit(*this);
// Add implicit return // Add implicit return
if (!m_functionBlocks.back()->IsTerminated()) if (!m_functionBlocks.back()->IsTerminated())
@ -920,8 +919,7 @@ namespace Nz
void SpirvAstVisitor::Visit(ShaderAst::MultiStatement& node) void SpirvAstVisitor::Visit(ShaderAst::MultiStatement& node)
{ {
for (auto& statement : node.statements) HandleStatementList(node.statements);
statement->Visit(*this);
} }
void SpirvAstVisitor::Visit(ShaderAst::ReturnStatement& node) void SpirvAstVisitor::Visit(ShaderAst::ReturnStatement& node)
@ -1155,6 +1153,25 @@ namespace Nz
m_currentBlock = m_functionBlocks.back().get(); m_currentBlock = m_functionBlocks.back().get();
} }
void SpirvAstVisitor::HandleStatementList(const std::vector<ShaderAst::StatementPtr>& statements)
{
for (auto& statement : statements)
{
// Handle termination statements
switch (statement->GetType())
{
case ShaderAst::NodeType::DiscardStatement:
case ShaderAst::NodeType::ReturnStatement:
statement->Visit(*this);
return; //< stop processing statements after this one
default:
statement->Visit(*this);
break;
}
}
}
void SpirvAstVisitor::PushResultId(UInt32 value) void SpirvAstVisitor::PushResultId(UInt32 value)
{ {
m_resultIds.push_back(value); m_resultIds.push_back(value);