Shader: Fix SPIRV shaders terminating before function last statement
This commit is contained in:
parent
8146ec251a
commit
83deecd8f1
|
|
@ -138,6 +138,8 @@ namespace Nz
|
|||
};
|
||||
|
||||
private:
|
||||
void HandleStatementList(const std::vector<ShaderAst::StatementPtr>& statements);
|
||||
|
||||
void PushResultId(UInt32 value);
|
||||
UInt32 PopResultId();
|
||||
|
||||
|
|
|
|||
|
|
@ -655,8 +655,7 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
for (auto& statementPtr : node.statements)
|
||||
statementPtr->Visit(*this);
|
||||
HandleStatementList(node.statements);
|
||||
|
||||
// Add implicit return
|
||||
if (!m_functionBlocks.back()->IsTerminated())
|
||||
|
|
@ -920,8 +919,7 @@ namespace Nz
|
|||
|
||||
void SpirvAstVisitor::Visit(ShaderAst::MultiStatement& node)
|
||||
{
|
||||
for (auto& statement : node.statements)
|
||||
statement->Visit(*this);
|
||||
HandleStatementList(node.statements);
|
||||
}
|
||||
|
||||
void SpirvAstVisitor::Visit(ShaderAst::ReturnStatement& node)
|
||||
|
|
@ -1155,6 +1153,25 @@ namespace Nz
|
|||
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)
|
||||
{
|
||||
m_resultIds.push_back(value);
|
||||
|
|
|
|||
Loading…
Reference in New Issue