diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 89a4a69f74..d975c5d65a 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -2930,8 +2930,6 @@ impl<'a, W: Write> Writer<'a, W> { Mf::Determinant => "determinant", // bits Mf::CountLeadingZeros => { - use std::f32::consts::LOG2_E; - match *ctx.info[arg].ty.inner_with(&self.module.types) { crate::TypeInner::Vector { size, kind, .. } => { let s = back::vector_size_str(size); @@ -2942,9 +2940,9 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, "ivec{s}(")?; } - write!(self.out, "mix(vec{s}(31.0) - floor(log(vec{s}(")?; + write!(self.out, "mix(vec{s}(31.0) - floor(log2(vec{s}(")?; self.write_expr(arg, ctx)?; - write!(self.out, ") + 0.5) * {LOG2_E}), ")?; + write!(self.out, ") + 0.5)), ")?; if let crate::ScalarKind::Uint = kind { write!(self.out, "vec{s}(32.0), lessThanEqual(")?; @@ -2970,9 +2968,9 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, " == 0 ? 32 : 0) : int(")?; } - write!(self.out, "31.0 - floor(log(float(")?; + write!(self.out, "31.0 - floor(log2(float(")?; self.write_expr(arg, ctx)?; - write!(self.out, ") + 0.5) * {LOG2_E})))")?; + write!(self.out, ") + 0.5))))")?; } _ => unreachable!(), }; diff --git a/tests/out/glsl/math-functions.main.Vertex.glsl b/tests/out/glsl/math-functions.main.Vertex.glsl index a401138ec7..d863ada72b 100644 --- a/tests/out/glsl/math-functions.main.Vertex.glsl +++ b/tests/out/glsl/math-functions.main.Vertex.glsl @@ -14,11 +14,11 @@ void main() { vec4 g = refract(v, v, 1.0); int const_dot = ( + ivec2(0, 0).x * ivec2(0, 0).x + ivec2(0, 0).y * ivec2(0, 0).y); uint first_leading_bit_abs = uint(findMSB(uint(abs(int(0u))))); - 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))); + int clz_a = (-1 <= 0 ? (-1 == 0 ? 32 : 0) : int(31.0 - floor(log2(float(-1) + 0.5)))); + uint clz_b = (1u == 0u ? 32u : uint(31.0 - floor(log2(float(1u) + 0.5)))); ivec2 _e20 = ivec2(-1); - 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)))); + ivec2 clz_c = ivec2(mix(vec2(31.0) - floor(log2(vec2(_e20) + 0.5)), mix(vec2(0.0), vec2(32.0), equal(_e20, ivec2(0))), lessThanEqual(_e20, ivec2(0)))); uvec2 _e23 = uvec2(1u); - uvec2 clz_d = uvec2(mix(vec2(31.0) - floor(log(vec2(_e23) + 0.5) * 1.442695), vec2(32.0), lessThanEqual(_e23, uvec2(0u)))); + uvec2 clz_d = uvec2(mix(vec2(31.0) - floor(log2(vec2(_e23) + 0.5)), vec2(32.0), lessThanEqual(_e23, uvec2(0u)))); }