[Bf-blender-cvs] [51ec9441b74] master: Cycles: Split vectorized types into separate files
Sergey Sharybin
noreply at git.blender.org
Tue Apr 25 10:44:33 CEST 2017
Commit: 51ec9441b74ccd02e5555b9385c3b2531f7411a6
Author: Sergey Sharybin
Date: Thu Apr 13 19:34:45 2017 +0200
Branches: master
https://developer.blender.org/rB51ec9441b74ccd02e5555b9385c3b2531f7411a6
Cycles: Split vectorized types into separate files
The final goal to reach is to make vectorized types much easier to maintain
and the previous design had following issues:
- Having all types and methods implementation made the source file rather
bloated and unfun to navigate in.
- It was not possible to quickly glance available API for the type you are
interested in.
- Adding more vectorization types will bloat the file even more, making
things even more tricky to follow.
===================================================================
M intern/cycles/kernel/CMakeLists.txt
M intern/cycles/util/CMakeLists.txt
M intern/cycles/util/util_types.h
A intern/cycles/util/util_types_float2.h
A intern/cycles/util/util_types_float2_impl.h
A intern/cycles/util/util_types_float3.h
A intern/cycles/util/util_types_float3_impl.h
A intern/cycles/util/util_types_float4.h
A intern/cycles/util/util_types_float4_impl.h
A intern/cycles/util/util_types_int2.h
A intern/cycles/util/util_types_int2_impl.h
A intern/cycles/util/util_types_int3.h
A intern/cycles/util/util_types_int3_impl.h
A intern/cycles/util/util_types_int4.h
A intern/cycles/util/util_types_int4_impl.h
A intern/cycles/util/util_types_uchar2.h
A intern/cycles/util/util_types_uchar2_impl.h
A intern/cycles/util/util_types_uchar3.h
A intern/cycles/util/util_types_uchar3_impl.h
A intern/cycles/util/util_types_uchar4.h
A intern/cycles/util/util_types_uchar4_impl.h
A intern/cycles/util/util_types_uint2.h
A intern/cycles/util/util_types_uint2_impl.h
A intern/cycles/util/util_types_uint3.h
A intern/cycles/util/util_types_uint3_impl.h
A intern/cycles/util/util_types_uint4.h
A intern/cycles/util/util_types_uint4_impl.h
A intern/cycles/util/util_types_vector3.h
A intern/cycles/util/util_types_vector3_impl.h
===================================================================
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index c3772dfa2d8..10eff10d809 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -200,6 +200,32 @@ set(SRC_UTIL_HEADERS
../util/util_transform.h
../util/util_texture.h
../util/util_types.h
+ ../util/util_types_float2.h
+ ../util/util_types_float2_impl.h
+ ../util/util_types_float3.h
+ ../util/util_types_float3_impl.h
+ ../util/util_types_float4.h
+ ../util/util_types_float4_impl.h
+ ../util/util_types_int2.h
+ ../util/util_types_int2_impl.h
+ ../util/util_types_int3.h
+ ../util/util_types_int3_impl.h
+ ../util/util_types_int4.h
+ ../util/util_types_int4_impl.h
+ ../util/util_types_uchar2.h
+ ../util/util_types_uchar2_impl.h
+ ../util/util_types_uchar3.h
+ ../util/util_types_uchar3_impl.h
+ ../util/util_types_uchar4.h
+ ../util/util_types_uchar4_impl.h
+ ../util/util_types_uint2.h
+ ../util/util_types_uint2_impl.h
+ ../util/util_types_uint3.h
+ ../util/util_types_uint3_impl.h
+ ../util/util_types_uint4.h
+ ../util/util_types_uint4_impl.h
+ ../util/util_types_vector3.h
+ ../util/util_types_vector3_impl.h
)
set(SRC_SPLIT_HEADERS
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index a015fef8284..8d0a6c9fff9 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -80,6 +80,32 @@ set(SRC_HEADERS
util_time.h
util_transform.h
util_types.h
+ util_types_float2.h
+ util_types_float2_impl.h
+ util_types_float3.h
+ util_types_float3_impl.h
+ util_types_float4.h
+ util_types_float4_impl.h
+ util_types_int2.h
+ util_types_int2_impl.h
+ util_types_int3.h
+ util_types_int3_impl.h
+ util_types_int4.h
+ util_types_int4_impl.h
+ util_types_uchar2.h
+ util_types_uchar2_impl.h
+ util_types_uchar3.h
+ util_types_uchar3_impl.h
+ util_types_uchar4.h
+ util_types_uchar4_impl.h
+ util_types_uint2.h
+ util_types_uint2_impl.h
+ util_types_uint3.h
+ util_types_uint3_impl.h
+ util_types_uint4.h
+ util_types_uint4_impl.h
+ util_types_vector3.h
+ util_types_vector3_impl.h
util_vector.h
util_version.h
util_view.h
diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h
index 756ab2cfe93..137cc73b70b 100644
--- a/intern/cycles/util/util_types.h
+++ b/intern/cycles/util/util_types.h
@@ -125,339 +125,6 @@ typedef int32_t ssize_t;
/* Generic Memory Pointer */
typedef uint64_t device_ptr;
-
-/* Vector Types */
-
-struct uchar2 {
- uchar x, y;
-
- __forceinline uchar operator[](int i) const { return *(&x + i); }
- __forceinline uchar& operator[](int i) { return *(&x + i); }
-};
-
-struct uchar3 {
- uchar x, y, z;
-
- __forceinline uchar operator[](int i) const { return *(&x + i); }
- __forceinline uchar& operator[](int i) { return *(&x + i); }
-};
-
-struct uchar4 {
- uchar x, y, z, w;
-
- __forceinline uchar operator[](int i) const { return *(&x + i); }
- __forceinline uchar& operator[](int i) { return *(&x + i); }
-};
-
-struct int2 {
- int x, y;
-
- __forceinline int operator[](int i) const { return *(&x + i); }
- __forceinline int& operator[](int i) { return *(&x + i); }
-};
-
-struct ccl_try_align(16) int3 {
-#ifdef __KERNEL_SSE__
- union {
- __m128i m128;
- struct { int x, y, z, w; };
- };
-
- __forceinline int3() {}
- __forceinline explicit int3(const __m128i& a) : m128(a) {}
- __forceinline operator const __m128i&(void) const { return m128; }
- __forceinline operator __m128i&(void) { return m128; }
-
- int3(const int3& a) { m128 = a.m128; }
- int3& operator =(const int3& a) { m128 = a.m128; return *this; }
-#else
- int x, y, z, w;
-#endif
-
- __forceinline int operator[](int i) const { return *(&x + i); }
- __forceinline int& operator[](int i) { return *(&x + i); }
-};
-
-struct ccl_try_align(16) int4 {
-#ifdef __KERNEL_SSE__
- union {
- __m128i m128;
- struct { int x, y, z, w; };
- };
-
- __forceinline int4() {}
- __forceinline explicit int4(const __m128i& a) : m128(a) {}
- __forceinline operator const __m128i&(void) const { return m128; }
- __forceinline operator __m128i&(void) { return m128; }
-
- int4(const int4& a) : m128(a.m128) {}
- int4& operator=(const int4& a) { m128 = a.m128; return *this; }
-#else
- int x, y, z, w;
-#endif
-
- __forceinline int operator[](int i) const { return *(&x + i); }
- __forceinline int& operator[](int i) { return *(&x + i); }
-};
-
-struct uint2 {
- uint x, y;
-
- __forceinline uint operator[](uint i) const { return *(&x + i); }
- __forceinline uint& operator[](uint i) { return *(&x + i); }
-};
-
-struct uint3 {
- uint x, y, z;
-
- __forceinline uint operator[](uint i) const { return *(&x + i); }
- __forceinline uint& operator[](uint i) { return *(&x + i); }
-};
-
-struct uint4 {
- uint x, y, z, w;
-
- __forceinline uint operator[](uint i) const { return *(&x + i); }
- __forceinline uint& operator[](uint i) { return *(&x + i); }
-};
-
-struct float2 {
- float x, y;
-
- __forceinline float operator[](int i) const { return *(&x + i); }
- __forceinline float& operator[](int i) { return *(&x + i); }
-};
-
-struct ccl_try_align(16) float3 {
-#ifdef __KERNEL_SSE__
- union {
- __m128 m128;
- struct { float x, y, z, w; };
- };
-
- __forceinline float3() {}
- __forceinline explicit float3(const __m128& a) : m128(a) {}
- __forceinline operator const __m128&(void) const { return m128; }
- __forceinline operator __m128&(void) { return m128; }
-
- __forceinline float3(const float3& a) : m128(a.m128) {}
- __forceinline float3& operator =(const float3& a) { m128 = a.m128; return *this; }
-#else
- float x, y, z, w;
-#endif
-
- __forceinline float operator[](int i) const { return *(&x + i); }
- __forceinline float& operator[](int i) { return *(&x + i); }
-};
-
-struct ccl_try_align(16) float4 {
-#ifdef __KERNEL_SSE__
- union {
- __m128 m128;
- struct { float x, y, z, w; };
- };
-
- __forceinline float4() {}
- __forceinline explicit float4(const __m128& a) : m128(a) {}
- __forceinline operator const __m128&(void) const { return m128; }
- __forceinline operator __m128&(void) { return m128; }
-
- __forceinline float4(const float4& a) : m128(a.m128) {}
- __forceinline float4& operator =(const float4& a) { m128 = a.m128; return *this; }
-
-#else
- float x, y, z, w;
-#endif
-
- __forceinline float operator[](int i) const { return *(&x + i); }
- __forceinline float& operator[](int i) { return *(&x + i); }
-};
-
-template<typename T>
-class vector3
-{
-public:
- T x, y, z;
-
- ccl_always_inline vector3() {}
- ccl_always_inline vector3(const T& a)
- : x(a), y(a), z(a) {}
- ccl_always_inline vector3(const T& x, const T& y, const T& z)
- : x(x), y(y), z(z) {}
-};
-
-/* Vector Type Constructors
- *
- * OpenCL does not support C++ class, so we use these instead. */
-
-ccl_device_inline uchar2 make_uchar2(uchar x, uchar y)
-{
- uchar2 a = {x, y};
- return a;
-}
-
-ccl_device_inline uchar3 make_uchar3(uchar x, uchar y, uchar z)
-{
- uchar3 a = {x, y, z};
- return a;
-}
-
-ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w)
-{
- uchar4 a = {x, y, z, w};
- return a;
-}
-
-ccl_device_inline int2 make_int2(int x, int y)
-{
- int2 a = {x, y};
- return a;
-}
-
-ccl_device_inline int3 make_int3(int x, int y, int z)
-{
-#ifdef __KERNEL_SSE__
- int3 a;
- a.m128 = _mm_set_epi32(0, z, y, x);
-#else
- int3 a = {x, y, z, 0};
-#endif
-
- return a;
-}
-
-ccl_device_inline int4 make_int4(int x, int y, int z, int w)
-{
-#ifdef __KERNEL_SSE__
- int4 a;
- a.m128 = _mm_set_epi32(w, z, y, x);
-#else
- int4 a = {x, y, z, w};
-#endif
-
- return a;
-}
-
-ccl_device_inline uint2 make_uint2(uint x, uint y)
-{
- uint2 a = {x, y};
- return a;
-}
-
-ccl_device_inline uint3 make_uint3(uint x, uint y, uint z)
-{
- uint3 a = {x, y, z};
- return a;
-}
-
-ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w)
-{
- uint4 a = {x, y, z, w};
- return a;
-}
-
-ccl_device_inline float2 make_float2(float x, float y)
-{
- float2 a = {x, y};
- return a;
-}
-
-ccl_device_inline float3 make_float3(float x, float y, float z)
-{
-#ifdef __KERNEL_SSE__
- float3 a;
- a.m128 = _mm_set_ps(0.0f, z, y, x);
-#else
- float3 a = {x, y, z, 0.0f};
-#endif
-
- return a;
-}
-
-ccl_device_inline float4 make_float4(float x, float y, float z, float w)
-{
-#ifdef __KERNEL_SSE__
- float4 a;
- a.m128 = _mm_set_ps(w, z, y, x);
-#else
- float4 a = {x, y, z, w};
-#endif
-
- return a;
-}
-
-ccl_device_inline int3 make_int3(int i)
-{
-#ifdef __KERNEL_SSE__
- int3 a;
- a.m128 = _mm_set1_epi32(i);
-#else
- int3 a = {i, i, i, i};
-#endif
-
- return a;
-}
-
-ccl_device_inline int4 make_int4(int i)
-{
-#ifdef __KERNEL_SSE__
- int4 a;
- a.m128 = _mm_set1_epi32(i);
-#else
- int4 a = {i, i, i, i};
-#endif
-
- return a;
-}
-
-ccl_device_inline float3 make_float3(float f)
-{
-#ifdef __KERNEL_SSE__
- float3 a;
- a.m128 = _mm_set1_ps(f);
-#else
- float3 a = {f, f, f, f};
-#endif
-
- return a;
-}
-
-ccl_device_inline float4 make_float4(float f)
-{
-#ifdef __KERNEL_SSE__
- float4 a;
- a.m128 = _mm_set1_ps(f);
-#else
- float4 a = {f, f, f, f};
-#endif
-
- return a;
-}
-
-ccl_device_inline float4 make_float4(const int4& i)
-{
-#ifdef __KERNEL_SSE__
- float4 a;
- a.m128 = _mm_cvtepi32_ps(i.m128);
-#else
- float4 a = {(float)i.x, (float)i.y, (float)i.z, (float)i.w};
-#endif
-
- return a;
-}
-
-ccl_device_inline int4 make_int4(const float3& f)
-{
-#ifdef __KERNEL_SSE__
- int4 a;
- a.m128 = _mm_cvtps_epi32(f.m128);
-#else
- int4 a = {(int)f.x, (int)f.y, (int)f.z, (int)f.w};
-#endif
-
- return a;
-}
-
#endif /* __KERNEL_GPU__ */
ccl_device_inline size_t align_up(size_t offset, size_t alignment)
@@ -554,5 +221,50 @@ template<typename T> static inline T decltype_helper(T x) { return x; }
CCL_NAMESPACE_END
+#ifndef __KERNEL_GPU__
+# include <cassert>
+# define util_assert(statement) assert(statement)
+#else
+# define util_assert(statement)
+#endif
+
+/* Vectorized types declaration. */
+#include "util/util_types_uchar2.h"
+#include "util/util_types_uchar3.h"
+#include "util/util_types_uchar4.h"
+
+#include "util/util_types_int2.h"
+#include "util/util_types_int3.h"
+#include "util/util_types_int4.h"
+
+#include "util/util_types_uint2.h"
+#include "util/util_types_uint3.h"
+#include "util/util_types_uint4.h"
+
+#include "util/util_types_float2.h"
+#include "util/u
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list