This commit is contained in:
erwincoumans 2013-06-20 12:55:35 -07:00
commit 47403c7e6f
66 changed files with 1026 additions and 914 deletions

View File

@ -182,6 +182,10 @@ BasicGpuDemo::~BasicGpuDemo()
void BasicGpuDemo::initPhysics()
{
//use the Bullet 2.x btQuickprof for profiling of Bullet 3.x
b3SetCustomEnterProfileZoneFunc(CProfileManager::Start_Profile);
b3SetCustomLeaveProfileZoneFunc(CProfileManager::Stop_Profile);
setTexturing(true);
setShadows(false);//too slow with many objects
@ -284,9 +288,8 @@ void BasicGpuDemo::initPhysics()
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
//btBoxShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
btCollisionShape* colShape = new btSphereShape(btScalar(SCALING*1.f));
btBoxShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
//btCollisionShape* colShape = new btSphereShape(btScalar(SCALING*1.f));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects

View File

@ -145,7 +145,8 @@ int b3GpuDynamicsWorld::stepSimulation( btScalar timeStepUnused, int maxSubStep
if (body)
{
b3Vector3 pos = (const b3Vector3&)m_collisionObjects[i]->getWorldTransform().getOrigin();
b3Quaternion orn = (const b3Quaternion&)m_collisionObjects[i]->getWorldTransform().getRotation();
btQuaternion orn2 = m_collisionObjects[i]->getWorldTransform().getRotation();
b3Quaternion orn(orn2[0],orn2[1],orn2[2],orn2[3]);
body->integrateVelocities(fixedTimeStep);
m_np->setObjectTransformCpu(&pos[0],&orn[0],i);
b3Vector3 linVel = (const b3Vector3&)body->getLinearVelocity();

View File

@ -19,7 +19,6 @@ static char* particleKernelsString =
#include "GpuDemoInternalData.h"
#include "Bullet3Common/b3Quickprof.h"
//1000000 particles
//#define NUM_PARTICLES_X 100

View File

@ -1,5 +1,4 @@
#include "PairBench.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "Bullet3Common/b3Quaternion.h"
@ -10,6 +9,7 @@
#include "OpenGLWindow/OpenGLInclude.h"
#include "OpenGLWindow/GLInstanceRendererInternalData.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
#include "../../../btgui/Timing/b3Quickprof.h"
static b3KeyboardCallback oldCallback = 0;
extern bool gReset;
@ -172,7 +172,10 @@ void PairBench::initPhysics(const ConstructionInfo& ci)
m_instancingRenderer = ci.m_instancingRenderer;
#ifndef B3_NO_PROFILE
b3ProfileManager::CleanupMemory();
#endif //B3_NO_PROFILE
int strideInBytes = 9*sizeof(float);
int numVertices = sizeof(cube_vertices)/strideInBytes;
int numIndices = sizeof(cube_vertices)/sizeof(int);

View File

@ -21,7 +21,6 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
//#include "OpenGL3CoreRenderer.h"
#include "Bullet3Common/b3Quickprof.h"
//#include "b3GpuDynamicsWorld.h"
#include <assert.h>
#include <string.h>
@ -37,6 +36,9 @@
#include "rigidbody/GpuSphereScene.h"
#include "rigidbody/Bullet2FileDemo.h"
#include "softbody/GpuSoftBodyDemo.h"
#include "../btgui/Timing/b3Quickprof.h"
//#include "BroadphaseBenchmark.h"
@ -412,6 +414,10 @@ int main(int argc, char* argv[])
{
//b3OpenCLUtils::setCachePath("/Users/erwincoumans/develop/mycache");
b3SetCustomEnterProfileZoneFunc(b3ProfileManager::Start_Profile);
b3SetCustomLeaveProfileZoneFunc(b3ProfileManager::Stop_Profile);
b3SetCustomPrintfFunc(myprintf);
b3Vector3 test(1,2,3);
test.x = 1;
@ -456,7 +462,7 @@ int main(int argc, char* argv[])
#ifndef B3_NO_PROFILE
#ifndef B3_NO_PROFILE
b3ProfileManager::Reset();
#endif //B3_NO_PROFILE

View File

@ -63,6 +63,10 @@ function createProject(vendor)
"../../btgui/FontFiles/OpenSans.cpp",
"../../btgui/stb_image/stb_image.cpp",
"../../btgui/stb_image/stb_image.h",
"../../btgui/Timing/b3Quickprof.cpp",
"../../btgui/Timing/b3Quickprof.h",
"../../btgui/Timing/b3Clock.cpp",
"../../btgui/Timing/b3Clock.h",
}
if os.is("Windows") then

View File

@ -19,7 +19,6 @@ extern bool enableExperimentalCpuConcaveCollision;
#include "OpenGLWindow/GLInstancingRenderer.h"
//#include "LinearMath/b3Quickprof.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3Matrix3x3.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3ConvexUtility.h"

View File

@ -1,6 +1,5 @@
#include "ConcaveScene.h"
#include "GpuRigidBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"

View File

@ -1,6 +1,5 @@
#include "GpuCompoundScene.h"
#include "GpuRigidBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"

View File

@ -1,6 +1,5 @@
#include "GpuConvexScene.h"
#include "GpuRigidBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
@ -459,7 +458,7 @@ void GpuRaytraceScene::renderScene()
//m_raycaster->castRaysHost(rays, hits, this->m_data->m_np->getNumRigidBodies(), m_data->m_np->getBodiesCpu(), m_data->m_np->getNumCollidablesGpu(), m_data->m_np->getCollidablesCpu());
m_raycaster->castRays(rays, hits, this->m_data->m_np->getNumRigidBodies(), m_data->m_np->getBodiesCpu(), m_data->m_np->getNumCollidablesGpu(), m_data->m_np->getCollidablesCpu());
m_raycaster->castRays(rays, hits, this->m_data->m_np->getNumRigidBodies(), m_data->m_np->getBodiesCpu(), m_data->m_np->getNumCollidablesGpu(), m_data->m_np->getCollidablesCpu(), m_data->m_np->getInternalData());

View File

@ -1,5 +1,4 @@
#include "GpuRigidBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "Bullet3Common/b3Quaternion.h"
@ -110,7 +109,7 @@ void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
b3Config config;
config.m_maxConvexBodies = b3Max(config.m_maxConvexBodies,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ+10);
config.m_maxConvexShapes = config.m_maxConvexBodies;
config.m_maxBroadphasePairs = 8*config.m_maxConvexBodies;
config.m_maxBroadphasePairs = 12*config.m_maxConvexBodies;
config.m_maxContactCapacity = config.m_maxBroadphasePairs;

View File

@ -1,6 +1,5 @@
#include "GpuSphereScene.h"
#include "GpuRigidBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "Bullet3Common/b3Quaternion.h"

View File

@ -1,5 +1,4 @@
#include "GpuSoftBodyDemo.h"
#include "Bullet3Common/b3Quickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "Bullet3Common/b3Quaternion.h"

View File

@ -11,7 +11,6 @@
#include "OpenGLWindow/GLPrimitiveRenderer.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
//#include "OpenGL3CoreRenderer.h"
#include "Bullet3Common/b3Quickprof.h"
//#include "b3GpuDynamicsWorld.h"
#include <assert.h>
#include <string.h>
@ -19,7 +18,7 @@
#include "OpenGLTrueTypeFont/opengl_fontstashcallbacks.h"
#include "OpenGLWindow/GwenOpenGL3CoreRenderer.h"
#include "../btgui/Timing/b3Quickprof.h"
#include "Gwen/Gwen.h"
#include "Gwen/Controls/Button.h"

View File

@ -49,10 +49,12 @@ function createProject(vendor)
"../../src/Bullet3Geometry/b3ConvexHullComputer.cpp",
"../../src/Bullet3Geometry/b3ConvexHullComputer.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h",
"../../src/Bullet3Common/b3Logging.cpp",
"../../src/Bullet3Common/b3Logging.h",
"../../src/Bullet3Common/b3logging.cpp",
"../../src/Bullet3Common/b3logging.h",
"../../btgui/Timing/b3Quickprof.cpp",
"../../btgui/Timing/b3Quickprof.h",
"../../btgui/Timing/b3Clock.cpp",
"../../btgui/Timing/b3Clock.h",
}

View File

@ -56,7 +56,7 @@ function createGpuDemos( demos, incdirs, linknames, vendor)
initOpenCL(vendor)
kind "ConsoleApp"
targetdir ".."
targetdir "../bin"
links {"Bullet3OpenCL_" .. vendor }

View File

@ -42,8 +42,10 @@
"../../src/Bullet3Common/b3Logging.h",
"../../src/Bullet3Common/b3Logging.cpp",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h",
"../../btgui/Timing/b3Quickprof.cpp",
"../../btgui/Timing/b3Quickprof.h",
"../../btgui/Timing/b3Clock.cpp",
"../../btgui/Timing/b3Clock.h",
"**.cpp",
"**.h",
}

View File

@ -24,8 +24,10 @@
"../OpenGLWindow/LoadShader.cpp",
"../OpenGLWindow/LoadShader.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h" ,
"../Timing/b3Quickprof.cpp",
"../Timing/b3Quickprof.h" ,
"../Timing/b3Clock.cpp",
"../Timing/b3Clock.h" ,
"fontstash.cpp",
"fontstash.h",
"opengl_fontstashcallbacks.cpp",

View File

@ -29,7 +29,6 @@ subject to the following restrictions:
#include <assert.h>
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3Common/b3Quaternion.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3Common/b3Matrix3x3.h"
#include "LoadShader.h"

View File

@ -44,8 +44,10 @@
"../../src/Bullet3Geometry/b3ConvexHullComputer.cpp",
"../../src/Bullet3Geometry/b3ConvexHullComputer.h",
"../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../src/Bullet3Common/b3Quickprof.cpp",
"../../src/Bullet3Common/b3Quickprof.h"
"../Timing/b3Quickprof.cpp",
"../Timing/b3Quickprof.h",
"../Timing/b3Clock.cpp",
"../Timing/b3Clock.h",
}
if os.is("Windows") then

