Shader: Fix SPIRV operand for vector / primitive division

This commit is contained in:
Jérôme Leclercq 2021-05-14 02:10:29 +02:00
parent bb207fea4f
commit 8840f0bba8
1 changed files with 25 additions and 0 deletions

View File

@ -316,6 +316,31 @@ namespace Nz
if (swapOperands)
std::swap(leftOperand, rightOperand);
if (node.op == ShaderAst::BinaryType::Divide)
{
//TODO: Handle other cases
if (IsVectorType(leftType) && IsPrimitiveType(rightType))
{
const ShaderAst::VectorType& leftVec = std::get<ShaderAst::VectorType>(leftType);
UInt32 vecType = m_writer.GetTypeId(leftType);
UInt32 rightAsVec = m_writer.AllocateResultId();
m_currentBlock->AppendVariadic(SpirvOp::OpCompositeConstruct, [&](auto&& append)
{
append(vecType);
append(rightAsVec);
for (std::size_t i = 0; i < leftVec.componentCount; ++i)
append(rightOperand);
});
rightOperand = rightAsVec;
}
else if (!IsPrimitiveType(leftType) || !IsPrimitiveType(rightType))
throw std::runtime_error("unexpected division operands");
}
m_currentBlock->Append(op, m_writer.GetTypeId(resultType), resultId, leftOperand, rightOperand);
PushResultId(resultId);
}