Shader: Add support for max/min intrinsic

This commit is contained in:
Jérôme Leclercq
2021-05-19 20:31:26 +02:00
parent 0339ea346f
commit a7235ab02d
7 changed files with 84 additions and 0 deletions

View File

@@ -448,6 +448,8 @@ namespace Nz::ShaderAst
{
case IntrinsicType::CrossProduct:
case IntrinsicType::DotProduct:
case IntrinsicType::Max:
case IntrinsicType::Min:
{
if (clone->parameters.size() != 2)
throw AstError { "Expected two parameters" };
@@ -523,6 +525,21 @@ namespace Nz::ShaderAst
break;
}
case IntrinsicType::Max:
case IntrinsicType::Min:
{
const ExpressionType& type = GetExpressionType(*clone->parameters.front());
if (!IsPrimitiveType(type) && !IsVectorType(type))
throw AstError{ "max and min only work with primitive and vector types" };
if ((IsPrimitiveType(type) && std::get<PrimitiveType>(type) == PrimitiveType::Boolean) ||
(IsVectorType(type) && std::get<VectorType>(type).type == PrimitiveType::Boolean))
throw AstError{ "max and min do not work with booleans" };
clone->cachedExpressionType = type;
break;
}
case IntrinsicType::SampleTexture:
{
clone->cachedExpressionType = VectorType{ 4, std::get<SamplerType>(GetExpressionType(*clone->parameters.front())).sampledType };