223
btgui/Timing/b3Clock.cpp Normal file
View File

@ -0,0 +1,223 @@
#include "b3Clock.h"
template <class T>
const T& b3ClockMin(const T& a, const T& b)
{
return a < b ? a : b ;
}
#ifdef __CELLOS_LV2__
#include <sys/sys_time.h>
#include <sys/time_util.h>
#include <stdio.h>
#endif
#if defined (SUNOS) || defined (__SUNOS__)
#include <stdio.h>
#endif
#if defined(WIN32) || defined(_WIN32)
#define B3_USE_WINDOWS_TIMERS
#define WIN32_LEAN_AND_MEAN
#define NOWINRES
#define NOMCX
#define NOIME
#ifdef _XBOX
#include <Xtl.h>
#else //_XBOX
#include <windows.h>
#endif //_XBOX
#include <time.h>
#else //_WIN32
#include <sys/time.h>
#endif //_WIN32
struct b3ClockData
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER mClockFrequency;
DWORD mStartTick;
LONGLONG mPrevElapsedTime;
LARGE_INTEGER mStartTime;
#else
#ifdef __CELLOS_LV2__
uint64_t mStartTime;
#else
struct timeval mStartTime;
#endif
#endif //__CELLOS_LV2__
};
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
b3Clock::b3Clock()
{
m_data = new b3ClockData;
#ifdef B3_USE_WINDOWS_TIMERS
QueryPerformanceFrequency(&m_data->mClockFrequency);
#endif
reset();
}
b3Clock::~b3Clock()
{
delete m_data;
}
b3Clock::b3Clock(const b3Clock& other)
{
m_data = new b3ClockData;
*m_data = *other.m_data;
}
b3Clock& b3Clock::operator=(const b3Clock& other)
{
*m_data = *other.m_data;
return *this;
}
/// Resets the initial reference time.
void b3Clock::reset()
{
#ifdef B3_USE_WINDOWS_TIMERS
QueryPerformanceCounter(&m_data->mStartTime);
m_data->mStartTick = GetTickCount();
m_data->mPrevElapsedTime = 0;
#else
#ifdef __CELLOS_LV2__
typedef uint64_t ClockSize;
ClockSize newTime;
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
SYS_TIMEBASE_GET( newTime );
m_data->mStartTime = newTime;
#else
gettimeofday(&m_data->mStartTime, 0);
#endif
#endif
}
/// Returns the time in ms since the last call to reset or since
/// the b3Clock was created.
unsigned long int b3Clock::getTimeMilliseconds()
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = b3ClockMin(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
// Recompute the number of millisecond ticks elapsed.
msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
}
// Store the current elapsed time for adjustments next time.
m_data->mPrevElapsedTime = elapsedTime;
return msecTicks;
#else
#ifdef __CELLOS_LV2__
uint64_t freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq) / 1000.0;
typedef uint64_t ClockSize;
ClockSize newTime;
SYS_TIMEBASE_GET( newTime );
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
#else
struct timeval currentTime;
gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000;
#endif //__CELLOS_LV2__
#endif
}
/// Returns the time in us since the last call to reset or since
/// the Clock was created.
unsigned long int b3Clock::getTimeMicroseconds()
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = b3ClockMin(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
}
// Store the current elapsed time for adjustments next time.
m_data->mPrevElapsedTime = elapsedTime;
// Convert to microseconds.
unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
return usecTicks;
#else
#ifdef __CELLOS_LV2__
uint64_t freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq)/ 1000000.0;
typedef uint64_t ClockSize;
ClockSize newTime;
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
SYS_TIMEBASE_GET( newTime );
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
#else
struct timeval currentTime;
gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec);
#endif//__CELLOS_LV2__
#endif
}

31
btgui/Timing/b3Clock.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef B3_CLOCK_H
#define B3_CLOCK_H
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
class b3Clock
{
public:
b3Clock();
b3Clock(const b3Clock& other);
b3Clock& operator=(const b3Clock& other);
~b3Clock();
/// Resets the initial reference time.
void reset();
/// Returns the time in ms since the last call to reset or since
/// the b3Clock was created.
unsigned long int getTimeMilliseconds();
/// Returns the time in us since the last call to reset or since
/// the Clock was created.
unsigned long int getTimeMicroseconds();
private:
struct b3ClockData* m_data;
};
#endif //B3_CLOCK_H

View File

@ -27,8 +27,9 @@ subject to the following restrictions:
// Credits: The Clock class was inspired by the Timer classes in
// Ogre (www.ogre3d.org).
#include "Bullet3Common/b3MinMax.h"
#include "b3Quickprof.h"
#include "b3MinMax.h"
#ifndef B3_NO_PROFILE
@ -36,220 +37,6 @@ subject to the following restrictions:
static b3Clock b3s_profileClock;
#ifdef __CELLOS_LV2__
#include <sys/sys_time.h>
#include <sys/time_util.h>
#include <stdio.h>
#endif
#if defined (SUNOS) || defined (__SUNOS__)
#include <stdio.h>
#endif
#if defined(WIN32) || defined(_WIN32)
#define B3_USE_WINDOWS_TIMERS
#define WIN32_LEAN_AND_MEAN
#define NOWINRES
#define NOMCX
#define NOIME
#ifdef _XBOX
#include <Xtl.h>
#else //_XBOX
#include <windows.h>
#endif //_XBOX
#include <time.h>
#else //_WIN32
#include <sys/time.h>
#endif //_WIN32
struct b3ClockData
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER mClockFrequency;
DWORD mStartTick;
LONGLONG mPrevElapsedTime;
LARGE_INTEGER mStartTime;
#else
#ifdef __CELLOS_LV2__
uint64_t mStartTime;
#else
struct timeval mStartTime;
#endif
#endif //__CELLOS_LV2__
};
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
b3Clock::b3Clock()
{
m_data = new b3ClockData;
#ifdef B3_USE_WINDOWS_TIMERS
QueryPerformanceFrequency(&m_data->mClockFrequency);
#endif
reset();
}
b3Clock::~b3Clock()
{
delete m_data;
}
b3Clock::b3Clock(const b3Clock& other)
{
m_data = new b3ClockData;
*m_data = *other.m_data;
}
b3Clock& b3Clock::operator=(const b3Clock& other)
{
*m_data = *other.m_data;
return *this;
}
/// Resets the initial reference time.
void b3Clock::reset()
{
#ifdef B3_USE_WINDOWS_TIMERS
QueryPerformanceCounter(&m_data->mStartTime);
m_data->mStartTick = GetTickCount();
m_data->mPrevElapsedTime = 0;
#else
#ifdef __CELLOS_LV2__
typedef uint64_t ClockSize;
ClockSize newTime;
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
SYS_TIMEBASE_GET( newTime );
m_data->mStartTime = newTime;
#else
gettimeofday(&m_data->mStartTime, 0);
#endif
#endif
}
/// Returns the time in ms since the last call to reset or since
/// the b3Clock was created.
unsigned long int b3Clock::getTimeMilliseconds()
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = b3Min(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
// Recompute the number of millisecond ticks elapsed.
msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
}
// Store the current elapsed time for adjustments next time.
m_data->mPrevElapsedTime = elapsedTime;
return msecTicks;
#else
#ifdef __CELLOS_LV2__
uint64_t freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq) / 1000.0;
typedef uint64_t ClockSize;
ClockSize newTime;
SYS_TIMEBASE_GET( newTime );
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
#else
struct timeval currentTime;
gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000;
#endif //__CELLOS_LV2__
#endif
}
/// Returns the time in us since the last call to reset or since
/// the Clock was created.
unsigned long int b3Clock::getTimeMicroseconds()
{
#ifdef B3_USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
m_data->mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = b3Min(msecOff *
m_data->mClockFrequency.QuadPart / 1000, elapsedTime -
m_data->mPrevElapsedTime);
m_data->mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
}
// Store the current elapsed time for adjustments next time.
m_data->mPrevElapsedTime = elapsedTime;
// Convert to microseconds.
unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime /
m_data->mClockFrequency.QuadPart);
return usecTicks;
#else
#ifdef __CELLOS_LV2__
uint64_t freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq)/ 1000000.0;
typedef uint64_t ClockSize;
ClockSize newTime;
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
SYS_TIMEBASE_GET( newTime );
return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq);
#else
struct timeval currentTime;
gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 +
(currentTime.tv_usec - m_data->mStartTime.tv_usec);
#endif//__CELLOS_LV2__
#endif
}

View File

