From 2ff7dcb417f47fe80ab8ba87539239fb7ff72fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Tue, 3 Aug 2021 00:19:31 +0100 Subject: [PATCH] [glsl-in] Fix mix ordering for boolean selector The mix builtin is defined with the inverse order for it's arguments compared to the IR when the selector is a boolean vector. --- src/front/glsl/functions.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/front/glsl/functions.rs b/src/front/glsl/functions.rs index b6c7189bee..c5309d6b4f 100644 --- a/src/front/glsl/functions.rs +++ b/src/front/glsl/functions.rs @@ -730,10 +730,19 @@ impl Program { .resolve_type(ctx, selector, selector_meta)? .scalar_kind() { + // When the selector is a boolean vector the result is + // calculated per component, for each component of the + // selector if it's false the respective component from the + // first argument is selected, if it's true the respective + // component from the second argument is selected + // + // Note(jcapucho): yes, it's inverted in comparison with the + // IR and SPIR-V and yes I spent a full debugging a shader + // because of this weird behavior Some(ScalarKind::Bool) => Expression::Select { condition: selector, - accept: arg, - reject: arg1, + accept: arg1, + reject: arg, }, _ => Expression::Math { fun: MathFunction::Mix,