Avoid using SSE in API when BT_USE_SSE_IN_API is not defined

Fixes Issue 683.
This commit is contained in:
erwin.coumans
2012-12-20 22:09:59 +00:00
parent 0c555a5afe
commit 02a22f6329
8 changed files with 37 additions and 20 deletions

View File

@@ -397,10 +397,13 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
printf("new numVertices = %d\n", hull->numVertices ()); printf("new numVertices = %d\n", hull->numVertices ());
btConvexHullShape* convexShape = new btConvexHullShape(); btConvexHullShape* convexShape = new btConvexHullShape();
bool updateLocalAabb = false;
for (i=0;i<hull->numVertices();i++) for (i=0;i<hull->numVertices();i++)
{ {
convexShape->addPoint(hull->getVertexPointer()[i]); convexShape->addPoint(hull->getVertexPointer()[i],updateLocalAabb);
} }
convexShape->recalcLocalAabb();
if (sEnableSAT) if (sEnableSAT)
convexShape->initializePolyhedralFeatures(); convexShape->initializePolyhedralFeatures();

View File

@@ -1400,8 +1400,8 @@ void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData)
} }
bool isDynamic = mass!=0.f; bool isDynamic = mass!=0.f;
btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name); btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name);
body->setFriction(colObjData->m_collisionObjectData.m_friction); body->setFriction(btScalar(colObjData->m_collisionObjectData.m_friction));
body->setRestitution(colObjData->m_collisionObjectData.m_restitution); body->setRestitution(btScalar(colObjData->m_collisionObjectData.m_restitution));
#ifdef USE_INTERNAL_EDGE_UTILITY #ifdef USE_INTERNAL_EDGE_UTILITY

View File

@@ -13,6 +13,10 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#if defined (_WIN32) || defined (__i386__)
#define BT_USE_SSE_IN_API
#endif
#include "btConvexHullShape.h" #include "btConvexHullShape.h"
#include "BulletCollision/CollisionShapes/btCollisionMargin.h" #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
@@ -45,10 +49,11 @@ void btConvexHullShape::setLocalScaling(const btVector3& scaling)
recalcLocalAabb(); recalcLocalAabb();
} }
void btConvexHullShape::addPoint(const btVector3& point) void btConvexHullShape::addPoint(const btVector3& point, bool recalculateLocalAabb)
{ {
m_unscaledPoints.push_back(point); m_unscaledPoints.push_back(point);
recalcLocalAabb(); if (recalculateLocalAabb)
recalcLocalAabb();
} }

View File

@@ -36,7 +36,7 @@ public:
///btConvexHullShape make an internal copy of the points. ///btConvexHullShape make an internal copy of the points.
btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btVector3)); btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btVector3));
void addPoint(const btVector3& point); void addPoint(const btVector3& point, bool recalculateLocalAabb = true);
btVector3* getUnscaledPoints() btVector3* getUnscaledPoints()

View File

@@ -13,6 +13,10 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#if defined (_WIN32) || defined (__i386__)
#define BT_USE_SSE_IN_API
#endif
#include "btConvexShape.h" #include "btConvexShape.h"
#include "btTriangleShape.h" #include "btTriangleShape.h"
#include "btSphereShape.h" #include "btSphereShape.h"

View File

