diff --git a/Demos/OpenCLClothDemo/cl_cloth_demo.cpp b/Demos/OpenCLClothDemo/cl_cloth_demo.cpp index 8a354e37b..5a48709b7 100644 --- a/Demos/OpenCLClothDemo/cl_cloth_demo.cpp +++ b/Demos/OpenCLClothDemo/cl_cloth_demo.cpp @@ -20,7 +20,7 @@ subject to the following restrictions: #ifndef USE_MINICL -//#define USE_SIMDAWARE_SOLVER +#define USE_SIMDAWARE_SOLVER #endif #if !defined (__APPLE__) diff --git a/Demos/SerializeDemo/AMD/CMakeLists.txt b/Demos/SerializeDemo/AMD/CMakeLists.txt index abe46ebac..88644d5d9 100644 --- a/Demos/SerializeDemo/AMD/CMakeLists.txt +++ b/Demos/SerializeDemo/AMD/CMakeLists.txt @@ -115,7 +115,24 @@ IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES AND NOT INTERNAL_UPDATE_ ADD_CUSTOM_COMMAND( TARGET AppSerializeDemo_AMD POST_BUILD - COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/Demos/SerializeDemo/testFile.bullet ${CMAKE_CURRENT_BINARY_DIR}/testFile.bullet + 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 () diff --git a/Demos/SerializeDemo/SerializeDemo.cpp b/Demos/SerializeDemo/SerializeDemo.cpp index 7d131c676..704cf8b3b 100644 --- a/Demos/SerializeDemo/SerializeDemo.cpp +++ b/Demos/SerializeDemo/SerializeDemo.cpp @@ -13,7 +13,6 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ - #define TEST_SERIALIZATION 1 //#undef DESERIALIZE_SOFT_BODIES @@ -57,6 +56,8 @@ subject to the following restrictions: #ifdef USE_AMD_OPENCL #include #include + #include "../SharedOpenCL/btOpenCLUtils.h" + extern cl_context g_cxMainContext; extern cl_device_id g_cdDevice; extern cl_command_queue g_cqCommandQue; @@ -198,7 +199,39 @@ void SerializeDemo::clientMoveAndDisplay() 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) { @@ -277,18 +310,13 @@ void SerializeDemo::setupEmptyDynamicsWorld() { case kSolverAccelerationOpenCL_GPU: { - fSoftBodySolver - = new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue, - g_cxMainContext ); - // fSoftBodySolver = new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext); - - /*if (!fSoftBodySolver->checkInitialized()) - { - btAssert(0); - delete fSoftBodySolver; - fSoftBodySolver = NULL; - } - */ + btOpenCLSoftBodySolverSIMDAware* softSolv= new btOpenCLSoftBodySolverSIMDAware( g_cqCommandQue, g_cxMainContext ); + //btOpenCLSoftBodySolver* softSolv= new btOpenCLSoftBodySolver( g_cqCommandQue, g_cxMainContext); + fSoftBodySolver = softSolv; + + CLFunctions* funcs = new CachingCLFuncs(g_cqCommandQue, g_cxMainContext,g_cdDevice); + softSolv->setCLFunctions(funcs); + break; } @@ -516,14 +544,14 @@ public: psb->m_cfg.diterations=softBodyData->m_config.m_driftIterations; psb->m_cfg.citerations=softBodyData->m_config.m_clusterIterations; psb->m_cfg.viterations=softBodyData->m_config.m_velocityIterations; - + //psb->setTotalMass(0.1); psb->m_cfg.aeromodel = (btSoftBody::eAeroModel::_)softBodyData->m_config.m_aeroModel; psb->m_cfg.kLF = softBodyData->m_config.m_lift; psb->m_cfg.kDG = softBodyData->m_config.m_drag; psb->m_cfg.kMT = softBodyData->m_config.m_poseMatch; 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.kPR = softBodyData->m_config.m_pressure; psb->m_cfg.kVC = softBodyData->m_config.m_volume; @@ -715,7 +743,7 @@ void SerializeDemo::initPhysics() setTexturing(true); setShadows(true); - setCameraDistance(btScalar(SCALING*50.)); + setCameraDistance(btScalar(SCALING*30.)); setupEmptyDynamicsWorld(); diff --git a/Demos/SerializeDemo/testFileCloth.bullet b/Demos/SerializeDemo/testFileCloth.bullet new file mode 100644 index 000000000..7dd84b68a Binary files /dev/null and b/Demos/SerializeDemo/testFileCloth.bullet differ diff --git a/Demos/SharedOpenCL/btOpenCLUtils.cpp b/Demos/SharedOpenCL/btOpenCLUtils.cpp index e0b50e737..5b7b6e23e 100644 --- a/Demos/SharedOpenCL/btOpenCLUtils.cpp +++ b/Demos/SharedOpenCL/btOpenCLUtils.cpp @@ -22,6 +22,9 @@ subject to the following restrictions: #include #include +#define BT_MAX_CL_DEVICES 16 //who needs 16 devices? +//#define BT_USE_CACHE_DIR + #ifdef _WIN32 #include #include @@ -30,7 +33,7 @@ subject to the following restrictions: #endif //Set the preferred platform vendor using the OpenCL SDK -static const char* spPlatformVendor = +static char* spPlatformVendor = #if defined(CL_PLATFORM_MINI_CL) "MiniCL, SCEA"; #elif defined(CL_PLATFORM_AMD) @@ -105,7 +108,7 @@ void btOpenCLUtils::getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInf 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_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}; cps[0] = CL_CONTEXT_PLATFORM; cps[1] = (cl_context_properties)platform; -#if defined (_WIN32) && defined(_MSC_VER) && !defined (CL_PLATFORM_MINI_CL) if (pGLContext && pGLDC) { +#if defined(CL_PLATFORM_AMD) || defined(CL_PLATFORM_NVIDIA) cps[2] = CL_GL_CONTEXT_KHR; cps[3] = (cl_context_properties)pGLContext; cps[4] = CL_WGL_HDC_KHR; cps[5] = (cl_context_properties)pGLDC; - } #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; - retContext = clCreateContextFromType(cprops, - deviceType, - NULL, - NULL, - &ciErrNum); + + if (pGLContext) + { + //search for the GPU that relates to the OpenCL context + for (int i=0;i=0 && preferredDeviceIndex=0 && i==preferredPlatformIndex) { cl_platform_id tmpPlatform = platforms[0]; platforms[0] = platforms[i]; platforms[i] = tmpPlatform; 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]; assert(platform); - retContext = btOpenCLUtils::createContextFromPlatform(platform,deviceType,pErrNum,pGLContext,pGLDC); + retContext = btOpenCLUtils::createContextFromPlatform(platform,deviceType,pErrNum,pGLContext,pGLDC,preferredDeviceIndex); if (retContext) { - printf("OpenCL platform details:\n"); +// printf("OpenCL platform details:\n"); btOpenCLPlatformInfo 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_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_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_GROUP_SIZE:\t%d\n", (int)info.m_workgroupSize); - printf(" CL_DEVICE_MAX_CLOCK_FREQUENCY:\t%d MHz\n", (int)info.m_clockFrequency); + printf(" CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:\t%u\n", info.m_workitemDims); + 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%u\n", info.m_workgroupSize); + 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_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))); @@ -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_WRITE_IMAGE_ARGS:\t%u\n", info.m_maxWriteImageArgs); printf("\n CL_DEVICE_IMAGE "); - printf("\t\t\t2D_MAX_WIDTH\t %d\n", (int)info.m_image2dMaxWidth); - printf("\t\t\t\t\t2D_MAX_HEIGHT\t %d\n", (int)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_HEIGHT\t %d\n", (int)info.m_image3dMaxHeight); - printf("\t\t\t\t\t3D_MAX_DEPTH\t %d\n", (int)info.m_image3dMaxDepth); + printf("\t\t\t2D_MAX_WIDTH\t %u\n", info.m_image2dMaxWidth); + printf("\t\t\t\t\t2D_MAX_HEIGHT\t %u\n", info.m_image2dMaxHeight); + printf("\t\t\t\t\t3D_MAX_WIDTH\t %u\n", info.m_image3dMaxWidth); + printf("\t\t\t\t\t3D_MAX_HEIGHT\t %u\n", info.m_image3dMaxHeight); + printf("\t\t\t\t\t3D_MAX_DEPTH\t %u\n", info.m_image3dMaxDepth); if (info.m_deviceExtensions != 0) printf("\n CL_DEVICE_EXTENSIONS:%s\n",info.m_deviceExtensions); 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); } -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 patcnt = 0; const char * oriptr; const char * patloc; // find how many times the pattern occurs in the original string for (oriptr = name; patloc = strstr(oriptr, pattern); oriptr = patloc + patlen) { - patcnt++; + if (numOccurences) + (*numOccurences)++; } 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; @@ -411,7 +517,6 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de char binaryFileName[522]; -#if defined (_WIN32) && defined(_MSC_VER) if (clFileNameForCaching) { @@ -423,15 +528,23 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de const char* strippedName = strip2(clFileNameForCaching,"\\"); 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 ); - //printf("searching for %s\n", binaryFileName); +#endif + + //printf("searching for %s\n", binaryFileName); bool fileUpToDate = false; bool binaryFileValid=false; 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); @@ -494,7 +607,6 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de } else { -#ifdef _DEBUG DWORD errorCode; errorCode = GetLastError(); 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 - assert(0); -#else - //if we cannot find the source, assume it is OK in release builds - fileUpToDate = true; -#endif + fileUpToDate = false; } } @@ -557,88 +665,88 @@ cl_program btOpenCLUtils::compileCLProgramFromString(cl_context clContext, cl_de btAssert(0); m_cpProgram = 0; } + delete[] binary; } } +#endif //_WIN32 } -#endif if (!m_cpProgram) { -// cl_kernel kernel; - cl_int localErrNum; - size_t program_length = strlen(kernelSource); - - m_cpProgram = clCreateProgramWithSource(clContext, 1, (const char**)&kernelSource, &program_length, &localErrNum); - if (localErrNum!= CL_SUCCESS) + + FILE* file = fopen(clFileNameForCaching, "r"); + if (file) { - 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; - } - -#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 ); - + fseek( file, 0L, SEEK_END ); + size_t fileSize= ftell( file ); + rewind( file ); + char* kernelSource2 = new char[fileSize+1]; + fread( kernelSource2, sizeof(char), fileSize, file ); + fclose( file ); + kernelSource2[fileSize]=0; + int numOccurences = 0; + ///patch/remove the MSTRINGIFY( and ); + char* kernelSource = strip1(kernelSource2,"MSTRINGIFY(",&numOccurences); + int newlen = strlen(kernelSource); + if (numOccurences) { - FILE* file = fopen(binaryFileName, "wb"); - if (file) + int i=newlen-1; + + for (;i>=0;i--) { - fwrite( binary, sizeof(char), binarySize, file ); - fclose( file ); - } else + if (kernelSource[i] == ';') + { + 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; diff --git a/Demos/SharedOpenCL/btOpenCLUtils.h b/Demos/SharedOpenCL/btOpenCLUtils.h index 5e5d20467..e9f422897 100644 --- a/Demos/SharedOpenCL/btOpenCLUtils.h +++ b/Demos/SharedOpenCL/btOpenCLUtils.h @@ -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 /// 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 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 = "" ); //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 static int getNumPlatforms(cl_int* pErrNum=0); @@ -96,7 +99,7 @@ public: static cl_platform_id getPlatform(int nr, cl_int* pErrNum=0); static void getPlatformInfo(cl_platform_id platform, btOpenCLPlatformInfo& platformInfo); 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); }; diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp index 96b8b2ee6..7e58f3c53 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.cpp @@ -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 "../BulletFileLoader/btBulletFile.h" @@ -454,23 +469,24 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap { case 0: { - shape = createCapsuleShapeX(implicitShapeDimensions.getY(),2*implicitShapeDimensions.getX()); + shape = createCapsuleShapeX(implicitShapeDimensions.getY()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getX()); break; } case 1: { - shape = createCapsuleShapeY(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getY()); + shape = createCapsuleShapeY(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getY()); break; } case 2: { - shape = createCapsuleShapeZ(implicitShapeDimensions.getX(),2*implicitShapeDimensions.getZ()); + shape = createCapsuleShapeZ(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getZ()); break; } default: { printf("error: wrong up axis for btCapsuleShape\n"); } + bsd->m_collisionMargin = 0.f; }; @@ -567,7 +583,7 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap if (shape) { - shape->setMargin(bsd->m_collisionMargin); + //shape->setMargin(bsd->m_collisionMargin); btVector3 localScaling; localScaling.deSerializeFloat(bsd->m_localScaling); shape->setLocalScaling(localScaling); @@ -654,7 +670,9 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap compoundShape->addChildShape(localTransform,childShape); } else { +#ifdef _DEBUG printf("error: couldn't create childShape for compoundShape\n"); +#endif } } @@ -668,7 +686,9 @@ btCollisionShape* btBulletWorldImporter::convertCollisionShape( btCollisionShap } default: { +#ifdef _DEBUG 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; 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 if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) { @@ -857,7 +881,9 @@ bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile startTransform.deSerializeDouble(colObjData->m_worldTransform); btCollisionShape* shape = (btCollisionShape*)*shapePtr; btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name); - + body->setFriction(colObjData->m_friction); + body->setRestitution(colObjData->m_restitution); + #ifdef USE_INTERNAL_EDGE_UTILITY if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) { diff --git a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h index ee57c2e2e..05c3ccbfc 100644 --- a/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h +++ b/Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h @@ -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 { protected: diff --git a/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolver_DX11.cpp b/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolver_DX11.cpp index 5efd3576e..b66722bdc 100644 --- a/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolver_DX11.cpp +++ b/src/BulletMultiThreaded/GpuSoftBodySolvers/DX11/btSoftBodySolver_DX11.cpp @@ -20,7 +20,7 @@ subject to the following restrictions: #include "btSoftBodySolverVertexBuffer_DX11.h" #include "BulletSoftBody/btSoftBody.h" #include "BulletCollision/CollisionShapes/btCapsuleShape.h" - +#include //printf #define MSTRINGIFY(A) #A static char* PrepareLinksHLSLString = #include "HLSL/PrepareLinks.hlsl" @@ -2190,7 +2190,9 @@ void btDX11SoftBodySolver::processCollision( btSoftBody *softBody, btCollisionOb m_collisionObjectDetails.push_back( newCollisionShapeDescription ); } else { - btAssert("Unsupported collision shape type\n"); +#ifdef _DEBUG + printf("Unsupported collision shape type\n"); +#endif } } else { btAssert("Unknown soft body"); diff --git a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl index ba57c8869..870902258 100644 --- a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl +++ b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/OpenCLC10/SolveCollisionsAndUpdateVelocitiesSIMDBatched.cl @@ -1,9 +1,23 @@ 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; } +float mylength3(float4 a) +{ + a.w = 0; + return length(a); +} + +float4 mynormalize3(float4 a) +{ + a.w = 0; + return normalize(a); +} typedef struct { @@ -37,8 +51,7 @@ typedef struct // From btBroadphaseProxy.h __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 returnVector; @@ -66,7 +79,8 @@ SolveCollisionsAndUpdateVelocitiesKernel( __global float4 * g_vertexForces, __global float4 *g_vertexVelocities, __global float4 *g_vertexPositions, - __local CollisionShapeDescription *localCollisionShapes) + __local CollisionShapeDescription *localCollisionShapes, + __global float * g_vertexInverseMasses) { int nodeID = get_global_id(0); float4 forceOnVertex = (float4)(0.f, 0.f, 0.f, 0.f); @@ -78,18 +92,20 @@ SolveCollisionsAndUpdateVelocitiesKernel( return; - float4 position = (float4)(g_vertexPositions[nodeID].xyz, 1.f); - float4 previousPosition = (float4)(g_vertexPreviousPositions[nodeID].xyz, 1.f); + float4 position = (float4)(g_vertexPositions[nodeID].xyz, 0.f); + float4 previousPosition = (float4)(g_vertexPreviousPositions[nodeID].xyz, 0.f); + float clothFriction = g_perClothFriction[clothIdentifier]; float dampingFactor = g_clothDampingFactor[clothIdentifier]; float velocityCoefficient = (1.f - dampingFactor); - - // Update velocity float4 difference = position - previousPosition; float4 velocity = difference*velocityCoefficient*isolverdt; + float inverseMass = g_vertexInverseMasses[nodeID]; + CollisionObjectIndices collisionObjectIndices = g_perClothCollisionObjectIndices[clothIdentifier]; int numObjects = collisionObjectIndices.endObject - collisionObjectIndices.firstObject; + if( numObjects > 0 ) { // We have some possible collisions to deal with @@ -113,7 +129,7 @@ SolveCollisionsAndUpdateVelocitiesKernel( // We have some possible collisions to deal with for( int collision = 0; collision < numObjects; ++collision ) { - //CollisionShapeDescription shapeDescription = localCollisionShapes[collision]; + CollisionShapeDescription shapeDescription = localCollisionShapes[collision]; float colliderFriction = localCollisionShapes[collision].friction; if( localCollisionShapes[collision].collisionShapeType == CAPSULE_SHAPE_PROXYTYPE ) @@ -125,14 +141,14 @@ SolveCollisionsAndUpdateVelocitiesKernel( float capsuleMargin = localCollisionShapes[collision].margin; int capsuleupAxis = localCollisionShapes[collision].upAxis; + if ( capsuleHalfHeight <= 0 ) + capsuleHalfHeight = 0.0001f; float4 worldTransform[4]; worldTransform[0] = localCollisionShapes[collision].shapeTransform[0]; worldTransform[1] = localCollisionShapes[collision].shapeTransform[1]; worldTransform[2] = localCollisionShapes[collision].shapeTransform[2]; 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 float4 c1 = (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 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 - float distanceAlongSegment = -( mydot3( (worldC1 - position), segment ) / mydot3(segment, segment) ); - - float4 closestPoint = (worldC1 + (float4)(segment * distanceAlongSegment)); - float distanceFromLine = length(position - closestPoint); - float distanceFromC1 = length(worldC1 - position); - float distanceFromC2 = length(worldC2 - position); - + float4 closestPointOnSegment = (worldC1 + (float4)(segmentNormalized * distanceAlongSegment)); + float distanceFromLine = mylength3(position - closestPointOnSegment); + float distanceFromC1 = mylength3(worldC1 - position); + float distanceFromC2 = mylength3(worldC2 - position); + // Final distance from collision, point to push from, direction to push in // for impulse force float dist; float4 normalVector; + if( distanceAlongSegment < 0 ) { dist = distanceFromC1; - normalVector = normalize(position - worldC1); - } else if( distanceAlongSegment > 1.f ) { + normalVector = (float4)(normalize(position - worldC1).xyz, 0.f); + } else if( distanceAlongSegment > length(segment) ) { dist = distanceFromC2; - normalVector = normalize(position - worldC2); + normalVector = (float4)(normalize(position - worldC2).xyz, 0.f); } else { 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; - - // In case of no collision, this is the value of velocity - velocity = (position - previousPosition) * velocityCoefficient * isolverdt; + float4 closestPointOnSurface = (float4)((position + (minDistance - dist) * normalVector).xyz, 0.f); + + 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 if( dist < minDistance ) { // Project back to surface along normal - position = position + (float4)((minDistance - dist)*normalVector*0.9f); + position = closestPointOnSurface; velocity = (position - previousPosition) * velocityCoefficient * isolverdt; float4 relativeVelocity = velocity - velocityOfSurfacePoint; - float4 p1 = (float4)(normalize(cross(normalVector, segment)).xyz, 0.f); - float4 p2 = (float4)(normalize(cross(p1, normalVector)).xyz, 0.f); - // 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 p1 = mynormalize3(cross(normalVector, segment)); + float4 p2 = mynormalize3(cross(p1, normalVector)); + 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; + + } } } } diff --git a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.cpp b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.cpp index a9b5d01c3..0a5ca008b 100644 --- a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.cpp +++ b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCL.cpp @@ -739,7 +739,7 @@ void btOpenCLSoftBodySolver::optimize( btAlignedObjectArray< btSoftBody * > &sof m_perClothDragFactor.push_back( softBody->m_cfg.kDG ); m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density); // 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) ); // Add space for new vertices and triangles in the default solver for now @@ -1737,7 +1737,9 @@ void btOpenCLSoftBodySolver::processCollision( btSoftBody *softBody, btCollision } else { +#ifdef _DEBUG printf("Unsupported collision shape type\n"); +#endif //btAssert(0 && "Unsupported collision shape type\n"); } } else { diff --git a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.cpp b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.cpp index e9c6f7de4..2216768a9 100644 --- a/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.cpp +++ b/src/BulletMultiThreaded/GpuSoftBodySolvers/OpenCL/btSoftBodySolver_OpenCLSIMDAware.cpp @@ -217,7 +217,7 @@ void btOpenCLSoftBodySolverSIMDAware::optimize( btAlignedObjectArray< btSoftBody m_perClothDragFactor.push_back( softBody->m_cfg.kDG ); m_perClothMediumDensity.push_back(softBody->getWorldInfo()->air_density); // 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) ); // 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); } + for( int vertex = numVertices; vertex < maxVertices; ++vertex ) + { + m_anchorIndex.push_back(-1.0); + } // Copy triangles similarly // 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, 10, sizeof(cl_mem),&m_vertexData.m_clVertexPosition.m_buffer); 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); if (numWorkItems) diff --git a/src/MiniCL/MiniCL.cpp b/src/MiniCL/MiniCL.cpp index e998f1dfe..24f6751fc 100644 --- a/src/MiniCL/MiniCL.cpp +++ b/src/MiniCL/MiniCL.cpp @@ -646,7 +646,9 @@ extern CL_API_ENTRY cl_int CL_API_CALL clGetContextInfo(cl_context /* co 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 , void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */, void * /* user_data */, @@ -706,6 +708,28 @@ CL_API_ENTRY cl_context CL_API_CALL clCreateContextFromType(cl_context_propertie 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 { diff --git a/src/MiniCL/cl.h b/src/MiniCL/cl.h index 053491ee2..352829883 100644 --- a/src/MiniCL/cl.h +++ b/src/MiniCL/cl.h @@ -437,7 +437,7 @@ clGetDeviceInfo(cl_device_id /* device */, // Context APIs extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(cl_context_properties * /* properties */, +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 *) /* pfn_notify */, @@ -445,7 +445,7 @@ clCreateContext(cl_context_properties * /* properties */, cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 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 */, void (*pfn_notify)(const char *, const void *, size_t, void *) /* pfn_notify */, void * /* user_data */,