btGpuDefines.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
  3. Copyright (C) 2006, 2009 Sony Computer Entertainment Inc.
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. // definitions for "GPU on CPU" code
  14. #ifndef BT_GPU_DEFINES_H
  15. #define BT_GPU_DEFINES_H
  16. typedef unsigned int uint;
  17. struct int2
  18. {
  19. int x, y;
  20. };
  21. struct uint2
  22. {
  23. unsigned int x, y;
  24. };
  25. struct int3
  26. {
  27. int x, y, z;
  28. };
  29. struct uint3
  30. {
  31. unsigned int x, y, z;
  32. };
  33. struct float4
  34. {
  35. float x, y, z, w;
  36. };
  37. struct float3
  38. {
  39. float x, y, z;
  40. };
  41. #define BT_GPU___device__ inline
  42. #define BT_GPU___devdata__
  43. #define BT_GPU___constant__
  44. #define BT_GPU_max(a, b) ((a) > (b) ? (a) : (b))
  45. #define BT_GPU_min(a, b) ((a) < (b) ? (a) : (b))
  46. #define BT_GPU_params s3DGridBroadphaseParams
  47. #define BT_GPU___mul24(a, b) ((a)*(b))
  48. #define BT_GPU___global__ inline
  49. #define BT_GPU___shared__ static
  50. #define BT_GPU___syncthreads()
  51. #define CUDART_PI_F SIMD_PI
  52. static inline uint2 bt3dGrid_make_uint2(unsigned int x, unsigned int y)
  53. {
  54. uint2 t; t.x = x; t.y = y; return t;
  55. }
  56. #define BT_GPU_make_uint2(x, y) bt3dGrid_make_uint2(x, y)
  57. static inline int3 bt3dGrid_make_int3(int x, int y, int z)
  58. {
  59. int3 t; t.x = x; t.y = y; t.z = z; return t;
  60. }
  61. #define BT_GPU_make_int3(x, y, z) bt3dGrid_make_int3(x, y, z)
  62. static inline float3 bt3dGrid_make_float3(float x, float y, float z)
  63. {
  64. float3 t; t.x = x; t.y = y; t.z = z; return t;
  65. }
  66. #define BT_GPU_make_float3(x, y, z) bt3dGrid_make_float3(x, y, z)
  67. static inline float3 bt3dGrid_make_float34(float4 f)
  68. {
  69. float3 t; t.x = f.x; t.y = f.y; t.z = f.z; return t;
  70. }
  71. #define BT_GPU_make_float34(f) bt3dGrid_make_float34(f)
  72. static inline float3 bt3dGrid_make_float31(float f)
  73. {
  74. float3 t; t.x = t.y = t.z = f; return t;
  75. }
  76. #define BT_GPU_make_float31(x) bt3dGrid_make_float31(x)
  77. static inline float4 bt3dGrid_make_float42(float3 v, float f)
  78. {
  79. float4 t; t.x = v.x; t.y = v.y; t.z = v.z; t.w = f; return t;
  80. }
  81. #define BT_GPU_make_float42(a, b) bt3dGrid_make_float42(a, b)
  82. static inline float4 bt3dGrid_make_float44(float a, float b, float c, float d)
  83. {
  84. float4 t; t.x = a; t.y = b; t.z = c; t.w = d; return t;
  85. }
  86. #define BT_GPU_make_float44(a, b, c, d) bt3dGrid_make_float44(a, b, c, d)
  87. inline int3 operator+(int3 a, int3 b)
  88. {
  89. return bt3dGrid_make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
  90. }
  91. inline float4 operator+(const float4& a, const float4& b)
  92. {
  93. float4 r; r.x = a.x+b.x; r.y = a.y+b.y; r.z = a.z+b.z; r.w = a.w+b.w; return r;
  94. }
  95. inline float4 operator*(const float4& a, float fact)
  96. {
  97. float4 r; r.x = a.x*fact; r.y = a.y*fact; r.z = a.z*fact; r.w = a.w*fact; return r;
  98. }
  99. inline float4 operator*(float fact, float4& a)
  100. {
  101. return (a * fact);
  102. }
  103. inline float4& operator*=(float4& a, float fact)
  104. {
  105. a = fact * a;
  106. return a;
  107. }
  108. inline float4& operator+=(float4& a, const float4& b)
  109. {
  110. a = a + b;
  111. return a;
  112. }
  113. inline float3 operator+(const float3& a, const float3& b)
  114. {
  115. float3 r; r.x = a.x+b.x; r.y = a.y+b.y; r.z = a.z+b.z; return r;
  116. }
  117. inline float3 operator-(const float3& a, const float3& b)
  118. {
  119. float3 r; r.x = a.x-b.x; r.y = a.y-b.y; r.z = a.z-b.z; return r;
  120. }
  121. static inline float bt3dGrid_dot(float3& a, float3& b)
  122. {
  123. return a.x*b.x+a.y*b.y+a.z*b.z;
  124. }
  125. #define BT_GPU_dot(a,b) bt3dGrid_dot(a,b)
  126. static inline float bt3dGrid_dot4(float4& a, float4& b)
  127. {
  128. return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w;
  129. }
  130. #define BT_GPU_dot4(a,b) bt3dGrid_dot4(a,b)
  131. static inline float3 bt3dGrid_cross(const float3& a, const float3& b)
  132. {
  133. float3 r; r.x = a.y*b.z-a.z*b.y; r.y = -a.x*b.z+a.z*b.x; r.z = a.x*b.y-a.y*b.x; return r;
  134. }
  135. #define BT_GPU_cross(a,b) bt3dGrid_cross(a,b)
  136. inline float3 operator*(const float3& a, float fact)
  137. {
  138. float3 r; r.x = a.x*fact; r.y = a.y*fact; r.z = a.z*fact; return r;
  139. }
  140. inline float3& operator+=(float3& a, const float3& b)
  141. {
  142. a = a + b;
  143. return a;
  144. }
  145. inline float3& operator-=(float3& a, const float3& b)
  146. {
  147. a = a - b;
  148. return a;
  149. }
  150. inline float3& operator*=(float3& a, float fact)
  151. {
  152. a = a * fact;
  153. return a;
  154. }
  155. inline float3 operator-(const float3& v)
  156. {
  157. float3 r; r.x = -v.x; r.y = -v.y; r.z = -v.z; return r;
  158. }
  159. #define BT_GPU_FETCH(a, b) a[b]
  160. #define BT_GPU_FETCH4(a, b) a[b]
  161. #define BT_GPU_PREF(func) btGpu_##func
  162. #define BT_GPU_SAFE_CALL(func) func
  163. #define BT_GPU_Memset memset
  164. #define BT_GPU_MemcpyToSymbol(a, b, c) memcpy(&a, b, c)
  165. #define BT_GPU_BindTexture(a, b, c, d)
  166. #define BT_GPU_UnbindTexture(a)
  167. static uint2 s_blockIdx, s_blockDim, s_threadIdx;
  168. #define BT_GPU_blockIdx s_blockIdx
  169. #define BT_GPU_blockDim s_blockDim
  170. #define BT_GPU_threadIdx s_threadIdx
  171. #define BT_GPU_EXECKERNEL(numb, numt, kfunc, args) {s_blockDim.x=numt;for(int nb=0;nb<numb;nb++){s_blockIdx.x=nb;for(int nt=0;nt<numt;nt++){s_threadIdx.x=nt;kfunc args;}}}
  172. #define BT_GPU_CHECK_ERROR(s)
  173. #endif //BT_GPU_DEFINES_H