diff options
Diffstat (limited to 'intern/cycles/util/util_math.h')
-rw-r--r-- | intern/cycles/util/util_math.h | 302 |
1 files changed, 151 insertions, 151 deletions
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h index 987ef4f17ac..6db532faf74 100644 --- a/intern/cycles/util/util_math.h +++ b/intern/cycles/util/util_math.h @@ -89,12 +89,12 @@ CCL_NAMESPACE_BEGIN #ifndef __KERNEL_OPENCL__ -__device_inline float fmaxf(float a, float b) +ccl_device_inline float fmaxf(float a, float b) { return (a > b)? a: b; } -__device_inline float fminf(float a, float b) +ccl_device_inline float fminf(float a, float b) { return (a < b)? a: b; } @@ -105,63 +105,63 @@ __device_inline float fminf(float a, float b) #ifndef __KERNEL_GPU__ -__device_inline int max(int a, int b) +ccl_device_inline int max(int a, int b) { return (a > b)? a: b; } -__device_inline int min(int a, int b) +ccl_device_inline int min(int a, int b) { return (a < b)? a: b; } -__device_inline float max(float a, float b) +ccl_device_inline float max(float a, float b) { return (a > b)? a: b; } -__device_inline float min(float a, float b) +ccl_device_inline float min(float a, float b) { return (a < b)? a: b; } -__device_inline double max(double a, double b) +ccl_device_inline double max(double a, double b) { return (a > b)? a: b; } -__device_inline double min(double a, double b) +ccl_device_inline double min(double a, double b) { return (a < b)? a: b; } #endif -__device_inline float min4(float a, float b, float c, float d) +ccl_device_inline float min4(float a, float b, float c, float d) { return min(min(a, b), min(c, d)); } -__device_inline float max4(float a, float b, float c, float d) +ccl_device_inline float max4(float a, float b, float c, float d) { return max(max(a, b), max(c, d)); } #ifndef __KERNEL_OPENCL__ -__device_inline int clamp(int a, int mn, int mx) +ccl_device_inline int clamp(int a, int mn, int mx) { return min(max(a, mn), mx); } -__device_inline float clamp(float a, float mn, float mx) +ccl_device_inline float clamp(float a, float mn, float mx) { return min(max(a, mn), mx); } #endif -__device_inline int float_to_int(float f) +ccl_device_inline int float_to_int(float f) { #if defined(__KERNEL_SSE2__) && !defined(_MSC_VER) return _mm_cvtt_ss2si(_mm_load_ss(&f)); @@ -170,22 +170,22 @@ __device_inline int float_to_int(float f) #endif } -__device_inline int floor_to_int(float f) +ccl_device_inline int floor_to_int(float f) { return float_to_int(floorf(f)); } -__device_inline int ceil_to_int(float f) +ccl_device_inline int ceil_to_int(float f) { return float_to_int(ceilf(f)); } -__device_inline float signf(float f) +ccl_device_inline float signf(float f) { return (f < 0.0f)? -1.0f: 1.0f; } -__device_inline float nonzerof(float f, float eps) +ccl_device_inline float nonzerof(float f, float eps) { if(fabsf(f) < eps) return signf(f)*eps; @@ -193,7 +193,7 @@ __device_inline float nonzerof(float f, float eps) return f; } -__device_inline float smoothstepf(float f) +ccl_device_inline float smoothstepf(float f) { float ff = f*f; return (3.0f*ff - 2.0f*ff*f); @@ -203,7 +203,7 @@ __device_inline float smoothstepf(float f) #ifndef __KERNEL_OPENCL__ -__device_inline bool is_zero(const float2 a) +ccl_device_inline bool is_zero(const float2 a) { return (a.x == 0.0f && a.y == 0.0f); } @@ -212,7 +212,7 @@ __device_inline bool is_zero(const float2 a) #ifndef __KERNEL_OPENCL__ -__device_inline float average(const float2 a) +ccl_device_inline float average(const float2 a) { return (a.x + a.y)*(1.0f/2.0f); } @@ -221,85 +221,85 @@ __device_inline float average(const float2 a) #ifndef __KERNEL_OPENCL__ -__device_inline float2 operator-(const float2 a) +ccl_device_inline float2 operator-(const float2 a) { return make_float2(-a.x, -a.y); } -__device_inline float2 operator*(const float2 a, const float2 b) +ccl_device_inline float2 operator*(const float2 a, const float2 b) { return make_float2(a.x*b.x, a.y*b.y); } -__device_inline float2 operator*(const float2 a, float f) +ccl_device_inline float2 operator*(const float2 a, float f) { return make_float2(a.x*f, a.y*f); } -__device_inline float2 operator*(float f, const float2 a) +ccl_device_inline float2 operator*(float f, const float2 a) { return make_float2(a.x*f, a.y*f); } -__device_inline float2 operator/(float f, const float2 a) +ccl_device_inline float2 operator/(float f, const float2 a) { return make_float2(f/a.x, f/a.y); } -__device_inline float2 operator/(const float2 a, float f) +ccl_device_inline float2 operator/(const float2 a, float f) { float invf = 1.0f/f; return make_float2(a.x*invf, a.y*invf); } -__device_inline float2 operator/(const float2 a, const float2 b) +ccl_device_inline float2 operator/(const float2 a, const float2 b) { return make_float2(a.x/b.x, a.y/b.y); } -__device_inline float2 operator+(const float2 a, const float2 b) +ccl_device_inline float2 operator+(const float2 a, const float2 b) { return make_float2(a.x+b.x, a.y+b.y); } -__device_inline float2 operator-(const float2 a, const float2 b) +ccl_device_inline float2 operator-(const float2 a, const float2 b) { return make_float2(a.x-b.x, a.y-b.y); } -__device_inline float2 operator+=(float2& a, const float2 b) +ccl_device_inline float2 operator+=(float2& a, const float2 b) { return a = a + b; } -__device_inline float2 operator*=(float2& a, const float2 b) +ccl_device_inline float2 operator*=(float2& a, const float2 b) { return a = a * b; } -__device_inline float2 operator*=(float2& a, float f) +ccl_device_inline float2 operator*=(float2& a, float f) { return a = a * f; } -__device_inline float2 operator/=(float2& a, const float2 b) +ccl_device_inline float2 operator/=(float2& a, const float2 b) { return a = a / b; } -__device_inline float2 operator/=(float2& a, float f) +ccl_device_inline float2 operator/=(float2& a, float f) { float invf = 1.0f/f; return a = a * invf; } -__device_inline float dot(const float2 a, const float2 b) +ccl_device_inline float dot(const float2 a, const float2 b) { return a.x*b.x + a.y*b.y; } -__device_inline float cross(const float2 a, const float2 b) +ccl_device_inline float cross(const float2 a, const float2 b) { return (a.x*b.y - a.y*b.x); } @@ -308,58 +308,58 @@ __device_inline float cross(const float2 a, const float2 b) #ifndef __KERNEL_OPENCL__ -__device_inline bool operator==(const int2 a, const int2 b) +ccl_device_inline bool operator==(const int2 a, const int2 b) { return (a.x == b.x && a.y == b.y); } -__device_inline float len(const float2 a) +ccl_device_inline float len(const float2 a) { return sqrtf(dot(a, a)); } -__device_inline float2 normalize(const float2 a) +ccl_device_inline float2 normalize(const float2 a) { return a/len(a); } -__device_inline float2 normalize_len(const float2 a, float *t) +ccl_device_inline float2 normalize_len(const float2 a, float *t) { *t = len(a); return a/(*t); } -__device_inline bool operator==(const float2 a, const float2 b) +ccl_device_inline bool operator==(const float2 a, const float2 b) { return (a.x == b.x && a.y == b.y); } -__device_inline bool operator!=(const float2 a, const float2 b) +ccl_device_inline bool operator!=(const float2 a, const float2 b) { return !(a == b); } -__device_inline float2 min(float2 a, float2 b) +ccl_device_inline float2 min(float2 a, float2 b) { return make_float2(min(a.x, b.x), min(a.y, b.y)); } -__device_inline float2 max(float2 a, float2 b) +ccl_device_inline float2 max(float2 a, float2 b) { return make_float2(max(a.x, b.x), max(a.y, b.y)); } -__device_inline float2 clamp(float2 a, float2 mn, float2 mx) +ccl_device_inline float2 clamp(float2 a, float2 mn, float2 mx) { return min(max(a, mn), mx); } -__device_inline float2 fabs(float2 a) +ccl_device_inline float2 fabs(float2 a) { return make_float2(fabsf(a.x), fabsf(a.y)); } -__device_inline float2 as_float2(const float4 a) +ccl_device_inline float2 as_float2(const float4 a) { return make_float2(a.x, a.y); } @@ -368,7 +368,7 @@ __device_inline float2 as_float2(const float4 a) #ifndef __KERNEL_GPU__ -__device_inline void print_float2(const char *label, const float2& a) +ccl_device_inline void print_float2(const char *label, const float2& a) { printf("%s: %.8f %.8f\n", label, (double)a.x, (double)a.y); } @@ -377,7 +377,7 @@ __device_inline void print_float2(const char *label, const float2& a) #ifndef __KERNEL_OPENCL__ -__device_inline float2 interp(float2 a, float2 b, float t) +ccl_device_inline float2 interp(float2 a, float2 b, float t) { return a + t*(b - a); } @@ -388,84 +388,84 @@ __device_inline float2 interp(float2 a, float2 b, float t) #ifndef __KERNEL_OPENCL__ -__device_inline float3 operator-(const float3 a) +ccl_device_inline float3 operator-(const float3 a) { return make_float3(-a.x, -a.y, -a.z); } -__device_inline float3 operator*(const float3 a, const float3 b) +ccl_device_inline float3 operator*(const float3 a, const float3 b) { return make_float3(a.x*b.x, a.y*b.y, a.z*b.z); } -__device_inline float3 operator*(const float3 a, float f) +ccl_device_inline float3 operator*(const float3 a, float f) { return make_float3(a.x*f, a.y*f, a.z*f); } -__device_inline float3 operator*(float f, const float3 a) +ccl_device_inline float3 operator*(float f, const float3 a) { return make_float3(a.x*f, a.y*f, a.z*f); } -__device_inline float3 operator/(float f, const float3 a) +ccl_device_inline float3 operator/(float f, const float3 a) { return make_float3(f/a.x, f/a.y, f/a.z); } -__device_inline float3 operator/(const float3 a, float f) +ccl_device_inline float3 operator/(const float3 a, float f) { float invf = 1.0f/f; return make_float3(a.x*invf, a.y*invf, a.z*invf); } -__device_inline float3 operator/(const float3 a, const float3 b) +ccl_device_inline float3 operator/(const float3 a, const float3 b) { return make_float3(a.x/b.x, a.y/b.y, a.z/b.z); } -__device_inline float3 operator+(const float3 a, const float3 b) +ccl_device_inline float3 operator+(const float3 a, const float3 b) { return make_float3(a.x+b.x, a.y+b.y, a.z+b.z); } -__device_inline float3 operator-(const float3 a, const float3 b) +ccl_device_inline float3 operator-(const float3 a, const float3 b) { return make_float3(a.x-b.x, a.y-b.y, a.z-b.z); } -__device_inline float3 operator+=(float3& a, const float3 b) +ccl_device_inline float3 operator+=(float3& a, const float3 b) { return a = a + b; } -__device_inline float3 operator*=(float3& a, const float3 b) +ccl_device_inline float3 operator*=(float3& a, const float3 b) { return a = a * b; } -__device_inline float3 operator*=(float3& a, float f) +ccl_device_inline float3 operator*=(float3& a, float f) { return a = a * f; } -__device_inline float3 operator/=(float3& a, const float3 b) +ccl_device_inline float3 operator/=(float3& a, const float3 b) { return a = a / b; } -__device_inline float3 operator/=(float3& a, float f) +ccl_device_inline float3 operator/=(float3& a, float f) { float invf = 1.0f/f; return a = a * invf; } -__device_inline float dot(const float3 a, const float3 b) +ccl_device_inline float dot(const float3 a, const float3 b) { return a.x*b.x + a.y*b.y + a.z*b.z; } -__device_inline float3 cross(const float3 a, const float3 b) +ccl_device_inline float3 cross(const float3 a, const float3 b) { float3 r = make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); return r; @@ -473,26 +473,26 @@ __device_inline float3 cross(const float3 a, const float3 b) #endif -__device_inline float len(const float3 a) +ccl_device_inline float len(const float3 a) { return sqrtf(dot(a, a)); } -__device_inline float len_squared(const float3 a) +ccl_device_inline float len_squared(const float3 a) { return dot(a, a); } #ifndef __KERNEL_OPENCL__ -__device_inline float3 normalize(const float3 a) +ccl_device_inline float3 normalize(const float3 a) { return a/len(a); } #endif -__device_inline float3 normalize_len(const float3 a, float *t) +ccl_device_inline float3 normalize_len(const float3 a, float *t) { *t = len(a); return a/(*t); @@ -500,7 +500,7 @@ __device_inline float3 normalize_len(const float3 a, float *t) #ifndef __KERNEL_OPENCL__ -__device_inline bool operator==(const float3 a, const float3 b) +ccl_device_inline bool operator==(const float3 a, const float3 b) { #ifdef __KERNEL_SSE__ return (_mm_movemask_ps(_mm_cmpeq_ps(a.m128, b.m128)) & 7) == 7; @@ -509,12 +509,12 @@ __device_inline bool operator==(const float3 a, const float3 b) #endif } -__device_inline bool operator!=(const float3 a, const float3 b) +ccl_device_inline bool operator!=(const float3 a, const float3 b) { return !(a == b); } -__device_inline float3 min(float3 a, float3 b) +ccl_device_inline float3 min(float3 a, float3 b) { #ifdef __KERNEL_SSE__ return _mm_min_ps(a.m128, b.m128); @@ -523,7 +523,7 @@ __device_inline float3 min(float3 a, float3 b) #endif } -__device_inline float3 max(float3 a, float3 b) +ccl_device_inline float3 max(float3 a, float3 b) { #ifdef __KERNEL_SSE__ return _mm_max_ps(a.m128, b.m128); @@ -532,12 +532,12 @@ __device_inline float3 max(float3 a, float3 b) #endif } -__device_inline float3 clamp(float3 a, float3 mn, float3 mx) +ccl_device_inline float3 clamp(float3 a, float3 mn, float3 mx) { return min(max(a, mn), mx); } -__device_inline float3 fabs(float3 a) +ccl_device_inline float3 fabs(float3 a) { #ifdef __KERNEL_SSE__ __m128 mask = _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff)); @@ -549,29 +549,29 @@ __device_inline float3 fabs(float3 a) #endif -__device_inline float3 float2_to_float3(const float2 a) +ccl_device_inline float3 float2_to_float3(const float2 a) { return make_float3(a.x, a.y, 0.0f); } -__device_inline float3 float4_to_float3(const float4 a) +ccl_device_inline float3 float4_to_float3(const float4 a) { return make_float3(a.x, a.y, a.z); } -__device_inline float4 float3_to_float4(const float3 a) +ccl_device_inline float4 float3_to_float4(const float3 a) { return make_float4(a.x, a.y, a.z, 1.0f); } #ifndef __KERNEL_GPU__ -__device_inline void print_float3(const char *label, const float3& a) +ccl_device_inline void print_float3(const char *label, const float3& a) { printf("%s: %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z); } -__device_inline float3 rcp(const float3& a) +ccl_device_inline float3 rcp(const float3& a) { #ifdef __KERNEL_SSE__ float4 r = _mm_rcp_ps(a.m128); @@ -583,12 +583,12 @@ __device_inline float3 rcp(const float3& a) #endif -__device_inline float3 interp(float3 a, float3 b, float t) +ccl_device_inline float3 interp(float3 a, float3 b, float t) { return a + t*(b - a); } -__device_inline bool is_zero(const float3 a) +ccl_device_inline bool is_zero(const float3 a) { #ifdef __KERNEL_SSE__ return a == make_float3(0.0f); @@ -597,7 +597,7 @@ __device_inline bool is_zero(const float3 a) #endif } -__device_inline float reduce_add(const float3 a) +ccl_device_inline float reduce_add(const float3 a) { #ifdef __KERNEL_SSE__ return (a.x + a.y + a.z); @@ -606,7 +606,7 @@ __device_inline float reduce_add(const float3 a) #endif } -__device_inline float average(const float3 a) +ccl_device_inline float average(const float3 a) { return reduce_add(a)*(1.0f/3.0f); } @@ -639,7 +639,7 @@ template<> __forceinline const float4 shuffle<0, 1, 0, 1>(const float4& b) #ifndef __KERNEL_OPENCL__ -__device_inline float4 operator-(const float4& a) +ccl_device_inline float4 operator-(const float4& a) { #ifdef __KERNEL_SSE__ __m128 mask = _mm_castsi128_ps(_mm_set1_epi32(0x80000000)); @@ -649,7 +649,7 @@ __device_inline float4 operator-(const float4& a) #endif } -__device_inline float4 operator*(const float4& a, const float4& b) +ccl_device_inline float4 operator*(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return _mm_mul_ps(a.m128, b.m128); @@ -658,7 +658,7 @@ __device_inline float4 operator*(const float4& a, const float4& b) #endif } -__device_inline float4 operator*(const float4& a, float f) +ccl_device_inline float4 operator*(const float4& a, float f) { #ifdef __KERNEL_SSE__ return a * make_float4(f); @@ -667,12 +667,12 @@ __device_inline float4 operator*(const float4& a, float f) #endif } -__device_inline float4 operator*(float f, const float4& a) +ccl_device_inline float4 operator*(float f, const float4& a) { return a * f; } -__device_inline float4 rcp(const float4& a) +ccl_device_inline float4 rcp(const float4& a) { #ifdef __KERNEL_SSE__ float4 r = _mm_rcp_ps(a.m128); @@ -682,12 +682,12 @@ __device_inline float4 rcp(const float4& a) #endif } -__device_inline float4 operator/(const float4& a, float f) +ccl_device_inline float4 operator/(const float4& a, float f) { return a * (1.0f/f); } -__device_inline float4 operator/(const float4& a, const float4& b) +ccl_device_inline float4 operator/(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return a * rcp(b); @@ -697,7 +697,7 @@ __device_inline float4 operator/(const float4& a, const float4& b) } -__device_inline float4 operator+(const float4& a, const float4& b) +ccl_device_inline float4 operator+(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return _mm_add_ps(a.m128, b.m128); @@ -706,7 +706,7 @@ __device_inline float4 operator+(const float4& a, const float4& b) #endif } -__device_inline float4 operator-(const float4& a, const float4& b) +ccl_device_inline float4 operator-(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return _mm_sub_ps(a.m128, b.m128); @@ -715,22 +715,22 @@ __device_inline float4 operator-(const float4& a, const float4& b) #endif } -__device_inline float4 operator+=(float4& a, const float4& b) +ccl_device_inline float4 operator+=(float4& a, const float4& b) { return a = a + b; } -__device_inline float4 operator*=(float4& a, const float4& b) +ccl_device_inline float4 operator*=(float4& a, const float4& b) { return a = a * b; } -__device_inline float4 operator/=(float4& a, float f) +ccl_device_inline float4 operator/=(float4& a, float f) { return a = a / f; } -__device_inline int4 operator<(const float4& a, const float4& b) +ccl_device_inline int4 operator<(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return _mm_cvtps_epi32(_mm_cmplt_ps(a.m128, b.m128)); /* todo: avoid cvt */ @@ -739,7 +739,7 @@ __device_inline int4 operator<(const float4& a, const float4& b) #endif } -__device_inline int4 operator>=(float4 a, float4 b) +ccl_device_inline int4 operator>=(float4 a, float4 b) { #ifdef __KERNEL_SSE__ return _mm_cvtps_epi32(_mm_cmpge_ps(a.m128, b.m128)); /* todo: avoid cvt */ @@ -748,7 +748,7 @@ __device_inline int4 operator>=(float4 a, float4 b) #endif } -__device_inline int4 operator<=(const float4& a, const float4& b) +ccl_device_inline int4 operator<=(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return _mm_cvtps_epi32(_mm_cmple_ps(a.m128, b.m128)); /* todo: avoid cvt */ @@ -757,7 +757,7 @@ __device_inline int4 operator<=(const float4& a, const float4& b) #endif } -__device_inline bool operator==(const float4 a, const float4 b) +ccl_device_inline bool operator==(const float4 a, const float4 b) { #ifdef __KERNEL_SSE__ return (_mm_movemask_ps(_mm_cmpeq_ps(a.m128, b.m128)) & 15) == 15; @@ -766,7 +766,7 @@ __device_inline bool operator==(const float4 a, const float4 b) #endif } -__device_inline float4 cross(const float4& a, const float4& b) +ccl_device_inline float4 cross(const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ return (shuffle<1,2,0,0>(a)*shuffle<2,0,1,0>(b)) - (shuffle<2,0,1,0>(a)*shuffle<1,2,0,0>(b)); @@ -775,7 +775,7 @@ __device_inline float4 cross(const float4& a, const float4& b) #endif } -__device_inline bool is_zero(const float4& a) +ccl_device_inline bool is_zero(const float4& a) { #ifdef __KERNEL_SSE__ return a == make_float4(0.0f); @@ -784,7 +784,7 @@ __device_inline bool is_zero(const float4& a) #endif } -__device_inline float reduce_add(const float4& a) +ccl_device_inline float reduce_add(const float4& a) { #ifdef __KERNEL_SSE__ float4 h = shuffle<1,0,3,2>(a) + a; @@ -794,27 +794,27 @@ __device_inline float reduce_add(const float4& a) #endif } -__device_inline float average(const float4& a) +ccl_device_inline float average(const float4& a) { return reduce_add(a) * 0.25f; } -__device_inline float dot(const float4& a, const float4& b) +ccl_device_inline float dot(const float4& a, const float4& b) { return reduce_add(a * b); } -__device_inline float len(const float4 a) +ccl_device_inline float len(const float4 a) { return sqrtf(dot(a, a)); } -__device_inline float4 normalize(const float4 a) +ccl_device_inline float4 normalize(const float4 a) { return a/len(a); } -__device_inline float4 min(float4 a, float4 b) +ccl_device_inline float4 min(float4 a, float4 b) { #ifdef __KERNEL_SSE__ return _mm_min_ps(a.m128, b.m128); @@ -823,7 +823,7 @@ __device_inline float4 min(float4 a, float4 b) #endif } -__device_inline float4 max(float4 a, float4 b) +ccl_device_inline float4 max(float4 a, float4 b) { #ifdef __KERNEL_SSE__ return _mm_max_ps(a.m128, b.m128); @@ -836,7 +836,7 @@ __device_inline float4 max(float4 a, float4 b) #ifndef __KERNEL_GPU__ -__device_inline float4 select(const int4& mask, const float4& a, const float4& b) +ccl_device_inline float4 select(const int4& mask, const float4& a, const float4& b) { #ifdef __KERNEL_SSE__ /* blendv is sse4, and apparently broken on vs2008 */ @@ -846,7 +846,7 @@ __device_inline float4 select(const int4& mask, const float4& a, const float4& b #endif } -__device_inline float4 reduce_min(const float4& a) +ccl_device_inline float4 reduce_min(const float4& a) { #ifdef __KERNEL_SSE__ float4 h = min(shuffle<1,0,3,2>(a), a); @@ -856,7 +856,7 @@ __device_inline float4 reduce_min(const float4& a) #endif } -__device_inline float4 reduce_max(const float4& a) +ccl_device_inline float4 reduce_max(const float4& a) { #ifdef __KERNEL_SSE__ float4 h = max(shuffle<1,0,3,2>(a), a); @@ -867,7 +867,7 @@ __device_inline float4 reduce_max(const float4& a) } #if 0 -__device_inline float4 reduce_add(const float4& a) +ccl_device_inline float4 reduce_add(const float4& a) { #ifdef __KERNEL_SSE__ float4 h = shuffle<1,0,3,2>(a) + a; @@ -878,7 +878,7 @@ __device_inline float4 reduce_add(const float4& a) } #endif -__device_inline void print_float4(const char *label, const float4& a) +ccl_device_inline void print_float4(const char *label, const float4& a) { printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w); } @@ -889,7 +889,7 @@ __device_inline void print_float4(const char *label, const float4& a) #ifndef __KERNEL_OPENCL__ -__device_inline int3 min(int3 a, int3 b) +ccl_device_inline int3 min(int3 a, int3 b) { #ifdef __KERNEL_SSE__ return _mm_min_epi32(a.m128, b.m128); @@ -898,7 +898,7 @@ __device_inline int3 min(int3 a, int3 b) #endif } -__device_inline int3 max(int3 a, int3 b) +ccl_device_inline int3 max(int3 a, int3 b) { #ifdef __KERNEL_SSE__ return _mm_max_epi32(a.m128, b.m128); @@ -907,7 +907,7 @@ __device_inline int3 max(int3 a, int3 b) #endif } -__device_inline int3 clamp(const int3& a, int mn, int mx) +ccl_device_inline int3 clamp(const int3& a, int mn, int mx) { #ifdef __KERNEL_SSE__ return min(max(a, make_int3(mn)), make_int3(mx)); @@ -916,7 +916,7 @@ __device_inline int3 clamp(const int3& a, int mn, int mx) #endif } -__device_inline int3 clamp(const int3& a, int3& mn, int mx) +ccl_device_inline int3 clamp(const int3& a, int3& mn, int mx) { #ifdef __KERNEL_SSE__ return min(max(a, mn), make_int3(mx)); @@ -929,7 +929,7 @@ __device_inline int3 clamp(const int3& a, int3& mn, int mx) #ifndef __KERNEL_GPU__ -__device_inline void print_int3(const char *label, const int3& a) +ccl_device_inline void print_int3(const char *label, const int3& a) { printf("%s: %d %d %d\n", label, a.x, a.y, a.z); } @@ -940,7 +940,7 @@ __device_inline void print_int3(const char *label, const int3& a) #ifndef __KERNEL_GPU__ -__device_inline int4 operator+(const int4& a, const int4& b) +ccl_device_inline int4 operator+(const int4& a, const int4& b) { #ifdef __KERNEL_SSE__ return _mm_add_epi32(a.m128, b.m128); @@ -949,12 +949,12 @@ __device_inline int4 operator+(const int4& a, const int4& b) #endif } -__device_inline int4 operator+=(int4& a, const int4& b) +ccl_device_inline int4 operator+=(int4& a, const int4& b) { return a = a + b; } -__device_inline int4 operator>>(const int4& a, int i) +ccl_device_inline int4 operator>>(const int4& a, int i) { #ifdef __KERNEL_SSE__ return _mm_srai_epi32(a.m128, i); @@ -963,7 +963,7 @@ __device_inline int4 operator>>(const int4& a, int i) #endif } -__device_inline int4 min(int4 a, int4 b) +ccl_device_inline int4 min(int4 a, int4 b) { #ifdef __KERNEL_SSE__ return _mm_min_epi32(a.m128, b.m128); @@ -972,7 +972,7 @@ __device_inline int4 min(int4 a, int4 b) #endif } -__device_inline int4 max(int4 a, int4 b) +ccl_device_inline int4 max(int4 a, int4 b) { #ifdef __KERNEL_SSE__ return _mm_max_epi32(a.m128, b.m128); @@ -981,12 +981,12 @@ __device_inline int4 max(int4 a, int4 b) #endif } -__device_inline int4 clamp(const int4& a, const int4& mn, const int4& mx) +ccl_device_inline int4 clamp(const int4& a, const int4& mn, const int4& mx) { return min(max(a, mn), mx); } -__device_inline int4 select(const int4& mask, const int4& a, const int4& b) +ccl_device_inline int4 select(const int4& mask, const int4& a, const int4& b) { #ifdef __KERNEL_SSE__ __m128 m = _mm_cvtepi32_ps(mask); @@ -996,7 +996,7 @@ __device_inline int4 select(const int4& mask, const int4& a, const int4& b) #endif } -__device_inline void print_int4(const char *label, const int4& a) +ccl_device_inline void print_int4(const char *label, const int4& a) { printf("%s: %d %d %d %d\n", label, a.x, a.y, a.z, a.w); } @@ -1007,49 +1007,49 @@ __device_inline void print_int4(const char *label, const int4& a) #ifndef __KERNEL_OPENCL__ -__device_inline int as_int(uint i) +ccl_device_inline int as_int(uint i) { union { uint ui; int i; } u; u.ui = i; return u.i; } -__device_inline uint as_uint(int i) +ccl_device_inline uint as_uint(int i) { union { uint ui; int i; } u; u.i = i; return u.ui; } -__device_inline uint as_uint(float f) +ccl_device_inline uint as_uint(float f) { union { uint i; float f; } u; u.f = f; return u.i; } -__device_inline int __float_as_int(float f) +ccl_device_inline int __float_as_int(float f) { union { int i; float f; } u; u.f = f; return u.i; } -__device_inline float __int_as_float(int i) +ccl_device_inline float __int_as_float(int i) { union { int i; float f; } u; u.i = i; return u.f; } -__device_inline uint __float_as_uint(float f) +ccl_device_inline uint __float_as_uint(float f) { union { uint i; float f; } u; u.f = f; return u.i; } -__device_inline float __uint_as_float(uint i) +ccl_device_inline float __uint_as_float(uint i) { union { uint i; float f; } u; u.i = i; @@ -1065,7 +1065,7 @@ template<class A, class B> A lerp(const A& a, const A& b, const B& t) /* Triangle */ -__device_inline float triangle_area(const float3 v1, const float3 v2, const float3 v3) +ccl_device_inline float triangle_area(const float3 v1, const float3 v2, const float3 v3) { return len(cross(v3 - v2, v1 - v2))*0.5f; } @@ -1074,7 +1074,7 @@ __device_inline float triangle_area(const float3 v1, const float3 v2, const floa /* Orthonormal vectors */ -__device_inline void make_orthonormals(const float3 N, float3 *a, float3 *b) +ccl_device_inline void make_orthonormals(const float3 N, float3 *a, float3 *b) { #if 0 if(fabsf(N.y) >= 0.999f) { @@ -1100,7 +1100,7 @@ __device_inline void make_orthonormals(const float3 N, float3 *a, float3 *b) /* Color division */ -__device_inline float3 safe_divide_color(float3 a, float3 b) +ccl_device_inline float3 safe_divide_color(float3 a, float3 b) { float x, y, z; @@ -1111,7 +1111,7 @@ __device_inline float3 safe_divide_color(float3 a, float3 b) return make_float3(x, y, z); } -__device_inline float3 safe_divide_even_color(float3 a, float3 b) +ccl_device_inline float3 safe_divide_even_color(float3 a, float3 b) { float x, y, z; @@ -1149,7 +1149,7 @@ __device_inline float3 safe_divide_even_color(float3 a, float3 b) /* Rotation of point around axis and angle */ -__device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle) +ccl_device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle) { float costheta = cosf(angle); float sintheta = sinf(angle); @@ -1172,12 +1172,12 @@ __device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle) /* NaN-safe math ops */ -__device_inline float safe_sqrtf(float f) +ccl_device_inline float safe_sqrtf(float f) { return sqrtf(max(f, 0.0f)); } -__device float safe_asinf(float a) +ccl_device float safe_asinf(float a) { if(a <= -1.0f) return -M_PI_2_F; @@ -1187,7 +1187,7 @@ __device float safe_asinf(float a) return asinf(a); } -__device float safe_acosf(float a) +ccl_device float safe_acosf(float a) { if(a <= -1.0f) return M_PI_F; @@ -1197,7 +1197,7 @@ __device float safe_acosf(float a) return acosf(a); } -__device float compatible_powf(float x, float y) +ccl_device float compatible_powf(float x, float y) { /* GPU pow doesn't accept negative x, do manual checks here */ if(x < 0.0f) { @@ -1212,7 +1212,7 @@ __device float compatible_powf(float x, float y) return powf(x, y); } -__device float safe_powf(float a, float b) +ccl_device float safe_powf(float a, float b) { if(b == 0.0f) return 1.0f; @@ -1224,7 +1224,7 @@ __device float safe_powf(float a, float b) return compatible_powf(a, b); } -__device float safe_logf(float a, float b) +ccl_device float safe_logf(float a, float b) { if(a < 0.0f || b < 0.0f) return 0.0f; @@ -1232,19 +1232,19 @@ __device float safe_logf(float a, float b) return logf(a)/logf(b); } -__device float safe_divide(float a, float b) +ccl_device float safe_divide(float a, float b) { return (b != 0.0f)? a/b: 0.0f; } -__device float safe_modulo(float a, float b) +ccl_device float safe_modulo(float a, float b) { return (b != 0.0f)? fmodf(a, b): 0.0f; } /* Ray Intersection */ -__device bool ray_sphere_intersect( +ccl_device bool ray_sphere_intersect( float3 ray_P, float3 ray_D, float ray_t, float3 sphere_P, float sphere_radius, float3 *isect_P, float *isect_t) @@ -1276,7 +1276,7 @@ __device bool ray_sphere_intersect( return false; } -__device bool ray_aligned_disk_intersect( +ccl_device bool ray_aligned_disk_intersect( float3 ray_P, float3 ray_D, float ray_t, float3 disk_P, float disk_radius, float3 *isect_P, float *isect_t) @@ -1305,7 +1305,7 @@ __device bool ray_aligned_disk_intersect( return true; } -__device bool ray_triangle_intersect( +ccl_device bool ray_triangle_intersect( float3 ray_P, float3 ray_D, float ray_t, float3 v0, float3 v1, float3 v2, float3 *isect_P, float *isect_t) @@ -1348,7 +1348,7 @@ __device bool ray_triangle_intersect( return true; } -__device bool ray_quad_intersect( +ccl_device bool ray_quad_intersect( float3 ray_P, float3 ray_D, float ray_t, float3 quad_P, float3 quad_u, float3 quad_v, float3 *isect_P, float *isect_t) |