Remove btSoftBodySolver_CPU.*

Move btSoftBodySolverData.h to src/BulletMultiThreaded/GpuSoftBodySolvers/Shared/btSoftBodySolverData.h
Attempt to re-enable MiniCL version of OpenCLClothDemo (cloth-capsule collision still broken)
Add optional OpenCL acceleration to SerializeDemo (just for cloth)
This commit is contained in:
erwin.coumans
2011-11-11 19:00:26 +00:00
parent 14352169ab
commit 66c349caa6
40 changed files with 2442 additions and 1649 deletions

View File

@@ -0,0 +1,131 @@
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader
${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletWorldImporter
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL
${AMD_OPENCL_INCLUDES}
)
ADD_DEFINITIONS(-DDESERIALIZE_SOFT_BODIES)
ADD_DEFINITIONS(-DUSE_AMD_OPENCL)
ADD_DEFINITIONS(-DCL_PLATFORM_AMD)
IF (CMAKE_CL_64)
SET(CMAK_GLEW_LIBRARY
${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew64.lib )
ELSE(CMAKE_CL_64)
SET(CMAK_GLEW_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew32.lib )
ENDIF(CMAKE_CL_64)
IF (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport
BulletWorldImporter
BulletSoftBody
BulletDynamics
BulletCollision
BulletFileLoader
LinearMath
BulletSoftBodySolvers_OpenCL_AMD
BulletMultiThreaded
${GLUT_glut_LIBRARY}
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${CMAK_GLEW_LIBRARY}
${CMAKE_ATISTREAMSDK_LIBPATH}/OpenCL.lib
)
IF (WIN32)
ADD_EXECUTABLE(AppSerializeDemo_AMD
../main.cpp
../SerializeDemo.cpp
../SerializeDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/clew.c
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/clew.h
)
ELSE()
ADD_EXECUTABLE(AppSerializeDemo_AMD
../main.cpp
../SerializeDemo.cpp
../SerializeDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/clew.c
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/clew.h
)
ENDIF()
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
IF (WIN32)
IF (CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET AppSerializeDemo_AMD
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}
)
ELSE(CMAKE_CL_64)
ADD_CUSTOM_COMMAND(
TARGET AppSerializeDemo_AMD
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}
)
ENDIF(CMAKE_CL_64)
ENDIF(WIN32)
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
ELSE (USE_GLUT)
LINK_LIBRARIES(
OpenGLSupport
BulletWorldImporter
BulletSoftBody
BulletDynamics
BulletCollision
BulletFileLoader
LinearMath
BulletSoftBodySolvers_OpenCL_AMD
BulletMultiThreaded
${OPENGL_gl_LIBRARY}
${OPENGL_glu_LIBRARY}
${CMAK_GLEW_LIBRARY}
${CMAKE_ATISTREAMSDK_LIBPATH}/OpenCL.lib
)
ADD_EXECUTABLE(AppSerializeDemo_AMD
WIN32
../../OpenGL/Win32AppMain.cpp
../Win32SerializeDemo.cpp
../SerializeDemo.cpp
../SerializeDemo.h
${BULLET_PHYSICS_SOURCE_DIR}/msvc/bullet.rc
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.h
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclUtils.cpp
${BULLET_PHYSICS_SOURCE_DIR}/Demos/SharedOpenCL/btOclCommon.cpp
)
ENDIF (USE_GLUT)
IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES AND NOT INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
ADD_CUSTOM_COMMAND(
TARGET AppSerializeDemo_AMD
POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
)
ENDIF ()
IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppSerializeDemo_AMD PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppSerializeDemo_AMD PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppSerializeDemo_AMD PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)

View File

@@ -0,0 +1,65 @@
hasCL = findOpenCL_AMD()
if (hasCL) then
project "AppOpenCLClothDemo_AMD"
defines { "USE_AMD_OPENCL","CL_PLATFORM_AMD"}
initOpenCL_AMD()
language "C++"
kind "ConsoleApp"
targetdir "../../.."
libdirs {"../../../Glut"}
links {
"LinearMath",
"BulletCollision",
"BulletDynamics",
"BulletSoftBody",
"BulletSoftBodySolvers_OpenCL_AMD",
"opengl32"
}
configuration "x64"
links {
"glut64",
"glew64"
}
configuration "x32"
links {
"glut32",
"glew32"
}
configuration{}
includedirs {
"../../../src",
"../../../Glut",
"../../SharedOpenCL",
"../../OpenGL"
}
files {
"../cl_cloth_demo.cpp",
"../../SharedOpenCL/btOclUtils.h",
"../../SharedOpenCL/btOclCommon.h",
"../../SharedOpenCL/btOclUtils.cpp",
"../../SharedOpenCL/btOclCommon.cpp",
"../../OpenGL/GLDebugDrawer.cpp",
"../../OpenGL/stb_image.cpp",
"../../OpenGL/stb_image.h",
"../gl_win.cpp",
"../clstuff.cpp",
"../clstuff.h",
"../gl_win.h",
"../cloth.h"
}
end

