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
00032
00033
00034 #define CLK_LOCAL_MEM_FENCE 0x01
00035 #define CLK_GLOBAL_MEM_FENCE 0x02
00036
00037 static void barrier(unsigned int a)
00038 {
00039
00040 }
00041
00042
00043 struct float8
00044 {
00045 float s0;
00046 float s1;
00047 float s2;
00048 float s3;
00049 float s4;
00050 float s5;
00051 float s6;
00052 float s7;
00053
00054 float8(float scalar)
00055 {
00056 s0=s1=s2=s3=s4=s5=s6=s7=scalar;
00057 }
00058 };
00059
00060
00061 float select( float arg0, float arg1, bool select)
00062 {
00063 if (select)
00064 return arg0;
00065 return arg1;
00066 }
00067
00068 #define __constant
00069
00070
00071 struct float3
00072 {
00073 float x,y,z;
00074
00075 float3& operator+=(const float3& other)
00076 {
00077 x += other.x;
00078 y += other.y;
00079 z += other.z;
00080 return *this;
00081 }
00082
00083 float3& operator-=(const float3& other)
00084 {
00085 x -= other.x;
00086 y -= other.y;
00087 z -= other.z;
00088 return *this;
00089 }
00090
00091 };
00092
00093 static float dot(const float3&a ,const float3& b)
00094 {
00095 float3 tmp;
00096 tmp.x = a.x*b.x;
00097 tmp.y = a.y*b.y;
00098 tmp.z = a.z*b.z;
00099 return tmp.x+tmp.y+tmp.z;
00100 }
00101
00102 static float3 operator-(const float3& a,const float3& b)
00103 {
00104 float3 tmp;
00105 tmp.x = a.x - b.x;
00106 tmp.y = a.y - b.y;
00107 tmp.z = a.z - b.z;
00108 return tmp;
00109 }
00110
00111 static float3 operator*(const float& scalar,const float3& b)
00112 {
00113 float3 tmp;
00114 tmp.x = scalar * b.x;
00115 tmp.y = scalar * b.y;
00116 tmp.z = scalar * b.z;
00117 return tmp;
00118 }
00119
00120 static float3 operator*(const float3& a,const float& scalar)
00121 {
00122 float3 tmp;
00123 tmp.x = a.x * scalar;
00124 tmp.y = a.y * scalar;
00125 tmp.z = a.z * scalar;
00126 return tmp;
00127 }
00128
00129
00130 static float3 operator*(const float3& a,const float3& b)
00131 {
00132 float3 tmp;
00133 tmp.x = a.x * b.x;
00134 tmp.y = a.y * b.y;
00135 tmp.z = a.z * b.z;
00136 return tmp;
00137 }
00138
00139
00140
00141 struct float4
00142 {
00143 union
00144 {
00145 struct {
00146 float x;
00147 float y;
00148 float z;
00149 };
00150 float3 xyz;
00151 };
00152 float w;
00153
00154 float4() {}
00155
00156 float4(float v0, float v1, float v2, float v3)
00157 {
00158 x=v0;
00159 y=v1;
00160 z=v2;
00161 w=v3;
00162
00163 }
00164 float4(float3 xyz, float scalarW)
00165 {
00166 x = xyz.x;
00167 y = xyz.y;
00168 z = xyz.z;
00169 w = scalarW;
00170 }
00171
00172 float4(float v)
00173 {
00174 x = y = z = w = v;
00175 }
00176 float4 operator*(const float4& other)
00177 {
00178 float4 tmp;
00179 tmp.x = x*other.x;
00180 tmp.y = y*other.y;
00181 tmp.z = z*other.z;
00182 tmp.w = w*other.w;
00183 return tmp;
00184 }
00185
00186
00187
00188 float4 operator*(const float& other)
00189 {
00190 float4 tmp;
00191 tmp.x = x*other;
00192 tmp.y = y*other;
00193 tmp.z = z*other;
00194 tmp.w = w*other;
00195 return tmp;
00196 }
00197
00198
00199
00200 float4& operator+=(const float4& other)
00201 {
00202 x += other.x;
00203 y += other.y;
00204 z += other.z;
00205 w += other.w;
00206 return *this;
00207 }
00208
00209 float4& operator-=(const float4& other)
00210 {
00211 x -= other.x;
00212 y -= other.y;
00213 z -= other.z;
00214 w -= other.w;
00215 return *this;
00216 }
00217
00218 float4& operator *=(float scalar)
00219 {
00220 x *= scalar;
00221 y *= scalar;
00222 z *= scalar;
00223 w *= scalar;
00224 return (*this);
00225 }
00226
00227
00228
00229
00230
00231 };
00232
00233 static float4 fabs(const float4& a)
00234 {
00235 float4 tmp;
00236 tmp.x = a.x < 0.f ? 0.f : a.x;
00237 tmp.y = a.y < 0.f ? 0.f : a.y;
00238 tmp.z = a.z < 0.f ? 0.f : a.z;
00239 tmp.w = a.w < 0.f ? 0.f : a.w;
00240 return tmp;
00241 }
00242 static float4 operator+(const float4& a,const float4& b)
00243 {
00244 float4 tmp;
00245 tmp.x = a.x + b.x;
00246 tmp.y = a.y + b.y;
00247 tmp.z = a.z + b.z;
00248 tmp.w = a.w + b.w;
00249 return tmp;
00250 }
00251
00252
00253 static float8 operator+(const float8& a,const float8& b)
00254 {
00255 float8 tmp(0);
00256 tmp.s0 = a.s0 + b.s0;
00257 tmp.s1 = a.s1 + b.s1;
00258 tmp.s2 = a.s2 + b.s2;
00259 tmp.s3 = a.s3 + b.s3;
00260 tmp.s4 = a.s4 + b.s4;
00261 tmp.s5 = a.s5 + b.s5;
00262 tmp.s6 = a.s6 + b.s6;
00263 tmp.s7 = a.s7 + b.s7;
00264 return tmp;
00265 }
00266
00267
00268 static float4 operator-(const float4& a,const float4& b)
00269 {
00270 float4 tmp;
00271 tmp.x = a.x - b.x;
00272 tmp.y = a.y - b.y;
00273 tmp.z = a.z - b.z;
00274 tmp.w = a.w - b.w;
00275 return tmp;
00276 }
00277
00278 static float8 operator-(const float8& a,const float8& b)
00279 {
00280 float8 tmp(0);
00281 tmp.s0 = a.s0 - b.s0;
00282 tmp.s1 = a.s1 - b.s1;
00283 tmp.s2 = a.s2 - b.s2;
00284 tmp.s3 = a.s3 - b.s3;
00285 tmp.s4 = a.s4 - b.s4;
00286 tmp.s5 = a.s5 - b.s5;
00287 tmp.s6 = a.s6 - b.s6;
00288 tmp.s7 = a.s7 - b.s7;
00289 return tmp;
00290 }
00291
00292 static float4 operator*(float a,const float4& b)
00293 {
00294 float4 tmp;
00295 tmp.x = a * b.x;
00296 tmp.y = a * b.y;
00297 tmp.z = a * b.z;
00298 tmp.w = a * b.w;
00299 return tmp;
00300 }
00301
00302 static float4 operator/(const float4& b,float a)
00303 {
00304 float4 tmp;
00305 tmp.x = b.x/a;
00306 tmp.y = b.y/a;
00307 tmp.z = b.z/a;
00308 tmp.w = b.w/a;
00309 return tmp;
00310 }
00311
00312
00313
00314
00315
00316 static float dot(const float4&a ,const float4& b)
00317 {
00318 float4 tmp;
00319 tmp.x = a.x*b.x;
00320 tmp.y = a.y*b.y;
00321 tmp.z = a.z*b.z;
00322 tmp.w = a.w*b.w;
00323 return tmp.x+tmp.y+tmp.z+tmp.w;
00324 }
00325
00326 static float length(const float4&a)
00327 {
00328 float l = sqrtf(a.x*a.x+a.y*a.y+a.z*a.z);
00329 return l;
00330 }
00331
00332 static float4 normalize(const float4&a)
00333 {
00334 float4 tmp;
00335 float l = length(a);
00336 tmp = 1.f/l*a;
00337 return tmp;
00338 }
00339
00340
00341
00342 static float4 cross(const float4&a ,const float4& b)
00343 {
00344 float4 tmp;
00345 tmp.x = a.y*b.z - a.z*b.y;
00346 tmp.y = -a.x*b.z + a.z*b.x;
00347 tmp.z = a.x*b.y - a.y*b.x;
00348 tmp.w = 0.f;
00349 return tmp;
00350 }
00351
00352 static float max(float a, float b)
00353 {
00354 return (a >= b) ? a : b;
00355 }
00356
00357
00358 static float min(float a, float b)
00359 {
00360 return (a <= b) ? a : b;
00361 }
00362
00363 static float fmax(float a, float b)
00364 {
00365 return (a >= b) ? a : b;
00366 }
00367
00368 static float fmin(float a, float b)
00369 {
00370 return (a <= b) ? a : b;
00371 }
00372
00373 struct int2
00374 {
00375 int x,y;
00376 };
00377
00378 struct uint2
00379 {
00380 unsigned int x,y;
00381 };
00382
00383
00384
00385 typedef unsigned int uint;
00386
00387 struct int4
00388 {
00389 int x,y,z,w;
00390 };
00391
00392 struct uint4
00393 {
00394 unsigned int x,y,z,w;
00395 uint4() {}
00396 uint4(uint val) { x = y = z = w = val; }
00397 uint4& operator+=(const uint4& other)
00398 {
00399 x += other.x;
00400 y += other.y;
00401 z += other.z;
00402 w += other.w;
00403 return *this;
00404 }
00405 };
00406 static uint4 operator+(const uint4& a,const uint4& b)
00407 {
00408 uint4 tmp;
00409 tmp.x = a.x + b.x;
00410 tmp.y = a.y + b.y;
00411 tmp.z = a.z + b.z;
00412 tmp.w = a.w + b.w;
00413 return tmp;
00414 }
00415 static uint4 operator-(const uint4& a,const uint4& b)
00416 {
00417 uint4 tmp;
00418 tmp.x = a.x - b.x;
00419 tmp.y = a.y - b.y;
00420 tmp.z = a.z - b.z;
00421 tmp.w = a.w - b.w;
00422 return tmp;
00423 }
00424
00425 #define native_sqrt sqrtf
00426 #define native_sin sinf
00427 #define native_cos cosf
00428 #define native_powr powf
00429
00430 #define GUID_ARG ,int __guid_arg
00431 #define GUID_ARG_VAL ,__guid_arg
00432
00433
00434 #define as_int(a) (*((int*)&(a)))
00435
00436 extern "C" int gMiniCLNumOutstandingTasks;
00437
00438
00439