Skip to content

Commit

Permalink
[glsl-out] Polyfill frexp
Browse files Browse the repository at this point in the history
  • Loading branch information
evahop authored and teoxoy committed Sep 25, 2023
1 parent 711aa1a commit dc3d2b1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ impl Version {
*self >= Version::Desktop(400) || *self >= Version::new_gles(310)
}

fn supports_frexp_function(&self) -> bool {
*self >= Version::Desktop(400) || *self >= Version::new_gles(310)
}

fn supports_derivative_control(&self) -> bool {
*self >= Version::Desktop(450)
}
Expand Down Expand Up @@ -667,15 +671,27 @@ impl<'a, W: Write> Writer<'a, W> {
let struct_name = &self.names[&NameKey::Type(*struct_ty)];

writeln!(self.out)?;
writeln!(
self.out,
"{} {defined_func_name}({arg_type_name} arg) {{
if !self.options.version.supports_frexp_function()
&& matches!(type_key, &crate::PredeclaredType::FrexpResult { .. })
{
writeln!(
self.out,
"{struct_name} {defined_func_name}({arg_type_name} arg) {{
{other_type_name} other = arg == {arg_type_name}(0) ? {other_type_name}(0) : {other_type_name}({arg_type_name}(1) + log2(arg));
{arg_type_name} fract = arg * exp2({arg_type_name}(-other));
return {struct_name}(fract, other);
}}",
)?;
} else {
writeln!(
self.out,
"{struct_name} {defined_func_name}({arg_type_name} arg) {{
{other_type_name} other;
{arg_type_name} fract = {called_func_name}(arg, other);
return {}(fract, other);
return {struct_name}(fract, other);
}}",
struct_name, struct_name
)?;
)?;
}
}
&crate::PredeclaredType::AtomicCompareExchangeWeakResult { .. } => {}
}
Expand Down

0 comments on commit dc3d2b1

Please sign in to comment.