@@ -13,7 +13,9 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#if defined (_WIN32) || defined (__i386__)
#define BT_USE_SSE_IN_API
#endif
#include "btMultiSphereShape.h" #include "btMultiSphereShape.h"
#include "BulletCollision/CollisionShapes/btCollisionMargin.h" #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
@@ -40,7 +42,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScala
} }
#ifndef MIN #ifndef MIN
#define MIN( _a, _b) ((_a) < (_b) ? (_a) : (_b)) #define MIN( _a, _b) ((_a) < (_b) ? (_a) : (_b))
#endif #endif
btVector3 btMultiSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const btVector3 btMultiSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
{ {
@@ -67,10 +69,10 @@ btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScala
const btScalar* rad = &m_radiArray[0]; const btScalar* rad = &m_radiArray[0];
int numSpheres = m_localPositionArray.size(); int numSpheres = m_localPositionArray.size();
for( int k = 0; k < numSpheres; k+= 128 ) for( int k = 0; k < numSpheres; k+= 128 )
{ {
btVector3 temp[128]; btVector3 temp[128];
int inner_count = MIN( numSpheres - k, 128 ); int inner_count = MIN( numSpheres - k, 128 );
for( long i = 0; i < inner_count; i++ ) for( long i = 0; i < inner_count; i++ )
{ {
temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin(); temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();

View File

@@ -12,6 +12,9 @@ subject to the following restrictions:
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#if defined (_WIN32) || defined (__i386__)
#define BT_USE_SSE_IN_API
#endif
#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
#include "btConvexPolyhedron.h" #include "btConvexPolyhedron.h"

View File

@@ -229,7 +229,7 @@ public:
* @param v The other vector in the dot product */ * @param v The other vector in the dot product */
SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const SIMD_FORCE_INLINE btScalar dot(const btVector3& v) const
{ {
#if defined BT_USE_SIMD_VECTOR3 #if defined BT_USE_SIMD_VECTOR3 && defined (BT_USE_SSE_IN_API) && defined (BT_USE_SSE)
__m128 vd = _mm_mul_ps(mVec128, v.mVec128); __m128 vd = _mm_mul_ps(mVec128, v.mVec128);
__m128 z = _mm_movehl_ps(vd, vd); __m128 z = _mm_movehl_ps(vd, vd);
__m128 y = _mm_shuffle_ps(vd, vd, 0x55); __m128 y = _mm_shuffle_ps(vd, vd, 0x55);
@@ -989,7 +989,7 @@ SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btS
SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long array_count, btScalar &dotOut ) const SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long array_count, btScalar &dotOut ) const
{ {
#if defined BT_USE_SIMD_VECTOR3 #if (defined BT_USE_SSE && defined BT_USE_SIMD_VECTOR3 && defined BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
#if defined _WIN32 || defined (BT_USE_SSE) #if defined _WIN32 || defined (BT_USE_SSE)
const long scalar_cutoff = 10; const long scalar_cutoff = 10;
long _maxdot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut ); long _maxdot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut );
@@ -998,7 +998,7 @@ SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long arra
extern long (*_maxdot_large)( const float *array, const float *vec, unsigned long array_count, float *dotOut ); extern long (*_maxdot_large)( const float *array, const float *vec, unsigned long array_count, float *dotOut );
#endif #endif
if( array_count < scalar_cutoff ) if( array_count < scalar_cutoff )
#endif//BT_USE_SIMD_VECTOR3 #endif
{ {
btScalar maxDot = -SIMD_INFINITY; btScalar maxDot = -SIMD_INFINITY;
int i = 0; int i = 0;
@@ -1017,14 +1017,14 @@ SIMD_FORCE_INLINE long btVector3::maxDot( const btVector3 *array, long arra
dotOut = maxDot; dotOut = maxDot;
return ptIndex; return ptIndex;
} }
#if defined BT_USE_SIMD_VECTOR3 #if (defined BT_USE_SSE && defined BT_USE_SIMD_VECTOR3 && defined BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
return _maxdot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut ); return _maxdot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut );
#endif//BT_USE_SIMD_VECTOR3 #endif
} }
SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long array_count, btScalar &dotOut ) const SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long array_count, btScalar &dotOut ) const
{ {
#if defined BT_USE_SIMD_VECTOR3 #if (defined BT_USE_SSE && defined BT_USE_SIMD_VECTOR3 && defined BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
#if defined BT_USE_SSE #if defined BT_USE_SSE
const long scalar_cutoff = 10; const long scalar_cutoff = 10;
long _mindot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut ); long _mindot_large( const float *array, const float *vec, unsigned long array_count, float *dotOut );
@@ -1036,7 +1036,7 @@ SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long arra
#endif #endif
if( array_count < scalar_cutoff ) if( array_count < scalar_cutoff )
#endif//BT_USE_SIMD_VECTOR3 #endif
{ {
btScalar minDot = SIMD_INFINITY; btScalar minDot = SIMD_INFINITY;
int i = 0; int i = 0;
@@ -1057,7 +1057,7 @@ SIMD_FORCE_INLINE long btVector3::minDot( const btVector3 *array, long arra
return ptIndex; return ptIndex;
} }
#if defined BT_USE_SIMD_VECTOR3 #if (defined BT_USE_SSE && defined BT_USE_SIMD_VECTOR3 && defined BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
return _mindot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut ); return _mindot_large( (float*) array, (float*) &m_floats[0], array_count, &dotOut );
#endif//BT_USE_SIMD_VECTOR3 #endif//BT_USE_SIMD_VECTOR3
} }