cl_MiniCL_Defs.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library, Copyright (c) 2007 Erwin Coumans
  3. This software is provided 'as-is', without any express or implied warranty.
  4. In no event will the authors be held liable for any damages arising from the use of this software.
  5. Permission is granted to anyone to use this software for any purpose,
  6. including commercial applications, and to alter it and redistribute it freely,
  7. subject to the following restrictions:
  8. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  9. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  10. 3. This notice may not be removed or altered from any source distribution.
  11. */
  12. #include <float.h>
  13. #include <math.h>
  14. #include "bullet/LinearMath/btScalar.h"
  15. #include "bullet/MiniCL/cl.h"
  16. #define __kernel
  17. #define __global
  18. #define __local
  19. #define get_global_id(a) __guid_arg
  20. #define get_local_id(a) ((__guid_arg) % gMiniCLNumOutstandingTasks)
  21. #define get_local_size(a) (gMiniCLNumOutstandingTasks)
  22. #define get_group_id(a) ((__guid_arg) / gMiniCLNumOutstandingTasks)
  23. //static unsigned int as_uint(float val) { return *((unsigned int*)&val); }
  24. #define CLK_LOCAL_MEM_FENCE 0x01
  25. #define CLK_GLOBAL_MEM_FENCE 0x02
  26. static void barrier(unsigned int a)
  27. {
  28. // TODO : implement
  29. }
  30. //ATTRIBUTE_ALIGNED16(struct) float8
  31. struct float8
  32. {
  33. float s0;
  34. float s1;
  35. float s2;
  36. float s3;
  37. float s4;
  38. float s5;
  39. float s6;
  40. float s7;
  41. float8(float scalar)
  42. {
  43. s0=s1=s2=s3=s4=s5=s6=s7=scalar;
  44. }
  45. };
  46. float select( float arg0, float arg1, bool select)
  47. {
  48. if (select)
  49. return arg0;
  50. return arg1;
  51. }
  52. #define __constant
  53. struct float3
  54. {
  55. float x,y,z;
  56. float3& operator+=(const float3& other)
  57. {
  58. x += other.x;
  59. y += other.y;
  60. z += other.z;
  61. return *this;
  62. }
  63. float3& operator-=(const float3& other)
  64. {
  65. x -= other.x;
  66. y -= other.y;
  67. z -= other.z;
  68. return *this;
  69. }
  70. };
  71. static float dot(const float3&a ,const float3& b)
  72. {
  73. float3 tmp;
  74. tmp.x = a.x*b.x;
  75. tmp.y = a.y*b.y;
  76. tmp.z = a.z*b.z;
  77. return tmp.x+tmp.y+tmp.z;
  78. }
  79. static float3 operator-(const float3& a,const float3& b)
  80. {
  81. float3 tmp;
  82. tmp.x = a.x - b.x;
  83. tmp.y = a.y - b.y;
  84. tmp.z = a.z - b.z;
  85. return tmp;
  86. }
  87. static float3 operator*(const float& scalar,const float3& b)
  88. {
  89. float3 tmp;
  90. tmp.x = scalar * b.x;
  91. tmp.y = scalar * b.y;
  92. tmp.z = scalar * b.z;
  93. return tmp;
  94. }
  95. static float3 operator*(const float3& a,const float& scalar)
  96. {
  97. float3 tmp;
  98. tmp.x = a.x * scalar;
  99. tmp.y = a.y * scalar;
  100. tmp.z = a.z * scalar;
  101. return tmp;
  102. }
  103. static float3 operator*(const float3& a,const float3& b)
  104. {
  105. float3 tmp;
  106. tmp.x = a.x * b.x;
  107. tmp.y = a.y * b.y;
  108. tmp.z = a.z * b.z;
  109. return tmp;
  110. }
  111. //ATTRIBUTE_ALIGNED16(struct) float4
  112. struct float4
  113. {
  114. union
  115. {
  116. struct {
  117. float x;
  118. float y;
  119. float z;
  120. };
  121. float3 xyz;
  122. };
  123. float w;
  124. float4() {}
  125. float4(float v0, float v1, float v2, float v3)
  126. {
  127. x=v0;
  128. y=v1;
  129. z=v2;
  130. w=v3;
  131. }
  132. float4(float3 xyz, float scalarW)
  133. {
  134. x = xyz.x;
  135. y = xyz.y;
  136. z = xyz.z;
  137. w = scalarW;
  138. }
  139. float4(float v)
  140. {
  141. x = y = z = w = v;
  142. }
  143. float4 operator*(const float4& other)
  144. {
  145. float4 tmp;
  146. tmp.x = x*other.x;
  147. tmp.y = y*other.y;
  148. tmp.z = z*other.z;
  149. tmp.w = w*other.w;
  150. return tmp;
  151. }
  152. float4 operator*(const float& other)
  153. {
  154. float4 tmp;
  155. tmp.x = x*other;
  156. tmp.y = y*other;
  157. tmp.z = z*other;
  158. tmp.w = w*other;
  159. return tmp;
  160. }
  161. float4& operator+=(const float4& other)
  162. {
  163. x += other.x;
  164. y += other.y;
  165. z += other.z;
  166. w += other.w;
  167. return *this;
  168. }
  169. float4& operator-=(const float4& other)
  170. {
  171. x -= other.x;
  172. y -= other.y;
  173. z -= other.z;
  174. w -= other.w;
  175. return *this;
  176. }
  177. float4& operator *=(float scalar)
  178. {
  179. x *= scalar;
  180. y *= scalar;
  181. z *= scalar;
  182. w *= scalar;
  183. return (*this);
  184. }
  185. };
  186. static float4 fabs(const float4& a)
  187. {
  188. float4 tmp;
  189. tmp.x = a.x < 0.f ? 0.f : a.x;
  190. tmp.y = a.y < 0.f ? 0.f : a.y;
  191. tmp.z = a.z < 0.f ? 0.f : a.z;
  192. tmp.w = a.w < 0.f ? 0.f : a.w;
  193. return tmp;
  194. }
  195. static float4 operator+(const float4& a,const float4& b)
  196. {
  197. float4 tmp;
  198. tmp.x = a.x + b.x;
  199. tmp.y = a.y + b.y;
  200. tmp.z = a.z + b.z;
  201. tmp.w = a.w + b.w;
  202. return tmp;
  203. }
  204. static float8 operator+(const float8& a,const float8& b)
  205. {
  206. float8 tmp(0);
  207. tmp.s0 = a.s0 + b.s0;
  208. tmp.s1 = a.s1 + b.s1;
  209. tmp.s2 = a.s2 + b.s2;
  210. tmp.s3 = a.s3 + b.s3;
  211. tmp.s4 = a.s4 + b.s4;
  212. tmp.s5 = a.s5 + b.s5;
  213. tmp.s6 = a.s6 + b.s6;
  214. tmp.s7 = a.s7 + b.s7;
  215. return tmp;
  216. }
  217. static float4 operator-(const float4& a,const float4& b)
  218. {
  219. float4 tmp;
  220. tmp.x = a.x - b.x;
  221. tmp.y = a.y - b.y;
  222. tmp.z = a.z - b.z;
  223. tmp.w = a.w - b.w;
  224. return tmp;
  225. }
  226. static float8 operator-(const float8& a,const float8& b)
  227. {
  228. float8 tmp(0);
  229. tmp.s0 = a.s0 - b.s0;
  230. tmp.s1 = a.s1 - b.s1;
  231. tmp.s2 = a.s2 - b.s2;
  232. tmp.s3 = a.s3 - b.s3;
  233. tmp.s4 = a.s4 - b.s4;
  234. tmp.s5 = a.s5 - b.s5;
  235. tmp.s6 = a.s6 - b.s6;
  236. tmp.s7 = a.s7 - b.s7;
  237. return tmp;
  238. }
  239. static float4 operator*(float a,const float4& b)
  240. {
  241. float4 tmp;
  242. tmp.x = a * b.x;
  243. tmp.y = a * b.y;
  244. tmp.z = a * b.z;
  245. tmp.w = a * b.w;
  246. return tmp;
  247. }
  248. static float4 operator/(const float4& b,float a)
  249. {
  250. float4 tmp;
  251. tmp.x = b.x/a;
  252. tmp.y = b.y/a;
  253. tmp.z = b.z/a;
  254. tmp.w = b.w/a;
  255. return tmp;
  256. }
  257. static float dot(const float4&a ,const float4& b)
  258. {
  259. float4 tmp;
  260. tmp.x = a.x*b.x;
  261. tmp.y = a.y*b.y;
  262. tmp.z = a.z*b.z;
  263. tmp.w = a.w*b.w;
  264. return tmp.x+tmp.y+tmp.z+tmp.w;
  265. }
  266. static float length(const float4&a)
  267. {
  268. float l = sqrtf(a.x*a.x+a.y*a.y+a.z*a.z);
  269. return l;
  270. }
  271. static float4 normalize(const float4&a)
  272. {
  273. float4 tmp;
  274. float l = length(a);
  275. tmp = 1.f/l*a;
  276. return tmp;
  277. }
  278. static float4 cross(const float4&a ,const float4& b)
  279. {
  280. float4 tmp;
  281. tmp.x = a.y*b.z - a.z*b.y;
  282. tmp.y = -a.x*b.z + a.z*b.x;
  283. tmp.z = a.x*b.y - a.y*b.x;
  284. tmp.w = 0.f;
  285. return tmp;
  286. }
  287. static float max(float a, float b)
  288. {
  289. return (a >= b) ? a : b;
  290. }
  291. static float min(float a, float b)
  292. {
  293. return (a <= b) ? a : b;
  294. }
  295. static float fmax(float a, float b)
  296. {
  297. return (a >= b) ? a : b;
  298. }
  299. static float fmin(float a, float b)
  300. {
  301. return (a <= b) ? a : b;
  302. }
  303. struct int2
  304. {
  305. int x,y;
  306. };
  307. struct uint2
  308. {
  309. unsigned int x,y;
  310. };
  311. //typedef int2 uint2;
  312. typedef unsigned int uint;
  313. struct int4
  314. {
  315. int x,y,z,w;
  316. };
  317. struct uint4
  318. {
  319. unsigned int x,y,z,w;
  320. uint4() {}
  321. uint4(uint val) { x = y = z = w = val; }
  322. uint4& operator+=(const uint4& other)
  323. {
  324. x += other.x;
  325. y += other.y;
  326. z += other.z;
  327. w += other.w;
  328. return *this;
  329. }
  330. };
  331. static uint4 operator+(const uint4& a,const uint4& b)
  332. {
  333. uint4 tmp;
  334. tmp.x = a.x + b.x;
  335. tmp.y = a.y + b.y;
  336. tmp.z = a.z + b.z;
  337. tmp.w = a.w + b.w;
  338. return tmp;
  339. }
  340. static uint4 operator-(const uint4& a,const uint4& b)
  341. {
  342. uint4 tmp;
  343. tmp.x = a.x - b.x;
  344. tmp.y = a.y - b.y;
  345. tmp.z = a.z - b.z;
  346. tmp.w = a.w - b.w;
  347. return tmp;
  348. }
  349. #define native_sqrt sqrtf
  350. #define native_sin sinf
  351. #define native_cos cosf
  352. #define native_powr powf
  353. #define GUID_ARG ,int __guid_arg
  354. #define GUID_ARG_VAL ,__guid_arg
  355. #define as_int(a) (*((int*)&(a)))
  356. extern "C" int gMiniCLNumOutstandingTasks;
  357. // extern "C" void __kernel_func();