Exemplo n.º 1
0
void btFillCL::execute(btOpenCLArray<btInt2> &src, const btInt2 &value, int n, int offset)
{
	btAssert( n>0 );
	btConstData constBuffer;
	{
		constBuffer.m_offset = offset;
		constBuffer.m_n = n;
		constBuffer.m_data = btMakeInt4( value.x, value.y, 0, 0 );
	}

	{
		btBufferInfoCL bInfo[] = { btBufferInfoCL( src.getBufferCL() ) };

		btLauncherCL launcher(m_commandQueue, m_fillKernelInt2);
		launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(btBufferInfoCL) );
		launcher.setConst(n);
		launcher.setConst(value);
		launcher.setConst(offset);

		//( constBuffer );
		launcher.launch1D( n );
	}
}
Exemplo n.º 2
0
void Solver::solveContactConstraint(  const btOpenCLArray<RigidBodyBase::Body>* bodyBuf, const btOpenCLArray<RigidBodyBase::Inertia>* shapeBuf,
                                      btOpenCLArray<Constraint4>* constraint, void* additionalData, int n ,int maxNumBatches)
{


    btInt4 cdata = btMakeInt4( n, 0, 0, 0 );
    {

        const int nn = N_SPLIT*N_SPLIT;

        cdata.x = 0;
        cdata.y = maxNumBatches;//250;


        int numWorkItems = 64*nn/N_BATCHES;
#ifdef DEBUG_ME
        SolverDebugInfo* debugInfo = new  SolverDebugInfo[numWorkItems];
        adl::btOpenCLArray<SolverDebugInfo> gpuDebugInfo(data->m_device,numWorkItems);
#endif



        {

            BT_PROFILE("m_batchSolveKernel iterations");
            for(int iter=0; iter<m_nIterations; iter++)
            {
                for(int ib=0; ib<N_BATCHES; ib++)
                {
#ifdef DEBUG_ME
                    memset(debugInfo,0,sizeof(SolverDebugInfo)*numWorkItems);
                    gpuDebugInfo.write(debugInfo,numWorkItems);
#endif


                    cdata.z = ib;
                    cdata.w = N_SPLIT;

                    btLauncherCL launcher( m_queue, m_solveContactKernel );
#if 1

                    btBufferInfoCL bInfo[] = {

                        btBufferInfoCL( bodyBuf->getBufferCL() ),
                        btBufferInfoCL( shapeBuf->getBufferCL() ),
                        btBufferInfoCL( constraint->getBufferCL() ),
                        btBufferInfoCL( m_numConstraints->getBufferCL() ),
                        btBufferInfoCL( m_offsets->getBufferCL() )
#ifdef DEBUG_ME
                        ,	btBufferInfoCL(&gpuDebugInfo)
#endif
                    };



                    launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(btBufferInfoCL) );
                    //launcher.setConst(  cdata.x );
                    launcher.setConst(  cdata.y );
                    launcher.setConst(  cdata.z );
                    launcher.setConst(  cdata.w );
                    launcher.launch1D( numWorkItems, 64 );


#else
                    const char* fileName = "m_batchSolveKernel.bin";
                    FILE* f = fopen(fileName,"rb");
                    if (f)
                    {
                        int sizeInBytes=0;
                        if (fseek(f, 0, SEEK_END) || (sizeInBytes = ftell(f)) == EOF || fseek(f, 0, SEEK_SET))
                        {
                            printf("error, cannot get file size\n");
                            exit(0);
                        }

                        unsigned char* buf = (unsigned char*) malloc(sizeInBytes);
                        fread(buf,sizeInBytes,1,f);
                        int serializedBytes = launcher.deserializeArgs(buf, sizeInBytes,m_context);
                        int num = *(int*)&buf[serializedBytes];

                        launcher.launch1D( num);

                        //this clFinish is for testing on errors
                        clFinish(m_queue);
                    }

#endif


#ifdef DEBUG_ME
                    clFinish(m_queue);
                    gpuDebugInfo.read(debugInfo,numWorkItems);
                    clFinish(m_queue);
                    for (int i=0; i<numWorkItems; i++)
                    {
                        if (debugInfo[i].m_valInt2>0)
                        {
                            printf("debugInfo[i].m_valInt2 = %d\n",i,debugInfo[i].m_valInt2);
                        }

                        if (debugInfo[i].m_valInt3>0)
                        {
                            printf("debugInfo[i].m_valInt3 = %d\n",i,debugInfo[i].m_valInt3);
                        }
                    }
#endif //DEBUG_ME


                }
            }

            clFinish(m_queue);


        }

        cdata.x = 1;
        bool applyFriction=true;
        if (applyFriction)
        {
            BT_PROFILE("m_batchSolveKernel iterations2");
            for(int iter=0; iter<m_nIterations; iter++)
            {
                for(int ib=0; ib<N_BATCHES; ib++)
                {
                    cdata.z = ib;
                    cdata.w = N_SPLIT;

                    btBufferInfoCL bInfo[] = {
                        btBufferInfoCL( bodyBuf->getBufferCL() ),
                        btBufferInfoCL( shapeBuf->getBufferCL() ),
                        btBufferInfoCL( constraint->getBufferCL() ),
                        btBufferInfoCL( m_numConstraints->getBufferCL() ),
                        btBufferInfoCL( m_offsets->getBufferCL() )
#ifdef DEBUG_ME
                        ,btBufferInfoCL(&gpuDebugInfo)
#endif //DEBUG_ME
                    };
                    btLauncherCL launcher( m_queue, m_solveFrictionKernel );
                    launcher.setBuffers( bInfo, sizeof(bInfo)/sizeof(btBufferInfoCL) );
                    //launcher.setConst(  cdata.x );
                    launcher.setConst(  cdata.y );
                    launcher.setConst(  cdata.z );
                    launcher.setConst(  cdata.w );

                    launcher.launch1D( 64*nn/N_BATCHES, 64 );
                }
            }
            clFinish(m_queue);

        }
#ifdef DEBUG_ME
        delete[] debugInfo;
#endif //DEBUG_ME
    }


}