///todo: add some acceleration structure (AABBs, tree etc) void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults, int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables, const struct b3GpuNarrowPhaseInternalData* narrowphaseData) { //castRaysHost(rays,hitResults,numBodies,bodies,numCollidables,collidables,narrowphaseData); B3_PROFILE("castRaysGPU"); b3OpenCLArray<b3RayInfo> gpuRays(m_data->m_context,m_data->m_q); b3OpenCLArray<b3RayHit> gpuHitResults(m_data->m_context,m_data->m_q); { B3_PROFILE("raycast copyFromHost"); gpuRays.copyFromHost(rays); gpuHitResults.resize(hitResults.size()); gpuHitResults.copyFromHost(hitResults); } //run kernel { B3_PROFILE("raycast launch1D"); b3LauncherCL launcher(m_data->m_q,m_data->m_raytraceKernel,"m_raytraceKernel"); int numRays = rays.size(); launcher.setConst(numRays); launcher.setBuffer(gpuRays.getBufferCL()); launcher.setBuffer(gpuHitResults.getBufferCL()); launcher.setConst(numBodies); launcher.setBuffer(narrowphaseData->m_bodyBufferGPU->getBufferCL()); launcher.setBuffer(narrowphaseData->m_collidablesGPU->getBufferCL()); launcher.setBuffer(narrowphaseData->m_convexFacesGPU->getBufferCL()); launcher.setBuffer(narrowphaseData->m_convexPolyhedraGPU->getBufferCL()); launcher.launch1D(numRays); clFinish(m_data->m_q); } //copy results { B3_PROFILE("raycast copyToHost"); gpuHitResults.copyToHost(hitResults); } }
void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults, int numBodies,const struct b3RigidBodyCL* bodies, int numCollidables, const struct b3Collidable* collidables) { B3_PROFILE("castRaysGPU"); b3OpenCLArray<b3RayInfo> gpuRays(m_data->m_context,m_data->m_q); gpuRays.copyFromHost(rays); b3OpenCLArray<b3RayHit> gpuHitResults(m_data->m_context,m_data->m_q); gpuHitResults.resize(hitResults.size()); b3OpenCLArray<b3RigidBodyCL> gpuBodies(m_data->m_context,m_data->m_q); gpuBodies.resize(numBodies); gpuBodies.copyFromHostPointer(bodies,numBodies); b3OpenCLArray<b3Collidable> gpuCollidables(m_data->m_context,m_data->m_q); gpuCollidables.resize(numCollidables); gpuCollidables.copyFromHostPointer(collidables,numCollidables); //run kernel { B3_PROFILE("raycast launch1D"); b3LauncherCL launcher(m_data->m_q,m_data->m_raytraceKernel); int numRays = rays.size(); launcher.setConst(numRays); launcher.setBuffer(gpuRays.getBufferCL()); launcher.setBuffer(gpuHitResults.getBufferCL()); launcher.setConst(numBodies); launcher.setBuffer(gpuBodies.getBufferCL()); launcher.setBuffer(gpuCollidables.getBufferCL()); launcher.launch1D(numRays); clFinish(m_data->m_q); } //copy results gpuHitResults.copyToHost(hitResults); }