Skip to content

Commit

Permalink
Perform the type conv after mix
Browse files Browse the repository at this point in the history
  • Loading branch information
evahop committed Jan 31, 2023
1 parent 48fea6a commit 2ccf92b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,28 +2938,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, .. } => {
Expand Down
4 changes: 2 additions & 2 deletions tests/out/glsl/math-functions.main.Vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
}

0 comments on commit 2ccf92b

Please sign in to comment.