|
Bullet Collision Detection & Physics Library
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org 00003 Copyright (C) 2006, 2009 Sony Computer Entertainment Inc. 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 00017 00018 // definitions for "GPU on CPU" code 00019 00020 00021 #ifndef BT_GPU_DEFINES_H 00022 #define BT_GPU_DEFINES_H 00023 00024 typedef unsigned int uint; 00025 00026 struct int2 00027 { 00028 int x, y; 00029 }; 00030 00031 struct uint2 00032 { 00033 unsigned int x, y; 00034 }; 00035 00036 struct int3 00037 { 00038 int x, y, z; 00039 }; 00040 00041 struct uint3 00042 { 00043 unsigned int x, y, z; 00044 }; 00045 00046 struct float4 00047 { 00048 float x, y, z, w; 00049 }; 00050 00051 struct float3 00052 { 00053 float x, y, z; 00054 }; 00055 00056 00057 #define BT_GPU___device__ inline 00058 #define BT_GPU___devdata__ 00059 #define BT_GPU___constant__ 00060 #define BT_GPU_max(a, b) ((a) > (b) ? (a) : (b)) 00061 #define BT_GPU_min(a, b) ((a) < (b) ? (a) : (b)) 00062 #define BT_GPU_params s3DGridBroadphaseParams 00063 #define BT_GPU___mul24(a, b) ((a)*(b)) 00064 #define BT_GPU___global__ inline 00065 #define BT_GPU___shared__ static 00066 #define BT_GPU___syncthreads() 00067 #define CUDART_PI_F SIMD_PI 00068 00069 static inline uint2 bt3dGrid_make_uint2(unsigned int x, unsigned int y) 00070 { 00071 uint2 t; t.x = x; t.y = y; return t; 00072 } 00073 #define BT_GPU_make_uint2(x, y) bt3dGrid_make_uint2(x, y) 00074 00075 static inline int3 bt3dGrid_make_int3(int x, int y, int z) 00076 { 00077 int3 t; t.x = x; t.y = y; t.z = z; return t; 00078 } 00079 #define BT_GPU_make_int3(x, y, z) bt3dGrid_make_int3(x, y, z) 00080 00081 static inline float3 bt3dGrid_make_float3(float x, float y, float z) 00082 { 00083 float3 t; t.x = x; t.y = y; t.z = z; return t; 00084 } 00085 #define BT_GPU_make_float3(x, y, z) bt3dGrid_make_float3(x, y, z) 00086 00087 static inline float3 bt3dGrid_make_float34(float4 f) 00088 { 00089 float3 t; t.x = f.x; t.y = f.y; t.z = f.z; return t; 00090 } 00091 #define BT_GPU_make_float34(f) bt3dGrid_make_float34(f) 00092 00093 static inline float3 bt3dGrid_make_float31(float f) 00094 { 00095 float3 t; t.x = t.y = t.z = f; return t; 00096 } 00097 #define BT_GPU_make_float31(x) bt3dGrid_make_float31(x) 00098 00099 static inline float4 bt3dGrid_make_float42(float3 v, float f) 00100 { 00101 float4 t; t.x = v.x; t.y = v.y; t.z = v.z; t.w = f; return t; 00102 } 00103 #define BT_GPU_make_float42(a, b) bt3dGrid_make_float42(a, b) 00104 00105 static inline float4 bt3dGrid_make_float44(float a, float b, float c, float d) 00106 { 00107 float4 t; t.x = a; t.y = b; t.z = c; t.w = d; return t; 00108 } 00109 #define BT_GPU_make_float44(a, b, c, d) bt3dGrid_make_float44(a, b, c, d) 00110 00111 inline int3 operator+(int3 a, int3 b) 00112 { 00113 return bt3dGrid_make_int3(a.x + b.x, a.y + b.y, a.z + b.z); 00114 } 00115 00116 inline float4 operator+(const float4& a, const float4& b) 00117 { 00118 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; 00119 } 00120 inline float4 operator*(const float4& a, float fact) 00121 { 00122 float4 r; r.x = a.x*fact; r.y = a.y*fact; r.z = a.z*fact; r.w = a.w*fact; return r; 00123 } 00124 inline float4 operator*(float fact, float4& a) 00125 { 00126 return (a * fact); 00127 } 00128 inline float4& operator*=(float4& a, float fact) 00129 { 00130 a = fact * a; 00131 return a; 00132 } 00133 inline float4& operator+=(float4& a, const float4& b) 00134 { 00135 a = a + b; 00136 return a; 00137 } 00138 00139 inline float3 operator+(const float3& a, const float3& b) 00140 { 00141 float3 r; r.x = a.x+b.x; r.y = a.y+b.y; r.z = a.z+b.z; return r; 00142 } 00143 inline float3 operator-(const float3& a, const float3& b) 00144 { 00145 float3 r; r.x = a.x-b.x; r.y = a.y-b.y; r.z = a.z-b.z; return r; 00146 } 00147 static inline float bt3dGrid_dot(float3& a, float3& b) 00148 { 00149 return a.x*b.x+a.y*b.y+a.z*b.z; 00150 } 00151 #define BT_GPU_dot(a,b) bt3dGrid_dot(a,b) 00152 00153 static inline float bt3dGrid_dot4(float4& a, float4& b) 00154 { 00155 return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w; 00156 } 00157 #define BT_GPU_dot4(a,b) bt3dGrid_dot4(a,b) 00158 00159 static inline float3 bt3dGrid_cross(const float3& a, const float3& b) 00160 { 00161 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; 00162 } 00163 #define BT_GPU_cross(a,b) bt3dGrid_cross(a,b) 00164 00165 00166 inline float3 operator*(const float3& a, float fact) 00167 { 00168 float3 r; r.x = a.x*fact; r.y = a.y*fact; r.z = a.z*fact; return r; 00169 } 00170 00171 00172 inline float3& operator+=(float3& a, const float3& b) 00173 { 00174 a = a + b; 00175 return a; 00176 } 00177 inline float3& operator-=(float3& a, const float3& b) 00178 { 00179 a = a - b; 00180 return a; 00181 } 00182 inline float3& operator*=(float3& a, float fact) 00183 { 00184 a = a * fact; 00185 return a; 00186 } 00187 inline float3 operator-(const float3& v) 00188 { 00189 float3 r; r.x = -v.x; r.y = -v.y; r.z = -v.z; return r; 00190 } 00191 00192 00193 #define BT_GPU_FETCH(a, b) a[b] 00194 #define BT_GPU_FETCH4(a, b) a[b] 00195 #define BT_GPU_PREF(func) btGpu_##func 00196 #define BT_GPU_SAFE_CALL(func) func 00197 #define BT_GPU_Memset memset 00198 #define BT_GPU_MemcpyToSymbol(a, b, c) memcpy(&a, b, c) 00199 #define BT_GPU_BindTexture(a, b, c, d) 00200 #define BT_GPU_UnbindTexture(a) 00201 00202 static uint2 s_blockIdx, s_blockDim, s_threadIdx; 00203 #define BT_GPU_blockIdx s_blockIdx 00204 #define BT_GPU_blockDim s_blockDim 00205 #define BT_GPU_threadIdx s_threadIdx 00206 #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;}}} 00207 00208 #define BT_GPU_CHECK_ERROR(s) 00209 00210 00211 #endif //BT_GPU_DEFINES_H