cl_MiniCL_Defs.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <float.h>
00017 #include <math.h>
00018 #include "LinearMath/btScalar.h"
00019
00020 #include "MiniCL/cl.h"
00021
00022
00023 #define __kernel
00024 #define __global
00025 #define __local
00026 #define get_global_id(a) __guid_arg
00027 #define get_local_id(a) ((__guid_arg) % gMiniCLNumOutstandingTasks)
00028 #define get_local_size(a) (gMiniCLNumOutstandingTasks)
00029 #define get_group_id(a) ((__guid_arg) / gMiniCLNumOutstandingTasks)
00030
00031 #define CLK_LOCAL_MEM_FENCE 0x01
00032 #define CLK_GLOBAL_MEM_FENCE 0x02
00033
00034 static void barrier(unsigned int a)
00035 {
00036
00037 }
00038
00039 struct float8
00040 {
00041 float s0;
00042 float s1;
00043 float s2;
00044 float s3;
00045 float s4;
00046 float s5;
00047 float s6;
00048 float s7;
00049
00050 float8(float scalar)
00051 {
00052 s0=s1=s2=s3=s4=s5=s6=s7=scalar;
00053 }
00054 };
00055
00056 struct float4
00057 {
00058 float x,y,z,w;
00059 float4() {}
00060 float4(float v)
00061 {
00062 x = y = z = w = v;
00063 }
00064 float4 operator*(const float4& other)
00065 {
00066 float4 tmp;
00067 tmp.x = x*other.x;
00068 tmp.y = y*other.y;
00069 tmp.z = z*other.z;
00070 tmp.w = w*other.w;
00071 return tmp;
00072 }
00073
00074 float4 operator*(const float& other)
00075 {
00076 float4 tmp;
00077 tmp.x = x*other;
00078 tmp.y = y*other;
00079 tmp.z = z*other;
00080 tmp.w = w*other;
00081 return tmp;
00082 }
00083
00084
00085
00086 float4& operator+=(const float4& other)
00087 {
00088 x += other.x;
00089 y += other.y;
00090 z += other.z;
00091 w += other.w;
00092 return *this;
00093 }
00094
00095 float4& operator-=(const float4& other)
00096 {
00097 x -= other.x;
00098 y -= other.y;
00099 z -= other.z;
00100 w -= other.w;
00101 return *this;
00102 }
00103
00104 float4& operator *=(float scalar)
00105 {
00106 x *= scalar;
00107 y *= scalar;
00108 z *= scalar;
00109 w *= scalar;
00110 return (*this);
00111 }
00112
00113
00114
00115
00116
00117 };
00118
00119 static float4 fabs(const float4& a)
00120 {
00121 float4 tmp;
00122 tmp.x = a.x < 0.f ? 0.f : a.x;
00123 tmp.y = a.y < 0.f ? 0.f : a.y;
00124 tmp.z = a.z < 0.f ? 0.f : a.z;
00125 tmp.w = a.w < 0.f ? 0.f : a.w;
00126 return tmp;
00127 }
00128 static float4 operator+(const float4& a,const float4& b)
00129 {
00130 float4 tmp;
00131 tmp.x = a.x + b.x;
00132 tmp.y = a.y + b.y;
00133 tmp.z = a.z + b.z;
00134 tmp.w = a.w + b.w;
00135 return tmp;
00136 }
00137
00138 static float4 operator-(const float4& a,const float4& b)
00139 {
00140 float4 tmp;
00141 tmp.x = a.x - b.x;
00142 tmp.y = a.y - b.y;
00143 tmp.z = a.z - b.z;
00144 tmp.w = a.w - b.w;
00145 return tmp;
00146 }
00147 static float4 operator*(float a,const float4& b)
00148 {
00149 float4 tmp;
00150 tmp.x = a * b.x;
00151 tmp.y = a * b.y;
00152 tmp.z = a * b.z;
00153 tmp.w = a * b.w;
00154 return tmp;
00155 }
00156
00157
00158 static float dot(const float4&a ,const float4& b)
00159 {
00160 float4 tmp;
00161 tmp.x = a.x*b.x;
00162 tmp.y = a.y*b.y;
00163 tmp.z = a.z*b.z;
00164 tmp.w = a.w*b.w;
00165 return tmp.x+tmp.y+tmp.z+tmp.w;
00166 }
00167
00168 static float4 cross(const float4&a ,const float4& b)
00169 {
00170 float4 tmp;
00171 tmp.x = a.y*b.z - a.z*b.y;
00172 tmp.y = -a.x*b.z + a.z*b.x;
00173 tmp.z = a.x*b.y - a.y*b.x;
00174 tmp.w = 0.f;
00175 return tmp;
00176 }
00177
00178 static float max(float a, float b)
00179 {
00180 return (a >= b) ? a : b;
00181 }
00182
00183
00184 static float min(float a, float b)
00185 {
00186 return (a <= b) ? a : b;
00187 }
00188
00189 static float fmax(float a, float b)
00190 {
00191 return (a >= b) ? a : b;
00192 }
00193
00194 static float fmin(float a, float b)
00195 {
00196 return (a <= b) ? a : b;
00197 }
00198
00199 struct int2
00200 {
00201 int x,y;
00202 };
00203
00204 struct uint2
00205 {
00206 unsigned int x,y;
00207 };
00208
00209
00210
00211 typedef unsigned int uint;
00212
00213 struct int4
00214 {
00215 int x,y,z,w;
00216 };
00217
00218 struct uint4
00219 {
00220 unsigned int x,y,z,w;
00221 uint4() {}
00222 uint4(uint val) { x = y = z = w = val; }
00223 uint4& operator+=(const uint4& other)
00224 {
00225 x += other.x;
00226 y += other.y;
00227 z += other.z;
00228 w += other.w;
00229 return *this;
00230 }
00231 };
00232 static uint4 operator+(const uint4& a,const uint4& b)
00233 {
00234 uint4 tmp;
00235 tmp.x = a.x + b.x;
00236 tmp.y = a.y + b.y;
00237 tmp.z = a.z + b.z;
00238 tmp.w = a.w + b.w;
00239 return tmp;
00240 }
00241 static uint4 operator-(const uint4& a,const uint4& b)
00242 {
00243 uint4 tmp;
00244 tmp.x = a.x - b.x;
00245 tmp.y = a.y - b.y;
00246 tmp.z = a.z - b.z;
00247 tmp.w = a.w - b.w;
00248 return tmp;
00249 }
00250
00251 #define native_sqrt sqrtf
00252 #define native_sin sinf
00253 #define native_cos cosf
00254 #define native_powr powf
00255
00256 #define GUID_ARG ,int __guid_arg
00257 #define GUID_ARG_VAL ,__guid_arg
00258
00259
00260 #define as_int(a) (*((int*)&(a)))
00261
00262 extern "C" int gMiniCLNumOutstandingTasks;
00263
00264
00265