Skip to content

Commit

Permalink
Fix SIMD normalize precision by default
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Feb 9, 2024
1 parent 90f2b02 commit 7c0d7fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions glm/detail/func_geometric_simd.inl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ namespace detail
}
};

template<>
struct compute_normalize<4, float, lowp, true>
{
GLM_FUNC_QUALIFIER static vec<4, float, lowp> call(vec<4, float, lowp> const& v)
{
vec<4, float, lowp> Result;
Result.data = glm_vec4_fast_normalize(v.data);
return Result;
}
};

template<qualifier Q>
struct compute_faceforward<4, float, Q, true>
{
Expand Down
9 changes: 9 additions & 0 deletions glm/simd/geometric.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_cross(glm_vec4 v1, glm_vec4 v2)
}

GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_normalize(glm_vec4 v)
{
glm_vec4 const dot0 = glm_vec4_dot(v, v);
glm_vec4 const sqr0 = _mm_sqrt_ps(dot0);
glm_vec4 const isr0 = _mm_div_ps(_mm_set1_ps(1.0f), sqr0);
glm_vec4 const mul0 = _mm_mul_ps(v, isr0);
return mul0;
}

GLM_FUNC_QUALIFIER glm_vec4 glm_vec4_fast_normalize(glm_vec4 v)
{
glm_vec4 const dot0 = glm_vec4_dot(v, v);
glm_vec4 const isr0 = _mm_rsqrt_ps(dot0);
Expand Down

0 comments on commit 7c0d7fd

Please sign in to comment.