View File

@@ -11,6 +11,10 @@ SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
# You shouldn't have to modify anything below this line
########################################################
IF(BUILD_AMD_OPENCL_DEMOS)
SUBDIRS(AMD)
ENDIF()
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src
${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL
@@ -86,4 +90,6 @@ IF (INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
SET_TARGET_PROPERTIES(AppSerializeDemo PROPERTIES DEBUG_POSTFIX "_Debug")
SET_TARGET_PROPERTIES(AppSerializeDemo PROPERTIES MINSIZEREL_POSTFIX "_MinsizeRel")
SET_TARGET_PROPERTIES(AppSerializeDemo PROPERTIES RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo")
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)
ENDIF(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES)

View File

@@ -51,12 +51,26 @@ subject to the following restrictions:
#ifdef DESERIALIZE_SOFT_BODIES
#include "BulletSoftBody/btSoftBodySolvers.h"
#ifdef USE_AMD_OPENCL
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.h>
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.h>
extern cl_context g_cxMainContext;
extern cl_device_id g_cdDevice;
extern cl_command_queue g_cqCommandQue;
#endif
btSoftBodySolver* fSoftBodySolver=0;
#include "BulletSoftBody/btSoftBodyHelpers.h"
#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
#endif
void SerializeDemo::clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -69,8 +83,27 @@ void SerializeDemo::clientMoveAndDisplay()
{
m_dynamicsWorld->stepSimulation(ms / 1000000.f);
//optional but useful: debug drawing
if (fSoftBodySolver)
fSoftBodySolver->copyBackToSoftBodies();
m_dynamicsWorld->debugDrawWorld();
if (m_dynamicsWorld->getWorldType()==BT_SOFT_RIGID_DYNAMICS_WORLD)
{
//optional but useful: debug drawing
btSoftRigidDynamicsWorld* softWorld = (btSoftRigidDynamicsWorld*)m_dynamicsWorld;
for ( int i=0;i<softWorld->getSoftBodyArray().size();i++)
{
btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i];
if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe)))
{
btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer());
btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags());
}
}
}
}
renderme();
@@ -87,6 +120,22 @@ void SerializeDemo::displayCallback(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (m_dynamicsWorld->getWorldType()==BT_SOFT_RIGID_DYNAMICS_WORLD)
{
//optional but useful: debug drawing
btSoftRigidDynamicsWorld* softWorld = (btSoftRigidDynamicsWorld*)m_dynamicsWorld;
for ( int i=0;i<softWorld->getSoftBodyArray().size();i++)
{
btSoftBody* psb=(btSoftBody*)softWorld->getSoftBodyArray()[i];
if (softWorld->getDebugDrawer() && !(softWorld->getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe)))
{
btSoftBodyHelpers::DrawFrame(psb,softWorld->getDebugDrawer());
btSoftBodyHelpers::Draw(psb,softWorld->getDebugDrawer(),softWorld->getDrawFlags());
}
}
}
renderme();
//optional but useful: debug drawing to detect problems
@@ -97,7 +146,12 @@ void SerializeDemo::displayCallback(void) {
swapBuffers();
}
enum SolverType
{
kSolverAccelerationOpenCL_CPU = 1,
kSolverAccelerationOpenCL_GPU = 2,
kSolverAccelerationNone = 3
};
void SerializeDemo::setupEmptyDynamicsWorld()
@@ -123,7 +177,62 @@ void SerializeDemo::setupEmptyDynamicsWorld()
m_solver = sol;
#ifdef DESERIALIZE_SOFT_BODIES
btSoftRigidDynamicsWorld* world = new btSoftRigidDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
#ifdef USE_AMD_OPENCL
int solverAccel = kSolverAccelerationOpenCL_GPU;
if ( 1 ) {
switch (solverAccel)
{
case kSolverAccelerationOpenCL_GPU:
{
fSoftBodySolver
= new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue,
g_cxMainContext );
// fSoftBodySolver = new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext);
/*if (!fSoftBodySolver->checkInitialized())
{
btAssert(0);
delete fSoftBodySolver;
fSoftBodySolver = NULL;
}
*/
break;
}
case kSolverAccelerationOpenCL_CPU:
{
//fSoftBodySolver = new btCPUSoftBodySolver();
break;
};
case kSolverAccelerationNone:
default:
{
fSoftBodySolver = NULL;
}
};
}
else
{
if ( solverAccel != kSolverAccelerationNone )
{
}
else
{
}
fSoftBodySolver = NULL;
}
#else
fSoftBodySolver = NULL;
#endif
btSoftRigidDynamicsWorld* world = new btSoftRigidDynamicsWorld(m_dispatcher, m_broadphase, m_solver,
m_collisionConfiguration, fSoftBodySolver);
m_dynamicsWorld = world;
//world->setDrawFlags(world->getDrawFlags()^fDrawFlags::Clusters);
#else
@@ -510,6 +619,7 @@ SerializeDemo::~SerializeDemo()
void SerializeDemo::initPhysics()
{
m_idle = true;
setTexturing(true);
setShadows(true);

View File

@@ -19,69 +19,93 @@ subject to the following restrictions:
#include "btBulletDynamicsCommon.h"
#include "LinearMath/btHashMap.h"
class OurValue
{
int m_uid;
public:
OurValue(const btVector3& initialPos)
:m_position(initialPos)
{
static int gUid=0;
m_uid=gUid;
gUid++;
}
btVector3 m_position;
int getUid() const
{
return m_uid;
}
};
#ifdef USE_AMD_OPENCL
#ifdef _DEBUG
bool bDebug = true;
#else
bool bDebug = false;
#endif
#include "btOclCommon.h"
#include "btOclUtils.h"
#include <LinearMath/btScalar.h>
cl_context g_cxMainContext;
cl_device_id g_cdDevice;
cl_command_queue g_cqCommandQue;
// Returns true if OpenCL is initialized properly, false otherwise.
bool initCL( void* glCtx, void* glDC )
{
int ciErrNum = 0;
#ifdef BT_USE_CLEW
ciErrNum = clewInit( "OpenCL.dll" );
if ( ciErrNum != CLEW_SUCCESS ) {
return false;
}
#endif
#if defined(CL_PLATFORM_MINI_CL)
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
#elif defined(CL_PLATFORM_AMD)
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
#elif defined(CL_PLATFORM_NVIDIA)
cl_device_type deviceType = CL_DEVICE_TYPE_GPU;
#else
cl_device_type deviceType = CL_DEVICE_TYPE_CPU;
#endif
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_ALL, &ciErrNum);
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_GPU, &ciErrNum);
//g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_CPU, &ciErrNum);
//try CL_DEVICE_TYPE_DEBUG for sequential, non-threaded execution, when using MiniCL on CPU, it gives a full callstack at the crash in the kernel
//#ifdef USE_MINICL
// g_cxMainContext = btOclCommon::createContextFromType(CL_DEVICE_TYPE_DEBUG, &ciErrNum);
//#else
g_cxMainContext = btOclCommon::createContextFromType(deviceType, &ciErrNum, glCtx, glDC);
//#endif
oclCHECKERROR(ciErrNum, CL_SUCCESS);
g_cdDevice = btOclGetMaxFlopsDev(g_cxMainContext);
if ( bDebug ) {
btOclPrintDevInfo(g_cdDevice);
}
// create a command-queue
g_cqCommandQue = clCreateCommandQueue(g_cxMainContext, g_cdDevice, 0, &ciErrNum);
oclCHECKERROR(ciErrNum, CL_SUCCESS);
return true;
}
#endif //#ifdef USE_AMD_OPENCL
int main(int argc,char** argv)
{
GLDebugDrawer gDebugDrawer;
#ifdef USE_AMD_OPENCL
bool initialized = initCL(0,0);
btAssert(initialized);
#endif //USE_AMD_OPENCL
///testing the btHashMap
btHashMap<btHashKey<OurValue>,OurValue> map;
OurValue value1(btVector3(2,3,4));
btHashKey<OurValue> key1(value1.getUid());
map.insert(key1,value1);
OurValue value2(btVector3(5,6,7));
btHashKey<OurValue> key2(value2.getUid());
map.insert(key2,value2);
{
OurValue value3(btVector3(7,8,9));
btHashKey<OurValue> key3(value3.getUid());
map.insert(key3,value3);
}
map.remove(key2);
// const OurValue* ourPtr = map.find(key1);
// for (int i=0;i<map.size();i++)
// {
// OurValue* tmp = map.getAtIndex(i);
// //printf("tmp value=%f,%f,%f\n",tmp->m_position.getX(),tmp->m_position.getY(),tmp->m_position.getZ());
// }
SerializeDemo ccdDemo;
ccdDemo.initPhysics();
ccdDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
SerializeDemo serializeDemo;
serializeDemo.initPhysics();
serializeDemo.getDynamicsWorld()->setDebugDrawer(&gDebugDrawer);
#ifdef CHECK_MEMORY_LEAKS
ccdDemo.exitPhysics();
serializeDemo.exitPhysics();
#else
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.org",&ccdDemo);
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://bulletphysics.org",&serializeDemo);
#endif
//default glut doesn't return from mainloop

Binary file not shown.