Răsfoiți Sursa

Added SIMD optimization for geometric functions

Christophe Riccio 9 ani în urmă
părinte
comite
f6810a9c0e
2 a modificat fișierele cu 25 adăugiri și 2 ștergeri
  1. 13 2
      glm/detail/func_geometric.inl
  2. 12 0
      glm/detail/func_geometric_simd.inl

+ 13 - 2
glm/detail/func_geometric.inl

@@ -76,6 +76,17 @@ namespace detail
 			return v * inversesqrt(dot(v, v));
 		}
 	};
+
+	template <typename T, precision P, template <typename, precision> class vecType>
+	struct compute_faceforward
+	{
+		GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
+		{
+			GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'normalize' accepts only floating-point inputs");
+
+			return dot(Nref, I) < static_cast<T>(0) ? N : -N;
+		}
+	};
 }//namespace detail
 
 	// length
@@ -146,7 +157,7 @@ namespace detail
 	{
 		GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'normalize' accepts only floating-point inputs");
 
-		return x * inversesqrt(dot(x, x));
+		return detail::compute_normalize<T, P, vecType>::call(x);
 	}
 
 	// faceforward
@@ -159,7 +170,7 @@ namespace detail
 	template <typename T, precision P, template <typename, precision> class vecType>
 	GLM_FUNC_QUALIFIER vecType<T, P> faceforward(vecType<T, P> const & N, vecType<T, P> const & I, vecType<T, P> const & Nref)
 	{
-		return dot(Nref, I) < static_cast<T>(0) ? N : -N;
+		return detail::compute_faceforward<T, P, vecType>::call(N, I, Nref);
 	}
 
 	// reflect

+ 12 - 0
glm/detail/func_geometric_simd.inl

@@ -42,6 +42,18 @@ namespace detail
 			return result;
 		}
 	};
+
+	template <precision P>
+	struct compute_faceforward<float, P, tvec4>
+	{
+		GLM_FUNC_QUALIFIER static tvec4<float, P> call(tvec4<float, P> const & N, tvec4<float, P> const & I, tvec4<float, P> const & Nref)
+		{
+			__m128 const ffd0 = glm_f32v4_ffd(v.data);
+			tvec4<float, P> result(uninitialize);
+			result.data = ffd0;
+			return result;
+		}
+	};
 }//namespace detail
 }//namespace glm