@ -32,44 +32,14 @@ subject to the following restrictions:
//#define B3_NO_PROFILE 1
#ifndef B3_NO_PROFILE
#include <stdio.h>//@todo remove this, backwards compatibility
#include "b3Scalar.h"
#include "b3AlignedAllocator.h"
#include "Bullet3Common/b3Scalar.h"
#include "Bullet3Common/b3AlignedAllocator.h"
#include <new>
#define B3_USE_CLOCK 1
#ifdef B3_USE_CLOCK
///The b3Clock is a portable basic clock that measures accurate time in seconds, use for profiling.
class b3Clock
{
public:
b3Clock();
b3Clock(const b3Clock& other);
b3Clock& operator=(const b3Clock& other);
~b3Clock();
/// Resets the initial reference time.
void reset();
/// Returns the time in ms since the last call to reset or since
/// the b3Clock was created.
unsigned long int getTimeMilliseconds();
/// Returns the time in us since the last call to reset or since
/// the Clock was created.
unsigned long int getTimeMicroseconds();
private:
struct b3ClockData* m_data;
};
#endif //B3_USE_CLOCK
#include "b3Clock.h"
@ -187,27 +157,12 @@ private:
};
///ProfileSampleClass is a simple way to profile a function's scope
///Use the B3_PROFILE macro at the start of scope to time
class b3ProfileSample {
public:
b3ProfileSample( const char * name )
{
b3ProfileManager::Start_Profile( name );
}
~b3ProfileSample( void )
{
b3ProfileManager::Stop_Profile();
}
};
#define B3_PROFILE( name ) b3ProfileSample __profile( name )
#else
#define B3_PROFILE( name )
#endif //#ifndef B3_NO_PROFILE

View File

@ -24,3 +24,5 @@
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solveContact.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solveContact.h" --stringname="solveContactCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/RigidBody//kernels/solveFriction.cl" --headerfile="../src/Bullet3OpenCL/RigidBody//kernels/solveFriction.h" --stringname="solveFrictionCL" stringify
./premake4_linux --file=stringifyKernel.lua --kernelfile="../src/Bullet3OpenCL/Raycast/kernels/rayCastKernels.cl" --headerfile="../src/Bullet3OpenCL/Raycast/kernels/rayCastKernels.h" --stringname="rayCastKernelCL" stringify

View File

