Fix SIMD normalize precision by default

This commit is contained in:
Christophe 2024-02-09 09:34:10 +01:00
parent 90f2b025b1
commit 7c0d7fd6e1
2 changed files with 20 additions and 0 deletions

View File

@ -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>
{

View File

@ -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);