Support aligned *vec* even when SIMD isn't enabled
This commit is contained in:
parent
416632ea37
commit
fd4ada5843
@ -57,7 +57,7 @@ namespace detail
|
|||||||
template <>
|
template <>
|
||||||
GLM_FUNC_QUALIFIER int bitCount(uint64 x)
|
GLM_FUNC_QUALIFIER int bitCount(uint64 x)
|
||||||
{
|
{
|
||||||
return _mm_popcnt_u64(x);
|
return static_cast<int>(_mm_popcnt_u64(x));
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
@ -6,8 +6,68 @@
|
|||||||
#include "precision.hpp"
|
#include "precision.hpp"
|
||||||
#include "type_int.hpp"
|
#include "type_int.hpp"
|
||||||
|
|
||||||
namespace glm
|
namespace glm{
|
||||||
|
namespace detail
|
||||||
{
|
{
|
||||||
|
template <typename T, std::size_t size, bool aligned>
|
||||||
|
struct simd_data
|
||||||
|
{
|
||||||
|
typedef struct type {
|
||||||
|
uint8 data[size];
|
||||||
|
} type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, std::size_t size>
|
||||||
|
struct simd_data<T, size, true>
|
||||||
|
{
|
||||||
|
typedef GLM_ALIGNED_STRUCT(size) type {
|
||||||
|
uint8 data[size];
|
||||||
|
} type;
|
||||||
|
};
|
||||||
|
|
||||||
|
# if GLM_ARCH & GLM_ARCH_SSE2_BIT
|
||||||
|
template <>
|
||||||
|
struct simd_data<float, 16, true>
|
||||||
|
{
|
||||||
|
typedef glm_vec4 type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct simd_data<int, 16, true>
|
||||||
|
{
|
||||||
|
typedef glm_ivec4 type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct simd_data<unsigned int, 16, true>
|
||||||
|
{
|
||||||
|
typedef glm_uvec4 type;
|
||||||
|
};
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if (GLM_ARCH & GLM_ARCH_AVX_BIT)
|
||||||
|
template <>
|
||||||
|
struct simd_data<double, 32, true>
|
||||||
|
{
|
||||||
|
typedef glm_dvec4 type;
|
||||||
|
};
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
|
||||||
|
template <>
|
||||||
|
struct simd_data<int64, 32, true>
|
||||||
|
{
|
||||||
|
typedef glm_i64vec4 type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct simd_data<uint64, 32, true>
|
||||||
|
{
|
||||||
|
typedef glm_u64vec4 type;
|
||||||
|
};
|
||||||
|
# endif
|
||||||
|
}//namespace detail
|
||||||
|
|
||||||
template <typename T, precision P> struct tvec1;
|
template <typename T, precision P> struct tvec1;
|
||||||
template <typename T, precision P> struct tvec2;
|
template <typename T, precision P> struct tvec2;
|
||||||
template <typename T, precision P> struct tvec3;
|
template <typename T, precision P> struct tvec3;
|
||||||
|
@ -14,64 +14,8 @@
|
|||||||
#endif //GLM_SWIZZLE
|
#endif //GLM_SWIZZLE
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace glm{
|
namespace glm
|
||||||
namespace detail
|
|
||||||
{
|
{
|
||||||
template <typename T, bool aligned>
|
|
||||||
struct simd_data
|
|
||||||
{
|
|
||||||
typedef T type[4];
|
|
||||||
};
|
|
||||||
/*
|
|
||||||
template <typename T>
|
|
||||||
GLM_ALIGNED_STRUCT(16) struct simd_data<T, true>
|
|
||||||
{
|
|
||||||
typedef T type[4];
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
# if (GLM_ARCH & GLM_ARCH_SSE2_BIT)
|
|
||||||
template <>
|
|
||||||
struct simd_data<float, true>
|
|
||||||
{
|
|
||||||
typedef glm_vec4 type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct simd_data<int, true>
|
|
||||||
{
|
|
||||||
typedef glm_ivec4 type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct simd_data<unsigned int, true>
|
|
||||||
{
|
|
||||||
typedef glm_uvec4 type;
|
|
||||||
};
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if (GLM_ARCH & GLM_ARCH_AVX_BIT)
|
|
||||||
template <>
|
|
||||||
struct simd_data<double, true>
|
|
||||||
{
|
|
||||||
typedef glm_dvec4 type;
|
|
||||||
};
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if (GLM_ARCH & GLM_ARCH_AVX2_BIT)
|
|
||||||
template <>
|
|
||||||
struct simd_data<int64, true>
|
|
||||||
{
|
|
||||||
typedef glm_i64vec4 type;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct simd_data<uint64, true>
|
|
||||||
{
|
|
||||||
typedef glm_u64vec4 type;
|
|
||||||
};
|
|
||||||
# endif
|
|
||||||
}//namespace detail
|
|
||||||
|
|
||||||
template <typename T, precision P = defaultp>
|
template <typename T, precision P = defaultp>
|
||||||
struct tvec4
|
struct tvec4
|
||||||
{
|
{
|
||||||
@ -90,7 +34,7 @@ namespace detail
|
|||||||
struct { T r, g, b, a; };
|
struct { T r, g, b, a; };
|
||||||
struct { T s, t, p, q; };
|
struct { T s, t, p, q; };
|
||||||
|
|
||||||
typename detail::simd_data<T, detail::is_aligned<P>::value>::type data;
|
typename detail::simd_data<T, sizeof(T) * 4, detail::is_aligned<P>::value>::type data;
|
||||||
|
|
||||||
# ifdef GLM_SWIZZLE
|
# ifdef GLM_SWIZZLE
|
||||||
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w)
|
_GLM_SWIZZLE4_2_MEMBERS(T, P, glm::tvec2, x, y, z, w)
|
||||||
|
@ -347,13 +347,6 @@ int test_vec4_size()
|
|||||||
Error += glm::vec4().length() == 4 ? 0 : 1;
|
Error += glm::vec4().length() == 4 ? 0 : 1;
|
||||||
Error += glm::dvec4().length() == 4 ? 0 : 1;
|
Error += glm::dvec4().length() == 4 ? 0 : 1;
|
||||||
|
|
||||||
struct my_struct
|
|
||||||
{
|
|
||||||
glm::uint32 a;
|
|
||||||
glm::vec4 b;
|
|
||||||
};
|
|
||||||
GLM_STATIC_ASSERT(sizeof(my_struct) == sizeof(glm::uint32) + sizeof(glm::vec4), "glm::vec4 alignment is not correct");
|
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,9 +3,69 @@
|
|||||||
#define GLM_FORCE_ALIGNED
|
#define GLM_FORCE_ALIGNED
|
||||||
#include <glm/gtc/type_aligned.hpp>
|
#include <glm/gtc/type_aligned.hpp>
|
||||||
|
|
||||||
|
struct my_vec4_packed
|
||||||
|
{
|
||||||
|
glm::uint32 a;
|
||||||
|
glm::vec4 b;
|
||||||
|
};
|
||||||
|
GLM_STATIC_ASSERT(sizeof(my_vec4_packed) == sizeof(glm::uint32) + sizeof(glm::vec4), "glm::vec4 packed is not correct");
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
struct my_dvec4_packed
|
||||||
|
{
|
||||||
|
glm::uint64 a;
|
||||||
|
glm::dvec4 b;
|
||||||
|
};
|
||||||
|
GLM_STATIC_ASSERT(sizeof(my_dvec4_packed) == sizeof(glm::uint64) + sizeof(glm::dvec4), "glm::dvec4 packed is not correct");
|
||||||
|
|
||||||
|
struct my_dvec4_aligned
|
||||||
|
{
|
||||||
|
glm::uint64 a;
|
||||||
|
glm::aligned_dvec4 b;
|
||||||
|
};
|
||||||
|
GLM_STATIC_ASSERT(sizeof(my_dvec4_aligned) == sizeof(glm::aligned_dvec4) * 2, "glm::dvec4 aligned is not correct");
|
||||||
|
|
||||||
|
struct my_ivec4_packed
|
||||||
|
{
|
||||||
|
glm::uint32 a;
|
||||||
|
glm::ivec4 b;
|
||||||
|
};
|
||||||
|
GLM_STATIC_ASSERT(sizeof(my_ivec4_packed) == sizeof(glm::uint32) + sizeof(glm::ivec4), "glm::ivec4 packed is not correct");
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
struct my_u8vec4_packed
|
||||||
|
{
|
||||||
|
glm::uint32 a;
|
||||||
|
glm::u8vec4 b;
|
||||||
|
};
|
||||||
|
GLM_STATIC_ASSERT(sizeof(my_u8vec4_packed) == sizeof(glm::uint32) + sizeof(glm::u8vec4), "glm::u8vec4 packed is not correct");
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
|
my_vec4_aligned GNA;
|
||||||
|
my_dvec4_aligned GNI;
|
||||||
|
|
||||||
|
std::size_t A0 = sizeof(my_dvec4_aligned);
|
||||||
|
std::size_t B0 = sizeof(my_dvec4_packed);
|
||||||
|
std::size_t C0 = sizeof(glm::aligned_dvec4);
|
||||||
|
|
||||||
|
std::size_t A1 = sizeof(my_vec4_aligned);
|
||||||
|
std::size_t B1 = sizeof(my_vec4_packed);
|
||||||
|
std::size_t C1 = sizeof(glm::aligned_vec4);
|
||||||
|
|
||||||
return Error;
|
return Error;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user