From 05f264968fc7027ae4b54d4d18182a8ca1d02a8a Mon Sep 17 00:00:00 2001 From: Evan Mark Hopkins Date: Tue, 31 Jan 2023 02:48:15 -0500 Subject: [PATCH] Perform the type conv after mix --- src/back/glsl/mod.rs | 14 ++++++-------- tests/out/glsl/math-functions.main.Vertex.glsl | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 41f93b90ba..89a4a69f74 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -2936,28 +2936,26 @@ impl<'a, W: Write> Writer<'a, W> { crate::TypeInner::Vector { size, kind, .. } => { let s = back::vector_size_str(size); - write!(self.out, "mix(")?; - if let crate::ScalarKind::Uint = kind { write!(self.out, "uvec{s}(")?; } else { write!(self.out, "ivec{s}(")?; } - write!(self.out, "vec{s}(31.0) - floor(log(vec{s}(")?; + write!(self.out, "mix(vec{s}(31.0) - floor(log(vec{s}(")?; self.write_expr(arg, ctx)?; - write!(self.out, ") + 0.5) * {LOG2_E})), ")?; + write!(self.out, ") + 0.5) * {LOG2_E}), ")?; if let crate::ScalarKind::Uint = kind { - write!(self.out, "uvec{s}(32u), lessThanEqual(")?; + write!(self.out, "vec{s}(32.0), lessThanEqual(")?; self.write_expr(arg, ctx)?; - write!(self.out, ", uvec{s}(0u)))")?; + write!(self.out, ", uvec{s}(0u))))")?; } else { - write!(self.out, "mix(ivec{s}(0u), ivec{s}(32u), equal(")?; + write!(self.out, "mix(vec{s}(0.0), vec{s}(32.0), equal(")?; self.write_expr(arg, ctx)?; write!(self.out, ", ivec{s}(0))), lessThanEqual(")?; self.write_expr(arg, ctx)?; - write!(self.out, ", ivec{s}(0)))")?; + write!(self.out, ", ivec{s}(0))))")?; } } crate::TypeInner::Scalar { kind, .. } => { diff --git a/tests/out/glsl/math-functions.main.Vertex.glsl b/tests/out/glsl/math-functions.main.Vertex.glsl index f08e6292c2..a401138ec7 100644 --- a/tests/out/glsl/math-functions.main.Vertex.glsl +++ b/tests/out/glsl/math-functions.main.Vertex.glsl @@ -17,8 +17,8 @@ void main() { int clz_a = (-1 <= 0 ? (-1 == 0 ? 32 : 0) : int(31.0 - floor(log(float(-1) + 0.5) * 1.442695))); uint clz_b = (1u == 0u ? 32u : uint(31.0 - floor(log(float(1u) + 0.5) * 1.442695))); ivec2 _e20 = ivec2(-1); - ivec2 clz_c = mix(ivec2(vec2(31.0) - floor(log(vec2(_e20) + 0.5) * 1.442695)), mix(ivec2(0u), ivec2(32u), equal(_e20, ivec2(0))), lessThanEqual(_e20, ivec2(0))); + ivec2 clz_c = ivec2(mix(vec2(31.0) - floor(log(vec2(_e20) + 0.5) * 1.442695), mix(vec2(0.0), vec2(32.0), equal(_e20, ivec2(0))), lessThanEqual(_e20, ivec2(0)))); uvec2 _e23 = uvec2(1u); - uvec2 clz_d = mix(uvec2(vec2(31.0) - floor(log(vec2(_e23) + 0.5) * 1.442695)), uvec2(32u), lessThanEqual(_e23, uvec2(0u))); + uvec2 clz_d = uvec2(mix(vec2(31.0) - floor(log(vec2(_e23) + 0.5) * 1.442695), vec2(32.0), lessThanEqual(_e23, uvec2(0u)))); }