From 7c0d7fd6e1a40b479dc23556f7c57ccc3f0922b2 Mon Sep 17 00:00:00 2001 From: Christophe Date: Fri, 9 Feb 2024 09:34:10 +0100 Subject: [PATCH] Fix SIMD normalize precision by default --- glm/detail/func_geometric_simd.inl | 11 +++++++++++ glm/simd/geometric.h | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/glm/detail/func_geometric_simd.inl b/glm/detail/func_geometric_simd.inl index 4c7f56bf6..809ce70fe 100644 --- a/glm/detail/func_geometric_simd.inl +++ b/glm/detail/func_geometric_simd.inl @@ -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 struct compute_faceforward<4, float, Q, true> { diff --git a/glm/simd/geometric.h b/glm/simd/geometric.h index 07d7cbcc4..680dda495 100644 --- a/glm/simd/geometric.h +++ b/glm/simd/geometric.h @@ -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);