Skip to content

Commit

Permalink
ad
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Aug 23, 2023
1 parent 9defdd1 commit b642440
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
17 changes: 9 additions & 8 deletions src/back/hlsl/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,11 @@ impl<'a, W: Write> super::Writer<'a, W> {
"float".to_string()
};

let (defined_func_name, called_func_name) =
let (defined_func_name, called_func_name, second_field_name) =
if matches!(type_key, &crate::SpecialType::ModfResult { .. }) {
(super::writer::MODF_FUNCTION, "modf")
(super::writer::MODF_FUNCTION, "modf", "whole")
} else {
(super::writer::FREXP_FUNCTION, "frexp")
(super::writer::FREXP_FUNCTION, "frexp", "exp")
};

// TODO: Separate arg_type_name for frexp (int)
Expand All @@ -812,12 +812,13 @@ impl<'a, W: Write> super::Writer<'a, W> {
writeln!(self.out)?;
writeln!(
self.out,
"{} {defined_func_name}({arg_type_name} arg) {{
"{struct_name} {defined_func_name}({arg_type_name} arg) {{
{arg_type_name} other;
{arg_type_name} fract = {called_func_name}(arg, other);
return {}(fract, other);
}}",
struct_name, struct_name
{struct_name} result;
{struct_name}.fract = {called_func_name}(arg, other);
{arg_type_name}.{second_field_name} = other;
return result;
}}"
)?;
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/out/glsl/math-functions.main.Fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ __modf_result_f32_ naga_modf(float arg) {
return __modf_result_f32_(fract, other);
}

__frexp_result_f32_ naga_frexp(float arg) {
int other;
float fract = frexp(arg, other);
return __frexp_result_f32_(fract, other);
}

__modf_result_vec2_f32_ naga_modf(vec2 arg) {
vec2 other;
vec2 fract = modf(arg, other);
return __modf_result_vec2_f32_(fract, other);
}

__frexp_result_f32_ naga_frexp(float arg) {
int other;
float fract = frexp(arg, other);
return __frexp_result_f32_(fract, other);
}

void main() {
vec4 v = vec4(0.0);
float a = degrees(1.0);
Expand Down
26 changes: 16 additions & 10 deletions tests/out/hlsl/math-functions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ struct __frexp_result_f32_ {

__modf_result_f32_ naga_modf(float arg) {
float other;
float fract = modf(arg, other);
return __modf_result_f32_(fract, other);
}

__frexp_result_f32_ naga_frexp(float arg) {
float other;
float fract = frexp(arg, other);
return __frexp_result_f32_(fract, other);
__modf_result_f32_ result;
__modf_result_f32_.fract = modf(arg, other);
float.whole = other;
return result;
}

__modf_result_vec2_f32_ naga_modf(float2 arg) {
float2 other;
float2 fract = modf(arg, other);
return __modf_result_vec2_f32_(fract, other);
__modf_result_vec2_f32_ result;
__modf_result_vec2_f32_.fract = modf(arg, other);
float2.whole = other;
return result;
}

__frexp_result_f32_ naga_frexp(float arg) {
float other;
__frexp_result_f32_ result;
__frexp_result_f32_.fract = frexp(arg, other);
float.exp = other;
return result;
}
void main()
{
Expand Down
12 changes: 6 additions & 6 deletions tests/out/msl/math-functions.msl
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ __modf_result_f32_ naga_modf(float arg) {
return __modf_result_f32_{ fract, other };
}

__frexp_result_f32_ naga_frexp(float arg) {
int other;
float fract = metal::frexp(arg, other);
return __frexp_result_f32_{ fract, other };
}

__modf_result_vec2_f32_ naga_modf(metal::float2 arg) {
metal::float2 other;
metal::float2 fract = metal::modf(arg, other);
return __modf_result_vec2_f32_{ fract, other };
}

__frexp_result_f32_ naga_frexp(float arg) {
int other;
float fract = metal::frexp(arg, other);
return __frexp_result_f32_{ fract, other };
}

fragment void main_(
) {
metal::float4 v = metal::float4(0.0);
Expand Down

0 comments on commit b642440

Please sign in to comment.