Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Aug 21, 2023
1 parent 9526372 commit bb43bfd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ impl<'a, W: Write> Writer<'a, W> {
self.out,
"struct {FREXP_STRUCT} {{
float fract;
float exp;
int exp;
}};
{FREXP_STRUCT} {FREXP_FUNCTION}(float arg) {{
float exp;
float fract = modf(arg, exp);
return {MODF_STRUCT}(fract, exp);
int exp;
float fract = frexp(arg, exp);
return {FREXP_STRUCT}(fract, exp);
}}"
)?;
}
Expand Down Expand Up @@ -3039,7 +3039,7 @@ impl<'a, W: Write> Writer<'a, W> {
Mf::Fract => "fract",
Mf::Trunc => "trunc",
Mf::Modf => MODF_FUNCTION,
Mf::Frexp => "frexp",
Mf::Frexp => FREXP_FUNCTION,
Mf::Ldexp => "ldexp",
// exponent
Mf::Exp => "exp",
Expand Down
4 changes: 2 additions & 2 deletions src/back/hlsl/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,12 @@ impl<'a, W: Write> super::Writer<'a, W> {
self.out,
"struct {struct_name} {{
float fract;
float exp;
int exp;
}};
{struct_name} {function_name}(in float arg) {{
float exp;
float fract = modf(arg, exp);
float fract = frexp(arg, exp);
{struct_name} result;
result.exp = exp;
result.fract = fract;
Expand Down
31 changes: 29 additions & 2 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2168,9 +2168,19 @@ impl<W: Write> Writer<W> {
write!(self.out, ".{}", back::COMPONENTS[index as usize])?;
}
}
crate::TypeInner::ModfResult => {
crate::TypeInner::FrexpResult | crate::TypeInner::ModfResult => {
self.put_access_chain(base, policy, context)?;
write!(self.out, ".{}", if index == 0 { "fract" } else { "whole" })?;
write!(
self.out,
".{}",
if index == 0 {
"fract"
} else if *base_ty == crate::TypeInner::FrexpResult {
"exp"
} else {
"whole"
}
)?;
}
_ => {
self.put_subscripted_access_chain(
Expand Down Expand Up @@ -3276,6 +3286,23 @@ impl<W: Write> Writer<W> {
}
}

if module.special_types.frexp_result.is_some() {
writeln!(
self.out,
"
struct {FREXP_STRUCT} {{
float fract;
int exp;
}};
struct {FREXP_STRUCT} {FREXP_FUNCTION}(float arg) {{
int exp;
float fract = {NAMESPACE}::frexp(arg, exp);
return {FREXP_STRUCT}{{ fract, exp }};
}};"
)?;
}

if module.special_types.modf_result.is_some() {
writeln!(
self.out,
Expand Down
36 changes: 27 additions & 9 deletions src/proc/typifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,22 @@ impl<'a> ResolveContext<'a> {
}
}
Ti::BindingArray { base, .. } => Ti::Pointer { base, space },
Ti::FrexpResult | Ti::ModfResult if (0..=1).contains(&index) => {
Ti::ValuePointer {
size: None,
kind: crate::ScalarKind::Float,
width: 4,
space,
}
}
Ti::FrexpResult if (0..=1).contains(&index) => Ti::ValuePointer {
size: None,
kind: if index == 0 {
crate::ScalarKind::Float
} else {
crate::ScalarKind::Sint
},
width: 4,
space,
},
Ti::ModfResult if (0..=1).contains(&index) => Ti::ValuePointer {
size: None,
kind: crate::ScalarKind::Float,
width: 4,
space,
},
ref other => {
log::error!("Access index sub-type {:?}", other);
return Err(ResolveError::InvalidSubAccess {
Expand All @@ -408,7 +416,17 @@ impl<'a> ResolveContext<'a> {
}
}),
Ti::BindingArray { base, .. } => TypeResolution::Handle(base),
Ti::FrexpResult | Ti::ModfResult if (0..=1).contains(&index) => {
Ti::FrexpResult if (0..=1).contains(&index) => {
TypeResolution::Value(Ti::Scalar {
kind: if index == 0 {
crate::ScalarKind::Float
} else {
crate::ScalarKind::Sint
},
width: 4,
})
}
Ti::ModfResult if (0..=1).contains(&index) => {
TypeResolution::Value(Ti::Scalar {
kind: crate::ScalarKind::Float,
width: 4,
Expand Down

0 comments on commit bb43bfd

Please sign in to comment.