diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-13 20:34:45 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-04-25 11:33:26 +0300 |
commit | 51ec9441b74ccd02e5555b9385c3b2531f7411a6 (patch) | |
tree | aa580862491e63e42e91b9d1d63317d3f3baf01b /intern | |
parent | b06cd746ce9fb8dfe5361fa9d148bde73c26f5d3 (diff) |
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.
Diffstat (limited to 'intern')
29 files changed, 1534 insertions, 333 deletions
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/util_types_float3.h" +#include "util/util_types_float4.h" + +#include "util/util_types_vector3.h" + +/* Vectorized types implementation. */ +#include "util/util_types_uchar2_impl.h" +#include "util/util_types_uchar3_impl.h" +#include "util/util_types_uchar4_impl.h" + +#include "util/util_types_int2_impl.h" +#include "util/util_types_int3_impl.h" +#include "util/util_types_int4_impl.h" + +#include "util/util_types_uint2_impl.h" +#include "util/util_types_uint3_impl.h" +#include "util/util_types_uint4_impl.h" + +#include "util/util_types_float2_impl.h" +#include "util/util_types_float3_impl.h" +#include "util/util_types_float4_impl.h" + +#include "util/util_types_vector3_impl.h" + #endif /* __UTIL_TYPES_H__ */ diff --git a/intern/cycles/util/util_types_float2.h b/intern/cycles/util/util_types_float2.h new file mode 100644 index 00000000000..877ea7c9a3b --- /dev/null +++ b/intern/cycles/util/util_types_float2.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT2_H__ +#define __UTIL_TYPES_FLOAT2_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct float2 { + float x, y; + + __forceinline float operator[](int i) const; + __forceinline float& operator[](int i); +}; + +ccl_device_inline float2 make_float2(float x, float y); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT2_H__ */ diff --git a/intern/cycles/util/util_types_float2_impl.h b/intern/cycles/util/util_types_float2_impl.h new file mode 100644 index 00000000000..7ef390d7da4 --- /dev/null +++ b/intern/cycles/util/util_types_float2_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT2_IMPL_H__ +#define __UTIL_TYPES_FLOAT2_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +__forceinline float float2::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +__forceinline float& float2::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +ccl_device_inline float2 make_float2(float x, float y) +{ + float2 a = {x, y}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT2_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_float3.h b/intern/cycles/util/util_types_float3.h new file mode 100644 index 00000000000..31646f64a1d --- /dev/null +++ b/intern/cycles/util/util_types_float3.h @@ -0,0 +1,56 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT3_H__ +#define __UTIL_TYPES_FLOAT3_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct ccl_try_align(16) float3 { +#ifdef __KERNEL_SSE__ + union { + __m128 m128; + struct { float x, y, z, w; }; + }; + + __forceinline float3(); + __forceinline float3(const float3& a); + __forceinline explicit float3(const __m128& a); + + __forceinline operator const __m128&(void) const; + __forceinline operator __m128&(void); + + __forceinline float3& operator =(const float3& a); +#else /* __KERNEL_SSE__ */ + float x, y, z, w; +#endif /* __KERNEL_SSE__ */ + + __forceinline float operator[](int i) const; + __forceinline float& operator[](int i); +}; + +ccl_device_inline float3 make_float3(float f); +ccl_device_inline float3 make_float3(float x, float y, float z); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT3_H__ */ diff --git a/intern/cycles/util/util_types_float3_impl.h b/intern/cycles/util/util_types_float3_impl.h new file mode 100644 index 00000000000..f062d970b26 --- /dev/null +++ b/intern/cycles/util/util_types_float3_impl.h @@ -0,0 +1,96 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT3_IMPL_H__ +#define __UTIL_TYPES_FLOAT3_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +#ifdef __KERNEL_SSE__ +__forceinline float3::float3() +{ +} + +__forceinline float3::float3(const float3& a) + : m128(a.m128) +{ +} + +__forceinline float3::float3(const __m128& a) + : m128(a) +{ +} + +__forceinline float3::operator const __m128&(void) const +{ + return m128; +} + +__forceinline float3::operator __m128&(void) +{ + return m128; +} + +__forceinline float3& float3::operator =(const float3& a) +{ + m128 = a.m128; + return *this; +} +#endif /* __KERNEL_SSE__ */ + +__forceinline float float3::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +__forceinline float& float3::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +ccl_device_inline float3 make_float3(float f) +{ +#ifdef __KERNEL_SSE__ + float3 a(_mm_set1_ps(f)); +#else + float3 a = {f, f, f, f}; +#endif + return a; +} + +ccl_device_inline float3 make_float3(float x, float y, float z) +{ +#ifdef __KERNEL_SSE__ + float3 a(_mm_set_ps(0.0f, z, y, x)); +#else + float3 a = {x, y, z, 0.0f}; +#endif + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT3_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_float4.h b/intern/cycles/util/util_types_float4.h new file mode 100644 index 00000000000..f0fc0d8f73a --- /dev/null +++ b/intern/cycles/util/util_types_float4.h @@ -0,0 +1,60 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT4_H__ +#define __UTIL_TYPES_FLOAT4_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct int4; + +struct ccl_try_align(16) float4 { +#ifdef __KERNEL_SSE__ + union { + __m128 m128; + struct { float x, y, z, w; }; + }; + + __forceinline float4(); + __forceinline float4(const float4& a); + __forceinline explicit float4(const __m128& a); + + __forceinline operator const __m128&(void) const; + __forceinline operator __m128&(void); + + __forceinline float4& operator =(const float4& a); + +#else /* __KERNEL_SSE__ */ + float x, y, z, w; +#endif /* __KERNEL_SSE__ */ + + __forceinline float operator[](int i) const; + __forceinline float& operator[](int i); +}; + +ccl_device_inline float4 make_float4(float f); +ccl_device_inline float4 make_float4(float x, float y, float z, float w); +ccl_device_inline float4 make_float4(const int4& i); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT4_H__ */ diff --git a/intern/cycles/util/util_types_float4_impl.h b/intern/cycles/util/util_types_float4_impl.h new file mode 100644 index 00000000000..1c59f5fb4f9 --- /dev/null +++ b/intern/cycles/util/util_types_float4_impl.h @@ -0,0 +1,106 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_FLOAT4_IMPL_H__ +#define __UTIL_TYPES_FLOAT4_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +#ifdef __KERNEL_SSE__ +__forceinline float4::float4() +{ +} + +__forceinline float4::float4(const float4& a) + : m128(a.m128) +{ +} + +__forceinline float4::float4(const __m128& a) + : m128(a) +{ +} + +__forceinline float4::operator const __m128&(void) const +{ + return m128; +} + +__forceinline float4::operator __m128&(void) +{ + return m128; +} + +__forceinline float4& float4::operator =(const float4& a) +{ + m128 = a.m128; + return *this; +} +#endif /* __KERNEL_SSE__ */ + +__forceinline float float4::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +__forceinline float& float4::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +ccl_device_inline float4 make_float4(float f) +{ +#ifdef __KERNEL_SSE__ + float4 a(_mm_set1_ps(f)); +#else + float4 a = {f, f, f, f}; +#endif + return a; +} + +ccl_device_inline float4 make_float4(float x, float y, float z, float w) +{ +#ifdef __KERNEL_SSE__ + float4 a(_mm_set_ps(w, z, y, x)); +#else + float4 a = {x, y, z, w}; +#endif + return a; +} + +ccl_device_inline float4 make_float4(const int4& i) +{ +#ifdef __KERNEL_SSE__ + float4 a(_mm_cvtepi32_ps(i.m128)); +#else + float4 a = {(float)i.x, (float)i.y, (float)i.z, (float)i.w}; +#endif + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_FLOAT4_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_int2.h b/intern/cycles/util/util_types_int2.h new file mode 100644 index 00000000000..82e860f89eb --- /dev/null +++ b/intern/cycles/util/util_types_int2.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT2_H__ +#define __UTIL_TYPES_INT2_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct int2 { + int x, y; + + __forceinline int operator[](int i) const; + __forceinline int& operator[](int i); +}; + +ccl_device_inline int2 make_int2(int x, int y); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT2_H__ */ diff --git a/intern/cycles/util/util_types_int2_impl.h b/intern/cycles/util/util_types_int2_impl.h new file mode 100644 index 00000000000..c7d3942e723 --- /dev/null +++ b/intern/cycles/util/util_types_int2_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT2_IMPL_H__ +#define __UTIL_TYPES_INT2_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +int int2::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +int& int2::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +ccl_device_inline int2 make_int2(int x, int y) +{ + int2 a = {x, y}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT2_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_int3.h b/intern/cycles/util/util_types_int3.h new file mode 100644 index 00000000000..6179148a1b2 --- /dev/null +++ b/intern/cycles/util/util_types_int3.h @@ -0,0 +1,56 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT3_H__ +#define __UTIL_TYPES_INT3_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct ccl_try_align(16) int3 { +#ifdef __KERNEL_SSE__ + union { + __m128i m128; + struct { int x, y, z, w; }; + }; + + __forceinline int3(); + __forceinline int3(const int3& a); + __forceinline explicit int3(const __m128i& a); + + __forceinline operator const __m128i&(void) const; + __forceinline operator __m128i&(void); + + __forceinline int3& operator =(const int3& a); +#else /* __KERNEL_SSE__ */ + int x, y, z, w; +#endif /* __KERNEL_SSE__ */ + + __forceinline int operator[](int i) const; + __forceinline int& operator[](int i); +}; + +ccl_device_inline int3 make_int3(int i); +ccl_device_inline int3 make_int3(int x, int y, int z); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT3_H__ */ diff --git a/intern/cycles/util/util_types_int3_impl.h b/intern/cycles/util/util_types_int3_impl.h new file mode 100644 index 00000000000..4fc9daf5fd8 --- /dev/null +++ b/intern/cycles/util/util_types_int3_impl.h @@ -0,0 +1,97 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT3_IMPL_H__ +#define __UTIL_TYPES_INT3_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +#ifdef __KERNEL_SSE__ +__forceinline int3::int3() +{ +} + +__forceinline int3::int3(const __m128i& a) + : m128(a) +{ +} + +__forceinline int3::int3(const int3& a) + : m128(a.m128) +{ +} + +__forceinline int3::operator const __m128i&(void) const +{ + return m128; +} + +__forceinline int3::operator __m128i&(void) +{ + return m128; +} + +__forceinline int3& int3::operator =(const int3& a) +{ + m128 = a.m128; + return *this; +} +#endif /* __KERNEL_SSE__ */ + +__forceinline int int3::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +__forceinline int& int3::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +ccl_device_inline int3 make_int3(int i) +{ +#ifdef __KERNEL_SSE__ + int3 a(_mm_set1_epi32(i)); +#else + int3 a = {i, i, i, i}; +#endif + return a; +} + +ccl_device_inline int3 make_int3(int x, int y, int z) +{ +#ifdef __KERNEL_SSE__ + int3 a(_mm_set_epi32(0, z, y, x)); +#else + int3 a = {x, y, z, 0}; +#endif + + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT3_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_int4.h b/intern/cycles/util/util_types_int4.h new file mode 100644 index 00000000000..1963893d3cc --- /dev/null +++ b/intern/cycles/util/util_types_int4.h @@ -0,0 +1,60 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT4_H__ +#define __UTIL_TYPES_INT4_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ + +struct float3; + +struct ccl_try_align(16) int4 { +#ifdef __KERNEL_SSE__ + union { + __m128i m128; + struct { int x, y, z, w; }; + }; + + __forceinline int4(); + __forceinline int4(const int4& a); + __forceinline explicit int4(const __m128i& a); + + __forceinline operator const __m128i&(void) const; + __forceinline operator __m128i&(void); + + __forceinline int4& operator=(const int4& a); +#else /* __KERNEL_SSE__ */ + int x, y, z, w; +#endif /* __KERNEL_SSE__ */ + + __forceinline int operator[](int i) const; + __forceinline int& operator[](int i); +}; + +ccl_device_inline int4 make_int4(int i); +ccl_device_inline int4 make_int4(int x, int y, int z, int w); +ccl_device_inline int4 make_int4(const float3& f); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT4_H__ */ diff --git a/intern/cycles/util/util_types_int4_impl.h b/intern/cycles/util/util_types_int4_impl.h new file mode 100644 index 00000000000..52cda1c74b5 --- /dev/null +++ b/intern/cycles/util/util_types_int4_impl.h @@ -0,0 +1,106 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_INT4_IMPL_H__ +#define __UTIL_TYPES_INT4_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +#ifdef __KERNEL_SSE__ +__forceinline int4::int4() +{ +} + +__forceinline int4::int4(const int4& a) + : m128(a.m128) +{ +} + +__forceinline int4::int4(const __m128i& a) + : m128(a) +{ +} + +__forceinline int4::operator const __m128i&(void) const +{ + return m128; +} + +__forceinline int4::operator __m128i&(void) +{ + return m128; +} + +__forceinline int4& int4::operator=(const int4& a) +{ + m128 = a.m128; + return *this; +} +#endif /* __KERNEL_SSE__ */ + +__forceinline int int4::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +__forceinline int& int4::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +ccl_device_inline int4 make_int4(int i) +{ +#ifdef __KERNEL_SSE__ + int4 a(_mm_set1_epi32(i)); +#else + int4 a = {i, i, i, i}; +#endif + return a; +} + +ccl_device_inline int4 make_int4(int x, int y, int z, int w) +{ +#ifdef __KERNEL_SSE__ + int4 a(_mm_set_epi32(w, z, y, x)); +#else + int4 a = {x, y, z, w}; +#endif + return a; +} + +ccl_device_inline int4 make_int4(const float3& f) +{ +#ifdef __KERNEL_SSE__ + int4 a(_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_NAMESPACE_END + +#endif /* __UTIL_TYPES_INT4_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uchar2.h b/intern/cycles/util/util_types_uchar2.h new file mode 100644 index 00000000000..f618a2234ca --- /dev/null +++ b/intern/cycles/util/util_types_uchar2.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR2_H__ +#define __UTIL_TYPES_UCHAR2_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uchar2 { + uchar x, y; + + __forceinline uchar operator[](int i) const; + __forceinline uchar& operator[](int i); +}; + +ccl_device_inline uchar2 make_uchar2(uchar x, uchar y); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR2_H__ */ diff --git a/intern/cycles/util/util_types_uchar2_impl.h b/intern/cycles/util/util_types_uchar2_impl.h new file mode 100644 index 00000000000..d5f196d0ce0 --- /dev/null +++ b/intern/cycles/util/util_types_uchar2_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR2_IMPL_H__ +#define __UTIL_TYPES_UCHAR2_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +uchar uchar2::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +uchar& uchar2::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +ccl_device_inline uchar2 make_uchar2(uchar x, uchar y) +{ + uchar2 a = {x, y}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR2_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uchar3.h b/intern/cycles/util/util_types_uchar3.h new file mode 100644 index 00000000000..1e3644e6fd6 --- /dev/null +++ b/intern/cycles/util/util_types_uchar3.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR3_H__ +#define __UTIL_TYPES_UCHAR3_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uchar3 { + uchar x, y, z; + + __forceinline uchar operator[](int i) const; + __forceinline uchar& operator[](int i); +}; + +ccl_device_inline uchar3 make_uchar3(uchar x, uchar y, uchar z); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR3_H__ */ diff --git a/intern/cycles/util/util_types_uchar3_impl.h b/intern/cycles/util/util_types_uchar3_impl.h new file mode 100644 index 00000000000..611021efb7f --- /dev/null +++ b/intern/cycles/util/util_types_uchar3_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR3_IMPL_H__ +#define __UTIL_TYPES_UCHAR3_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +uchar uchar3::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +uchar& uchar3::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +ccl_device_inline uchar3 make_uchar3(uchar x, uchar y, uchar z) +{ + uchar3 a = {x, y, z}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR3_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uchar4.h b/intern/cycles/util/util_types_uchar4.h new file mode 100644 index 00000000000..3802cebbfb9 --- /dev/null +++ b/intern/cycles/util/util_types_uchar4.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR4_H__ +#define __UTIL_TYPES_UCHAR4_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uchar4 { + uchar x, y, z, w; + + __forceinline uchar operator[](int i) const; + __forceinline uchar& operator[](int i); +}; + +ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR4_H__ */ diff --git a/intern/cycles/util/util_types_uchar4_impl.h b/intern/cycles/util/util_types_uchar4_impl.h new file mode 100644 index 00000000000..03039f60c54 --- /dev/null +++ b/intern/cycles/util/util_types_uchar4_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UCHAR4_IMPL_H__ +#define __UTIL_TYPES_UCHAR4_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +uchar uchar4::operator[](int i) const +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +uchar& uchar4::operator[](int i) +{ + util_assert(i >= 0); + util_assert(i < 4); + return *(&x + i); +} + +ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w) +{ + uchar4 a = {x, y, z, w}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UCHAR4_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uint2.h b/intern/cycles/util/util_types_uint2.h new file mode 100644 index 00000000000..c4a31899614 --- /dev/null +++ b/intern/cycles/util/util_types_uint2.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT2_H__ +#define __UTIL_TYPES_UINT2_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uint2 { + uint x, y; + + __forceinline uint operator[](uint i) const; + __forceinline uint& operator[](uint i); +}; + +ccl_device_inline uint2 make_uint2(uint x, uint y); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT2_H__ */ diff --git a/intern/cycles/util/util_types_uint2_impl.h b/intern/cycles/util/util_types_uint2_impl.h new file mode 100644 index 00000000000..d5af59ec2bf --- /dev/null +++ b/intern/cycles/util/util_types_uint2_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT2_IMPL_H__ +#define __UTIL_TYPES_UINT2_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +__forceinline uint uint2::operator[](uint i) const +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +__forceinline uint& uint2::operator[](uint i) +{ + util_assert(i >= 0); + util_assert(i < 2); + return *(&x + i); +} + +ccl_device_inline uint2 make_uint2(uint x, uint y) +{ + uint2 a = {x, y}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT2_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uint3.h b/intern/cycles/util/util_types_uint3.h new file mode 100644 index 00000000000..aeeecd2df06 --- /dev/null +++ b/intern/cycles/util/util_types_uint3.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT3_H__ +#define __UTIL_TYPES_UINT3_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uint3 { + uint x, y, z; + + __forceinline uint operator[](uint i) const; + __forceinline uint& operator[](uint i); +}; + +ccl_device_inline uint3 make_uint3(uint x, uint y, uint z); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT3_H__ */ diff --git a/intern/cycles/util/util_types_uint3_impl.h b/intern/cycles/util/util_types_uint3_impl.h new file mode 100644 index 00000000000..22a6a1aa29a --- /dev/null +++ b/intern/cycles/util/util_types_uint3_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT3_IMPL_H__ +#define __UTIL_TYPES_UINT3_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +__forceinline uint uint3::operator[](uint i) const +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +__forceinline uint& uint3::operator[](uint i) +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +ccl_device_inline uint3 make_uint3(uint x, uint y, uint z) +{ + uint3 a = {x, y, z}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT3_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_uint4.h b/intern/cycles/util/util_types_uint4.h new file mode 100644 index 00000000000..2d3a7bb85e4 --- /dev/null +++ b/intern/cycles/util/util_types_uint4.h @@ -0,0 +1,39 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT4_H__ +#define __UTIL_TYPES_UINT4_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +struct uint4 { + uint x, y, z, w; + + __forceinline uint operator[](uint i) const; + __forceinline uint& operator[](uint i); +}; + +ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w); +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT4_H__ */ diff --git a/intern/cycles/util/util_types_uint4_impl.h b/intern/cycles/util/util_types_uint4_impl.h new file mode 100644 index 00000000000..2858e09dec7 --- /dev/null +++ b/intern/cycles/util/util_types_uint4_impl.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_UINT4_IMPL_H__ +#define __UTIL_TYPES_UINT4_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +__forceinline uint uint4::operator[](uint i) const +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +__forceinline uint& uint4::operator[](uint i) +{ + util_assert(i >= 0); + util_assert(i < 3); + return *(&x + i); +} + +ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w) +{ + uint4 a = {x, y, z, w}; + return a; +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_UINT4_IMPL_H__ */ diff --git a/intern/cycles/util/util_types_vector3.h b/intern/cycles/util/util_types_vector3.h new file mode 100644 index 00000000000..12acf9dc959 --- /dev/null +++ b/intern/cycles/util/util_types_vector3.h @@ -0,0 +1,41 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_VECTOR3_H__ +#define __UTIL_TYPES_VECTOR3_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +template<typename T> +class vector3 +{ +public: + T x, y, z; + + __forceinline vector3(); + __forceinline vector3(const T& a); + __forceinline vector3(const T& x, const T& y, const T& z); +}; +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_VECTOR3_H__ */ diff --git a/intern/cycles/util/util_types_vector3_impl.h b/intern/cycles/util/util_types_vector3_impl.h new file mode 100644 index 00000000000..2f6b8368540 --- /dev/null +++ b/intern/cycles/util/util_types_vector3_impl.h @@ -0,0 +1,47 @@ +/* + * Copyright 2011-2017 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTIL_TYPES_VECTOR3_IMPL_H__ +#define __UTIL_TYPES_VECTOR3_IMPL_H__ + +#ifndef __UTIL_TYPES_H__ +# error "Do not include this file directly, include util_types.h instead." +#endif + +CCL_NAMESPACE_BEGIN + +#ifndef __KERNEL_GPU__ +template<typename T> +ccl_always_inline vector3<T>::vector3() +{ +} + +template<typename T> +ccl_always_inline vector3<T>::vector3(const T& a) + : x(a), y(a), z(a) +{ +} + +template<typename T> +ccl_always_inline vector3<T>::vector3(const T& x, const T& y, const T& z) + : x(x), y(y), z(z) +{ +} +#endif /* __KERNEL_GPU__ */ + +CCL_NAMESPACE_END + +#endif /* __UTIL_TYPES_VECTOR3_IMPL_H__ */ |