23 #include "cuda_runtime.h"
40 inline float fminf(
float a,
float b)
50 inline float fmaxf(
float a,
float b)
60 inline int max(
int a,
int b)
70 inline int min(
int a,
int b)
81 return 1.0f / sqrtf(x);
231 return make_float3(
float(a.x),
float(a.y),
float(a.z));
240 return make_float3(
float(a.x),
float(a.y),
float(a.z));
266 inline __host__ __device__ int3
make_int3(int2 a,
int s)
277 return make_int3(
int(a.x),
int(a.y),
int(a.z));
286 return make_int3(
int(a.x),
int(a.y),
int(a.z));
369 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
378 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
404 inline __host__ __device__ int4
make_int4(int3 a,
int w)
415 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
424 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
519 return make_int4(-a.x, -a.y, -a.z, -a.w);
531 inline __host__ __device__ float2
operator+(float2 a, float2 b)
541 inline __host__ __device__
void operator+=(float2 &a, float2 b)
552 inline __host__ __device__ float2
operator+(float2 a,
float b)
562 inline __host__ __device__ float2
operator+(
float b, float2 a)
572 inline __host__ __device__
void operator+=(float2 &a,
float b)
583 inline __host__ __device__ int2
operator+(int2 a, int2 b)
604 inline __host__ __device__ int2
operator+(int2 a,
int b)
614 inline __host__ __device__ int2
operator+(
int b, int2 a)
635 inline __host__ __device__ uint2
operator+(uint2 a, uint2 b)
645 inline __host__ __device__
void operator+=(uint2 &a, uint2 b)
687 inline __host__ __device__ float3
operator+(float3 a, float3 b)
689 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
697 inline __host__ __device__
void operator+=(float3 &a, float3 b)
709 inline __host__ __device__ float3
operator+(float3 a,
float b)
719 inline __host__ __device__
void operator+=(float3 &a,
float b)
731 inline __host__ __device__ int3
operator+(int3 a, int3 b)
733 return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
753 inline __host__ __device__ int3
operator+(int3 a,
int b)
755 return make_int3(a.x + b, a.y + b, a.z + b);
775 inline __host__ __device__ uint3
operator+(uint3 a, uint3 b)
777 return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
785 inline __host__ __device__
void operator+=(uint3 &a, uint3 b)
819 inline __host__ __device__ int3
operator+(
int b, int3 a)
821 return make_int3(a.x + b, a.y + b, a.z + b);
839 inline __host__ __device__ float3
operator+(
float b, float3 a)
849 inline __host__ __device__ float4
operator+(float4 a, float4 b)
851 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
859 inline __host__ __device__
void operator+=(float4 &a, float4 b)
872 inline __host__ __device__ float4
operator+(float4 a,
float b)
874 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
882 inline __host__ __device__ float4
operator+(
float b, float4 a)
884 return make_float4(a.x + b, a.y + b, a.z + b, a.w + b);
892 inline __host__ __device__
void operator+=(float4 &a,
float b)
905 inline __host__ __device__ int4
operator+(int4 a, int4 b)
907 return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
928 inline __host__ __device__ int4
operator+(int4 a,
int b)
930 return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
938 inline __host__ __device__ int4
operator+(
int b, int4 a)
940 return make_int4(a.x + b, a.y + b, a.z + b, a.w + b);
961 inline __host__ __device__ uint4
operator+(uint4 a, uint4 b)
963 return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
971 inline __host__ __device__
void operator+=(uint4 &a, uint4 b)
986 return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
996 return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b);
1021 inline __host__ __device__ float2
operator-(float2 a, float2 b)
1042 inline __host__ __device__ float2
operator-(float2 a,
float b)
1052 inline __host__ __device__ float2
operator-(
float b, float2 a)
1125 inline __host__ __device__ uint2
operator-(uint2 a, uint2 b)
1177 inline __host__ __device__ float3
operator-(float3 a, float3 b)
1179 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
1199 inline __host__ __device__ float3
operator-(float3 a,
float b)
1209 inline __host__ __device__ float3
operator-(
float b, float3 a)
1233 return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
1255 return make_int3(a.x - b, a.y - b, a.z - b);
1265 return make_int3(b - a.x, b - a.y, b - a.z);
1285 inline __host__ __device__ uint3
operator-(uint3 a, uint3 b)
1287 return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
1309 return make_uint3(a.x - b, a.y - b, a.z - b);
1319 return make_uint3(b - a.x, b - a.y, b - a.z);
1339 inline __host__ __device__ float4
operator-(float4 a, float4 b)
1341 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1362 inline __host__ __device__ float4
operator-(float4 a,
float b)
1364 return make_float4(a.x - b, a.y - b, a.z - b, a.w - b);
1387 return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1410 return make_int4(a.x - b, a.y - b, a.z - b, a.w - b);
1420 return make_int4(b - a.x, b - a.y, b - a.z, b - a.w);
1441 inline __host__ __device__ uint4
operator-(uint4 a, uint4 b)
1443 return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
1466 return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b);
1476 return make_uint4(b - a.x, b - a.y, b - a.z, b - a.w);
1501 inline __host__ __device__ float2
operator*(float2 a, float2 b)
1522 inline __host__ __device__ float2
operator*(float2 a,
float b)
1532 inline __host__ __device__ float2
operator*(
float b, float2 a)
1605 inline __host__ __device__ uint2
operator*(uint2 a, uint2 b)
1657 inline __host__ __device__ float3
operator*(float3 a, float3 b)
1659 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
1679 inline __host__ __device__ float3
operator*(float3 a,
float b)
1689 inline __host__ __device__ float3
operator*(
float b, float3 a)
1713 return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
1735 return make_int3(a.x * b, a.y * b, a.z * b);
1745 return make_int3(b * a.x, b * a.y, b * a.z);
1765 inline __host__ __device__ uint3
operator*(uint3 a, uint3 b)
1767 return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
1789 return make_uint3(a.x * b, a.y * b, a.z * b);
1799 return make_uint3(b * a.x, b * a.y, b * a.z);
1819 inline __host__ __device__ float4
operator*(float4 a, float4 b)
1821 return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1842 inline __host__ __device__ float4
operator*(float4 a,
float b)
1844 return make_float4(a.x * b, a.y * b, a.z * b, a.w * b);
1852 inline __host__ __device__ float4
operator*(
float b, float4 a)
1854 return make_float4(b * a.x, b * a.y, b * a.z, b * a.w);
1877 return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1900 return make_int4(a.x * b, a.y * b, a.z * b, a.w * b);
1910 return make_int4(b * a.x, b * a.y, b * a.z, b * a.w);
1931 inline __host__ __device__ uint4
operator*(uint4 a, uint4 b)
1933 return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
1956 return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b);
1966 return make_uint4(b * a.x, b * a.y, b * a.z, b * a.w);
1991 inline __host__ __device__ float2
operator/(float2 a, float2 b)
2012 inline __host__ __device__ float2
operator/(float2 a,
float b)
2033 inline __host__ __device__ float2
operator/(
float b, float2 a)
2043 inline __host__ __device__ float3
operator/(float3 a, float3 b)
2045 return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
2065 inline __host__ __device__ float3
operator/(float3 a,
float b)
2087 inline __host__ __device__ float3
operator/(
float b, float3 a)
2097 inline __host__ __device__ float4
operator/(float4 a, float4 b)
2099 return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
2120 inline __host__ __device__ float4
operator/(float4 a,
float b)
2122 return make_float4(a.x / b, a.y / b, a.z / b, a.w / b);
2143 inline __host__ __device__ float4
operator/(
float b, float4 a)
2145 return make_float4(b / a.x, b / a.y, b / a.z, b / a.w);
2157 inline __host__ __device__ float2
fminf(float2 a, float2 b)
2167 inline __host__ __device__ float3
fminf(float3 a, float3 b)
2177 inline __host__ __device__ float4
fminf(float4 a, float4 b)
2187 inline __host__ __device__ int2
min(int2 a, int2 b)
2197 inline __host__ __device__ int3
min(int3 a, int3 b)
2207 inline __host__ __device__ int4
min(int4 a, int4 b)
2217 inline __host__ __device__ uint2
min(uint2 a, uint2 b)
2227 inline __host__ __device__ uint3
min(uint3 a, uint3 b)
2237 inline __host__ __device__ uint4
min(uint4 a, uint4 b)
2251 inline __host__ __device__ float2
fmaxf(float2 a, float2 b)
2261 inline __host__ __device__ float3
fmaxf(float3 a, float3 b)
2271 inline __host__ __device__ float4
fmaxf(float4 a, float4 b)
2281 inline __host__ __device__ int2
max(int2 a, int2 b)
2291 inline __host__ __device__ int3
max(int3 a, int3 b)
2301 inline __host__ __device__ int4
max(int4 a, int4 b)
2311 inline __host__ __device__ uint2
max(uint2 a, uint2 b)
2321 inline __host__ __device__ uint3
max(uint3 a, uint3 b)
2331 inline __host__ __device__ uint4
max(uint4 a, uint4 b)
2346 inline __device__ __host__
float lerp(
float a,
float b,
float t)
2357 inline __device__ __host__ float2
lerp(float2 a, float2 b,
float t)
2368 inline __device__ __host__ float3
lerp(float3 a, float3 b,
float t)
2379 inline __device__ __host__ float4
lerp(float4 a, float4 b,
float t)
2394 inline __device__ __host__
float clamp(
float f,
float a,
float b)
2405 inline __device__ __host__
int clamp(
int f,
int a,
int b)
2407 return max(a,
min(f, b));
2418 return max(a,
min(f, b));
2427 inline __device__ __host__ float2
clamp(float2 v,
float a,
float b)
2438 inline __device__ __host__ float2
clamp(float2 v, float2 a, float2 b)
2449 inline __device__ __host__ float3
clamp(float3 v,
float a,
float b)
2460 inline __device__ __host__ float3
clamp(float3 v, float3 a, float3 b)
2471 inline __device__ __host__ float4
clamp(float4 v,
float a,
float b)
2473 return make_float4(
clamp(v.x, a, b),
clamp(v.y, a, b),
clamp(v.z, a, b),
clamp(v.w, a, b));
2482 inline __device__ __host__ float4
clamp(float4 v, float4 a, float4 b)
2484 return make_float4(
clamp(v.x, a.x, b.x),
clamp(v.y, a.y, b.y),
clamp(v.z, a.z, b.z),
clamp(v.w, a.w, b.w));
2493 inline __device__ __host__ int2
clamp(int2 v,
int a,
int b)
2504 inline __device__ __host__ int2
clamp(int2 v, int2 a, int2 b)
2515 inline __device__ __host__ int3
clamp(int3 v,
int a,
int b)
2526 inline __device__ __host__ int3
clamp(int3 v, int3 a, int3 b)
2537 inline __device__ __host__ int4
clamp(int4 v,
int a,
int b)
2539 return make_int4(
clamp(v.x, a, b),
clamp(v.y, a, b),
clamp(v.z, a, b),
clamp(v.w, a, b));
2548 inline __device__ __host__ int4
clamp(int4 v, int4 a, int4 b)
2550 return make_int4(
clamp(v.x, a.x, b.x),
clamp(v.y, a.y, b.y),
clamp(v.z, a.z, b.z),
clamp(v.w, a.w, b.w));
2570 inline __device__ __host__ uint2
clamp(uint2 v, uint2 a, uint2 b)
2592 inline __device__ __host__ uint3
clamp(uint3 v, uint3 a, uint3 b)
2605 return make_uint4(
clamp(v.x, a, b),
clamp(v.y, a, b),
clamp(v.z, a, b),
clamp(v.w, a, b));
2614 inline __device__ __host__ uint4
clamp(uint4 v, uint4 a, uint4 b)
2616 return make_uint4(
clamp(v.x, a.x, b.x),
clamp(v.y, a.y, b.y),
clamp(v.z, a.z, b.z),
clamp(v.w, a.w, b.w));
2628 inline __host__ __device__
float dot(float2 a, float2 b)
2630 return a.x * b.x + a.y * b.y;
2638 inline __host__ __device__
float dot(float3 a, float3 b)
2640 return a.x * b.x + a.y * b.y + a.z * b.z;
2648 inline __host__ __device__
float dot(float4 a, float4 b)
2650 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2658 inline __host__ __device__
int dot(int2 a, int2 b)
2660 return a.x * b.x + a.y * b.y;
2668 inline __host__ __device__
int dot(int3 a, int3 b)
2670 return a.x * b.x + a.y * b.y + a.z * b.z;
2678 inline __host__ __device__
int dot(int4 a, int4 b)
2680 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2688 inline __host__ __device__
uint dot(uint2 a, uint2 b)
2690 return a.x * b.x + a.y * b.y;
2698 inline __host__ __device__
uint dot(uint3 a, uint3 b)
2700 return a.x * b.x + a.y * b.y + a.z * b.z;
2708 inline __host__ __device__
uint dot(uint4 a, uint4 b)
2710 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
2721 inline __host__ __device__
float length(float2 v)
2723 return sqrtf(
dot(v, v));
2730 inline __host__ __device__
float length(float3 v)
2732 return sqrtf(
dot(v, v));
2739 inline __host__ __device__
float length(float4 v)
2741 return sqrtf(
dot(v, v));
2786 inline __host__ __device__ float2
floorf(float2 v)
2795 inline __host__ __device__ float3
floorf(float3 v)
2804 inline __host__ __device__ float4
floorf(float4 v)
2817 inline __host__ __device__
float fracf(
float v)
2826 inline __host__ __device__ float2
fracf(float2 v)
2835 inline __host__ __device__ float3
fracf(float3 v)
2844 inline __host__ __device__ float4
fracf(float4 v)
2858 inline __host__ __device__ float2
fmodf(float2 a, float2 b)
2868 inline __host__ __device__ float3
fmodf(float3 a, float3 b)
2878 inline __host__ __device__ float4
fmodf(float4 a, float4 b)
2891 inline __host__ __device__ float2
fabs(float2 v)
2900 inline __host__ __device__ float3
fabs(float3 v)
2909 inline __host__ __device__ float4
fabs(float4 v)
2918 inline __host__ __device__ int2
abs(int2 v)
2927 inline __host__ __device__ int3
abs(int3 v)
2936 inline __host__ __device__ int4
abs(int4 v)
2950 inline __host__ __device__ float3
reflect(float3 i, float3 n)
2952 return i - 2.0f * n *
dot(n,i);
2964 inline __host__ __device__ float3
cross(float3 a, float3 b)
2966 return 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);
2979 inline __device__ __host__
float smoothstep(
float a,
float b,
float x)
2981 float y =
clamp((x - a) / (b - a), 0.0f, 1.0f);
2982 return (y*y*(3.0f - (2.0f*y)));
2991 inline __device__ __host__ float2
smoothstep(float2 a, float2 b, float2 x)
2993 float2 y =
clamp((x - a) / (b - a), 0.0f, 1.0f);
3003 inline __device__ __host__ float3
smoothstep(float3 a, float3 b, float3 x)
3005 float3 y =
clamp((x - a) / (b - a), 0.0f, 1.0f);
3015 inline __device__ __host__ float4
smoothstep(float4 a, float4 b, float4 x)
3017 float4 y =
clamp((x - a) / (b - a), 0.0f, 1.0f);
3021 #endif // HELPER_MATH_H