@ -1,486 +0,0 @@
Index: build/findOpenCL.lua
===================================================================
--- build/findOpenCL.lua (revision 2640)
+++ build/findOpenCL.lua (working copy)
@@ -1,5 +1,14 @@
- -- todo: add Apple OpenCL environment vars
+
+ function findOpenCL_Apple()
+ if os.is("macosx") then
+ return true
+ else
+ return false
+ end
+ end
+
+
function findOpenCL_AMD()
local amdopenclpath = os.getenv("AMDAPPSDKROOT")
if (amdopenclpath) then
@@ -17,13 +26,33 @@
end
function findOpenCL_Intel()
- local intelopenclpath = os.getenv("INTELOCLSDKROOT")
- if (intelopenclpath) then
+ if os.is("Windows") then
+ local intelopenclpath = os.getenv("INTELOCLSDKROOT")
+ if (intelopenclpath) then
return true
+ end
end
+ if os.is("Linux") then
+ local intelsdk = io.open("/usr/include/CL/opencl.h","r")
+ if (intelsdk) then
+ return true;
+ end
+ end
return false
end
-
+
+ function initOpenCL_Apple()
+ configuration{}
+ includedirs {
+ "/System/Library/Frameworks/OpenCL.framework"
+ }
+ libdirs "/System/Library/Frameworks/OpenCL.framework"
+ links
+ {
+ "OpenCL.framework"
+ }
+ end
+
function initOpenCL_AMD()
configuration {}
local amdopenclpath = os.getenv("AMDAPPSDKROOT")
@@ -65,6 +94,7 @@
function initOpenCL_Intel()
configuration {}
+ if os.is("Windows") then
local intelopenclpath = os.getenv("INTELOCLSDKROOT")
if (intelopenclpath) then
defines { "ADL_ENABLE_CL" , "CL_PLATFORM_INTEL"}
@@ -79,6 +109,43 @@
links {"OpenCL"}
return true
end
+ end
+ if os.is("Linux") then
+ defines { "ADL_ENABLE_CL" , "CL_PLATFORM_INTEL"}
+ configuration {}
+ links {"OpenCL"}
+ end
return false
end
-
\ No newline at end of file
+
+ function findOpenCL (vendor )
+ if vendor=="AMD" then
+ return findOpenCL_AMD()
+ end
+ if vendor=="NVIDIA" then
+ return findOpenCL_NVIDIA()
+ end
+ if vendor=="Intel" then
+ return findOpenCL_Intel()
+ end
+ if vendor=="Apple" then
+ return findOpenCL_Apple()
+ end
+ return false
+ end
+
+ function initOpenCL ( vendor )
+ if vendor=="AMD" then
+ initOpenCL_AMD()
+ end
+ if vendor=="NVIDIA" then
+ return initOpenCL_NVIDIA()
+ end
+ if vendor=="Intel" then
+ initOpenCL_Intel()
+ end
+ if vendor=="Apple" then
+ return initOpenCL_Apple()
+ end
+ end
+
Index: build/premake4.lua
===================================================================
--- build/premake4.lua (revision 2640)
+++ build/premake4.lua (working copy)
@@ -1,102 +1,47 @@
---add the 0 so the solution comes first in the directory (when sorted on name)
---print "uncomment this hello premake4 world for debugging the script"
-solution "0BulletSolution"
+ solution "0MySolution"
- newoption {
- trigger = "ios",
- description = "Enable iOS target (requires xcode4)"
- }
-
- newoption {
- trigger = "without-demos",
- description = "Disable demos and extras"
- }
+ -- Multithreaded compiling
+ if _ACTION == "vs2010" or _ACTION=="vs2008" then
+ buildoptions { "/MP" }
+ end
+
+ act = ""
+
+ if _ACTION then
+ act = _ACTION
+ end
- newoption {
- trigger = "with-double-precision",
- description = "Enable double precision build"
- }
-
- newoption {
- trigger = "with-nacl",
- description = "Enable Native Client build"
- }
+ newoption
+ {
+ trigger = "ios",
+ description = "Enable iOS target (requires xcode4)"
+ }
+
+ newoption
+ {
+ trigger = "bullet2gpu",
+ description = "Enable Bullet 2.x GPU using b3GpuDynamicsWorld bridge to Bullet 3.x"
+ }
- newoption {
- trigger = "with-dx11",
- description = "Enable DirectX11 build"
- }
-
- newoption {
- trigger = "with-opencl",
- description = "Enable OpenCL builds (various SDKs)"
- }
-
- newoption {
- trigger = "with-opencl-amd",
- description = "Enable OpenCL builds (AMD SDK)"
- }
-
- newoption {
- trigger = "with-opencl-intel",
- description = "Enable OpenCL builds (Intel SDK)"
- }
- newoption {
- trigger = "with-opencl-nvidia",
- description = "Enable OpenCL builds (NVIDIA SDK)"
- }
-
-
configurations {"Release", "Debug"}
configuration "Release"
- flags { "Optimize", "EnableSSE", "StaticRuntime", "NoMinimalRebuild", "FloatFast"}
+ flags { "Optimize", "EnableSSE","StaticRuntime", "NoMinimalRebuild", "FloatFast"}
configuration "Debug"
+ defines {"_DEBUG=1"}
flags { "Symbols", "StaticRuntime" , "NoMinimalRebuild", "NoEditAndContinue" ,"FloatFast"}
- platforms {"x32", "x64"}
- --platforms {"x32"}
-
- configuration {"Windows"}
- defines { "_CRT_SECURE_NO_WARNINGS","_CRT_SECURE_NO_DEPRECATE"}
-
- configuration{}
-
- postfix="";
-
- if _OPTIONS["with-double-precision"] then
- defines {"BT_USE_DOUBLE_PRECISION"}
- end
-
- if _ACTION == "xcode4" then
- if _OPTIONS["ios"] then
- postfix = "ios";
- xcodebuildsettings
- {
- 'INFOPLIST_FILE = "../../Test/Info.plist"',
- 'CODE_SIGN_IDENTITY = "iPhone Developer"',
- "SDKROOT = iphoneos",
- 'ARCHS = "armv7"',
- 'TARGETED_DEVICE_FAMILY = "1,2"',
- 'VALID_ARCHS = "armv7"',
- }
- else
- xcodebuildsettings
- {
- 'ARCHS = "$(ARCHS_STANDARD_32_BIT) $(ARCHS_STANDARD_64_BIT)"',
- 'VALID_ARCHS = "x86_64 i386"',
- }
+ if os.is("Linux") then
+ if os.is64bit() then
+ platforms {"x64"}
+ else
+ platforms {"x32"}
end
else
-
+ platforms {"x32", "x64"}
end
- act = ""
-
- if _ACTION then
- act = _ACTION
- end
configuration {"x32"}
targetsuffix ("_" .. act)
configuration "x64"
@@ -110,89 +55,91 @@
configuration{}
+ postfix=""
+ if _ACTION == "xcode4" then
+ if _OPTIONS["ios"] then
+ postfix = "ios";
+ xcodebuildsettings
+ {
+ 'CODE_SIGN_IDENTITY = "iPhone Developer"',
+ "SDKROOT = iphoneos",
+ 'ARCHS = "armv7"',
+ 'TARGETED_DEVICE_FAMILY = "1,2"',
+ 'VALID_ARCHS = "armv7"',
+ }
+ else
+ xcodebuildsettings
+ {
+ 'ARCHS = "$(ARCHS_STANDARD_32_BIT) $(ARCHS_STANDARD_64_BIT)"',
+ 'VALID_ARCHS = "x86_64 i386"',
+ }
+ end
+ end
-if not _OPTIONS["with-nacl"] then
-
- flags { "NoRTTI"}
+
+ flags { "NoRTTI", "NoExceptions"}
+ defines { "_HAS_EXCEPTIONS=0" }
targetdir "../bin"
+ location("./" .. act .. postfix)
- -- Disable exception handling on MSVC 2008 and higher. MSVC 2005 without service pack has some linker issue (ConvexDecompositionDemo uses STL through HACD library)
- if _ACTION == "vs2010" or _ACTION=="vs2008" then
- flags { "NoExceptions"}
- defines { "_HAS_EXCEPTIONS=0" }
- end
+
+ projectRootDir = os.getcwd() .. "/../"
+ print("Project root directroy: " .. projectRootDir);
- -- Multithreaded compiling
- if _ACTION == "vs2010" then
- buildoptions { "/MP" }
- end
-
-
-else
- targetdir "../bin_html"
-end
-
-
dofile ("findOpenCL.lua")
dofile ("findDirectX11.lua")
+ dofile ("findOpenGLGlewGlut.lua")
language "C++"
- location("./" .. act .. postfix)
+
+ if not _OPTIONS["ios"] then
+-- include "../demo/gpudemo"
+-- include "../btgui/MidiTest"
+-- include "../opencl/vector_add_simplified"
+-- include "../opencl/vector_add"
+ include "../btgui/Gwen"
+ include "../btgui/GwenOpenGLTest"
+
+ include "../test/OpenCL/BasicInitialize"
+-- include "../test/OpenCL/BroadphaseCollision"
+-- include "../test/OpenCL/NarrowphaseCollision"
+ include "../test/OpenCL/ParallelPrimitives"
+ include "../test/OpenCL/RadixSortBenchmark"
+ include "../test/OpenCL/BitonicSort"
+
+ include "../src/Bullet3Dynamics"
+ include "../src/Bullet3Common"
+ include "../src/Bullet3Geometry"
+ include "../src/Bullet3Collision"
+ include "../src/Bullet3Serialize/Bullet2FileLoader"
- if _OPTIONS["with-dx11"] then
- include "../Demos/DX11ClothDemo"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/DX11"
- end
+ include "../src/Bullet3OpenCL"
+ include "../Demos3/GpuDemos"
+
+-- include "../demo/gpu_initialize"
+-- include "../opencl/lds_bank_conflict"
+-- include "../opencl/reduce"
+-- include "../btgui/OpenGLTrueTypeFont"
+-- include "../btgui/OpenGLWindow"
+-- include "../demo/ObjLoader"
---choose any OpenCL sdk that is installed on the system
- if _OPTIONS["with-opencl"] then
- include "../Demos/OpenCLClothDemo/AMD"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/AMD"
- include "../Demos/OpenCLClothDemo/NVidia"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/NVidia"
- include "../Demos/OpenCLClothDemo/Intel"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/Intel"
- end
+
+-- include "../test/b3DynamicBvhBroadphase"
+
---choose a particular OpenCL sdk, this is useful for distributing project files that just work for one OpenCL SDK
- if _OPTIONS["with-opencl-amd"] then
- include "../Demos/OpenCLClothDemo/AMD"
- include "../Demos/OpenGL"
- include "../Demos/SoftDemo/AMD"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/AMD"
- end
-
- if _OPTIONS["with-opencl-intel"] then
- include "../Demos/OpenCLClothDemo/Intel"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/Intel"
- end
+
- if _OPTIONS["with-opencl-nvidia"] then
- include "../Demos/OpenCLClothDemo/NVidia"
- include "../src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/NVidia"
+ if _OPTIONS["bullet2gpu"] then
+ include "../src/LinearMath"
+ include "../src/BulletCollision"
+ include "../src/BulletDynamics"
+ include "../src/BulletSoftBody"
+ include "../Demos/HelloWorld"
+
+ include "../Demos3"
end
- if not _OPTIONS["without-demos"] then
- if not _OPTIONS["ios"] then
- include "../Demos"
end
- include "../Extras"
- end
-
-
- if _OPTIONS["with-nacl"] then
- include "../Demos/NativeClient"
- else
- include "../src/LinearMath"
- include "../src/BulletCollision"
- include "../src/BulletDynamics"
- include "../src/BulletSoftBody"
- end
-
- include "../Test"
- include "../Demos/HelloWorld"
- include "../Demos/Benchmarks"
-
Index: build/premake4_linux
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: build/premake4_osx
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: build/vs2010.bat
===================================================================
--- build/vs2010.bat (revision 2640)
+++ build/vs2010.bat (working copy)
@@ -1,4 +1,6 @@
+rem premake4 --with-pe vs2010
premake4 vs2010
+mkdir vs2010\cache
pause
\ No newline at end of file
Index: Demos/OpenGL/DemoApplication.cpp
===================================================================
--- Demos/OpenGL/DemoApplication.cpp (revision 2640)
+++ Demos/OpenGL/DemoApplication.cpp (working copy)
@@ -1182,8 +1182,8 @@
}
}
- btVector3 aabbMin,aabbMax;
- m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
+ btVector3 aabbMin(0,0,0),aabbMax(0,0,0);
+ //m_dynamicsWorld->getBroadphase()->getBroadphaseAabb(aabbMin,aabbMax);
aabbMin-=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
aabbMax+=btVector3(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
Index: Demos/OpenGL/DemoApplication.h
===================================================================
--- Demos/OpenGL/DemoApplication.h (revision 2640)
+++ Demos/OpenGL/DemoApplication.h (working copy)
@@ -149,6 +149,11 @@
{
m_azi = azi;
}
+
+ void setEle(float ele)
+ {
+ m_ele = ele;
+ }
void setCameraUp(const btVector3& camUp)
{
Index: src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
===================================================================
--- src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp (revision 2640)
+++ src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp (working copy)
@@ -73,7 +73,7 @@
m_debugDrawer(0),
m_forceUpdateAllAabbs(true)
{
- m_stackAlloc = collisionConfiguration->getStackAllocator();
+ m_stackAlloc = 0;//collisionConfiguration->getStackAllocator();
m_dispatchInfo.m_stackAllocator = m_stackAlloc;
}
Index: src/BulletDynamics/Dynamics/btDynamicsWorld.h
===================================================================
--- src/BulletDynamics/Dynamics/btDynamicsWorld.h (revision 2640)
+++ src/BulletDynamics/Dynamics/btDynamicsWorld.h (working copy)
@@ -33,7 +33,8 @@
BT_SIMPLE_DYNAMICS_WORLD=1,
BT_DISCRETE_DYNAMICS_WORLD=2,
BT_CONTINUOUS_DYNAMICS_WORLD=3,
- BT_SOFT_RIGID_DYNAMICS_WORLD=4
+ BT_SOFT_RIGID_DYNAMICS_WORLD=4,
+ BT_GPU_DYNAMICS_WORLD=5
};
///The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.

View File

@ -651,7 +651,7 @@ void b3DynamicBvh::extractLeaves(const b3DbvtNode* node,b3AlignedObjectArray<c
#include <stdio.h>
#include <stdlib.h>
#include "LinearMath/b3QuickProf.h"
/*
q6600,2.4ghz

View File

@ -36,7 +36,7 @@ subject to the following restrictions:
#if B3_DBVT_BP_PROFILE
#define B3_DBVT_BP_PROFILING_RATE 256
#include "LinearMath/b3Quickprof.h"
#endif

View File

@ -82,6 +82,37 @@ void b3OutputErrorMessageVarArgsInternal(const char *str, ...)
va_end(argList);
}
void b3EnterProfileZoneDefault(const char* name)
{
}
void b3LeaveProfileZoneDefault()
{
}
static b3EnterProfileZoneFunc* b3s_enterFunc = b3EnterProfileZoneDefault;
static b3LeaveProfileZoneFunc* b3s_leaveFunc = b3LeaveProfileZoneDefault;
void b3EnterProfileZone(const char* name)
{
(b3s_enterFunc)(name);
}
void b3LeaveProfileZone()
{
(b3s_leaveFunc)();
}
void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc)
{
b3s_enterFunc = enterFunc;
}
void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc)
{
b3s_leaveFunc = leaveFunc;
}
#ifndef _WIN32
#undef vsprintf_s
#endif

View File

@ -2,21 +2,6 @@
#ifndef B3_LOGGING_H
#define B3_LOGGING_H
typedef void (b3PrintfFunc)(const char* msg);
typedef void (b3WarningMessageFunc)(const char* msg);
typedef void (b3ErrorMessageFunc)(const char* msg);
///The developer can route b3Printf output using their own implementation
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
void b3OutputPrintfVarArgsInternal(const char *str, ...);
void b3OutputWarningMessageVarArgsInternal(const char *str, ...);
void b3OutputErrorMessageVarArgsInternal(const char *str, ...);
///We add the do/while so that the statement "if (condition) b3Printf("test"); else {...}" would fail
///You can also customize the message by uncommenting out a different line below
#define b3Printf(...) b3OutputPrintfVarArgsInternal(__VA_ARGS__)
@ -28,4 +13,57 @@ void b3OutputErrorMessageVarArgsInternal(const char *str, ...);
#define b3Warning(...) do {b3OutputWarningMessageVarArgsInternal("b3Warning[%s,%d]:\n",__FILE__,__LINE__);b3OutputWarningMessageVarArgsInternal(__VA_ARGS__); }while(0)
#define b3Error(...) do {b3OutputErrorMessageVarArgsInternal("b3Error[%s,%d]:\n",__FILE__,__LINE__);b3OutputErrorMessageVarArgsInternal(__VA_ARGS__); } while(0)
#ifndef B3_NO_PROFILE
void b3EnterProfileZone(const char* name);
void b3LeaveProfileZone();
class b3ProfileZone
{
public:
b3ProfileZone(const char* name)
{
b3EnterProfileZone( name );
}
~b3ProfileZone()
{
b3LeaveProfileZone();
}
};
#define B3_PROFILE( name ) b3ProfileZone __profile( name )
#else //B3_NO_PROFILE
#define B3_PROFILE( name )
#define b3StartProfile(a)
#define b3StopProfile
#endif //#ifndef B3_NO_PROFILE
typedef void (b3PrintfFunc)(const char* msg);
typedef void (b3WarningMessageFunc)(const char* msg);
typedef void (b3ErrorMessageFunc)(const char* msg);
typedef void (b3EnterProfileZoneFunc)(const char* msg);
typedef void (b3LeaveProfileZoneFunc)();
///The developer can route b3Printf output using their own implementation
void b3SetCustomPrintfFunc(b3PrintfFunc* printfFunc);
void b3SetCustomWarningMessageFunc(b3WarningMessageFunc* warningMsgFunc);
void b3SetCustomErrorMessageFunc(b3ErrorMessageFunc* errorMsgFunc);
///Set custom profile zone functions (zones can be nested)
void b3SetCustomEnterProfileZoneFunc(b3EnterProfileZoneFunc* enterFunc);
void b3SetCustomLeaveProfileZoneFunc(b3LeaveProfileZoneFunc* leaveFunc);
///Don't use those internal functions directly, use the b3Printf or b3SetCustomPrintfFunc instead (or warning/error version)
void b3OutputPrintfVarArgsInternal(const char *str, ...);
void b3OutputWarningMessageVarArgsInternal(const char *str, ...);
void b3OutputErrorMessageVarArgsInternal(const char *str, ...);
#endif//B3_LOGGING_H

View File

@ -25,7 +25,7 @@ subject to the following restrictions:
#include "b3TypedConstraint.h"
#include <new>
#include "Bullet3Common/b3StackAlloc.h"
#include "Bullet3Common/b3Quickprof.h"
//#include "b3SolverBody.h"
//#include "b3SolverConstraint.h"
#include "Bullet3Common/b3AlignedObjectArray.h"

View File

@ -2,7 +2,7 @@
#include "b3GpuSapBroadphase.h"
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "kernels/sapKernels.h"
#include "kernels/sapFastKernels.h"

View File

@ -28,7 +28,7 @@ int b3g_actualSATPairTests=0;
typedef b3AlignedObjectArray<b3Vector3> b3VertexArray;
#include "Bullet3Common/b3Quickprof.h"
#include <float.h> //for FLT_MAX
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"

View File

@ -319,10 +319,10 @@ void b3RadixSort32CL::execute(b3OpenCLArray<b3SortData>& keyValuesInOut, int sor
//fast prefix scan is not working properly on Mac OSX yet
#ifdef _WIN32
bool fastScan=!m_deviceCPU;//only use fast scan on GPU
#else
#ifdef __APPLE__
bool fastScan=false;
#else
bool fastScan=!m_deviceCPU;//only use fast scan on GPU
#endif
if (fastScan)
@ -653,11 +653,10 @@ void b3RadixSort32CL::execute(b3OpenCLArray<unsigned int>& keysInOut, int sortBi
//fast prefix scan is not working properly on Mac OSX yet
#ifdef _WIN32
bool fastScan=!m_deviceCPU;
#else
#ifdef __APPLE__
bool fastScan=false;
#else
bool fastScan=!m_deviceCPU;
#endif
if (fastScan)

View File

@ -2,7 +2,9 @@
#include "b3GpuRaycast.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3Collidable.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhaseInternalData.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
@ -73,9 +75,57 @@ bool sphere_intersect(const b3Vector3& spherePos, b3Scalar radius, const b3Vect
return false;
}
bool rayConvex(const b3Vector3& rayFromLocal, const b3Vector3& rayToLocal, const b3ConvexPolyhedronCL& poly,
const b3AlignedObjectArray<b3GpuFace>& faces, float& hitFraction, b3Vector3& hitNormal)
{
float exitFraction = hitFraction;
float enterFraction = -0.1f;
b3Vector3 curHitNormal(0,0,0);
for (int i=0;i<poly.m_numFaces;i++)
{
const b3GpuFace& face = faces[poly.m_faceOffset+i];
float fromPlaneDist = b3Dot(rayFromLocal,face.m_plane)+face.m_plane.w;
float toPlaneDist = b3Dot(rayToLocal,face.m_plane)+face.m_plane.w;
if (fromPlaneDist<0.f)
{
if (toPlaneDist >= 0.f)
{
float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);
if (exitFraction>fraction)
{
exitFraction = fraction;
}
}
} else
{
if (toPlaneDist<0.f)
{
float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);
if (enterFraction <= fraction)
{
enterFraction = fraction;
curHitNormal = face.m_plane;
curHitNormal.w = 0.f;
}
} else
{
return false;
}
}
if (exitFraction <= enterFraction)
return false;
}
if (enterFraction < 0.f)
return false;
hitFraction = enterFraction;
hitNormal = curHitNormal;
return true;
}
void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults,
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables,const struct b3Collidable* collidables)
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables,const struct b3Collidable* collidables, const struct b3GpuNarrowPhaseInternalData* narrowphaseData)
{
// return castRays(rays,hitResults,numBodies,bodies,numCollidables,collidables);
@ -88,6 +138,7 @@ void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3A
float hitFraction = hitResults[r].m_hitFraction;
int hitBodyIndex= -1;
b3Vector3 hitNormal;
for (int b=0;b<numBodies;b++)
{
@ -103,9 +154,34 @@ void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3A
if (sphere_intersect(pos, radius, rayFrom, rayTo,hitFraction))
{
hitBodyIndex = b;
b3Vector3 hitPoint;
hitPoint.setInterpolate3(rays[r].m_from, rays[r].m_to,hitFraction);
hitNormal = (hitPoint-bodies[b].m_pos).normalize();
}
}
case SHAPE_CONVEX_HULL:
{
b3Transform convexWorldTransform;
convexWorldTransform.setIdentity();
convexWorldTransform.setOrigin(bodies[b].m_pos);
convexWorldTransform.setRotation(bodies[b].m_quat);
b3Transform convexWorld2Local = convexWorldTransform.inverse();
b3Vector3 rayFromLocal = convexWorld2Local(rayFrom);
b3Vector3 rayToLocal = convexWorld2Local(rayTo);
int shapeIndex = collidables[bodies[b].m_collidableIdx].m_shapeIndex;
const b3ConvexPolyhedronCL& poly = narrowphaseData->m_convexPolyhedra[shapeIndex];
if (rayConvex(rayFromLocal, rayToLocal,poly,narrowphaseData->m_convexFaces, hitFraction, hitNormal))
{
hitBodyIndex = b;
}
break;
}
default:
{
static bool once=true;
@ -122,7 +198,7 @@ void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3A
hitResults[r].m_hitFraction = hitFraction;
hitResults[r].m_hitPoint.setInterpolate3(rays[r].m_from, rays[r].m_to,hitFraction);
hitResults[r].m_hitNormal = (hitResults[r].m_hitPoint-bodies[hitBodyIndex].m_pos).normalize();
hitResults[r].m_hitNormal = hitNormal;
hitResults[r].m_hitResult0 = hitBodyIndex;
}
@ -130,8 +206,9 @@ void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3A
}
void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults,
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables)
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables, const struct b3GpuNarrowPhaseInternalData* narrowphaseData)
{
B3_PROFILE("castRaysGPU");
b3OpenCLArray<b3RayInfo> gpuRays(m_data->m_context,m_data->m_q);
@ -141,14 +218,6 @@ void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3Align
gpuHitResults.resize(hitResults.size());
gpuHitResults.copyFromHost(hitResults);
b3OpenCLArray<b3RigidBodyCL> gpuBodies(m_data->m_context,m_data->m_q);
gpuBodies.resize(numBodies);
gpuBodies.copyFromHostPointer(bodies,numBodies);
b3OpenCLArray<b3Collidable> gpuCollidables(m_data->m_context,m_data->m_q);
gpuCollidables.resize(numCollidables);
gpuCollidables.copyFromHostPointer(collidables,numCollidables);
//run kernel
{
@ -162,8 +231,10 @@ void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3Align
launcher.setBuffer(gpuHitResults.getBufferCL());
launcher.setConst(numBodies);
launcher.setBuffer(gpuBodies.getBufferCL());
launcher.setBuffer(gpuCollidables.getBufferCL());
launcher.setBuffer(narrowphaseData->m_bodyBufferGPU->getBufferCL());
launcher.setBuffer(narrowphaseData->m_collidablesGPU->getBufferCL());
launcher.setBuffer(narrowphaseData->m_convexFacesGPU->getBufferCL());
launcher.setBuffer(narrowphaseData->m_convexPolyhedraGPU->getBufferCL());
launcher.launch1D(numRays);
clFinish(m_data->m_q);

View File

@ -18,10 +18,13 @@ public:
virtual ~b3GpuRaycast();
void castRaysHost(const b3AlignedObjectArray<b3RayInfo>& raysIn, b3AlignedObjectArray<b3RayHit>& hitResults,
int numBodies, const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables);
int numBodies, const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables,
const struct b3GpuNarrowPhaseInternalData* narrowphaseData);
void castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults,
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables);
int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables,
const struct b3GpuNarrowPhaseInternalData* narrowphaseData
);
/* const b3OpenCLArray<b3RigidBodyCL>* bodyBuf,
b3OpenCLArray<b3Contact4>* contactOut, int& nContacts,

View File

@ -47,6 +47,184 @@ typedef struct Collidable
} Collidable;
typedef struct
{
float4 m_localCenter;
float4 m_extents;
float4 mC;
float4 mE;
float m_radius;
int m_faceOffset;
int m_numFaces;
int m_numVertices;
int m_vertexOffset;
int m_uniqueEdgesOffset;
int m_numUniqueEdges;
int m_unused;
} ConvexPolyhedronCL;
typedef struct
{
float4 m_plane;
int m_indexOffset;
int m_numIndices;
} b3GpuFace;
///////////////////////////////////////
// Quaternion
///////////////////////////////////////
typedef float4 Quaternion;
__inline
Quaternion qtMul(Quaternion a, Quaternion b);
__inline
Quaternion qtNormalize(Quaternion in);
__inline
float4 qtRotate(Quaternion q, float4 vec);
__inline
Quaternion qtInvert(Quaternion q);
__inline
float dot3F4(float4 a, float4 b)
{
float4 a1 = (float4)(a.xyz,0.f);
float4 b1 = (float4)(b.xyz,0.f);
return dot(a1, b1);
}
__inline
Quaternion qtMul(Quaternion a, Quaternion b)
{
Quaternion ans;
ans = cross( a, b );
ans += a.w*b+b.w*a;
// ans.w = a.w*b.w - (a.x*b.x+a.y*b.y+a.z*b.z);
ans.w = a.w*b.w - dot3F4(a, b);
return ans;
}
__inline
Quaternion qtNormalize(Quaternion in)
{
return fast_normalize(in);
// in /= length( in );
// return in;
}
__inline
float4 qtRotate(Quaternion q, float4 vec)
{
Quaternion qInv = qtInvert( q );
float4 vcpy = vec;
vcpy.w = 0.f;
float4 out = qtMul(qtMul(q,vcpy),qInv);
return out;
}
__inline
Quaternion qtInvert(Quaternion q)
{
return (Quaternion)(-q.xyz, q.w);
}
__inline
float4 qtInvRotate(const Quaternion q, float4 vec)
{
return qtRotate( qtInvert( q ), vec );
}
__inline
float4 transform(const float4* p, const float4* translation, const Quaternion* orientation)
{
return qtRotate( *orientation, *p ) + (*translation);
}
void trInverse(float4 translationIn, Quaternion orientationIn,
float4* translationOut, Quaternion* orientationOut)
{
*orientationOut = qtInvert(orientationIn);
*translationOut = qtRotate(*orientationOut, -translationIn);
}
void trMul(float4 translationA, Quaternion orientationA,
float4 translationB, Quaternion orientationB,
float4* translationOut, Quaternion* orientationOut)
{
*orientationOut = qtMul(orientationA,orientationB);
*translationOut = transform(&translationB,&translationA,&orientationA);
}
bool rayConvex(float4 rayFromLocal, float4 rayToLocal, int numFaces, int faceOffset,
__global const b3GpuFace* faces, float* hitFraction, float4* hitNormal)
{
rayFromLocal.w = 0.f;
rayToLocal.w = 0.f;
bool result = true;
float exitFraction = *hitFraction;
float enterFraction = -0.1f;
float4 curHitNormal = (float4)(0,0,0,0);
for (int i=0;i<numFaces && result;i++)
{
b3GpuFace face = faces[faceOffset+i];
float fromPlaneDist = dot(rayFromLocal,face.m_plane)+face.m_plane.w;
float toPlaneDist = dot(rayToLocal,face.m_plane)+face.m_plane.w;
if (fromPlaneDist<0.f)
{
if (toPlaneDist >= 0.f)
{
float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);
if (exitFraction>fraction)
{
exitFraction = fraction;
}
}
} else
{
if (toPlaneDist<0.f)
{
float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);
if (enterFraction <= fraction)
{
enterFraction = fraction;
curHitNormal = face.m_plane;
curHitNormal.w = 0.f;
}
} else
{
result = false;
}
}
if (exitFraction <= enterFraction)
result = false;
}
result = result && (enterFraction < 0.f);
if (result)
{
*hitFraction = enterFraction;
*hitNormal = curHitNormal;
}
return result;
}
bool sphere_intersect(float4 spherePos, float radius, float4 rayFrom, float4 rayTo, float* hitFraction)
{
@ -88,10 +266,11 @@ __kernel void rayCastKernel(
__global b3RayHit* hitResults,
const int numBodies,
__global Body* bodies,
__global Collidable* collidables)
__global Collidable* collidables,
__global const b3GpuFace* faces,
__global const ConvexPolyhedronCL* convexShapes )
{
int i = get_global_id(0);
if (i<numRays)
{
@ -100,6 +279,8 @@ __kernel void rayCastKernel(
float4 rayFrom = rays[i].m_from;
float4 rayTo = rays[i].m_to;
float hitFraction = 1.f;
float4 hitPoint;
float4 hitNormal;
int hitBodyIndex= -1;
int cachedCollidableIndex = -1;
@ -109,7 +290,7 @@ __kernel void rayCastKernel(
{
float4 pos = bodies[b].m_pos;
// float4 orn = bodies[b].m_quat;
float4 orn = bodies[b].m_quat;
if (cachedCollidableIndex !=bodies[b].m_collidableIdx)
{
cachedCollidableIndex = bodies[b].m_collidableIdx;
@ -123,15 +304,38 @@ __kernel void rayCastKernel(
if (sphere_intersect(pos, radius, rayFrom, rayTo, &hitFraction))
{
hitBodyIndex = b;
hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);
hitNormal = (float4) (hitPoint-bodies[b].m_pos);
}
}
if (cachedCollidable.m_shapeType == SHAPE_CONVEX_HULL)
{
float4 invPos = (float4)(0,0,0,0);
float4 invOrn = (float4)(0,0,0,0);
float4 rayFromLocal = (float4)(0,0,0,0);
float4 rayToLocal = (float4)(0,0,0,0);
trInverse(pos,orn, &invPos, &invOrn);
rayFromLocal = transform(&rayFrom, &invPos, &invOrn);
rayToLocal = transform(&rayTo, &invPos, &invOrn);
int numFaces = convexShapes[cachedCollidable.m_shapeIndex].m_numFaces;
int faceOffset = convexShapes[cachedCollidable.m_shapeIndex].m_faceOffset;
if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))
{
hitBodyIndex = b;
}
}
}
if (hitBodyIndex>=0)
{
hitResults[i].m_hitFraction = hitFraction;
hitResults[i].m_hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);
float4 hitNormal = (float4) (hitResults[i].m_hitPoint-bodies[hitBodyIndex].m_pos);
hitResults[i].m_hitPoint = hitPoint;
hitResults[i].m_hitNormal = normalize(hitNormal);
hitResults[i].m_hitResult0 = hitBodyIndex;
}

View File

@ -49,6 +49,184 @@ static const char* rayCastKernelCL= \
"} Collidable;\n"
"\n"
"\n"
"typedef struct \n"
"{\n"
" float4 m_localCenter;\n"
" float4 m_extents;\n"
" float4 mC;\n"
" float4 mE;\n"
" \n"
" float m_radius;\n"
" int m_faceOffset;\n"
" int m_numFaces;\n"
" int m_numVertices;\n"
" \n"
" int m_vertexOffset;\n"
" int m_uniqueEdgesOffset;\n"
" int m_numUniqueEdges;\n"
" int m_unused;\n"
"\n"
"} ConvexPolyhedronCL;\n"
"\n"
"typedef struct\n"
"{\n"
" float4 m_plane;\n"
" int m_indexOffset;\n"
" int m_numIndices;\n"
"} b3GpuFace;\n"
"\n"
"\n"
"\n"
"///////////////////////////////////////\n"
"// Quaternion\n"
"///////////////////////////////////////\n"
"\n"
"typedef float4 Quaternion;\n"
"\n"
"__inline\n"
"Quaternion qtMul(Quaternion a, Quaternion b);\n"
"\n"
"__inline\n"
"Quaternion qtNormalize(Quaternion in);\n"
"\n"
"__inline\n"
"float4 qtRotate(Quaternion q, float4 vec);\n"
"\n"
"__inline\n"
"Quaternion qtInvert(Quaternion q);\n"
"\n"
"\n"
"__inline\n"
"float dot3F4(float4 a, float4 b)\n"
"{\n"
" float4 a1 = (float4)(a.xyz,0.f);\n"
" float4 b1 = (float4)(b.xyz,0.f);\n"
" return dot(a1, b1);\n"
"}\n"
"\n"
"\n"
"__inline\n"
"Quaternion qtMul(Quaternion a, Quaternion b)\n"
"{\n"
" Quaternion ans;\n"
" ans = cross( a, b );\n"
" ans += a.w*b+b.w*a;\n"
"// ans.w = a.w*b.w - (a.x*b.x+a.y*b.y+a.z*b.z);\n"
" ans.w = a.w*b.w - dot3F4(a, b);\n"
" return ans;\n"
"}\n"
"\n"
"__inline\n"
"Quaternion qtNormalize(Quaternion in)\n"
"{\n"
" return fast_normalize(in);\n"
"// in /= length( in );\n"
"// return in;\n"
"}\n"
"__inline\n"
"float4 qtRotate(Quaternion q, float4 vec)\n"
"{\n"
" Quaternion qInv = qtInvert( q );\n"
" float4 vcpy = vec;\n"
" vcpy.w = 0.f;\n"
" float4 out = qtMul(qtMul(q,vcpy),qInv);\n"
" return out;\n"
"}\n"
"\n"
"__inline\n"
"Quaternion qtInvert(Quaternion q)\n"
"{\n"
" return (Quaternion)(-q.xyz, q.w);\n"
"}\n"
"\n"
"__inline\n"
"float4 qtInvRotate(const Quaternion q, float4 vec)\n"
"{\n"
" return qtRotate( qtInvert( q ), vec );\n"
"}\n"
"\n"
"__inline\n"
"float4 transform(const float4* p, const float4* translation, const Quaternion* orientation)\n"
"{\n"
" return qtRotate( *orientation, *p ) + (*translation);\n"
"}\n"
"\n"
"void trInverse(float4 translationIn, Quaternion orientationIn,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
"{\n"
" *orientationOut = qtInvert(orientationIn);\n"
" *translationOut = qtRotate(*orientationOut, -translationIn);\n"
"}\n"
"\n"
"void trMul(float4 translationA, Quaternion orientationA,\n"
" float4 translationB, Quaternion orientationB,\n"
" float4* translationOut, Quaternion* orientationOut)\n"
"{\n"
" *orientationOut = qtMul(orientationA,orientationB);\n"
" *translationOut = transform(&translationB,&translationA,&orientationA);\n"
"}\n"
"\n"
"\n"
"\n"
"bool rayConvex(float4 rayFromLocal, float4 rayToLocal, int numFaces, int faceOffset,\n"
" __global const b3GpuFace* faces, float* hitFraction, float4* hitNormal)\n"
"{\n"
" rayFromLocal.w = 0.f;\n"
" rayToLocal.w = 0.f;\n"
" bool result = true;\n"
" \n"
" float exitFraction = *hitFraction;\n"
" float enterFraction = -0.1f;\n"
" float4 curHitNormal = (float4)(0,0,0,0);\n"
" for (int i=0;i<numFaces && result;i++)\n"
" {\n"
" b3GpuFace face = faces[faceOffset+i];\n"
" float fromPlaneDist = dot(rayFromLocal,face.m_plane)+face.m_plane.w;\n"
" float toPlaneDist = dot(rayToLocal,face.m_plane)+face.m_plane.w;\n"
" if (fromPlaneDist<0.f)\n"
" {\n"
" if (toPlaneDist >= 0.f)\n"
" {\n"
" float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);\n"
" if (exitFraction>fraction)\n"
" {\n"
" exitFraction = fraction;\n"
" }\n"
" } \n"
" } else\n"
" {\n"
" if (toPlaneDist<0.f)\n"
" {\n"
" float fraction = fromPlaneDist / (fromPlaneDist-toPlaneDist);\n"
" if (enterFraction <= fraction)\n"
" {\n"
" enterFraction = fraction;\n"
" curHitNormal = face.m_plane;\n"
" curHitNormal.w = 0.f;\n"
" }\n"
" } else\n"
" {\n"
" result = false;\n"
" }\n"
" }\n"
" if (exitFraction <= enterFraction)\n"
" result = false;\n"
" }\n"
" \n"
" result = result && (enterFraction < 0.f);\n"
" \n"
" if (result)\n"
" { \n"
" *hitFraction = enterFraction;\n"
" *hitNormal = curHitNormal;\n"
" }\n"
" return result;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"bool sphere_intersect(float4 spherePos, float radius, float4 rayFrom, float4 rayTo, float* hitFraction)\n"
"{\n"
@ -90,10 +268,11 @@ static const char* rayCastKernelCL= \
" __global b3RayHit* hitResults, \n"
" const int numBodies, \n"
" __global Body* bodies,\n"
" __global Collidable* collidables)\n"
" __global Collidable* collidables,\n"
" __global const b3GpuFace* faces,\n"
" __global const ConvexPolyhedronCL* convexShapes )\n"
"{\n"
"\n"
"\n"
" int i = get_global_id(0);\n"
" if (i<numRays)\n"
" {\n"
@ -102,6 +281,8 @@ static const char* rayCastKernelCL= \
" float4 rayFrom = rays[i].m_from;\n"
" float4 rayTo = rays[i].m_to;\n"
" float hitFraction = 1.f;\n"
" float4 hitPoint;\n"
" float4 hitNormal;\n"
" int hitBodyIndex= -1;\n"
" \n"
" int cachedCollidableIndex = -1; \n"
@ -111,7 +292,7 @@ static const char* rayCastKernelCL= \
" {\n"
" \n"
" float4 pos = bodies[b].m_pos;\n"
" // float4 orn = bodies[b].m_quat;\n"
" float4 orn = bodies[b].m_quat;\n"
" if (cachedCollidableIndex !=bodies[b].m_collidableIdx)\n"
" {\n"
" cachedCollidableIndex = bodies[b].m_collidableIdx;\n"
@ -125,15 +306,38 @@ static const char* rayCastKernelCL= \
" if (sphere_intersect(pos, radius, rayFrom, rayTo, &hitFraction))\n"
" {\n"
" hitBodyIndex = b;\n"
" hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);\n"
" hitNormal = (float4) (hitPoint-bodies[b].m_pos);\n"
" }\n"
" }\n"
" \n"
" if (cachedCollidable.m_shapeType == SHAPE_CONVEX_HULL)\n"
" {\n"
" \n"
" float4 invPos = (float4)(0,0,0,0);\n"
" float4 invOrn = (float4)(0,0,0,0);\n"
" float4 rayFromLocal = (float4)(0,0,0,0);\n"
" float4 rayToLocal = (float4)(0,0,0,0);\n"
" \n"
" trInverse(pos,orn, &invPos, &invOrn);\n"
" rayFromLocal = transform(&rayFrom, &invPos, &invOrn);\n"
" rayToLocal = transform(&rayTo, &invPos, &invOrn);\n"
" \n"
" int numFaces = convexShapes[cachedCollidable.m_shapeIndex].m_numFaces;\n"
" int faceOffset = convexShapes[cachedCollidable.m_shapeIndex].m_faceOffset;\n"
" \n"
" if (rayConvex(rayFromLocal, rayToLocal, numFaces, faceOffset,faces, &hitFraction, &hitNormal))\n"
" {\n"
" hitBodyIndex = b;\n"
" }\n"
" }\n"
" \n"
" }\n"
" \n"
" if (hitBodyIndex>=0)\n"
" {\n"
" hitResults[i].m_hitFraction = hitFraction;\n"
" hitResults[i].m_hitPoint = setInterpolate3(rayFrom, rayTo,hitFraction);\n"
" float4 hitNormal = (float4) (hitResults[i].m_hitPoint-bodies[hitBodyIndex].m_pos);\n"
" hitResults[i].m_hitPoint = hitPoint;\n"
" hitResults[i].m_hitNormal = normalize(hitNormal);\n"
" hitResults[i].m_hitResult0 = hitBodyIndex;\n"
" }\n"

View File

@ -19,7 +19,7 @@ struct b3Config
int m_maxTriConvexPairCapacity;
b3Config()
:m_maxConvexBodies(128*1024),
:m_maxConvexBodies(32*1024),
m_maxVerticesPerFace(64),
m_maxFacesPerShape(12),
m_maxConvexVertices(8192),
@ -29,7 +29,7 @@ struct b3Config
m_maxTriConvexPairCapacity(256*1024)
{
m_maxConvexShapes = m_maxConvexBodies;
m_maxBroadphasePairs = 8*m_maxConvexBodies;
m_maxBroadphasePairs = 12*m_maxConvexBodies;
m_maxContactCapacity = m_maxBroadphasePairs;
}
};

View File

@ -5,7 +5,7 @@ bool b3GpuSolveConstraint = true;
#include "b3GpuBatchingPgsSolver.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3RadixSort32CL.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3BoundSearchCL.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3PrefixScanCL.h"

View File

@ -12,73 +12,7 @@
#include "Bullet3Geometry/b3AabbUtil.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3BvhInfo.h"
struct b3GpuNarrowPhaseInternalData
{
b3AlignedObjectArray<b3ConvexUtility*>* m_convexData;
b3AlignedObjectArray<b3ConvexPolyhedronCL> m_convexPolyhedra;
b3AlignedObjectArray<b3Vector3> m_uniqueEdges;
b3AlignedObjectArray<b3Vector3> m_convexVertices;
b3AlignedObjectArray<int> m_convexIndices;
b3OpenCLArray<b3ConvexPolyhedronCL>* m_convexPolyhedraGPU;
b3OpenCLArray<b3Vector3>* m_uniqueEdgesGPU;
b3OpenCLArray<b3Vector3>* m_convexVerticesGPU;
b3OpenCLArray<int>* m_convexIndicesGPU;
b3OpenCLArray<b3Vector3>* m_worldVertsB1GPU;
b3OpenCLArray<b3Int4>* m_clippingFacesOutGPU;
b3OpenCLArray<b3Vector3>* m_worldNormalsAGPU;
b3OpenCLArray<b3Vector3>* m_worldVertsA1GPU;
b3OpenCLArray<b3Vector3>* m_worldVertsB2GPU;
b3AlignedObjectArray<b3GpuChildShape> m_cpuChildShapes;
b3OpenCLArray<b3GpuChildShape>* m_gpuChildShapes;
b3AlignedObjectArray<b3GpuFace> m_convexFaces;
b3OpenCLArray<b3GpuFace>* m_convexFacesGPU;
GpuSatCollision* m_gpuSatCollision;
b3AlignedObjectArray<b3Int2>* m_pBufPairsCPU;
//b3OpenCLArray<b3Int2>* m_convexPairsOutGPU;
//b3OpenCLArray<b3Int2>* m_planePairs;
b3OpenCLArray<b3Contact4>* m_pBufContactOutGPU;
b3AlignedObjectArray<b3Contact4>* m_pBufContactOutCPU;
b3AlignedObjectArray<b3RigidBodyCL>* m_bodyBufferCPU;
b3OpenCLArray<b3RigidBodyCL>* m_bodyBufferGPU;
b3AlignedObjectArray<b3InertiaCL>* m_inertiaBufferCPU;
b3OpenCLArray<b3InertiaCL>* m_inertiaBufferGPU;
int m_numAcceleratedShapes;
int m_numAcceleratedRigidBodies;
b3AlignedObjectArray<b3Collidable> m_collidablesCPU;
b3OpenCLArray<b3Collidable>* m_collidablesGPU;
b3OpenCLArray<b3SapAabb>* m_localShapeAABBGPU;
b3AlignedObjectArray<b3SapAabb>* m_localShapeAABBCPU;
b3AlignedObjectArray<class b3OptimizedBvh*> m_bvhData;
b3AlignedObjectArray<b3QuantizedBvhNode> m_treeNodesCPU;
b3AlignedObjectArray<b3BvhSubtreeInfo> m_subTreesCPU;
b3AlignedObjectArray<b3BvhInfo> m_bvhInfoCPU;
b3OpenCLArray<b3BvhInfo>* m_bvhInfoGPU;
b3OpenCLArray<b3QuantizedBvhNode>* m_treeNodesGPU;
b3OpenCLArray<b3BvhSubtreeInfo>* m_subTreesGPU;
b3Config m_config;
};
#include "b3GpuNarrowPhaseInternalData.h"

View File

@ -91,6 +91,11 @@ public:
b3Collidable& getCollidableCpu(int collidableIndex);
const b3Collidable& getCollidableCpu(int collidableIndex) const;
const b3GpuNarrowPhaseInternalData* getInternalData() const
{
return m_data;
}
const struct b3SapAabb& getLocalSpaceAabb(int collidableIndex) const;
};

View File

@ -0,0 +1,93 @@
#ifndef B3_GPU_NARROWPHASE_INTERNAL_DATA_H
#define B3_GPU_NARROWPHASE_INTERNAL_DATA_H
#include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3ConvexPolyhedronCL.h"
#include "b3Config.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3Collidable.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLInclude.h"
#include "Bullet3Common/b3AlignedObjectArray.h"
#include "Bullet3Common/b3Vector3.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3RigidBodyCL.h"
#include "Bullet3Collision/NarrowPhaseCollision/b3Contact4.h"
#include "Bullet3OpenCL/BroadphaseCollision/b3SapAabb.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3QuantizedBvh.h"
#include "Bullet3OpenCL/NarrowphaseCollision/b3BvhInfo.h"
#include "Bullet3Common/b3Int4.h"
#include "Bullet3Common/b3Int2.h"
class b3ConvexUtility;
struct b3GpuNarrowPhaseInternalData
{
b3AlignedObjectArray<b3ConvexUtility*>* m_convexData;
b3AlignedObjectArray<b3ConvexPolyhedronCL> m_convexPolyhedra;
b3AlignedObjectArray<b3Vector3> m_uniqueEdges;
b3AlignedObjectArray<b3Vector3> m_convexVertices;
b3AlignedObjectArray<int> m_convexIndices;
b3OpenCLArray<b3ConvexPolyhedronCL>* m_convexPolyhedraGPU;
b3OpenCLArray<b3Vector3>* m_uniqueEdgesGPU;
b3OpenCLArray<b3Vector3>* m_convexVerticesGPU;
b3OpenCLArray<int>* m_convexIndicesGPU;
b3OpenCLArray<b3Vector3>* m_worldVertsB1GPU;
b3OpenCLArray<b3Int4>* m_clippingFacesOutGPU;
b3OpenCLArray<b3Vector3>* m_worldNormalsAGPU;
b3OpenCLArray<b3Vector3>* m_worldVertsA1GPU;
b3OpenCLArray<b3Vector3>* m_worldVertsB2GPU;
b3AlignedObjectArray<b3GpuChildShape> m_cpuChildShapes;
b3OpenCLArray<b3GpuChildShape>* m_gpuChildShapes;
b3AlignedObjectArray<b3GpuFace> m_convexFaces;
b3OpenCLArray<b3GpuFace>* m_convexFacesGPU;
struct GpuSatCollision* m_gpuSatCollision;
b3AlignedObjectArray<b3Int2>* m_pBufPairsCPU;
//b3OpenCLArray<b3Int2>* m_convexPairsOutGPU;
//b3OpenCLArray<b3Int2>* m_planePairs;
b3OpenCLArray<b3Contact4>* m_pBufContactOutGPU;
b3AlignedObjectArray<b3Contact4>* m_pBufContactOutCPU;
b3AlignedObjectArray<b3RigidBodyCL>* m_bodyBufferCPU;
b3OpenCLArray<b3RigidBodyCL>* m_bodyBufferGPU;
b3AlignedObjectArray<b3InertiaCL>* m_inertiaBufferCPU;
b3OpenCLArray<b3InertiaCL>* m_inertiaBufferGPU;
int m_numAcceleratedShapes;
int m_numAcceleratedRigidBodies;
b3AlignedObjectArray<b3Collidable> m_collidablesCPU;
b3OpenCLArray<b3Collidable>* m_collidablesGPU;
b3OpenCLArray<b3SapAabb>* m_localShapeAABBGPU;
b3AlignedObjectArray<b3SapAabb>* m_localShapeAABBCPU;
b3AlignedObjectArray<class b3OptimizedBvh*> m_bvhData;
b3AlignedObjectArray<b3QuantizedBvhNode> m_treeNodesCPU;
b3AlignedObjectArray<b3BvhSubtreeInfo> m_subTreesCPU;
b3AlignedObjectArray<b3BvhInfo> m_bvhInfoCPU;
b3OpenCLArray<b3BvhInfo>* m_bvhInfoGPU;
b3OpenCLArray<b3QuantizedBvhNode>* m_treeNodesGPU;
b3OpenCLArray<b3BvhSubtreeInfo>* m_subTreesGPU;
b3Config m_config;
};
#endif //B3_GPU_NARROWPHASE_INTERNAL_DATA_H

View File

@ -31,7 +31,6 @@ bool dumpContactStats = false;
#include "b3GpuBatchingPgsSolver.h"
#include "b3Solver.h"
#include "Bullet3Common/b3Quickprof.h"
#include "b3Config.h"
#include "Bullet3OpenCL/Raycast/b3GpuRaycast.h"
@ -458,6 +457,9 @@ int b3GpuRigidBodyPipeline::registerPhysicsInstance(float mass, const float* po
void b3GpuRigidBodyPipeline::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults)
{
this->m_data->m_raycaster->castRays(rays,hitResults,getNumBodies(),this->m_data->m_narrowphase->getBodiesCpu(),m_data->m_narrowphase->getNumCollidablesGpu(), m_data->m_narrowphase->getCollidablesCpu());
this->m_data->m_raycaster->castRays(rays,hitResults,
getNumBodies(),this->m_data->m_narrowphase->getBodiesCpu(),
m_data->m_narrowphase->getNumCollidablesGpu(), m_data->m_narrowphase->getCollidablesCpu(), m_data->m_narrowphase->getInternalData()
);
}

View File

@ -37,7 +37,6 @@ bool useNewBatchingKernel = true;
#include "kernels/batchingKernelsNew.h"
#include "Bullet3Common/b3Quickprof.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
#include "Bullet3Common/b3Vector3.h"

View File

@ -18,8 +18,8 @@ subject to the following restrictions:
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
#include "Bullet3Common/b3Int2.h"
#include "Bullet3Common/b3Quickprof.h"
#include "../btgui/Timing/b3Clock.h"
#include "b3BitonicSort.h"
#include <stdio.h>

View File

@ -21,12 +21,12 @@ function createProject(vendor)
"b3BitonicSort.cpp",
"../../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../../src/Bullet3Common/b3AlignedAllocator.h",
"../../../src/Bullet3Common/b3Quickprof.cpp",
"../../../src/Bullet3Common/b3Quickprof.h",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.cpp",
"../../../src/Bullet3OpenCL/Initialize/b3OpenCLUtils.h",
"../../../src/Bullet3Common/b3Logging.cpp",
"../../../src/Bullet3Common/b3Logging.h",
"../../../btgui/Timing/b3Clock.cpp",
"../../../btgui/Timing/b3Clock.h",
}
end

View File

@ -66,7 +66,7 @@
#include "Bullet3OpenCL/ParallelPrimitives/b3RadixSort32CL.h"
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
#include "Bullet3Common/b3Quickprof.h"
#include "../btgui/Timing/b3Clock.h"
cl_context g_cxMainContext;
cl_device_id g_device;

View File

@ -27,10 +27,12 @@ function createProject(vendor)
"../../../src/Bullet3Common/b3AlignedAllocator.cpp",
"../../../src/Bullet3Common/b3AlignedAllocator.h",
"../../../src/Bullet3Common/b3AlignedObjectArray.h",
"../../../src/Bullet3Common/b3Quickprof.cpp",
"../../../src/Bullet3Common/b3Quickprof.h",
"../../../src/Bullet3Common/b3Logging.cpp",
"../../../src/Bullet3Common/b3Logging.h",
"../../../btgui/Timing/b3Quickprof.cpp",
"../../../btgui/Timing/b3Quickprof.h",
"../../../btgui/Timing/b3Clock.cpp",
"../../../btgui/Timing/b3Clock.h",
}