Esempio n. 1
0
void b2CLCommonData::initReadLastJointImpulses()
{
	if (b2clGlobal_OpenCLSupported)
	{
		printf("Initializing b2CLCommonData...\n");
    
		int err;
    
		//load opencl programs from files
		char* commonDataSource = 0;
		size_t commonDataSourceLen = 0;

		shrLog("...loading b2CLCommonData.cl\n");
    #ifdef linux
    	commonDataSource = b2clLoadProgSource(shrFindFilePath("/opt/apps/com.samsung.browser/include/Box2D/Common/OpenCL/b2CLCommonData.cl", NULL), "// My comment\n", &commonDataSourceLen);
	#elif defined (_WIN32)
		commonDataSource = b2clLoadProgSource(shrFindFilePath("../../Box2D/Common/OpenCL/b2CLCommonData.cl", NULL), "// My comment\n", &commonDataSourceLen);
    #elif defined (__EMSCRIPTEN__)
        commonDataSource = b2clLoadProgSource(shrFindFilePath("./Common/OpenCL/b2CLCommonData.cl", NULL), "// My comment\n", &commonDataSourceLen);
	#else
		commonDataSource = b2clLoadProgSource(shrFindFilePath("../../../Box2D/Common/OpenCL/b2CLCommonData.cl", NULL), "// My comment\n", &commonDataSourceLen);
	#endif
		if(commonDataSource == NULL)
		{
			b2Log("Could not load program source, is path 'b2CLCommonData.cl' correct?");
		}

		//create the compute program from source kernel code
		commonDataProgram = clCreateProgramWithSource(b2CLDevice::instance().GetContext(), 1, (const char**) &commonDataSource, NULL, &err);
		if (!commonDataProgram)
		{
			printf("Error: Failed to create compute program!\n");
			exit(1);
		}
    
		//build the program
		err = clBuildProgram(commonDataProgram, 0, NULL, OPENCL_BUILD_PATH, NULL, NULL);
		if (err != CL_SUCCESS)
		{
			size_t len;
			char buffer[20480];
        
			printf("Error: Failed to build program executable!\n");
			clGetProgramBuildInfo(commonDataProgram, b2CLDevice::instance().GetCurrentDevice(), CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
			printf("%s\n", buffer);
			exit(1);
		}
    
		//create the compute kernel
		readLastJointImpulseKernel = clCreateKernel(commonDataProgram, "ReadLastJointImpulses", &err);
		if (!readLastJointImpulseKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}
		b2CLDevice::instance().getMaximumKernelWorkGroupSize(readLastJointImpulseKernel, maxWorkGroupSizeForreadLastJointImpulse);
	}
}
Esempio n. 2
0
b2CLSolveTOI::b2CLSolveTOI()
{
	printf("Initializing b2CLSolveTOI...\n");
    
    int err;
    
    //load opencl programs from files
    char* TOIKernelSource = 0;
    size_t TOIKernelSourceLen = 0;

    shrLog("...loading b2CLSolveTOI.cl\n");
#ifdef linux
    TOIKernelSource = b2clLoadProgSource(shrFindFilePath("/opt/apps/com.samsung.browser/include/Box2D/Common/OpenCL/b2CLSolveTOI.cl", NULL), "// My comment\n", &TOIKernelSourceLen);
#elif defined (_WIN32)
    TOIKernelSource = b2clLoadProgSource(shrFindFilePath("../../Box2D/Common/OpenCL/b2CLSolveTOI.cl", NULL), "// My comment\n", &TOIKernelSourceLen);
#elif defined (__EMSCRIPTEN__)
    TOIKernelSource = b2clLoadProgSource(shrFindFilePath("./Common/OpenCL/b2CLSolveTOI.cl", NULL), "// My comment\n", &TOIKernelSourceLen);
#else
    TOIKernelSource = b2clLoadProgSource(shrFindFilePath("../../../Box2D/Common/OpenCL/b2CLSolveTOI.cl", NULL), "// My comment\n", &TOIKernelSourceLen);
#endif
    
	if(TOIKernelSource == NULL)
	{
		b2Log("Could not load program source, is path 'b2CLSolveTOI.cl' correct?");
	}

    //create the compute program from source kernel code
    SolveTOIProgram = clCreateProgramWithSource(b2CLDevice::instance().GetContext(), 1, (const char**)&TOIKernelSource, NULL, &err);
    if (!SolveTOIProgram)
    {
        printf("Error: Failed to create compute program!\n");
        exit(1);
    }
    
    //build the program
    err = clBuildProgram(SolveTOIProgram, 0, NULL, OPENCL_BUILD_PATH, NULL, NULL);
    if (err != CL_SUCCESS)
    {
        size_t len;
        char buffer[204800];
        
        printf("Error: Failed to build program executable!\n");
        clGetProgramBuildInfo(SolveTOIProgram, b2CLDevice::instance().GetCurrentDevice(), CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
        printf("%s\n", buffer);
        exit(1);
    }
#if 0	
	//create the compute kernel
	ComputeTOIKernel = clCreateKernel(SolveTOIProgram, "b2clComputeTOI", &err);
	if (!ComputeTOIKernel || err != CL_SUCCESS)
	{
		printf("Error: Failed to create compute kernel!\n");
		exit(1);
	}
	b2CLDevice::instance().getMaximumKernelWorkGroupSize(ComputeTOIKernel, ComputeTOIKernelWorkGroupSize);
		lastNumContacts = 0;
	sortCount = 0;
	ContactTOIsBuffer = NULL;
	ContactIndicesBuffer = NULL;

	//create the AdvanceBodiesKernel
	AdvanceBodiesKernel = clCreateKernel (SolveTOIProgram, "b2clAdvanceBodiesKernel", &err); 
	if (!AdvanceBodiesKernel || err != CL_SUCCESS)
	{
		printf("Error: Failed to create AdvanceBodiesKernel kernel!\n");
		exit(1);
	}
    b2CLDevice::instance().getMaximumKernelWorkGroupSize(AdvanceBodiesKernel, ComputeTOIKernelWorkGroupSize);

	this->MarkConnectedContactsKernel = clCreateKernel (SolveTOIProgram, "b2clMarkConnectedContactsKernel", &err); 
	if (!MarkConnectedContactsKernel || err != CL_SUCCESS) {
		printf("Error: Failed to create MarkConnectedContactsKernel kernel!\n");
		exit(1);
	}
#endif
	syncMovedBodyKernel = clCreateKernel (SolveTOIProgram, "b2clsyncMovedBodyKernel", &err); 
	if (!syncMovedBodyKernel || err != CL_SUCCESS) {
		printf("Error: Failed to create syncMovedBodyKernel kernel!\n");
		exit(1);
	}
	b2CLDevice::instance().getMaximumKernelWorkGroupSize(syncMovedBodyKernel, ComputeTOIKernelWorkGroupSize);
	movedBodyList = NULL ; bodyListSize = 0 ; 
	this->copyAllPositionList = NULL ; this->copyAllVelocityList = NULL; this->copyAllXFList = NULL ; copyBodyNum = 0 ; 

}
Esempio n. 3
0
b2CLNarrowPhase::b2CLNarrowPhase()
{
#if defined(NARROWPHASE_OPENCL)
	if (b2clGlobal_OpenCLSupported)
	{
		printf("Initializing b2CLNarrowPhase...\n");
    
		int err;
    
		//load opencl programs from files
		char* narrowPhaseKernelSource = 0;
		size_t narrowPhaseKernelSourceLen = 0;

		shrLog("...loading b2CLNarrowPhase.cl\n");
	#if defined(SCAN_OPENCL)
    #ifdef linux
    	narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("/opt/usr/apps/com.samsung.browser/include/Box2D/Common/OpenCL/b2CLNarrowPhase.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#elif defined (_WIN32)   
		narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("../../Box2D/Common/OpenCL/b2CLNarrowPhase.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#else
		narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("/usr/local/include/Box2D/Common/OpenCL/b2CLNarrowPhase.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#endif
	#else
    #ifdef linux
    	narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("/opt/usr/apps/com.samsung.browser/include/Box2D/Common/OpenCL/b2CLNarrowPhase_Alone.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#elif defined (_WIN32)
		narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("../../Box2D/Common/OpenCL/b2CLNarrowPhase_Alone.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#else
		narrowPhaseKernelSource = b2clLoadProgSource(shrFindFilePath("/usr/local/include/Box2D/Common/OpenCL/b2CLNarrowPhase_Alone.cl", NULL), "// My comment\n", &narrowPhaseKernelSourceLen);
	#endif
	#endif
		if(narrowPhaseKernelSource == NULL)
		{
			b2Log("Could not load program source, is path 'b2CLNarrowPhase.cl' correct?");
		}

		//create the compute program from source kernel code
		narrowPhaseProgram = clCreateProgramWithSource(b2CLDevice::instance().GetContext(), 1, (const char**)&narrowPhaseKernelSource, NULL, &err);
		if (!narrowPhaseProgram)
		{
			printf("Error: Failed to create compute program!\n");
			exit(1);
		}
    
		//build the program
		err = clBuildProgram(narrowPhaseProgram, 0, NULL, OPENCL_BUILD_PATH, NULL, NULL);
		if (err != CL_SUCCESS)
		{
			size_t len;
			char buffer[204800];
        
			printf("Error: Failed to build program executable!\n");
			clGetProgramBuildInfo(narrowPhaseProgram, b2CLDevice::instance().GetCurrentDevice(), CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
			printf("%s\n", buffer);
			exit(1);
		}
    
		//create the compute kernel
		collidePolygonsKernel = clCreateKernel(narrowPhaseProgram, "b2clCollidePolygons", &err);
		if (!collidePolygonsKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}
		collideCirclesKernel = clCreateKernel(narrowPhaseProgram, "b2clCollideCircles", &err);
		if (!collideCirclesKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}
		collidePolygonAndCircleKernel = clCreateKernel(narrowPhaseProgram, "b2clCollidePolygonAndCircle", &err);
		if (!collidePolygonAndCircleKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}
		collideEdgeAndCircleKernel = clCreateKernel(narrowPhaseProgram, "b2clCollideEdgeAndCircle", &err);
		if (!collideEdgeAndCircleKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}
		collideEdgeAndPolygonKernel = clCreateKernel(narrowPhaseProgram, "b2clCollideEdgeAndPolygon", &err);
		if (!collideEdgeAndPolygonKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}

		b2CLDevice::instance().getMaximumKernelWorkGroupSize(collidePolygonsKernel, kernel_work_group_size);
		//clGetKernelWorkGroupInfo(collidePolygonsKernel, b2CLDevice::instance().GetCurrentDevice(), CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, sizeof(size_t), &kernel_preferred_work_group_size_multiple, NULL);

		//create the compute kernel
		compactForOneContactKernel = clCreateKernel(narrowPhaseProgram, "b2clCompactForOneContact", &err);
		if (!compactForOneContactKernel || err != CL_SUCCESS)
		{
			printf("Error: Failed to create compute kernel!\n");
			exit(1);
		}

		/*old_xf_num = */old_contact_num = 0;
		xfListData = NULL;
		b2CLCommonData::instance().manifoldListData = NULL;
		globalIndicesData = pairIndicesData = NULL;
	#if !defined(BROADPHASE_OPENCL)
		b2CLCommonData::instance().manifoldListBuffers[0] = 
			b2CLCommonData::instance().manifoldListBuffers[1] =
			b2CLCommonData::instance().pairIndicesBuffer = 
	#endif
	#if defined(SCAN_OPENCL)
			b2CLCommonData::instance().manifoldBinaryBitListBuffer = 
			b2CLCommonData::instance().validContactIndicesBuffer = 
	#endif
			NULL;
		
		b2CLScan::instance(); // initializing b2CLScan
	}
#endif
	b2CLCommonData::instance().currentManifoldBuffer = 0;
	manifold_nums[0] = 0;
	manifold_nums[1] = 0;
}