Apply a patch that updates vertex position on GPU for the OpenCL version, by Dongsoo Han (saggita), work-in-progress

Removed the unused OpenCL kernels
Add example how to cache binary kernels, see SoftDemo compiled with OpenCL AMD using msvc/vs2008_opencl.bat
This commit is contained in:
erwin.coumans
2011-12-20 18:03:24 +00:00
parent 5cb40ed6e3
commit 1f7a67b7da
31 changed files with 441 additions and 1386 deletions

View File

@@ -20,10 +20,13 @@ subject to the following restrictions:
#include "btSoftBodySolver_OpenCL.h"
#include "BulletSoftBody/btSoftBodySolverVertexBuffer.h"
#include "BulletSoftBody/btSoftBody.h"
#include "BulletSoftBody/btSoftBodyInternals.h"
#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
#include "BulletCollision/COllisionShapes/btSphereShape.h"
#include "LinearMath/btQuickprof.h"
#include <limits.h>
#define BT_SUPPRESS_OPENCL_ASSERTS
#ifdef USE_MINICL
@@ -36,8 +39,7 @@ subject to the following restrictions:
#endif //__APPLE__
#endif//USE_MINICL
#define BT_DEFAULT_WORKGROUPSIZE 128
#define BT_DEFAULT_WORKGROUPSIZE 64
#define RELEASE_CL_KERNEL(kernelName) {if( kernelName ){ clReleaseKernel( kernelName ); kernelName = 0; }}
@@ -45,32 +47,6 @@ subject to the following restrictions:
//CL_VERSION_1_1 seems broken on NVidia SDK so just disable it
#if (0)//CL_VERSION_1_1 == 1)
//OpenCL 1.1 kernels use float3
#define MSTRINGIFY(A) #A
static const char* PrepareLinksCLString =
#include "OpenCLC/PrepareLinks.cl"
static const char* UpdatePositionsFromVelocitiesCLString =
#include "OpenCLC/UpdatePositionsFromVelocities.cl"
static const char* SolvePositionsCLString =
#include "OpenCLC/SolvePositions.cl"
static const char* UpdateNodesCLString =
#include "OpenCLC/UpdateNodes.cl"
static const char* UpdatePositionsCLString =
#include "OpenCLC/UpdatePositions.cl"
static const char* UpdateConstantsCLString =
#include "OpenCLC/UpdateConstants.cl"
static const char* IntegrateCLString =
#include "OpenCLC/Integrate.cl"
static const char* ApplyForcesCLString =
#include "OpenCLC/ApplyForces.cl"
static const char* UpdateNormalsCLString =
#include "OpenCLC/UpdateNormals.cl"
static const char* VSolveLinksCLString =
#include "OpenCLC/VSolveLinks.cl"
static const char* SolveCollisionsAndUpdateVelocitiesCLString =
#include "OpenCLC/SolveCollisionsAndUpdateVelocities.cl"
#else
////OpenCL 1.0 kernels don't use float3
#define MSTRINGIFY(A) #A
static const char* PrepareLinksCLString =
@@ -89,13 +65,14 @@ static const char* IntegrateCLString =
#include "OpenCLC10/Integrate.cl"
static const char* ApplyForcesCLString =
#include "OpenCLC10/ApplyForces.cl"
static const char* UpdateFixedVertexPositionsCLString =
#include "OpenCLC10/UpdateFixedVertexPositions.cl"
static const char* UpdateNormalsCLString =
#include "OpenCLC10/UpdateNormals.cl"
static const char* VSolveLinksCLString =
#include "OpenCLC10/VSolveLinks.cl"
static const char* SolveCollisionsAndUpdateVelocitiesCLString =
#include "OpenCLC10/SolveCollisionsAndUpdateVelocities.cl"
#endif //CL_VERSION_1_1
btSoftBodyVertexDataOpenCL::btSoftBodyVertexDataOpenCL( cl_command_queue queue, cl_context ctx) :
@@ -141,18 +118,42 @@ bool btSoftBodyVertexDataOpenCL::moveToAccelerator()
return success;
}
bool btSoftBodyVertexDataOpenCL::moveFromAccelerator()
bool btSoftBodyVertexDataOpenCL::moveFromAccelerator(bool bCopy, bool bCopyMinimum)
{
bool success = true;
success = success && m_clClothIdentifier.moveFromGPU();
success = success && m_clVertexPosition.moveFromGPU();
success = success && m_clVertexPreviousPosition.moveFromGPU();
success = success && m_clVertexVelocity.moveFromGPU();
success = success && m_clVertexForceAccumulator.moveFromGPU();
success = success && m_clVertexNormal.moveFromGPU();
success = success && m_clVertexInverseMass.moveFromGPU();
success = success && m_clVertexArea.moveFromGPU();
success = success && m_clVertexTriangleCount.moveFromGPU();
if (!bCopy)
{
success = success && m_clClothIdentifier.moveFromGPU();
success = success && m_clVertexPosition.moveFromGPU();
success = success && m_clVertexPreviousPosition.moveFromGPU();
success = success && m_clVertexVelocity.moveFromGPU();
success = success && m_clVertexForceAccumulator.moveFromGPU();
success = success && m_clVertexNormal.moveFromGPU();
success = success && m_clVertexInverseMass.moveFromGPU();
success = success && m_clVertexArea.moveFromGPU();
success = success && m_clVertexTriangleCount.moveFromGPU();
}
else
{
if (bCopyMinimum)
{
success = success && m_clVertexPosition.copyFromGPU();
success = success && m_clVertexNormal.copyFromGPU();
}
else
{
success = success && m_clClothIdentifier.copyFromGPU();
success = success && m_clVertexPosition.copyFromGPU();
success = success && m_clVertexPreviousPosition.copyFromGPU();
success = success && m_clVertexVelocity.copyFromGPU();
success = success && m_clVertexForceAccumulator.copyFromGPU();
success = success && m_clVertexNormal.copyFromGPU();
success = success && m_clVertexInverseMass.copyFromGPU();
success = success && m_clVertexArea.copyFromGPU();
success = success && m_clVertexTriangleCount.copyFromGPU();
}
}
if( success )
m_onGPU = true;
@@ -160,9 +161,6 @@ bool btSoftBodyVertexDataOpenCL::moveFromAccelerator()
return success;
}
btSoftBodyLinkDataOpenCL::btSoftBodyLinkDataOpenCL(cl_command_queue queue, cl_context ctx)
:m_cqCommandQue(queue),
m_clLinks( queue, ctx, &m_links, false ),
@@ -602,11 +600,12 @@ void btSoftBodyTriangleDataOpenCL::generateBatches()
btOpenCLSoftBodySolver::btOpenCLSoftBodySolver(cl_command_queue queue, cl_context ctx) :
btOpenCLSoftBodySolver::btOpenCLSoftBodySolver(cl_command_queue queue, cl_context ctx, bool bUpdateAchchoredNodePos) :
m_linkData(queue, ctx),
m_vertexData(queue, ctx),
m_triangleData(queue, ctx),
m_clFunctions(queue, ctx),
m_defaultCLFunctions(queue, ctx),
m_currentCLFunctions(&m_defaultCLFunctions),
m_clPerClothAcceleration(queue, ctx, &m_perClothAcceleration, true ),
m_clPerClothWindVelocity(queue, ctx, &m_perClothWindVelocity, true ),
m_clPerClothDampingFactor(queue,ctx, &m_perClothDampingFactor, true ),
@@ -617,10 +616,14 @@ btOpenCLSoftBodySolver::btOpenCLSoftBodySolver(cl_command_queue queue, cl_contex
m_clPerClothCollisionObjects( queue, ctx, &m_perClothCollisionObjects, true ),
m_clCollisionObjectDetails( queue, ctx, &m_collisionObjectDetails, true ),
m_clPerClothFriction( queue, ctx, &m_perClothFriction, false ),
m_clAnchorPosition( queue, ctx, &m_anchorPosition, true ),
m_clAnchorIndex( queue, ctx, &m_anchorIndex, true),
m_cqCommandQue( queue ),
m_cxMainContext(ctx),
m_defaultWorkGroupSize(BT_DEFAULT_WORKGROUPSIZE)
m_defaultWorkGroupSize(BT_DEFAULT_WORKGROUPSIZE),
m_bUpdateAnchoredNodePos(bUpdateAchchoredNodePos)
{
// Initial we will clearly need to update solver constants
// For now this is global for the cloths linked with this solver - we should probably make this body specific
// for performance in future once we understand more clearly when constants need to be updated
@@ -643,6 +646,7 @@ btOpenCLSoftBodySolver::btOpenCLSoftBodySolver(cl_command_queue queue, cl_contex
m_normalizeNormalsAndAreasKernel = 0;
m_outputToVertexArrayKernel = 0;
m_applyForcesKernel = 0;
m_updateFixedVertexPositionsKernel = 0;
}
btOpenCLSoftBodySolver::~btOpenCLSoftBodySolver()
@@ -666,14 +670,16 @@ void btOpenCLSoftBodySolver::releaseKernels()
RELEASE_CL_KERNEL( m_normalizeNormalsAndAreasKernel );
RELEASE_CL_KERNEL( m_outputToVertexArrayKernel );
RELEASE_CL_KERNEL( m_applyForcesKernel );
RELEASE_CL_KERNEL( m_updateFixedVertexPositionsKernel );
m_shadersInitialized = false;
}
void btOpenCLSoftBodySolver::copyBackToSoftBodies()
void btOpenCLSoftBodySolver::copyBackToSoftBodies(bool bMove)
{
// Move the vertex data back to the host first
m_vertexData.moveFromAccelerator();
m_vertexData.moveFromAccelerator(!bMove);
// Loop over soft bodies, copying all the vertex positions back for each body in turn
for( int softBodyIndex = 0; softBodyIndex < m_softBodySet.size(); ++softBodyIndex )
@@ -688,17 +694,18 @@ void btOpenCLSoftBodySolver::copyBackToSoftBodies()
for( int vertex = 0; vertex < numVertices; ++vertex )
{
using Vectormath::Aos::Point3;
Point3 vertexPosition( getVertexData().getVertexPositions()[firstVertex + vertex] );
Point3 vertexPosition( m_vertexData.getVertexPositions()[firstVertex + vertex] );
Point3 normal(m_vertexData.getNormal(firstVertex + vertex));
softBody->m_nodes[vertex].m_x.setX( vertexPosition.getX() );
softBody->m_nodes[vertex].m_x.setY( vertexPosition.getY() );
softBody->m_nodes[vertex].m_x.setZ( vertexPosition.getZ() );
softBody->m_nodes[vertex].m_n.setX( vertexPosition.getX() );
softBody->m_nodes[vertex].m_n.setY( vertexPosition.getY() );
softBody->m_nodes[vertex].m_n.setZ( vertexPosition.getZ() );
softBody->m_nodes[vertex].m_n.setX( normal.getX() );
softBody->m_nodes[vertex].m_n.setY( normal.getY() );
softBody->m_nodes[vertex].m_n.setZ( normal.getZ() );
}
}
}
} // btOpenCLSoftBodySolver::copyBackToSoftBodies
void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &softBodies, bool forceUpdate )
@@ -710,7 +717,10 @@ void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &sof
getTriangleData().clear();
getLinkData().clear();
m_softBodySet.resize(0);
m_anchorIndex.clear();
int maxPiterations = 0;
int maxViterations = 0;
for( int softBodyIndex = 0; softBodyIndex < softBodies.size(); ++softBodyIndex )
{
@@ -759,6 +769,8 @@ void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &sof
float vertexInverseMass = softBody->m_nodes[vertex].m_im;
desc.setInverseMass(vertexInverseMass);
getVertexData().setVertexAt( desc, firstVertex + vertex );
m_anchorIndex.push_back(-1.0);
}
// Copy triangles similarly
@@ -805,13 +817,76 @@ void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &sof
newSoftBody->setMaxTriangles( maxTriangles );
newSoftBody->setFirstLink( firstLink );
newSoftBody->setNumLinks( numLinks );
// Find maximum piterations and viterations
int piterations = softBody->m_cfg.piterations;
if ( piterations > maxPiterations )
maxPiterations = piterations;
int viterations = softBody->m_cfg.viterations;
if ( viterations > maxViterations )
maxViterations = viterations;
// zero mass
for( int vertex = 0; vertex < numVertices; ++vertex )
{
if ( softBody->m_nodes[vertex].m_im == 0 )
{
AnchorNodeInfoCL nodeInfo;
nodeInfo.clVertexIndex = firstVertex + vertex;
nodeInfo.pNode = &softBody->m_nodes[vertex];
m_anchorNodeInfoArray.push_back(nodeInfo);
}
}
// anchor position
if ( numVertices > 0 )
{
for ( int anchorIndex = 0; anchorIndex < softBody->m_anchors.size(); anchorIndex++ )
{
btSoftBody::Node* anchorNode = softBody->m_anchors[anchorIndex].m_node;
btSoftBody::Node* firstNode = &softBody->m_nodes[0];
AnchorNodeInfoCL nodeInfo;
nodeInfo.clVertexIndex = firstVertex + (int)(anchorNode - firstNode);
nodeInfo.pNode = anchorNode;
m_anchorNodeInfoArray.push_back(nodeInfo);
}
}
}
m_anchorPosition.clear();
m_anchorPosition.resize(m_anchorNodeInfoArray.size());
for ( int anchorNode = 0; anchorNode < m_anchorNodeInfoArray.size(); anchorNode++ )
{
const AnchorNodeInfoCL& anchorNodeInfo = m_anchorNodeInfoArray[anchorNode];
m_anchorIndex[anchorNodeInfo.clVertexIndex] = anchorNode;
getVertexData().getInverseMass(anchorNodeInfo.clVertexIndex) = 0.0f;
}
updateConstants(0.f);
// set position and velocity iterations
setNumberOfPositionIterations(maxPiterations);
setNumberOfVelocityIterations(maxViterations);
// set wind velocity
m_perClothWindVelocity.resize( m_softBodySet.size() );
for( int softBodyIndex = 0; softBodyIndex < m_softBodySet.size(); ++softBodyIndex )
{
btSoftBody *softBody = m_softBodySet[softBodyIndex]->getSoftBody();
m_perClothWindVelocity[softBodyIndex] = toVector3(softBody->getWindVelocity());
}
m_clPerClothWindVelocity.changedOnCPU();
// generate batches
m_linkData.generateBatches();
m_triangleData.generateBatches();
@@ -861,7 +936,6 @@ void btOpenCLSoftBodySolver::resetNormalsAndAreas( int numVertices )
void btOpenCLSoftBodySolver::normalizeNormalsAndAreas( int numVertices )
{
cl_int ciErrNum;
ciErrNum = clSetKernelArg(m_normalizeNormalsAndAreasKernel, 0, sizeof(int),(void*) &numVertices);
@@ -882,7 +956,6 @@ void btOpenCLSoftBodySolver::normalizeNormalsAndAreas( int numVertices )
void btOpenCLSoftBodySolver::executeUpdateSoftBodies( int firstTriangle, int numTriangles )
{
cl_int ciErrNum;
ciErrNum = clSetKernelArg(m_updateSoftBodiesKernel, 0, sizeof(int), (void*) &firstTriangle);
ciErrNum = clSetKernelArg(m_updateSoftBodiesKernel, 1, sizeof(int), &numTriangles);
@@ -948,16 +1021,41 @@ void btOpenCLSoftBodySolver::ApplyClampedForce( float solverdt, const Vectormath
}
}
void btOpenCLSoftBodySolver::updateFixedVertexPositions()
{
// Ensure data is on accelerator
m_vertexData.moveToAccelerator();
m_clAnchorPosition.moveToGPU();
m_clAnchorIndex.moveToGPU();
cl_int ciErrNum ;
int numVerts = m_vertexData.getNumVertices();
ciErrNum = clSetKernelArg(m_updateFixedVertexPositionsKernel, 0, sizeof(int), &numVerts);
ciErrNum = clSetKernelArg(m_updateFixedVertexPositionsKernel,1, sizeof(cl_mem), &m_clAnchorIndex.m_buffer);
ciErrNum = clSetKernelArg(m_updateFixedVertexPositionsKernel,2, sizeof(cl_mem), &m_vertexData.m_clVertexPosition.m_buffer);
ciErrNum = clSetKernelArg(m_updateFixedVertexPositionsKernel,3, sizeof(cl_mem), &m_clAnchorPosition.m_buffer);
size_t numWorkItems = m_defaultWorkGroupSize*((m_vertexData.getNumVertices() + (m_defaultWorkGroupSize-1)) / m_defaultWorkGroupSize);
if (numWorkItems)
{
ciErrNum = clEnqueueNDRangeKernel(m_cqCommandQue,m_updateFixedVertexPositionsKernel, 1, NULL, &numWorkItems, &m_defaultWorkGroupSize, 0,0,0);
if( ciErrNum != CL_SUCCESS )
{
btAssert( 0 && "enqueueNDRangeKernel(m_updateFixedVertexPositionsKernel)");
}
}
}
void btOpenCLSoftBodySolver::applyForces( float solverdt )
{
// Ensure data is on accelerator
m_vertexData.moveToAccelerator();
m_clPerClothAcceleration.moveToGPU();
m_clPerClothLiftFactor.moveToGPU();
m_clPerClothDragFactor.moveToGPU();
m_clPerClothMediumDensity.moveToGPU();
m_clPerClothWindVelocity.moveToGPU();
m_clPerClothWindVelocity.moveToGPU();
cl_int ciErrNum ;
int numVerts = m_vertexData.getNumVertices();
@@ -976,6 +1074,7 @@ void btOpenCLSoftBodySolver::applyForces( float solverdt )
ciErrNum = clSetKernelArg(m_applyForcesKernel,11, sizeof(cl_mem), &m_clPerClothMediumDensity.m_buffer);
ciErrNum = clSetKernelArg(m_applyForcesKernel,12, sizeof(cl_mem), &m_vertexData.m_clVertexForceAccumulator.m_buffer);
ciErrNum = clSetKernelArg(m_applyForcesKernel,13, sizeof(cl_mem), &m_vertexData.m_clVertexVelocity.m_buffer);
size_t numWorkItems = m_defaultWorkGroupSize*((m_vertexData.getNumVertices() + (m_defaultWorkGroupSize-1)) / m_defaultWorkGroupSize);
if (numWorkItems)
{
@@ -993,8 +1092,6 @@ void btOpenCLSoftBodySolver::applyForces( float solverdt )
*/
void btOpenCLSoftBodySolver::integrate( float solverdt )
{
// Ensure data is on accelerator
m_vertexData.moveToAccelerator();
@@ -1186,7 +1283,7 @@ void btOpenCLSoftBodySolver::solveConstraints( float solverdt )
updateVelocitiesFromPositionsWithoutVelocities( 1.f/solverdt );
}
// Solve drift
// Solve position
for( int iteration = 0; iteration < m_numberOfPositionIterations ; ++iteration )
{
for( int i = 0; i < m_linkData.m_batchStartLengths.size(); ++i )
@@ -1210,7 +1307,6 @@ void btOpenCLSoftBodySolver::solveConstraints( float solverdt )
// Kernel dispatches
void btOpenCLSoftBodySolver::prepareLinks()
{
cl_int ciErrNum;
int numLinks = m_linkData.getNumLinks();
ciErrNum = clSetKernelArg(m_prepareLinksKernel,0, sizeof(int), &numLinks);
@@ -1231,7 +1327,6 @@ void btOpenCLSoftBodySolver::prepareLinks()
void btOpenCLSoftBodySolver::updatePositionsFromVelocities( float solverdt )
{
cl_int ciErrNum;
int numVerts = m_vertexData.getNumVertices();
ciErrNum = clSetKernelArg(m_updatePositionsFromVelocitiesKernel,0, sizeof(int), &numVerts);
@@ -1251,7 +1346,6 @@ void btOpenCLSoftBodySolver::updatePositionsFromVelocities( float solverdt )
void btOpenCLSoftBodySolver::solveLinksForPosition( int startLink, int numLinks, float kst, float ti )
{
cl_int ciErrNum;
ciErrNum = clSetKernelArg(m_solvePositionsFromLinksKernel,0, sizeof(int), &startLink);
ciErrNum = clSetKernelArg(m_solvePositionsFromLinksKernel,1, sizeof(int), &numLinks);
@@ -1275,7 +1369,6 @@ void btOpenCLSoftBodySolver::solveLinksForPosition( int startLink, int numLinks,
void btOpenCLSoftBodySolver::solveLinksForVelocity( int startLink, int numLinks, float kst )
{
cl_int ciErrNum;
ciErrNum = clSetKernelArg(m_vSolveLinksKernel, 0, sizeof(int), &startLink);
ciErrNum = clSetKernelArg(m_vSolveLinksKernel, 1, sizeof(int), &numLinks);
@@ -1297,7 +1390,6 @@ void btOpenCLSoftBodySolver::solveLinksForVelocity( int startLink, int numLinks,
void btOpenCLSoftBodySolver::updateVelocitiesFromPositionsWithVelocities( float isolverdt )
{
cl_int ciErrNum;
int numVerts = m_vertexData.getNumVertices();
ciErrNum = clSetKernelArg(m_updateVelocitiesFromPositionsWithVelocitiesKernel,0, sizeof(int), &numVerts);
@@ -1322,7 +1414,6 @@ void btOpenCLSoftBodySolver::updateVelocitiesFromPositionsWithVelocities( float
void btOpenCLSoftBodySolver::updateVelocitiesFromPositionsWithoutVelocities( float isolverdt )
{
cl_int ciErrNum;
int numVerts = m_vertexData.getNumVertices();
ciErrNum = clSetKernelArg(m_updateVelocitiesFromPositionsWithoutVelocitiesKernel, 0, sizeof(int), &numVerts);
@@ -1347,7 +1438,6 @@ void btOpenCLSoftBodySolver::updateVelocitiesFromPositionsWithoutVelocities( flo
void btOpenCLSoftBodySolver::solveCollisionsAndUpdateVelocities( float isolverdt )
{
// Copy kernel parameters to GPU
m_vertexData.moveToAccelerator();
m_clPerClothFriction.moveToGPU();
@@ -1355,7 +1445,6 @@ void btOpenCLSoftBodySolver::solveCollisionsAndUpdateVelocities( float isolverdt
m_clPerClothCollisionObjects.moveToGPU();
m_clCollisionObjectDetails.moveToGPU();
cl_int ciErrNum;
int numVerts = m_vertexData.getNumVertices();
ciErrNum = clSetKernelArg(m_solveCollisionsAndUpdateVelocitiesKernel, 0, sizeof(int), &numVerts);
@@ -1446,7 +1535,7 @@ void btSoftBodySolverOutputCLtoCPU::copySoftBodyToVertexBuffer( const btSoftBody
cl_kernel CLFunctions::compileCLKernelFromString( const char* kernelSource, const char* kernelName, const char* additionalMacros )
cl_kernel CLFunctions::compileCLKernelFromString( const char* kernelSource, const char* kernelName, const char* additionalMacros ,const char* orgSrcFileNameForCaching)
{
printf("compiling kernelName: %s ",kernelName);
cl_kernel kernel=0;
@@ -1552,24 +1641,29 @@ void btOpenCLSoftBodySolver::predictMotion( float timeStep )
// Ensure that the DX11 ones are moved off the device so they will be updated correctly
m_clCollisionObjectDetails.changedOnCPU();
m_clPerClothCollisionObjects.changedOnCPU();
m_collisionObjectDetails.clear();
{
BT_PROFILE("perClothWindVelocity");
// Fill the force arrays with current acceleration data etc
m_perClothWindVelocity.resize( m_softBodySet.size() );
for( int softBodyIndex = 0; softBodyIndex < m_softBodySet.size(); ++softBodyIndex )
{
btSoftBody *softBody = m_softBodySet[softBodyIndex]->getSoftBody();
m_perClothWindVelocity[softBodyIndex] = toVector3(softBody->getWindVelocity());
}
}
{
BT_PROFILE("changedOnCPU");
m_clPerClothWindVelocity.changedOnCPU();
}
m_collisionObjectDetails.clear();
if ( m_bUpdateAnchoredNodePos )
{
// In OpenCL cloth solver, if softbody node has zero inverse mass(infinite mass) or anchor attached,
// we need to update the node position in case the node or anchor is animated externally.
// If there is no such node, we can eliminate the unnecessary CPU-to-GPU data trasferring.
for ( int i = 0; i < m_anchorNodeInfoArray.size(); i++ )
{
const AnchorNodeInfoCL& anchorNodeInfo = m_anchorNodeInfoArray[i];
btSoftBody::Node* node = anchorNodeInfo.pNode;
using Vectormath::Aos::Point3;
Point3 pos((float)node->m_x.getX(), (float)node->m_x.getY(), (float)node->m_x.getZ());
m_anchorPosition[i] = pos;
}
if ( m_anchorNodeInfoArray.size() > 0 )
m_clAnchorPosition.changedOnCPU();
updateFixedVertexPositions();
}
{
BT_PROFILE("applyForces");
// Apply forces that we know about to the cloths
@@ -1601,7 +1695,7 @@ static Vectormath::Aos::Transform3 toTransform3( const btTransform &transform )
void btOpenCLAcceleratedSoftBodyInterface::updateBounds( const btVector3 &lowerBound, const btVector3 &upperBound )
{
float scalarMargin = this->getSoftBody()->getCollisionShape()->getMargin();
float scalarMargin = (float)getSoftBody()->getCollisionShape()->getMargin();
btVector3 vectorMargin( scalarMargin, scalarMargin, scalarMargin );
m_softBody->m_bounds[0] = lowerBound - vectorMargin;
m_softBody->m_bounds[1] = upperBound + vectorMargin;
@@ -1641,7 +1735,8 @@ void btOpenCLSoftBodySolver::processCollision( btSoftBody *softBody, btCollision
newCollisionShapeDescription.angularVelocity = toVector3(body->getAngularVelocity());
m_collisionObjectDetails.push_back( newCollisionShapeDescription );
} else {
}
else {
printf("Unsupported collision shape type\n");
//btAssert(0 && "Unsupported collision shape type\n");
}
@@ -1688,32 +1783,36 @@ bool btOpenCLSoftBodySolver::checkInitialized()
bool btOpenCLSoftBodySolver::buildShaders()
{
if( m_shadersInitialized )
return true;
const char* additionalMacros="";
// Ensure current kernels are released first
releaseKernels();
if( m_shadersInitialized )
return true;
m_clFunctions.clearKernelCompilationFailures();
m_currentCLFunctions->clearKernelCompilationFailures();
m_prepareLinksKernel = m_clFunctions.compileCLKernelFromString( PrepareLinksCLString, "PrepareLinksKernel" );
m_updatePositionsFromVelocitiesKernel = m_clFunctions.compileCLKernelFromString( UpdatePositionsFromVelocitiesCLString, "UpdatePositionsFromVelocitiesKernel" );
m_solvePositionsFromLinksKernel = m_clFunctions.compileCLKernelFromString( SolvePositionsCLString, "SolvePositionsFromLinksKernel" );
m_vSolveLinksKernel = m_clFunctions.compileCLKernelFromString( VSolveLinksCLString, "VSolveLinksKernel" );
m_updateVelocitiesFromPositionsWithVelocitiesKernel = m_clFunctions.compileCLKernelFromString( UpdateNodesCLString, "updateVelocitiesFromPositionsWithVelocitiesKernel" );
m_updateVelocitiesFromPositionsWithoutVelocitiesKernel = m_clFunctions.compileCLKernelFromString( UpdatePositionsCLString, "updateVelocitiesFromPositionsWithoutVelocitiesKernel" );
m_solveCollisionsAndUpdateVelocitiesKernel = m_clFunctions.compileCLKernelFromString( SolveCollisionsAndUpdateVelocitiesCLString, "SolveCollisionsAndUpdateVelocitiesKernel" );
m_integrateKernel = m_clFunctions.compileCLKernelFromString( IntegrateCLString, "IntegrateKernel" );
m_applyForcesKernel = m_clFunctions.compileCLKernelFromString( ApplyForcesCLString, "ApplyForcesKernel" );
m_prepareLinksKernel = m_currentCLFunctions->compileCLKernelFromString( PrepareLinksCLString, "PrepareLinksKernel",additionalMacros,"OpenCLC10/PrepareLinks.cl" );
m_updatePositionsFromVelocitiesKernel = m_currentCLFunctions->compileCLKernelFromString( UpdatePositionsFromVelocitiesCLString, "UpdatePositionsFromVelocitiesKernel" ,additionalMacros,"OpenCLC10/UpdatePositionsFromVelocities.cl");
m_solvePositionsFromLinksKernel = m_currentCLFunctions->compileCLKernelFromString( SolvePositionsCLString, "SolvePositionsFromLinksKernel",additionalMacros,"OpenCLC10/SolvePositions.cl" );
m_vSolveLinksKernel = m_currentCLFunctions->compileCLKernelFromString( VSolveLinksCLString, "VSolveLinksKernel" ,additionalMacros,"OpenCLC10/VSolveLinks.cl");
m_updateVelocitiesFromPositionsWithVelocitiesKernel = m_currentCLFunctions->compileCLKernelFromString( UpdateNodesCLString, "updateVelocitiesFromPositionsWithVelocitiesKernel" ,additionalMacros,"OpenCLC10/UpdateNodes.cl");
m_updateVelocitiesFromPositionsWithoutVelocitiesKernel = m_currentCLFunctions->compileCLKernelFromString( UpdatePositionsCLString, "updateVelocitiesFromPositionsWithoutVelocitiesKernel" ,additionalMacros,"OpenCLC10/UpdatePositions.cl");
m_solveCollisionsAndUpdateVelocitiesKernel = m_currentCLFunctions->compileCLKernelFromString( SolveCollisionsAndUpdateVelocitiesCLString, "SolveCollisionsAndUpdateVelocitiesKernel" ,additionalMacros,"OpenCLC10/SolveCollisionsAndUpdateVelocities.cl");
m_integrateKernel = m_currentCLFunctions->compileCLKernelFromString( IntegrateCLString, "IntegrateKernel" ,additionalMacros,"OpenCLC10/Integrate.cl");
m_applyForcesKernel = m_currentCLFunctions->compileCLKernelFromString( ApplyForcesCLString, "ApplyForcesKernel" ,additionalMacros,"OpenCLC10/ApplyForces.cl");
m_updateFixedVertexPositionsKernel = m_currentCLFunctions->compileCLKernelFromString( UpdateFixedVertexPositionsCLString, "UpdateFixedVertexPositions" , additionalMacros, "OpenCLC10/UpdateFixedVertexPositions.cl");
// TODO: Rename to UpdateSoftBodies
m_resetNormalsAndAreasKernel = m_clFunctions.compileCLKernelFromString( UpdateNormalsCLString, "ResetNormalsAndAreasKernel" );
m_normalizeNormalsAndAreasKernel = m_clFunctions.compileCLKernelFromString( UpdateNormalsCLString, "NormalizeNormalsAndAreasKernel" );
m_updateSoftBodiesKernel = m_clFunctions.compileCLKernelFromString( UpdateNormalsCLString, "UpdateSoftBodiesKernel" );
m_resetNormalsAndAreasKernel = m_currentCLFunctions->compileCLKernelFromString( UpdateNormalsCLString, "ResetNormalsAndAreasKernel" ,additionalMacros,"OpenCLC10/UpdateNormals.cl");
m_normalizeNormalsAndAreasKernel = m_currentCLFunctions->compileCLKernelFromString( UpdateNormalsCLString, "NormalizeNormalsAndAreasKernel" ,additionalMacros,"OpenCLC10/UpdateNormals.cl");
m_updateSoftBodiesKernel = m_currentCLFunctions->compileCLKernelFromString( UpdateNormalsCLString, "UpdateSoftBodiesKernel" ,additionalMacros,"OpenCLC10/UpdateNormals.cl");
if( m_clFunctions.getKernelCompilationFailures()==0 )
if( m_currentCLFunctions->getKernelCompilationFailures()==0 )
m_shadersInitialized = true;
return m_shadersInitialized;
}