[glsl-in] Implicit splat min builtin

This commit is contained in:
João Capucho
2021-08-01 18:26:17 +01:00
committed by Dzmitry Malyshau
parent 9742f6820a
commit fde91c1d94

View File

@@ -598,7 +598,7 @@ impl Program<'_> {
body,
)))
}
"max" => {
"min" | "max" => {
if args.len() != 2 {
return Err(ErrorKind::wrong_function_args(name, 2, args.len(), meta));
}
@@ -606,23 +606,22 @@ impl Program<'_> {
let (mut arg0, arg0_meta) = args[0];
let (mut arg1, arg1_meta) = args[1];
let arg0_size = match *self.resolve_type(ctx, arg0, arg0_meta)? {
TypeInner::Vector { size, .. } => Some(size),
_ => None,
};
let arg1_size = match *self.resolve_type(ctx, arg1, arg1_meta)? {
TypeInner::Vector { size, .. } => Some(size),
_ => None,
};
ctx.binary_implicit_conversion(self, &mut arg0, arg0_meta, &mut arg1, arg1_meta)?;
ctx.implicit_splat(self, &mut arg0, arg0_meta, arg1_size)?;
ctx.implicit_splat(self, &mut arg1, arg1_meta, arg0_size)?;
if let TypeInner::Vector { size, .. } = *self.resolve_type(ctx, arg0, arg0_meta)? {
ctx.implicit_splat(self, &mut arg1, arg1_meta, Some(size))?;
}
if let TypeInner::Vector { size, .. } = *self.resolve_type(ctx, arg1, arg1_meta)? {
ctx.implicit_splat(self, &mut arg0, arg0_meta, Some(size))?;
}
Ok(Some(ctx.add_expression(
Expression::Math {
fun: MathFunction::Max,
fun: match name.as_str() {
"min" => MathFunction::Min,
"max" => MathFunction::Max,
_ => unreachable!(),
},
arg: arg0,
arg1: Some(arg1),
arg2: None,
@@ -630,8 +629,8 @@ impl Program<'_> {
body,
)))
}
"pow" | "dot" | "min" | "reflect" | "cross" | "outerProduct" | "distance" | "step"
| "modf" | "frexp" | "ldexp" => {
"pow" | "dot" | "reflect" | "cross" | "outerProduct" | "distance" | "step" | "modf"
| "frexp" | "ldexp" => {
if args.len() != 2 {
return Err(ErrorKind::wrong_function_args(name, 2, args.len(), meta));
}
@@ -646,7 +645,6 @@ impl Program<'_> {
fun: match name.as_str() {
"pow" => MathFunction::Pow,
"dot" => MathFunction::Dot,
"min" => MathFunction::Min,
"reflect" => MathFunction::Reflect,
"cross" => MathFunction::Cross,
"outerProduct" => MathFunction::Outer,