From fd10b7d9e80a340acc4e4fda099d527343c0062d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Mon, 23 Aug 2021 03:43:52 +0100 Subject: [PATCH] [glsl-out] Modulo operator on float must be converted to mod function (#1271) Fixes #1266 --- src/back/glsl/mod.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 62e360bb3..b3075c9e7 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -2112,13 +2112,13 @@ impl<'a, W: Write> Writer<'a, W> { Expression::Binary { op, left, right } => { // Holds `Some(function_name)` if the binary operation is // implemented as a function call - use crate::BinaryOperator as Bo; + use crate::{BinaryOperator as Bo, ScalarKind as Sk, TypeInner as Ti}; - let function = if let (&TypeInner::Vector { .. }, &TypeInner::Vector { .. }) = ( - ctx.info[left].ty.inner_with(&self.module.types), - ctx.info[right].ty.inner_with(&self.module.types), - ) { - match op { + let left_inner = ctx.info[left].ty.inner_with(&self.module.types); + let right_inner = ctx.info[right].ty.inner_with(&self.module.types); + + let function = match (left_inner, right_inner) { + (&Ti::Vector { .. }, &Ti::Vector { .. }) => match op { Bo::Less => Some("lessThan"), Bo::LessEqual => Some("lessThanEqual"), Bo::Greater => Some("greaterThan"), @@ -2126,9 +2126,14 @@ impl<'a, W: Write> Writer<'a, W> { Bo::Equal => Some("equal"), Bo::NotEqual => Some("notEqual"), _ => None, - } - } else { - None + }, + _ => match (left_inner.scalar_kind(), right_inner.scalar_kind()) { + (Some(Sk::Float), _) | (_, Some(Sk::Float)) => match op { + Bo::Modulo => Some("mod"), + _ => None, + }, + _ => None, + }, }; write!(self.out, "{}(", function.unwrap_or(""))?;