From b3d57f2cc92acaadd01c05aa69a8c842f27bb102 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 17 Jul 2016 03:06:58 +0200 Subject: [PATCH] Improved aligned types support --- glm/detail/setup.hpp | 4 ++++ glm/detail/type_vec.hpp | 29 +++++++++++++++++++++++++++-- glm/detail/type_vec1.hpp | 2 +- glm/detail/type_vec2.hpp | 2 +- glm/detail/type_vec3.hpp | 2 +- glm/detail/type_vec4.hpp | 2 +- glm/gtc/quaternion.hpp | 2 +- test/gtc/gtc_type_aligned.cpp | 9 ++++++--- 8 files changed, 42 insertions(+), 10 deletions(-) diff --git a/glm/detail/setup.hpp b/glm/detail/setup.hpp index 2cfa97a9c..889c7caba 100644 --- a/glm/detail/setup.hpp +++ b/glm/detail/setup.hpp @@ -647,6 +647,10 @@ # define GLM_EXPLICIT #endif +/////////////////////////////////////////////////////////////////////////////////// + +#define GLM_HAS_ALIGNED_TYPE GLM_HAS_UNRESTRICTED_UNIONS + /////////////////////////////////////////////////////////////////////////////////// // Length type diff --git a/glm/detail/type_vec.hpp b/glm/detail/type_vec.hpp index 99aa4d48f..82e4ba017 100644 --- a/glm/detail/type_vec.hpp +++ b/glm/detail/type_vec.hpp @@ -16,7 +16,7 @@ namespace detail uint8 data[size]; } type; }; -/* + template struct storage { @@ -24,7 +24,7 @@ namespace detail uint8 data[size]; } type; }; -*/ + # if GLM_ARCH & GLM_ARCH_SSE2_BIT template <> struct storage @@ -43,6 +43,31 @@ namespace detail { typedef glm_uvec4 type; }; +/* +# else + typedef union __declspec(align(16)) glm_128 + { + unsigned __int8 data[16]; + } glm_128; + + template <> + struct storage + { + typedef glm_128 type; + }; + + template <> + struct storage + { + typedef glm_128 type; + }; + + template <> + struct storage + { + typedef glm_128 type; + }; +*/ # endif # if (GLM_ARCH & GLM_ARCH_AVX_BIT) diff --git a/glm/detail/type_vec1.hpp b/glm/detail/type_vec1.hpp index d757abb13..ea25ba44c 100644 --- a/glm/detail/type_vec1.hpp +++ b/glm/detail/type_vec1.hpp @@ -27,7 +27,7 @@ namespace glm // -- Data -- -# if GLM_HAS_UNRESTRICTED_UNIONS && (defined(GLM_SWIZZLE) || (GLM_ARCH & (GLM_ARCH_SSE2_BIT | GLM_ARCH_NEON_BIT))) +# if GLM_HAS_ALIGNED_TYPE # if GLM_COMPILER & GLM_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" diff --git a/glm/detail/type_vec2.hpp b/glm/detail/type_vec2.hpp index e07ab389c..331782dd7 100644 --- a/glm/detail/type_vec2.hpp +++ b/glm/detail/type_vec2.hpp @@ -26,7 +26,7 @@ namespace glm // -- Data -- -# if GLM_HAS_UNRESTRICTED_UNIONS && (defined(GLM_SWIZZLE) || (GLM_ARCH & (GLM_ARCH_SSE2_BIT | GLM_ARCH_NEON_BIT))) +# if GLM_HAS_ALIGNED_TYPE # if GLM_COMPILER & GLM_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" diff --git a/glm/detail/type_vec3.hpp b/glm/detail/type_vec3.hpp index 800866798..64e159d89 100644 --- a/glm/detail/type_vec3.hpp +++ b/glm/detail/type_vec3.hpp @@ -26,7 +26,7 @@ namespace glm // -- Data -- -# if GLM_HAS_UNRESTRICTED_UNIONS && (defined(GLM_SWIZZLE) || (GLM_ARCH & (GLM_ARCH_SSE2_BIT | GLM_ARCH_NEON_BIT))) +# if GLM_HAS_ALIGNED_TYPE # if GLM_COMPILER & GLM_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" diff --git a/glm/detail/type_vec4.hpp b/glm/detail/type_vec4.hpp index 887e497ac..dcd59dd51 100644 --- a/glm/detail/type_vec4.hpp +++ b/glm/detail/type_vec4.hpp @@ -27,7 +27,7 @@ namespace glm // -- Data -- -# if GLM_HAS_UNRESTRICTED_UNIONS && (defined(GLM_SWIZZLE) || (GLM_ARCH & (GLM_ARCH_SSE2_BIT | GLM_ARCH_NEON_BIT))) +# if GLM_HAS_ALIGNED_TYPE # if GLM_COMPILER & GLM_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index b4762a87a..6a42bdf3c 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -40,7 +40,7 @@ namespace glm // -- Data -- -# if GLM_HAS_UNRESTRICTED_UNIONS && (defined(GLM_SWIZZLE) || (GLM_ARCH & (GLM_ARCH_SSE2_BIT | GLM_ARCH_NEON_BIT))) +# if GLM_HAS_ALIGNED_TYPE # if GLM_COMPILER & GLM_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wpedantic" diff --git a/test/gtc/gtc_type_aligned.cpp b/test/gtc/gtc_type_aligned.cpp index 202cc6fd4..e2d7005d3 100644 --- a/test/gtc/gtc_type_aligned.cpp +++ b/test/gtc/gtc_type_aligned.cpp @@ -21,7 +21,9 @@ struct my_vec4_aligned glm::uint32 a; glm::aligned_vec4 b; }; -GLM_STATIC_ASSERT(sizeof(my_vec4_aligned) == sizeof(glm::aligned_vec4) * 2, "glm::vec4 aligned is not correct"); +#if GLM_HAS_ALIGNED_TYPE + GLM_STATIC_ASSERT(sizeof(my_vec4_aligned) == sizeof(glm::aligned_vec4) * 2, "glm::vec4 aligned is not correct"); +#endif struct my_dvec4_packed { @@ -35,7 +37,6 @@ struct my_dvec4_aligned glm::uint64 a; glm::aligned_dvec4 b; }; -//FIXME //GLM_STATIC_ASSERT(sizeof(my_dvec4_aligned) == sizeof(glm::aligned_dvec4) * 2, "glm::dvec4 aligned is not correct"); struct my_ivec4_packed @@ -50,7 +51,9 @@ struct my_ivec4_aligned glm::uint32 a; glm::aligned_ivec4 b; }; -GLM_STATIC_ASSERT(sizeof(my_ivec4_aligned) == sizeof(glm::aligned_ivec4) * 2, "glm::ivec4 aligned is not correct"); +#if GLM_HAS_ALIGNED_TYPE + GLM_STATIC_ASSERT(sizeof(my_ivec4_aligned) == sizeof(glm::aligned_ivec4) * 2, "glm::ivec4 aligned is not correct"); +#endif struct my_u8vec4_packed {