Shader: Fix handling of if/else construct

This commit is contained in:
Jérôme Leclercq 2021-12-12 23:04:37 +01:00
parent 31c71e542e
commit 3185e73941
2 changed files with 8 additions and 0 deletions

View File

@ -458,7 +458,10 @@ namespace Nz::ShaderLang
} }
if (Peek().type == TokenType::Else) if (Peek().type == TokenType::Else)
{
Consume();
branch->elseStatement = ParseStatement(); branch->elseStatement = ParseStatement();
}
return branch; return branch;
} }

View File

@ -375,6 +375,9 @@ namespace Nz
firstCond.statement->Visit(*this); firstCond.statement->Visit(*this);
SpirvBlock mergeBlock(m_writer); SpirvBlock mergeBlock(m_writer);
previousContentBlock.Append(SpirvOp::OpBranch, mergeBlock.GetLabelId()); //< FIXME: Shouldn't terminate twice
m_functionBlocks.back().Append(SpirvOp::OpSelectionMerge, mergeBlock.GetLabelId(), SpirvSelectionControl::None); m_functionBlocks.back().Append(SpirvOp::OpSelectionMerge, mergeBlock.GetLabelId(), SpirvSelectionControl::None);
std::optional<std::size_t> nextBlock; std::optional<std::size_t> nextBlock;
@ -393,6 +396,8 @@ namespace Nz
m_currentBlock = &previousContentBlock; m_currentBlock = &previousContentBlock;
statement.statement->Visit(*this); statement.statement->Visit(*this);
previousContentBlock.Append(SpirvOp::OpBranch, mergeBlock.GetLabelId()); //< FIXME: Shouldn't terminate twice
} }
if (node.elseStatement) if (node.elseStatement)