Update btOpenCLUtils to allow caching of precompiled program binaries (save/load). See Bullet/Demos/SerializeDemo/AMD for an example use
Fix in btBulletWorldImporter: load friction/restitution and patch radius of btCapsuleShape (it needs to embed the margin) Partly apply a modified patch to make the SerializeDemo_AMD work, but avoid breaking the MiniCL version. See Issue 594
This commit is contained in:
@@ -20,7 +20,7 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
|
|
||||||
#ifndef USE_MINICL
|
#ifndef USE_MINICL
|
||||||
//#define USE_SIMDAWARE_SOLVER
|
#define USE_SIMDAWARE_SOLVER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined (__APPLE__)
|
#if !defined (__APPLE__)
|
||||||
|
|||||||
@@ -115,7 +115,24 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES AND NOT INTERNAL_UPDATE_
|
|||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET AppSerializeDemo_AMD
|
TARGET AppSerializeDemo_AMD
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFileCloth.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/ApplyForces.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/ApplyForces.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/ComputeBounds.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/ComputeBounds.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/Integrate.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/Integrate.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/OutputToVertexArray.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/OutputToVertexArray.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/PrepareLinks.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/PrepareLinks.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocities.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/SolveCollisionsAndUpdateVelocities.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolvePositions.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/SolvePositions.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolvePositionsSIMDBatched.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/SolvePositionsSIMDBatched.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdateConstants.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdateConstants.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdateFixedVertexPositions.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdateFixedVertexPositions.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdateNodes.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdateNodes.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdateNormals.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdateNormals.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdatePositions.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdatePositions.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/UpdatePositionsFromVelocities.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/UpdatePositionsFromVelocities.cl
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/VSolveLinks.cl ${CMAKE_CURRENT_BINARY_DIR}/OpenCLC10/VSolveLinks.cl
|
||||||
|
|
||||||
)
|
)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define TEST_SERIALIZATION 1
|
#define TEST_SERIALIZATION 1
|
||||||
//#undef DESERIALIZE_SOFT_BODIES
|
//#undef DESERIALIZE_SOFT_BODIES
|
||||||
|
|
||||||
@@ -57,6 +56,8 @@ subject to the following restrictions:
|
|||||||
#ifdef USE_AMD_OPENCL
|
#ifdef USE_AMD_OPENCL
|
||||||
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.h>
|
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.h>
|
||||||
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.h>
|
#include <BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.h>
|
||||||
|
#include "../SharedOpenCL/btOpenCLUtils.h"
|
||||||
|
|
||||||
extern cl_context g_cxMainContext;
|
extern cl_context g_cxMainContext;
|
||||||
extern cl_device_id g_cdDevice;
|
extern cl_device_id g_cdDevice;
|
||||||
extern cl_command_queue g_cqCommandQue;
|
extern cl_command_queue g_cqCommandQue;
|
||||||
@@ -198,7 +199,39 @@ void SerializeDemo::clientMoveAndDisplay()
|
|||||||
swapBuffers();
|
swapBuffers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#ifdef USE_AMD_OPENCL
|
||||||
|
|
||||||
|
///the CachingCLFuncs class will try to create/load precompiled binary programs, instead of the slow on-line compilation of programs
|
||||||
|
class CachingCLFuncs : public CLFunctions
|
||||||
|
{
|
||||||
|
cl_device_id m_device;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CachingCLFuncs (cl_command_queue cqCommandQue, cl_context cxMainContext, cl_device_id device)
|
||||||
|
:CLFunctions(cqCommandQue,cxMainContext),
|
||||||
|
m_device(device)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual cl_kernel compileCLKernelFromString( const char* kernelSource, const char* kernelName, const char* additionalMacros, const char* srcFileNameForCaching)
|
||||||
|
{
|
||||||
|
|
||||||
|
cl_int pErrNum;
|
||||||
|
cl_program prog;
|
||||||
|
|
||||||
|
prog = btOpenCLUtils::compileCLProgramFromFile( m_cxMainContext,m_device, &pErrNum,additionalMacros ,srcFileNameForCaching);
|
||||||
|
if (!prog)
|
||||||
|
{
|
||||||
|
printf("Using embedded kernel source instead:\n");
|
||||||
|
prog = btOpenCLUtils::compileCLProgramFromString( m_cxMainContext,m_device, kernelSource, &pErrNum,additionalMacros);
|
||||||
|
}
|
||||||
|
|
||||||
|
return btOpenCLUtils::compileCLKernelFromString( m_cxMainContext,m_device, kernelSource, kernelName, &pErrNum, prog,additionalMacros);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void SerializeDemo::displayCallback(void) {
|
void SerializeDemo::displayCallback(void) {
|
||||||
@@ -277,18 +310,13 @@ void SerializeDemo::setupEmptyDynamicsWorld()
|
|||||||
{
|
{
|
||||||
case kSolverAccelerationOpenCL_GPU:
|
case kSolverAccelerationOpenCL_GPU:
|
||||||
{
|
{
|
||||||
fSoftBodySolver
|
btOpenCLSoftBodySolverSIMDAware* softSolv= new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue, g_cxMainContext );
|
||||||
= new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue,
|
//btOpenCLSoftBodySolver* softSolv= new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext);
|
||||||
g_cxMainContext );
|
fSoftBodySolver = softSolv;
|
||||||
// fSoftBodySolver = new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext);
|
|
||||||
|
CLFunctions* funcs = new CachingCLFuncs(g_cqCommandQue, g_cxMainContext,g_cdDevice);
|
||||||
/*if (!fSoftBodySolver->checkInitialized())
|
softSolv->setCLFunctions(funcs);
|
||||||
{
|
|
||||||
btAssert(0);
|
|
||||||
delete fSoftBodySolver;
|
|
||||||
fSoftBodySolver = NULL;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -516,14 +544,14 @@ public:
|
|||||||
psb->m_cfg.diterations=softBodyData->m_config.m_driftIterations;
|
psb->m_cfg.diterations=softBodyData->m_config.m_driftIterations;
|
||||||
psb->m_cfg.citerations=softBodyData->m_config.m_clusterIterations;
|
psb->m_cfg.citerations=softBodyData->m_config.m_clusterIterations;
|
||||||
psb->m_cfg.viterations=softBodyData->m_config.m_velocityIterations;
|
psb->m_cfg.viterations=softBodyData->m_config.m_velocityIterations;
|
||||||
|
|
||||||
//psb->setTotalMass(0.1);
|
//psb->setTotalMass(0.1);
|
||||||
psb->m_cfg.aeromodel = (btSoftBody::eAeroModel::_)softBodyData->m_config.m_aeroModel;
|
psb->m_cfg.aeromodel = (btSoftBody::eAeroModel::_)softBodyData->m_config.m_aeroModel;
|
||||||
psb->m_cfg.kLF = softBodyData->m_config.m_lift;
|
psb->m_cfg.kLF = softBodyData->m_config.m_lift;
|
||||||
psb->m_cfg.kDG = softBodyData->m_config.m_drag;
|
psb->m_cfg.kDG = softBodyData->m_config.m_drag;
|
||||||
psb->m_cfg.kMT = softBodyData->m_config.m_poseMatch;
|
psb->m_cfg.kMT = softBodyData->m_config.m_poseMatch;
|
||||||
psb->m_cfg.collisions = softBodyData->m_config.m_collisionFlags;
|
psb->m_cfg.collisions = softBodyData->m_config.m_collisionFlags;
|
||||||
psb->m_cfg.kDF = softBodyData->m_config.m_dynamicFriction;
|
psb->m_cfg.kDF = 1.f;//softBodyData->m_config.m_dynamicFriction;
|
||||||
psb->m_cfg.kDP = softBodyData->m_config.m_damping;
|
psb->m_cfg.kDP = softBodyData->m_config.m_damping;
|
||||||
psb->m_cfg.kPR = softBodyData->m_config.m_pressure;
|
psb->m_cfg.kPR = softBodyData->m_config.m_pressure;
|
||||||
psb->m_cfg.kVC = softBodyData->m_config.m_volume;
|
psb->m_cfg.kVC = softBodyData->m_config.m_volume;
|
||||||
@@ -715,7 +743,7 @@ void SerializeDemo::initPhysics()
|
|||||||
setTexturing(true);
|
setTexturing(true);
|
||||||
setShadows(true);
|
setShadows(true);
|
||||||
|
|
||||||
setCameraDistance(btScalar(SCALING*50.));
|
setCameraDistance(btScalar(SCALING*30.));
|
||||||
|
|
||||||
setupEmptyDynamicsWorld();
|
setupEmptyDynamicsWorld();
|
||||||
|
|
||||||
|
|||||||
BIN
Demos/SerializeDemo/testFileCloth.bullet
Normal file
BIN
Demos/SerializeDemo/testFileCloth.bullet
Normal file
Binary file not shown.
@@ -22,6 +22,9 @@ subject to the following restrictions:
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define BT_MAX_CL_DEVICES 16 //who needs 16 devices?
|
||||||
|
//#define BT_USE_CACHE_DIR
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -30,7 +33,7 @@ subject to the following restrictions:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Set the preferred platform vendor using the OpenCL SDK
|
//Set the preferred platform vendor using the OpenCL SDK
|
||||||
static const char* spPlatformVendor =
|
static char* spPlatformVendor =
|
||||||
#if defined(CL_PLATFORM_MINI_CL)
|
#if defined(CL_PLATFORM_MINI_CL)
|
||||||
"MiniCL, SCEA";
|
"MiniCL, SCEA";
|
||||||
#elif defined(CL_PLATFORM_AMD)
|
#elif defined(CL_PLATFORM_AMD)
|
||||||
@@ -105,7 +108,7 @@ void btOpenCLUtils::getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInf
|
|||||||
oclCHECKERROR(ciErrNum,CL_SUCCESS);
|
oclCHECKERROR(ciErrNum,CL_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_context btOpenCLUtils::createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC)
|
cl_context btOpenCLUtils::createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC, int preferredDeviceIndex, int preferredPlatformIndex)
|
||||||
{
|
{
|
||||||
cl_context retContext = 0;
|
cl_context retContext = 0;
|
||||||
cl_int ciErrNum=0;
|
cl_int ciErrNum=0;
|
||||||
@@ -117,22 +120,52 @@ cl_context btOpenCLUtils::createContextFromPlatform(cl_platform_id platform, cl_
|
|||||||
cl_context_properties cps[7] = {0,0,0,0,0,0,0};
|
cl_context_properties cps[7] = {0,0,0,0,0,0,0};
|
||||||
cps[0] = CL_CONTEXT_PLATFORM;
|
cps[0] = CL_CONTEXT_PLATFORM;
|
||||||
cps[1] = (cl_context_properties)platform;
|
cps[1] = (cl_context_properties)platform;
|
||||||
#if defined (_WIN32) && defined(_MSC_VER) && !defined (CL_PLATFORM_MINI_CL)
|
|
||||||
if (pGLContext && pGLDC)
|
if (pGLContext && pGLDC)
|
||||||
{
|
{
|
||||||
|
#if defined(CL_PLATFORM_AMD) || defined(CL_PLATFORM_NVIDIA)
|
||||||
cps[2] = CL_GL_CONTEXT_KHR;
|
cps[2] = CL_GL_CONTEXT_KHR;
|
||||||
cps[3] = (cl_context_properties)pGLContext;
|
cps[3] = (cl_context_properties)pGLContext;
|
||||||
cps[4] = CL_WGL_HDC_KHR;
|
cps[4] = CL_WGL_HDC_KHR;
|
||||||
cps[5] = (cl_context_properties)pGLDC;
|
cps[5] = (cl_context_properties)pGLDC;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
cl_uint num_entries = BT_MAX_CL_DEVICES;
|
||||||
|
cl_device_id devices[BT_MAX_CL_DEVICES];
|
||||||
|
|
||||||
|
cl_uint num_devices=-1;
|
||||||
|
|
||||||
|
ciErrNum = clGetDeviceIDs(
|
||||||
|
platform,
|
||||||
|
deviceType,
|
||||||
|
num_entries,
|
||||||
|
devices,
|
||||||
|
&num_devices);
|
||||||
|
|
||||||
cl_context_properties* cprops = (NULL == platform) ? NULL : cps;
|
cl_context_properties* cprops = (NULL == platform) ? NULL : cps;
|
||||||
retContext = clCreateContextFromType(cprops,
|
|
||||||
deviceType,
|
if (pGLContext)
|
||||||
NULL,
|
{
|
||||||
NULL,
|
//search for the GPU that relates to the OpenCL context
|
||||||
&ciErrNum);
|
for (int i=0;i<num_devices;i++)
|
||||||
|
{
|
||||||
|
retContext = clCreateContext(cprops,1,&devices[i],NULL,NULL,&ciErrNum);
|
||||||
|
if (ciErrNum==CL_SUCCESS)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (preferredDeviceIndex>=0 && preferredDeviceIndex<num_devices)
|
||||||
|
{
|
||||||
|
//create a context of the preferred device index
|
||||||
|
retContext = clCreateContext(cprops,1,&devices[preferredDeviceIndex],NULL,NULL,&ciErrNum);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
//create a context of all devices
|
||||||
|
retContext = clCreateContext(cprops,num_devices,devices,NULL,NULL,&ciErrNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(pErrNum != NULL)
|
if(pErrNum != NULL)
|
||||||
{
|
{
|
||||||
*pErrNum = ciErrNum;
|
*pErrNum = ciErrNum;
|
||||||
@@ -141,7 +174,7 @@ cl_context btOpenCLUtils::createContextFromPlatform(cl_platform_id platform, cl_
|
|||||||
return retContext;
|
return retContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC )
|
cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLContext, void* pGLDC , int preferredDeviceIndex, int preferredPlatformIndex)
|
||||||
{
|
{
|
||||||
cl_uint numPlatforms;
|
cl_uint numPlatforms;
|
||||||
cl_context retContext = 0;
|
cl_context retContext = 0;
|
||||||
@@ -163,6 +196,7 @@ cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_in
|
|||||||
}
|
}
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
for ( i = 0; i < numPlatforms; ++i)
|
for ( i = 0; i < numPlatforms; ++i)
|
||||||
{
|
{
|
||||||
char pbuf[128];
|
char pbuf[128];
|
||||||
@@ -177,12 +211,21 @@ cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_in
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strcmp(pbuf, spPlatformVendor))
|
if (preferredPlatformIndex>=0 && i==preferredPlatformIndex)
|
||||||
{
|
{
|
||||||
cl_platform_id tmpPlatform = platforms[0];
|
cl_platform_id tmpPlatform = platforms[0];
|
||||||
platforms[0] = platforms[i];
|
platforms[0] = platforms[i];
|
||||||
platforms[i] = tmpPlatform;
|
platforms[i] = tmpPlatform;
|
||||||
break;
|
break;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if(!strcmp(pbuf, spPlatformVendor))
|
||||||
|
{
|
||||||
|
cl_platform_id tmpPlatform = platforms[0];
|
||||||
|
platforms[0] = platforms[i];
|
||||||
|
platforms[i] = tmpPlatform;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,11 +234,11 @@ cl_context btOpenCLUtils::createContextFromType(cl_device_type deviceType, cl_in
|
|||||||
cl_platform_id platform = platforms[i];
|
cl_platform_id platform = platforms[i];
|
||||||
assert(platform);
|
assert(platform);
|
||||||
|
|
||||||
retContext = btOpenCLUtils::createContextFromPlatform(platform,deviceType,pErrNum,pGLContext,pGLDC);
|
retContext = btOpenCLUtils::createContextFromPlatform(platform,deviceType,pErrNum,pGLContext,pGLDC,preferredDeviceIndex);
|
||||||
|
|
||||||
if (retContext)
|
if (retContext)
|
||||||
{
|
{
|
||||||
printf("OpenCL platform details:\n");
|
// printf("OpenCL platform details:\n");
|
||||||
btOpenCLPlatformInfo platformInfo;
|
btOpenCLPlatformInfo platformInfo;
|
||||||
|
|
||||||
btOpenCLUtils::getPlatformInfo(platform, platformInfo);
|
btOpenCLUtils::getPlatformInfo(platform, platformInfo);
|
||||||
@@ -270,10 +313,10 @@ void btOpenCLUtils::printDeviceInfo(cl_device_id device)
|
|||||||
printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");
|
printf(" CL_DEVICE_TYPE:\t\t\t%s\n", "CL_DEVICE_TYPE_DEFAULT");
|
||||||
|
|
||||||
printf(" CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%u\n", info.m_computeUnits);
|
printf(" CL_DEVICE_MAX_COMPUTE_UNITS:\t\t%u\n", info.m_computeUnits);
|
||||||
printf(" CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%d\n", (int)info.m_workitemDims);
|
printf(" CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%u\n", info.m_workitemDims);
|
||||||
printf(" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t%d / %d / %d \n", (int)info.m_workItemSize[0], (int)info.m_workItemSize[1],(int) info.m_workItemSize[2]);
|
printf(" CL_DEVICE_MAX_WORK_ITEM_SIZES:\t%u / %u / %u \n", info.m_workItemSize[0], info.m_workItemSize[1], info.m_workItemSize[2]);
|
||||||
printf(" CL_DEVICE_MAX_WORK_GROUP_SIZE:\t%d\n", (int)info.m_workgroupSize);
|
printf(" CL_DEVICE_MAX_WORK_GROUP_SIZE:\t%u\n", info.m_workgroupSize);
|
||||||
printf(" CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%d MHz\n", (int)info.m_clockFrequency);
|
printf(" CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%u MHz\n", info.m_clockFrequency);
|
||||||
printf(" CL_DEVICE_ADDRESS_BITS:\t\t%u\n", info.m_addressBits);
|
printf(" CL_DEVICE_ADDRESS_BITS:\t\t%u\n", info.m_addressBits);
|
||||||
printf(" CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_maxMemAllocSize/ (1024 * 1024)));
|
printf(" CL_DEVICE_MAX_MEM_ALLOC_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_maxMemAllocSize/ (1024 * 1024)));
|
||||||
printf(" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_globalMemSize/ (1024 * 1024)));
|
printf(" CL_DEVICE_GLOBAL_MEM_SIZE:\t\t%u MByte\n", (unsigned int)(info.m_globalMemSize/ (1024 * 1024)));
|
||||||
@@ -291,11 +334,11 @@ void btOpenCLUtils::printDeviceInfo(cl_device_id device)
|
|||||||
printf(" CL_DEVICE_MAX_READ_IMAGE_ARGS:\t%u\n", info.m_maxReadImageArgs);
|
printf(" CL_DEVICE_MAX_READ_IMAGE_ARGS:\t%u\n", info.m_maxReadImageArgs);
|
||||||
printf(" CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs);
|
printf(" CL_DEVICE_MAX_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs);
|
||||||
printf("\n CL_DEVICE_IMAGE <dim>");
|
printf("\n CL_DEVICE_IMAGE <dim>");
|
||||||
printf("\t\t\t2D_MAX_WIDTH\t %d\n", (int)info.m_image2dMaxWidth);
|
printf("\t\t\t2D_MAX_WIDTH\t %u\n", info.m_image2dMaxWidth);
|
||||||
printf("\t\t\t\t\t2D_MAX_HEIGHT\t %d\n", (int)info.m_image2dMaxHeight);
|
printf("\t\t\t\t\t2D_MAX_HEIGHT\t %u\n", info.m_image2dMaxHeight);
|
||||||
printf("\t\t\t\t\t3D_MAX_WIDTH\t %d\n", (int)info.m_image3dMaxWidth);
|
printf("\t\t\t\t\t3D_MAX_WIDTH\t %u\n", info.m_image3dMaxWidth);
|
||||||
printf("\t\t\t\t\t3D_MAX_HEIGHT\t %d\n", (int)info.m_image3dMaxHeight);
|
printf("\t\t\t\t\t3D_MAX_HEIGHT\t %u\n", info.m_image3dMaxHeight);
|
||||||
printf("\t\t\t\t\t3D_MAX_DEPTH\t %d\n", (int)info.m_image3dMaxDepth);
|
printf("\t\t\t\t\t3D_MAX_DEPTH\t %u\n", info.m_image3dMaxDepth);
|
||||||
if (info.m_deviceExtensions != 0)
|
if (info.m_deviceExtensions != 0)
|
||||||
printf("\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions);
|
printf("\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions);
|
||||||
else
|
else
|
||||||
@@ -389,21 +432,84 @@ void btOpenCLUtils::getDeviceInfo(cl_device_id device, btOpenCLDeviceInfo& info)
|
|||||||
clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &info.m_vecWidthDouble, NULL);
|
clGetDeviceInfo(device, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, sizeof(cl_uint), &info.m_vecWidthDouble, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* strip2(const char* name, const char* pattern)
|
static char* strip1(char* name, const char* pattern,int* numOccurences=0)
|
||||||
|
{
|
||||||
|
size_t const patlen = strlen(pattern);
|
||||||
|
char * oriptr;
|
||||||
|
char * patloc;
|
||||||
|
// find how many times the pattern occurs in the original string
|
||||||
|
for (oriptr = name; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
|
||||||
|
{
|
||||||
|
if (numOccurences)
|
||||||
|
(*numOccurences)++;
|
||||||
|
}
|
||||||
|
return oriptr;
|
||||||
|
}
|
||||||
|
static const char* strip2(const char* name, const char* pattern,int* numOccurences=0)
|
||||||
{
|
{
|
||||||
size_t const patlen = strlen(pattern);
|
size_t const patlen = strlen(pattern);
|
||||||
size_t patcnt = 0;
|
|
||||||
const char * oriptr;
|
const char * oriptr;
|
||||||
const char * patloc;
|
const char * patloc;
|
||||||
// find how many times the pattern occurs in the original string
|
// find how many times the pattern occurs in the original string
|
||||||
for (oriptr = name; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
|
for (oriptr = name; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen)
|
||||||
{
|
{
|
||||||
patcnt++;
|
if (numOccurences)
|
||||||
|
(*numOccurences)++;
|
||||||
}
|
}
|
||||||
return oriptr;
|
return oriptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_device_id device, const char* kernelSource, cl_int* pErrNum, const char* additionalMacros , const char* clFileNameForCaching)
|
cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_device_id device, const char* kernelSource, cl_int* pErrNum, const char* additionalMacros)
|
||||||
|
{
|
||||||
|
|
||||||
|
cl_int localErrNum;
|
||||||
|
size_t program_length = strlen(kernelSource);
|
||||||
|
|
||||||
|
cl_program m_cpProgram = clCreateProgramWithSource(clContext, 1, (const char**)&kernelSource, &program_length, &localErrNum);
|
||||||
|
if (localErrNum!= CL_SUCCESS)
|
||||||
|
{
|
||||||
|
if (pErrNum)
|
||||||
|
*pErrNum = localErrNum;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the program with 'mad' Optimization option
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MAC
|
||||||
|
char* flags = "-cl-mad-enable -DMAC -DGUID_ARG";
|
||||||
|
#else
|
||||||
|
//const char* flags = "-DGUID_ARG= -fno-alias";
|
||||||
|
const char* flags = "-DGUID_ARG= ";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char* compileFlags = new char[strlen(additionalMacros) + strlen(flags) + 5];
|
||||||
|
sprintf(compileFlags, "%s %s", flags, additionalMacros);
|
||||||
|
localErrNum = clBuildProgram(m_cpProgram, 1, &device, compileFlags, NULL, NULL);
|
||||||
|
if (localErrNum!= CL_SUCCESS)
|
||||||
|
{
|
||||||
|
char *build_log;
|
||||||
|
size_t ret_val_size;
|
||||||
|
clGetProgramBuildInfo(m_cpProgram, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
|
||||||
|
build_log = new char[ret_val_size+1];
|
||||||
|
clGetProgramBuildInfo(m_cpProgram, device, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
|
||||||
|
|
||||||
|
// to be carefully, terminate with \0
|
||||||
|
// there's no information in the reference whether the string is 0 terminated or not
|
||||||
|
build_log[ret_val_size] = '\0';
|
||||||
|
|
||||||
|
|
||||||
|
printf("Error in clBuildProgram, Line %u in file %s, Log: \n%s\n !!!\n\n", __LINE__, __FILE__, build_log);
|
||||||
|
delete[] build_log;
|
||||||
|
if (pErrNum)
|
||||||
|
*pErrNum = localErrNum;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
delete[] compileFlags;
|
||||||
|
return m_cpProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
cl_program btOpenCLUtils::compileCLProgramFromFile(cl_context clContext, cl_device_id device, cl_int* pErrNum, const char* additionalMacros , const char* clFileNameForCaching)
|
||||||
{
|
{
|
||||||
|
|
||||||
cl_program m_cpProgram=0;
|
cl_program m_cpProgram=0;
|
||||||
@@ -411,7 +517,6 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de
|
|||||||
|
|
||||||
char binaryFileName[522];
|
char binaryFileName[522];
|
||||||
|
|
||||||
#if defined (_WIN32) && defined(_MSC_VER)
|
|
||||||
if (clFileNameForCaching)
|
if (clFileNameForCaching)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -423,15 +528,23 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de
|
|||||||
|
|
||||||
const char* strippedName = strip2(clFileNameForCaching,"\\");
|
const char* strippedName = strip2(clFileNameForCaching,"\\");
|
||||||
strippedName = strip2(strippedName,"/");
|
strippedName = strip2(strippedName,"/");
|
||||||
|
#ifdef BT_USE_CACHE_DIR
|
||||||
|
sprintf_s(binaryFileName,"cache/%s.%s.%s.bin",strippedName, deviceName,driverVersion );
|
||||||
|
#else
|
||||||
sprintf_s(binaryFileName,"%s.%s.%s.bin",strippedName, deviceName,driverVersion );
|
sprintf_s(binaryFileName,"%s.%s.%s.bin",strippedName, deviceName,driverVersion );
|
||||||
//printf("searching for %s\n", binaryFileName);
|
#endif
|
||||||
|
|
||||||
|
//printf("searching for %s\n", binaryFileName);
|
||||||
|
|
||||||
bool fileUpToDate = false;
|
bool fileUpToDate = false;
|
||||||
bool binaryFileValid=false;
|
bool binaryFileValid=false;
|
||||||
|
|
||||||
FILETIME modtimeBinary;
|
FILETIME modtimeBinary;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef BT_USE_CACHE_DIR
|
||||||
|
CreateDirectory("cache",0);
|
||||||
|
#endif //BT_USE_CACHE_DIR
|
||||||
{
|
{
|
||||||
|
|
||||||
HANDLE binaryFileHandle = CreateFile(binaryFileName,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
|
HANDLE binaryFileHandle = CreateFile(binaryFileName,GENERIC_READ,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
|
||||||
@@ -494,7 +607,6 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
|
||||||
DWORD errorCode;
|
DWORD errorCode;
|
||||||
errorCode = GetLastError();
|
errorCode = GetLastError();
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
@@ -516,11 +628,7 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we should make sure the src file exists so we can verify the timestamp with binary
|
//we should make sure the src file exists so we can verify the timestamp with binary
|
||||||
assert(0);
|
fileUpToDate = false;
|
||||||
#else
|
|
||||||
//if we cannot find the source, assume it is OK in release builds
|
|
||||||
fileUpToDate = true;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,88 +665,88 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de
|
|||||||
btAssert(0);
|
btAssert(0);
|
||||||
m_cpProgram = 0;
|
m_cpProgram = 0;
|
||||||
}
|
}
|
||||||
|
delete[] binary;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif //_WIN32
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!m_cpProgram)
|
if (!m_cpProgram)
|
||||||
{
|
{
|
||||||
// cl_kernel kernel;
|
|
||||||
cl_int localErrNum;
|
FILE* file = fopen(clFileNameForCaching, "r");
|
||||||
size_t program_length = strlen(kernelSource);
|
if (file)
|
||||||
|
|
||||||
m_cpProgram = clCreateProgramWithSource(clContext, 1, (const char**)&kernelSource, &program_length, &localErrNum);
|
|
||||||
if (localErrNum!= CL_SUCCESS)
|
|
||||||
{
|
{
|
||||||
if (pErrNum)
|
fseek( file, 0L, SEEK_END );
|
||||||
*pErrNum = localErrNum;
|
size_t fileSize= ftell( file );
|
||||||
return 0;
|
rewind( file );
|
||||||
}
|
char* kernelSource2 = new char[fileSize+1];
|
||||||
|
fread( kernelSource2, sizeof(char), fileSize, file );
|
||||||
// Build the program with 'mad' Optimization option
|
fclose( file );
|
||||||
|
kernelSource2[fileSize]=0;
|
||||||
|
int numOccurences = 0;
|
||||||
#ifdef MAC
|
///patch/remove the MSTRINGIFY( and );
|
||||||
char* flags = "-cl-mad-enable -DMAC -DGUID_ARG";
|
char* kernelSource = strip1(kernelSource2,"MSTRINGIFY(",&numOccurences);
|
||||||
#else
|
int newlen = strlen(kernelSource);
|
||||||
//const char* flags = "-DGUID_ARG= -fno-alias";
|
if (numOccurences)
|
||||||
const char* flags = "-DGUID_ARG= ";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char* compileFlags = new char[strlen(additionalMacros) + strlen(flags) + 5];
|
|
||||||
sprintf(compileFlags, "%s %s", flags, additionalMacros);
|
|
||||||
localErrNum = clBuildProgram(m_cpProgram, 1, &device, compileFlags, NULL, NULL);
|
|
||||||
if (localErrNum!= CL_SUCCESS)
|
|
||||||
{
|
|
||||||
char *build_log;
|
|
||||||
size_t ret_val_size;
|
|
||||||
clGetProgramBuildInfo(m_cpProgram, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &ret_val_size);
|
|
||||||
build_log = new char[ret_val_size+1];
|
|
||||||
clGetProgramBuildInfo(m_cpProgram, device, CL_PROGRAM_BUILD_LOG, ret_val_size, build_log, NULL);
|
|
||||||
|
|
||||||
// to be carefully, terminate with \0
|
|
||||||
// there's no information in the reference whether the string is 0 terminated or not
|
|
||||||
build_log[ret_val_size] = '\0';
|
|
||||||
|
|
||||||
|
|
||||||
printf("Error in clBuildProgram, Line %u in file %s, Log: \n%s\n !!!\n\n", __LINE__, __FILE__, build_log);
|
|
||||||
delete[] build_log;
|
|
||||||
if (pErrNum)
|
|
||||||
*pErrNum = localErrNum;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined (_WIN32) && defined(_MSC_VER)
|
|
||||||
if( clFileNameForCaching )
|
|
||||||
{ // write to binary
|
|
||||||
size_t binarySize;
|
|
||||||
status = clGetProgramInfo( m_cpProgram, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binarySize, 0 );
|
|
||||||
btAssert( status == CL_SUCCESS );
|
|
||||||
|
|
||||||
char* binary = new char[binarySize];
|
|
||||||
|
|
||||||
status = clGetProgramInfo( m_cpProgram, CL_PROGRAM_BINARIES, sizeof(char*), &binary, 0 );
|
|
||||||
btAssert( status == CL_SUCCESS );
|
|
||||||
|
|
||||||
{
|
{
|
||||||
FILE* file = fopen(binaryFileName, "wb");
|
int i=newlen-1;
|
||||||
if (file)
|
|
||||||
|
for (;i>=0;i--)
|
||||||
{
|
{
|
||||||
fwrite( binary, sizeof(char), binarySize, file );
|
if (kernelSource[i] == ';')
|
||||||
fclose( file );
|
{
|
||||||
} else
|
kernelSource[i] = 0;//' ';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (;i>=0;i--)
|
||||||
{
|
{
|
||||||
printf("cannot write file %s\n", binaryFileName);
|
if (kernelSource[i] == ')')
|
||||||
|
{
|
||||||
|
kernelSource[i] = 0;//' ';
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_cpProgram = compileCLProgramFromString(clContext,device,kernelSource,pErrNum,additionalMacros);
|
||||||
|
|
||||||
|
if( clFileNameForCaching )
|
||||||
|
{ // write to binary
|
||||||
|
|
||||||
delete [] binary;
|
cl_uint numAssociatedDevices;
|
||||||
|
status = clGetProgramInfo( m_cpProgram, CL_PROGRAM_NUM_DEVICES, sizeof(cl_uint), &numAssociatedDevices, 0 );
|
||||||
|
btAssert( status == CL_SUCCESS );
|
||||||
|
if (numAssociatedDevices==1)
|
||||||
|
{
|
||||||
|
|
||||||
|
size_t binarySize;
|
||||||
|
status = clGetProgramInfo( m_cpProgram, CL_PROGRAM_BINARY_SIZES, sizeof(size_t), &binarySize, 0 );
|
||||||
|
btAssert( status == CL_SUCCESS );
|
||||||
|
|
||||||
|
char* binary = new char[binarySize];
|
||||||
|
|
||||||
|
status = clGetProgramInfo( m_cpProgram, CL_PROGRAM_BINARIES, sizeof(char*), &binary, 0 );
|
||||||
|
btAssert( status == CL_SUCCESS );
|
||||||
|
|
||||||
|
{
|
||||||
|
FILE* file = fopen(binaryFileName, "wb");
|
||||||
|
if (file)
|
||||||
|
{
|
||||||
|
fwrite( binary, sizeof(char), binarySize, file );
|
||||||
|
fclose( file );
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
printf("cannot write file %s\n", binaryFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] binary;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif//defined (_WIN32) && defined(_MSC_VER)
|
|
||||||
|
|
||||||
delete [] compileFlags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_cpProgram;
|
return m_cpProgram;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
/// CL Context optionally takes a GL context. This is a generic type because we don't really want this code
|
/// CL Context optionally takes a GL context. This is a generic type because we don't really want this code
|
||||||
/// to have to understand GL types. It is a HGLRC in _WIN32 or a GLXContext otherwise.
|
/// to have to understand GL types. It is a HGLRC in _WIN32 or a GLXContext otherwise.
|
||||||
static cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0);
|
static cl_context createContextFromType(cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0, int preferredDeviceIndex = -1, int preferredPlatformIndex= - 1);
|
||||||
|
|
||||||
static int getNumDevices(cl_context cxMainContext);
|
static int getNumDevices(cl_context cxMainContext);
|
||||||
static cl_device_id getDevice(cl_context cxMainContext, int nr);
|
static cl_device_id getDevice(cl_context cxMainContext, int nr);
|
||||||
@@ -88,7 +88,10 @@ public:
|
|||||||
static cl_kernel compileCLKernelFromString( cl_context clContext,cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum=0, cl_program prog=0,const char* additionalMacros = "" );
|
static cl_kernel compileCLKernelFromString( cl_context clContext,cl_device_id device, const char* kernelSource, const char* kernelName, cl_int* pErrNum=0, cl_program prog=0,const char* additionalMacros = "" );
|
||||||
|
|
||||||
//optional
|
//optional
|
||||||
static cl_program compileCLProgramFromString( cl_context clContext,cl_device_id device, const char* kernelSource, cl_int* pErrNum=0,const char* additionalMacros = "" , const char* srcFileNameForCaching=0);
|
static cl_program compileCLProgramFromString( cl_context clContext,cl_device_id device, const char* kernelSource, cl_int* pErrNum=0,const char* additionalMacros = "");
|
||||||
|
///compileCLProgramFromFile will attempt to save/load the binary precompiled program
|
||||||
|
static cl_program compileCLProgramFromFile( cl_context clContext,cl_device_id device, cl_int* pErrNum=0,const char* additionalMacros = "" , const char* srcFileNameForCaching=0);
|
||||||
|
|
||||||
|
|
||||||
//the following optional APIs provide access using specific platform information
|
//the following optional APIs provide access using specific platform information
|
||||||
static int getNumPlatforms(cl_int* pErrNum=0);
|
static int getNumPlatforms(cl_int* pErrNum=0);
|
||||||
@@ -96,7 +99,7 @@ public:
|
|||||||
static cl_platform_id getPlatform(int nr, cl_int* pErrNum=0);
|
static cl_platform_id getPlatform(int nr, cl_int* pErrNum=0);
|
||||||
static void getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInfo& platformInfo);
|
static void getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInfo& platformInfo);
|
||||||
static const char* getSdkVendorName();
|
static const char* getSdkVendorName();
|
||||||
static cl_context createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0);
|
static cl_context createContextFromPlatform(cl_platform_id platform, cl_device_type deviceType, cl_int* pErrNum, void* pGLCtx = 0, void* pGLDC = 0,int preferredDeviceIndex = -1, int preferredPlatformIndex= -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Bullet Continuous Collision Detection and Physics Library
|
||||||
|
Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "btBulletWorldImporter.h"
|
#include "btBulletWorldImporter.h"
|
||||||
#include "../BulletFileLoader/btBulletFile.h"
|
#include "../BulletFileLoader/btBulletFile.h"
|
||||||
@@ -454,23 +469,24 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
|
|||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
shape = createCapsuleShapeX(implicitShapeDimensions.getY(),2*implicitShapeDimensions.getX());
|
shape = createCapsuleShapeX(implicitShapeDimensions.getY()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getX());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
shape = createCapsuleShapeY(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getY());
|
shape = createCapsuleShapeY(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getY());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
shape = createCapsuleShapeZ(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getZ());
|
shape = createCapsuleShapeZ(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getZ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
printf("error: wrong up axis for btCapsuleShape\n");
|
printf("error: wrong up axis for btCapsuleShape\n");
|
||||||
}
|
}
|
||||||
|
bsd->m_collisionMargin = 0.f;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -567,7 +583,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
|
|||||||
|
|
||||||
if (shape)
|
if (shape)
|
||||||
{
|
{
|
||||||
shape->setMargin(bsd->m_collisionMargin);
|
//shape->setMargin(bsd->m_collisionMargin);
|
||||||
btVector3 localScaling;
|
btVector3 localScaling;
|
||||||
localScaling.deSerializeFloat(bsd->m_localScaling);
|
localScaling.deSerializeFloat(bsd->m_localScaling);
|
||||||
shape->setLocalScaling(localScaling);
|
shape->setLocalScaling(localScaling);
|
||||||
@@ -654,7 +670,9 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
|
|||||||
compoundShape->addChildShape(localTransform,childShape);
|
compoundShape->addChildShape(localTransform,childShape);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
printf("error: couldn't create childShape for compoundShape\n");
|
printf("error: couldn't create childShape for compoundShape\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -668,7 +686,9 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
|
printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -827,6 +847,10 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
|
|||||||
}
|
}
|
||||||
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->setRestitution(colObjData->m_collisionObjectData.m_restitution);
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_INTERNAL_EDGE_UTILITY
|
#ifdef USE_INTERNAL_EDGE_UTILITY
|
||||||
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
||||||
{
|
{
|
||||||
@@ -857,7 +881,9 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile
|
|||||||
startTransform.deSerializeDouble(colObjData->m_worldTransform);
|
startTransform.deSerializeDouble(colObjData->m_worldTransform);
|
||||||
btCollisionShape* shape = (btCollisionShape*)*shapePtr;
|
btCollisionShape* shape = (btCollisionShape*)*shapePtr;
|
||||||
btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name);
|
btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name);
|
||||||
|
body->setFriction(colObjData->m_friction);
|
||||||
|
body->setRestitution(colObjData->m_restitution);
|
||||||
|
|
||||||
#ifdef USE_INTERNAL_EDGE_UTILITY
|
#ifdef USE_INTERNAL_EDGE_UTILITY
|
||||||
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,6 +55,10 @@ namespace bParse
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///The btBulletWorldImporter is a starting point to import .bullet files.
|
||||||
|
///note that not all data is converted yet. You are expected to override or modify this class.
|
||||||
|
///See Bullet/Demos/SerializeDemo for a derived class that extract btSoftBody objects too.
|
||||||
class btBulletWorldImporter
|
class btBulletWorldImporter
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ subject to the following restrictions:
|
|||||||
#include "btSoftBodySolverVertexBuffer_DX11.h"
|
#include "btSoftBodySolverVertexBuffer_DX11.h"
|
||||||
#include "BulletSoftBody/btSoftBody.h"
|
#include "BulletSoftBody/btSoftBody.h"
|
||||||
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
|
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
|
||||||
|
#include <stdio.h> //printf
|
||||||
#define MSTRINGIFY(A) #A
|
#define MSTRINGIFY(A) #A
|
||||||
static char* PrepareLinksHLSLString =
|
static char* PrepareLinksHLSLString =
|
||||||
#include "HLSL/PrepareLinks.hlsl"
|
#include "HLSL/PrepareLinks.hlsl"
|
||||||
@@ -2190,7 +2190,9 @@ void btDX11SoftBodySolver::processCollision( btSoftBody *softBody, btCollisionOb
|
|||||||
m_collisionObjectDetails.push_back( newCollisionShapeDescription );
|
m_collisionObjectDetails.push_back( newCollisionShapeDescription );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
btAssert("Unsupported collision shape type\n");
|
#ifdef _DEBUG
|
||||||
|
printf("Unsupported collision shape type\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
btAssert("Unknown soft body");
|
btAssert("Unknown soft body");
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
MSTRINGIFY(
|
MSTRINGIFY(
|
||||||
float mydot3(float4 a, float4 b)
|
|
||||||
|
//#pragma OPENCL EXTENSION cl_amd_printf:enable\n
|
||||||
|
|
||||||
|
float mydot3a(float4 a, float4 b)
|
||||||
{
|
{
|
||||||
return a.x*b.x + a.y*b.y + a.z*b.z;
|
return a.x*b.x + a.y*b.y + a.z*b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float mylength3(float4 a)
|
||||||
|
{
|
||||||
|
a.w = 0;
|
||||||
|
return length(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
float4 mynormalize3(float4 a)
|
||||||
|
{
|
||||||
|
a.w = 0;
|
||||||
|
return normalize(a);
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -37,8 +51,7 @@ typedef struct
|
|||||||
// From btBroadphaseProxy.h
|
// From btBroadphaseProxy.h
|
||||||
__constant int CAPSULE_SHAPE_PROXYTYPE = 10;
|
__constant int CAPSULE_SHAPE_PROXYTYPE = 10;
|
||||||
|
|
||||||
|
// Multiply column-major matrix against vector
|
||||||
/* Multiply column-major matrix against vector */
|
|
||||||
float4 matrixVectorMul( float4 matrix[4], float4 vector )
|
float4 matrixVectorMul( float4 matrix[4], float4 vector )
|
||||||
{
|
{
|
||||||
float4 returnVector;
|
float4 returnVector;
|
||||||
@@ -66,7 +79,8 @@ SolveCollisionsAndUpdateVelocitiesKernel(
|
|||||||
__global float4 * g_vertexForces,
|
__global float4 * g_vertexForces,
|
||||||
__global float4 *g_vertexVelocities,
|
__global float4 *g_vertexVelocities,
|
||||||
__global float4 *g_vertexPositions,
|
__global float4 *g_vertexPositions,
|
||||||
__local CollisionShapeDescription *localCollisionShapes)
|
__local CollisionShapeDescription *localCollisionShapes,
|
||||||
|
__global float * g_vertexInverseMasses)
|
||||||
{
|
{
|
||||||
int nodeID = get_global_id(0);
|
int nodeID = get_global_id(0);
|
||||||
float4 forceOnVertex = (float4)(0.f, 0.f, 0.f, 0.f);
|
float4 forceOnVertex = (float4)(0.f, 0.f, 0.f, 0.f);
|
||||||
@@ -78,18 +92,20 @@ SolveCollisionsAndUpdateVelocitiesKernel(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
float4 position = (float4)(g_vertexPositions[nodeID].xyz, 1.f);
|
float4 position = (float4)(g_vertexPositions[nodeID].xyz, 0.f);
|
||||||
float4 previousPosition = (float4)(g_vertexPreviousPositions[nodeID].xyz, 1.f);
|
float4 previousPosition = (float4)(g_vertexPreviousPositions[nodeID].xyz, 0.f);
|
||||||
|
|
||||||
float clothFriction = g_perClothFriction[clothIdentifier];
|
float clothFriction = g_perClothFriction[clothIdentifier];
|
||||||
float dampingFactor = g_clothDampingFactor[clothIdentifier];
|
float dampingFactor = g_clothDampingFactor[clothIdentifier];
|
||||||
float velocityCoefficient = (1.f - dampingFactor);
|
float velocityCoefficient = (1.f - dampingFactor);
|
||||||
|
|
||||||
// Update velocity
|
|
||||||
float4 difference = position - previousPosition;
|
float4 difference = position - previousPosition;
|
||||||
float4 velocity = difference*velocityCoefficient*isolverdt;
|
float4 velocity = difference*velocityCoefficient*isolverdt;
|
||||||
|
float inverseMass = g_vertexInverseMasses[nodeID];
|
||||||
|
|
||||||
CollisionObjectIndices collisionObjectIndices = g_perClothCollisionObjectIndices[clothIdentifier];
|
CollisionObjectIndices collisionObjectIndices = g_perClothCollisionObjectIndices[clothIdentifier];
|
||||||
|
|
||||||
int numObjects = collisionObjectIndices.endObject - collisionObjectIndices.firstObject;
|
int numObjects = collisionObjectIndices.endObject - collisionObjectIndices.firstObject;
|
||||||
|
|
||||||
if( numObjects > 0 )
|
if( numObjects > 0 )
|
||||||
{
|
{
|
||||||
// We have some possible collisions to deal with
|
// We have some possible collisions to deal with
|
||||||
@@ -113,7 +129,7 @@ SolveCollisionsAndUpdateVelocitiesKernel(
|
|||||||
// We have some possible collisions to deal with
|
// We have some possible collisions to deal with
|
||||||
for( int collision = 0; collision < numObjects; ++collision )
|
for( int collision = 0; collision < numObjects; ++collision )
|
||||||
{
|
{
|
||||||
//CollisionShapeDescription shapeDescription = localCollisionShapes[collision];
|
CollisionShapeDescription shapeDescription = localCollisionShapes[collision];
|
||||||
float colliderFriction = localCollisionShapes[collision].friction;
|
float colliderFriction = localCollisionShapes[collision].friction;
|
||||||
|
|
||||||
if( localCollisionShapes[collision].collisionShapeType == CAPSULE_SHAPE_PROXYTYPE )
|
if( localCollisionShapes[collision].collisionShapeType == CAPSULE_SHAPE_PROXYTYPE )
|
||||||
@@ -125,14 +141,14 @@ SolveCollisionsAndUpdateVelocitiesKernel(
|
|||||||
float capsuleMargin = localCollisionShapes[collision].margin;
|
float capsuleMargin = localCollisionShapes[collision].margin;
|
||||||
int capsuleupAxis = localCollisionShapes[collision].upAxis;
|
int capsuleupAxis = localCollisionShapes[collision].upAxis;
|
||||||
|
|
||||||
|
if ( capsuleHalfHeight <= 0 )
|
||||||
|
capsuleHalfHeight = 0.0001f;
|
||||||
float4 worldTransform[4];
|
float4 worldTransform[4];
|
||||||
worldTransform[0] = localCollisionShapes[collision].shapeTransform[0];
|
worldTransform[0] = localCollisionShapes[collision].shapeTransform[0];
|
||||||
worldTransform[1] = localCollisionShapes[collision].shapeTransform[1];
|
worldTransform[1] = localCollisionShapes[collision].shapeTransform[1];
|
||||||
worldTransform[2] = localCollisionShapes[collision].shapeTransform[2];
|
worldTransform[2] = localCollisionShapes[collision].shapeTransform[2];
|
||||||
worldTransform[3] = localCollisionShapes[collision].shapeTransform[3];
|
worldTransform[3] = localCollisionShapes[collision].shapeTransform[3];
|
||||||
|
|
||||||
//float4 c1 = (float4)(0.f, -capsuleHalfHeight, 0.f, 1.f);
|
|
||||||
//float4 c2 = (float4)(0.f, +capsuleHalfHeight, 0.f, 1.f);
|
|
||||||
// Correctly define capsule centerline vector
|
// Correctly define capsule centerline vector
|
||||||
float4 c1 = (float4)(0.f, 0.f, 0.f, 1.f);
|
float4 c1 = (float4)(0.f, 0.f, 0.f, 1.f);
|
||||||
float4 c2 = (float4)(0.f, 0.f, 0.f, 1.f);
|
float4 c2 = (float4)(0.f, 0.f, 0.f, 1.f);
|
||||||
@@ -145,65 +161,72 @@ SolveCollisionsAndUpdateVelocitiesKernel(
|
|||||||
|
|
||||||
float4 worldC1 = matrixVectorMul(worldTransform, c1);
|
float4 worldC1 = matrixVectorMul(worldTransform, c1);
|
||||||
float4 worldC2 = matrixVectorMul(worldTransform, c2);
|
float4 worldC2 = matrixVectorMul(worldTransform, c2);
|
||||||
float4 segment = (worldC2 - worldC1);
|
float4 segment = (float4)((worldC2 - worldC1).xyz, 0.f);
|
||||||
|
|
||||||
|
float4 segmentNormalized = mynormalize3(segment);
|
||||||
|
float distanceAlongSegment =mydot3a( (position - worldC1), segmentNormalized );
|
||||||
|
|
||||||
// compute distance of tangent to vertex along line segment in capsule
|
float4 closestPointOnSegment = (worldC1 + (float4)(segmentNormalized * distanceAlongSegment));
|
||||||
float distanceAlongSegment = -( mydot3( (worldC1 - position), segment ) / mydot3(segment, segment) );
|
float distanceFromLine = mylength3(position - closestPointOnSegment);
|
||||||
|
float distanceFromC1 = mylength3(worldC1 - position);
|
||||||
float4 closestPoint = (worldC1 + (float4)(segment * distanceAlongSegment));
|
float distanceFromC2 = mylength3(worldC2 - position);
|
||||||
float distanceFromLine = length(position - closestPoint);
|
|
||||||
float distanceFromC1 = length(worldC1 - position);
|
|
||||||
float distanceFromC2 = length(worldC2 - position);
|
|
||||||
|
|
||||||
// Final distance from collision, point to push from, direction to push in
|
// Final distance from collision, point to push from, direction to push in
|
||||||
// for impulse force
|
// for impulse force
|
||||||
float dist;
|
float dist;
|
||||||
float4 normalVector;
|
float4 normalVector;
|
||||||
|
|
||||||
if( distanceAlongSegment < 0 )
|
if( distanceAlongSegment < 0 )
|
||||||
{
|
{
|
||||||
dist = distanceFromC1;
|
dist = distanceFromC1;
|
||||||
normalVector = normalize(position - worldC1);
|
normalVector = (float4)(normalize(position - worldC1).xyz, 0.f);
|
||||||
} else if( distanceAlongSegment > 1.f ) {
|
} else if( distanceAlongSegment > length(segment) ) {
|
||||||
dist = distanceFromC2;
|
dist = distanceFromC2;
|
||||||
normalVector = normalize(position - worldC2);
|
normalVector = (float4)(normalize(position - worldC2).xyz, 0.f);
|
||||||
} else {
|
} else {
|
||||||
dist = distanceFromLine;
|
dist = distanceFromLine;
|
||||||
normalVector = normalize(position - closestPoint);
|
normalVector = (float4)(normalize(position - closestPointOnSegment).xyz, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float4 colliderLinearVelocity = localCollisionShapes[collision].linearVelocity;
|
|
||||||
float4 colliderAngularVelocity = localCollisionShapes[collision].angularVelocity;
|
|
||||||
float4 velocityOfSurfacePoint = colliderLinearVelocity + cross(colliderAngularVelocity, position - (float4)(worldTransform[0].w, worldTransform[1].w, worldTransform[2].w, 0.f));
|
|
||||||
|
|
||||||
float minDistance = capsuleRadius + capsuleMargin;
|
float minDistance = capsuleRadius + capsuleMargin;
|
||||||
|
float4 closestPointOnSurface = (float4)((position + (minDistance - dist) * normalVector).xyz, 0.f);
|
||||||
// In case of no collision, this is the value of velocity
|
|
||||||
velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
|
float4 colliderLinearVelocity = shapeDescription.linearVelocity;
|
||||||
|
float4 colliderAngularVelocity = shapeDescription.angularVelocity;
|
||||||
|
float4 velocityOfSurfacePoint = colliderLinearVelocity + cross(colliderAngularVelocity, closestPointOnSurface - (float4)(worldTransform[0].w, worldTransform[1].w, worldTransform[2].w, 0.f));
|
||||||
|
|
||||||
|
|
||||||
// Check for a collision
|
// Check for a collision
|
||||||
if( dist < minDistance )
|
if( dist < minDistance )
|
||||||
{
|
{
|
||||||
// Project back to surface along normal
|
// Project back to surface along normal
|
||||||
position = position + (float4)((minDistance - dist)*normalVector*0.9f);
|
position = closestPointOnSurface;
|
||||||
velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
|
velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
|
||||||
float4 relativeVelocity = velocity - velocityOfSurfacePoint;
|
float4 relativeVelocity = velocity - velocityOfSurfacePoint;
|
||||||
|
|
||||||
float4 p1 = (float4)(normalize(cross(normalVector, segment)).xyz, 0.f);
|
float4 p1 = mynormalize3(cross(normalVector, segment));
|
||||||
float4 p2 = (float4)(normalize(cross(p1, normalVector)).xyz, 0.f);
|
float4 p2 = mynormalize3(cross(p1, normalVector));
|
||||||
// Full friction is sum of velocities in each direction of plane
|
|
||||||
float4 frictionVector = p1*mydot3(relativeVelocity, p1) + p2*mydot3(relativeVelocity, p2);
|
|
||||||
|
|
||||||
// Real friction is peak friction corrected by friction coefficients
|
|
||||||
frictionVector = frictionVector * (colliderFriction*clothFriction);
|
|
||||||
|
|
||||||
float approachSpeed = dot(relativeVelocity, normalVector);
|
|
||||||
|
|
||||||
if( approachSpeed <= 0.0f )
|
|
||||||
forceOnVertex -= frictionVector;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
float4 tangentialVel = p1*mydot3a(relativeVelocity, p1) + p2*mydot3a(relativeVelocity, p2);
|
||||||
|
float frictionCoef = (colliderFriction * clothFriction);
|
||||||
|
if (frictionCoef>1.f)
|
||||||
|
frictionCoef = 1.f;
|
||||||
|
|
||||||
|
//only apply friction if objects are not moving apart
|
||||||
|
float projVel = mydot3a(relativeVelocity,normalVector);
|
||||||
|
if ( projVel >= -0.001f)
|
||||||
|
{
|
||||||
|
if ( inverseMass > 0 )
|
||||||
|
{
|
||||||
|
//float4 myforceOnVertex = -tangentialVel * frictionCoef * isolverdt * (1.0f / inverseMass);
|
||||||
|
position += (-tangentialVel * frictionCoef) / (isolverdt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In case of no collision, this is the value of velocity
|
||||||
|
velocity = (position - previousPosition) * velocityCoefficient * isolverdt;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -739,7 +739,7 @@ void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &sof
|
|||||||
m_perClothDragFactor.push_back( softBody->m_cfg.kDG );
|
m_perClothDragFactor.push_back( softBody->m_cfg.kDG );
|
||||||
m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density);
|
m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density);
|
||||||
// Simple init values. Actually we'll put 0 and -1 into them at the appropriate time
|
// Simple init values. Actually we'll put 0 and -1 into them at the appropriate time
|
||||||
m_perClothFriction.push_back( softBody->getFriction() );
|
m_perClothFriction.push_back(softBody->m_cfg.kDF);
|
||||||
m_perClothCollisionObjects.push_back( CollisionObjectIndices(-1, -1) );
|
m_perClothCollisionObjects.push_back( CollisionObjectIndices(-1, -1) );
|
||||||
|
|
||||||
// Add space for new vertices and triangles in the default solver for now
|
// Add space for new vertices and triangles in the default solver for now
|
||||||
@@ -1737,7 +1737,9 @@ void btOpenCLSoftBodySolver::processCollision( btSoftBody *softBody, btCollision
|
|||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#ifdef _DEBUG
|
||||||
printf("Unsupported collision shape type\n");
|
printf("Unsupported collision shape type\n");
|
||||||
|
#endif
|
||||||
//btAssert(0 && "Unsupported collision shape type\n");
|
//btAssert(0 && "Unsupported collision shape type\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ void btOpenCLSoftBodySolverSIMDAware::optimize( btAlignedObjectArray< btSoftBody
|
|||||||
m_perClothDragFactor.push_back( softBody->m_cfg.kDG );
|
m_perClothDragFactor.push_back( softBody->m_cfg.kDG );
|
||||||
m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density);
|
m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density);
|
||||||
// Simple init values. Actually we'll put 0 and -1 into them at the appropriate time
|
// Simple init values. Actually we'll put 0 and -1 into them at the appropriate time
|
||||||
m_perClothFriction.push_back( softBody->getFriction() );
|
m_perClothFriction.push_back(softBody->m_cfg.kDF);
|
||||||
m_perClothCollisionObjects.push_back( CollisionObjectIndices(-1, -1) );
|
m_perClothCollisionObjects.push_back( CollisionObjectIndices(-1, -1) );
|
||||||
|
|
||||||
// Add space for new vertices and triangles in the default solver for now
|
// Add space for new vertices and triangles in the default solver for now
|
||||||
@@ -253,6 +253,10 @@ void btOpenCLSoftBodySolverSIMDAware::optimize( btAlignedObjectArray< btSoftBody
|
|||||||
|
|
||||||
m_anchorIndex.push_back(-1.0);
|
m_anchorIndex.push_back(-1.0);
|
||||||
}
|
}
|
||||||
|
for( int vertex = numVertices; vertex < maxVertices; ++vertex )
|
||||||
|
{
|
||||||
|
m_anchorIndex.push_back(-1.0);
|
||||||
|
}
|
||||||
|
|
||||||
// Copy triangles similarly
|
// Copy triangles similarly
|
||||||
// We're assuming here that vertex indices are based on the firstVertex rather than the entire scene
|
// We're assuming here that vertex indices are based on the firstVertex rather than the entire scene
|
||||||
@@ -524,6 +528,7 @@ void btOpenCLSoftBodySolverSIMDAware::solveCollisionsAndUpdateVelocities( float
|
|||||||
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 9, sizeof(cl_mem),&m_vertexData.m_clVertexVelocity.m_buffer);
|
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 9, sizeof(cl_mem),&m_vertexData.m_clVertexVelocity.m_buffer);
|
||||||
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 10, sizeof(cl_mem),&m_vertexData.m_clVertexPosition.m_buffer);
|
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 10, sizeof(cl_mem),&m_vertexData.m_clVertexPosition.m_buffer);
|
||||||
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 11, sizeof(CollisionShapeDescription)*16,0);
|
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 11, sizeof(CollisionShapeDescription)*16,0);
|
||||||
|
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 12, sizeof(cl_mem),&m_vertexData.m_clVertexInverseMass.m_buffer);
|
||||||
size_t numWorkItems = workGroupSize*((m_vertexData.getNumVertices() + (workGroupSize-1)) / workGroupSize);
|
size_t numWorkItems = workGroupSize*((m_vertexData.getNumVertices() + (workGroupSize-1)) / workGroupSize);
|
||||||
|
|
||||||
if (numWorkItems)
|
if (numWorkItems)
|
||||||
|
|||||||
@@ -646,7 +646,9 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetContextInfo(cl_context /* co
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(cl_context_properties * /* properties */,
|
|
||||||
|
|
||||||
|
CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(const cl_context_properties * /* properties */,
|
||||||
cl_device_type device_type ,
|
cl_device_type device_type ,
|
||||||
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
||||||
void * /* user_data */,
|
void * /* user_data */,
|
||||||
@@ -706,6 +708,28 @@ CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(cl_context_propertie
|
|||||||
return (cl_context)scheduler;
|
return (cl_context)scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CL_API_ENTRY cl_int CL_API_CALL
|
||||||
|
clGetDeviceIDs(cl_platform_id /* platform */,
|
||||||
|
cl_device_type /* device_type */,
|
||||||
|
cl_uint /* num_entries */,
|
||||||
|
cl_device_id * /* devices */,
|
||||||
|
cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CL_API_ENTRY cl_context CL_API_CALL
|
||||||
|
clCreateContext(const cl_context_properties * properties ,
|
||||||
|
cl_uint num_devices ,
|
||||||
|
const cl_device_id * devices ,
|
||||||
|
void (*pfn_notify)(const char *, const void *, size_t, void *),
|
||||||
|
void * user_data ,
|
||||||
|
cl_int * errcode_ret ) CL_API_SUFFIX__VERSION_1_0
|
||||||
|
{
|
||||||
|
|
||||||
|
return clCreateContextFromType(properties,CL_DEVICE_TYPE_ALL,pfn_notify,user_data,errcode_ret);
|
||||||
|
}
|
||||||
|
|
||||||
CL_API_ENTRY cl_int CL_API_CALL clReleaseContext(cl_context context ) CL_API_SUFFIX__VERSION_1_0
|
CL_API_ENTRY cl_int CL_API_CALL clReleaseContext(cl_context context ) CL_API_SUFFIX__VERSION_1_0
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ clGetDeviceInfo(cl_device_id /* device */,
|
|||||||
|
|
||||||
// Context APIs
|
// Context APIs
|
||||||
extern CL_API_ENTRY cl_context CL_API_CALL
|
extern CL_API_ENTRY cl_context CL_API_CALL
|
||||||
clCreateContext(cl_context_properties * /* properties */,
|
clCreateContext(const cl_context_properties * /* properties */,
|
||||||
cl_uint /* num_devices */,
|
cl_uint /* num_devices */,
|
||||||
const cl_device_id * /* devices */,
|
const cl_device_id * /* devices */,
|
||||||
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
||||||
@@ -445,7 +445,7 @@ clCreateContext(cl_context_properties * /* properties */,
|
|||||||
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
|
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0;
|
||||||
|
|
||||||
extern CL_API_ENTRY cl_context CL_API_CALL
|
extern CL_API_ENTRY cl_context CL_API_CALL
|
||||||
clCreateContextFromType(cl_context_properties * /* properties */,
|
clCreateContextFromType(const cl_context_properties * /* properties */,
|
||||||
cl_device_type /* device_type */,
|
cl_device_type /* device_type */,
|
||||||
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */,
|
||||||
void * /* user_data */,
|
void * /* user_data */,
|
||||||
|
|||||||
Reference in New Issue
Block a user