2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
#include "b3GpuRaycast.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3Collidable.h"
|
|
|
|
#include "Bullet3Collision/NarrowPhaseCollision/shared/b3RigidBodyData.h"
|
|
|
|
#include "Bullet3OpenCL/RigidBody/b3GpuNarrowPhaseInternalData.h"
|
|
|
|
|
|
|
|
#include "Bullet3OpenCL/Initialize/b3OpenCLUtils.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3OpenCLArray.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3LauncherCL.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3FillCL.h"
|
|
|
|
#include "Bullet3OpenCL/ParallelPrimitives/b3RadixSort32CL.h"
|
|
|
|
#include "Bullet3OpenCL/BroadphaseCollision/b3GpuBroadphaseInterface.h"
|
|
|
|
#include "Bullet3OpenCL/BroadphaseCollision/b3GpuParallelLinearBvh.h"
|
|
|
|
|
|
|
|
#include "Bullet3OpenCL/Raycast/kernels/rayCastKernels.h"
|
|
|
|
|
|
|
|
#define B3_RAYCAST_PATH "src/Bullet3OpenCL/Raycast/kernels/rayCastKernels.cl"
|
|
|
|
|
|
|
|
struct b3GpuRaycastInternalData
|
|
|
|
{
|
|
|
|
cl_context m_context;
|
|
|
|
cl_device_id m_device;
|
2019-01-03 13:26:51 +00:00
|
|
|
cl_command_queue m_q;
|
2017-08-01 12:30:58 +00:00
|
|
|
cl_kernel m_raytraceKernel;
|
|
|
|
cl_kernel m_raytracePairsKernel;
|
|
|
|
cl_kernel m_findRayRigidPairIndexRanges;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
b3GpuParallelLinearBvh* m_plbvh;
|
|
|
|
b3RadixSort32CL* m_radixSorter;
|
|
|
|
b3FillCL* m_fill;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
//1 element per ray
|
|
|
|
b3OpenCLArray<b3RayInfo>* m_gpuRays;
|
|
|
|
b3OpenCLArray<b3RayHit>* m_gpuHitResults;
|
|
|
|
b3OpenCLArray<int>* m_firstRayRigidPairIndexPerRay;
|
|
|
|
b3OpenCLArray<int>* m_numRayRigidPairsPerRay;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
//1 element per (ray index, rigid index) pair, where the ray intersects with the rigid's AABB
|
|
|
|
b3OpenCLArray<int>* m_gpuNumRayRigidPairs;
|
2019-01-03 13:26:51 +00:00
|
|
|
b3OpenCLArray<b3Int2>* m_gpuRayRigidPairs; //x == ray index, y == rigid index
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
int m_test;
|
|
|
|
};
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3GpuRaycast::b3GpuRaycast(cl_context ctx, cl_device_id device, cl_command_queue q)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
m_data = new b3GpuRaycastInternalData;
|
|
|
|
m_data->m_context = ctx;
|
|
|
|
m_data->m_device = device;
|
|
|
|
m_data->m_q = q;
|
|
|
|
m_data->m_raytraceKernel = 0;
|
|
|
|
m_data->m_raytracePairsKernel = 0;
|
|
|
|
m_data->m_findRayRigidPairIndexRanges = 0;
|
|
|
|
|
|
|
|
m_data->m_plbvh = new b3GpuParallelLinearBvh(ctx, device, q);
|
|
|
|
m_data->m_radixSorter = new b3RadixSort32CL(ctx, device, q);
|
|
|
|
m_data->m_fill = new b3FillCL(ctx, device, q);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
m_data->m_gpuRays = new b3OpenCLArray<b3RayInfo>(ctx, q);
|
|
|
|
m_data->m_gpuHitResults = new b3OpenCLArray<b3RayHit>(ctx, q);
|
|
|
|
m_data->m_firstRayRigidPairIndexPerRay = new b3OpenCLArray<int>(ctx, q);
|
|
|
|
m_data->m_numRayRigidPairsPerRay = new b3OpenCLArray<int>(ctx, q);
|
|
|
|
m_data->m_gpuNumRayRigidPairs = new b3OpenCLArray<int>(ctx, q);
|
|
|
|
m_data->m_gpuRayRigidPairs = new b3OpenCLArray<b3Int2>(ctx, q);
|
|
|
|
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
cl_int errNum = 0;
|
|
|
|
cl_program prog = b3OpenCLUtils::compileCLProgramFromString(m_data->m_context, m_data->m_device, rayCastKernelCL, &errNum, "", B3_RAYCAST_PATH);
|
|
|
|
b3Assert(errNum == CL_SUCCESS);
|
|
|
|
m_data->m_raytraceKernel = b3OpenCLUtils::compileCLKernelFromString(m_data->m_context, m_data->m_device, rayCastKernelCL, "rayCastKernel", &errNum, prog);
|
|
|
|
b3Assert(errNum == CL_SUCCESS);
|
|
|
|
m_data->m_raytracePairsKernel = b3OpenCLUtils::compileCLKernelFromString(m_data->m_context, m_data->m_device, rayCastKernelCL, "rayCastPairsKernel", &errNum, prog);
|
|
|
|
b3Assert(errNum == CL_SUCCESS);
|
|
|
|
m_data->m_findRayRigidPairIndexRanges = b3OpenCLUtils::compileCLKernelFromString(m_data->m_context, m_data->m_device, rayCastKernelCL, "findRayRigidPairIndexRanges", &errNum, prog);
|
|
|
|
b3Assert(errNum == CL_SUCCESS);
|
2017-08-01 12:30:58 +00:00
|
|
|
clReleaseProgram(prog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b3GpuRaycast::~b3GpuRaycast()
|
|
|
|
{
|
|
|
|
clReleaseKernel(m_data->m_raytraceKernel);
|
|
|
|
clReleaseKernel(m_data->m_raytracePairsKernel);
|
|
|
|
clReleaseKernel(m_data->m_findRayRigidPairIndexRanges);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
delete m_data->m_plbvh;
|
|
|
|
delete m_data->m_radixSorter;
|
|
|
|
delete m_data->m_fill;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
delete m_data->m_gpuRays;
|
|
|
|
delete m_data->m_gpuHitResults;
|
|
|
|
delete m_data->m_firstRayRigidPairIndexPerRay;
|
|
|
|
delete m_data->m_numRayRigidPairsPerRay;
|
|
|
|
delete m_data->m_gpuNumRayRigidPairs;
|
|
|
|
delete m_data->m_gpuRayRigidPairs;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
delete m_data;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
bool sphere_intersect(const b3Vector3& spherePos, b3Scalar radius, const b3Vector3& rayFrom, const b3Vector3& rayTo, float& hitFraction)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3 rs = rayFrom - spherePos;
|
|
|
|
b3Vector3 rayDir = rayTo - rayFrom;
|
|
|
|
|
|
|
|
float A = b3Dot(rayDir, rayDir);
|
|
|
|
float B = b3Dot(rs, rayDir);
|
|
|
|
float C = b3Dot(rs, rs) - (radius * radius);
|
|
|
|
|
|
|
|
float D = B * B - A * C;
|
|
|
|
|
|
|
|
if (D > 0.0)
|
|
|
|
{
|
|
|
|
float t = (-B - sqrt(D)) / A;
|
|
|
|
|
|
|
|
if ((t >= 0.0f) && (t < hitFraction))
|
|
|
|
{
|
2017-08-01 12:30:58 +00:00
|
|
|
hitFraction = t;
|
2019-01-03 13:26:51 +00:00
|
|
|
return true;
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rayConvex(const b3Vector3& rayFromLocal, const b3Vector3& rayToLocal, const b3ConvexPolyhedronData& poly,
|
2019-01-03 13:26:51 +00:00
|
|
|
const b3AlignedObjectArray<b3GpuFace>& faces, float& hitFraction, b3Vector3& hitNormal)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
float exitFraction = hitFraction;
|
|
|
|
float enterFraction = -0.1f;
|
2019-01-03 13:26:51 +00:00
|
|
|
b3Vector3 curHitNormal = b3MakeVector3(0, 0, 0);
|
|
|
|
for (int i = 0; i < poly.m_numFaces; i++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
const b3GpuFace& face = faces[poly.m_faceOffset + i];
|
|
|
|
float fromPlaneDist = b3Dot(rayFromLocal, face.m_plane) + face.m_plane.w;
|
|
|
|
float toPlaneDist = b3Dot(rayToLocal, face.m_plane) + face.m_plane.w;
|
|
|
|
if (fromPlaneDist < 0.f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
if (toPlaneDist >= 0.f)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
float fraction = fromPlaneDist / (fromPlaneDist - toPlaneDist);
|
|
|
|
if (exitFraction > fraction)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
exitFraction = fraction;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
if (toPlaneDist < 0.f)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
float fraction = fromPlaneDist / (fromPlaneDist - toPlaneDist);
|
2017-08-01 12:30:58 +00:00
|
|
|
if (enterFraction <= fraction)
|
|
|
|
{
|
|
|
|
enterFraction = fraction;
|
|
|
|
curHitNormal = face.m_plane;
|
|
|
|
curHitNormal.w = 0.f;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (exitFraction <= enterFraction)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enterFraction < 0.f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hitFraction = enterFraction;
|
|
|
|
hitNormal = curHitNormal;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
void b3GpuRaycast::castRaysHost(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults,
|
|
|
|
int numBodies, const struct b3RigidBodyData* bodies, int numCollidables, const struct b3Collidable* collidables, const struct b3GpuNarrowPhaseInternalData* narrowphaseData)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
// return castRays(rays,hitResults,numBodies,bodies,numCollidables,collidables);
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
B3_PROFILE("castRaysHost");
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int r = 0; r < rays.size(); r++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
b3Vector3 rayFrom = rays[r].m_from;
|
|
|
|
b3Vector3 rayTo = rays[r].m_to;
|
|
|
|
float hitFraction = hitResults[r].m_hitFraction;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
int hitBodyIndex = -1;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Vector3 hitNormal;
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
for (int b = 0; b < numBodies; b++)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
const b3Vector3& pos = bodies[b].m_pos;
|
|
|
|
//const b3Quaternion& orn = bodies[b].m_quat;
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
switch (collidables[bodies[b].m_collidableIdx].m_shapeType)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
case SHAPE_SPHERE:
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
b3Scalar radius = collidables[bodies[b].m_collidableIdx].m_radius;
|
2019-01-03 13:26:51 +00:00
|
|
|
if (sphere_intersect(pos, radius, rayFrom, rayTo, hitFraction))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
hitBodyIndex = b;
|
|
|
|
b3Vector3 hitPoint;
|
2019-01-03 13:26:51 +00:00
|
|
|
hitPoint.setInterpolate3(rays[r].m_from, rays[r].m_to, hitFraction);
|
|
|
|
hitNormal = (hitPoint - bodies[b].m_pos).normalize();
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
case SHAPE_CONVEX_HULL:
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
b3Transform convexWorldTransform;
|
|
|
|
convexWorldTransform.setIdentity();
|
|
|
|
convexWorldTransform.setOrigin(bodies[b].m_pos);
|
|
|
|
convexWorldTransform.setRotation(bodies[b].m_quat);
|
|
|
|
b3Transform convexWorld2Local = convexWorldTransform.inverse();
|
|
|
|
|
|
|
|
b3Vector3 rayFromLocal = convexWorld2Local(rayFrom);
|
|
|
|
b3Vector3 rayToLocal = convexWorld2Local(rayTo);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
int shapeIndex = collidables[bodies[b].m_collidableIdx].m_shapeIndex;
|
|
|
|
const b3ConvexPolyhedronData& poly = narrowphaseData->m_convexPolyhedra[shapeIndex];
|
2019-01-03 13:26:51 +00:00
|
|
|
if (rayConvex(rayFromLocal, rayToLocal, poly, narrowphaseData->m_convexFaces, hitFraction, hitNormal))
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
hitBodyIndex = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
default:
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
static bool once = true;
|
2017-08-01 12:30:58 +00:00
|
|
|
if (once)
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
once = false;
|
2017-08-01 12:30:58 +00:00
|
|
|
b3Warning("Raytest: unsupported shape type\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
if (hitBodyIndex >= 0)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
hitResults[r].m_hitFraction = hitFraction;
|
2019-01-03 13:26:51 +00:00
|
|
|
hitResults[r].m_hitPoint.setInterpolate3(rays[r].m_from, rays[r].m_to, hitFraction);
|
2017-08-01 12:30:58 +00:00
|
|
|
hitResults[r].m_hitNormal = hitNormal;
|
|
|
|
hitResults[r].m_hitBody = hitBodyIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
///todo: add some acceleration structure (AABBs, tree etc)
|
2019-01-03 13:26:51 +00:00
|
|
|
void b3GpuRaycast::castRays(const b3AlignedObjectArray<b3RayInfo>& rays, b3AlignedObjectArray<b3RayHit>& hitResults,
|
|
|
|
int numBodies, const struct b3RigidBodyData* bodies, int numCollidables, const struct b3Collidable* collidables,
|
|
|
|
const struct b3GpuNarrowPhaseInternalData* narrowphaseData, class b3GpuBroadphaseInterface* broadphase)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
//castRaysHost(rays,hitResults,numBodies,bodies,numCollidables,collidables,narrowphaseData);
|
|
|
|
|
|
|
|
B3_PROFILE("castRaysGPU");
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("raycast copyFromHost");
|
|
|
|
m_data->m_gpuRays->copyFromHost(rays);
|
|
|
|
m_data->m_gpuHitResults->copyFromHost(hitResults);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
int numRays = hitResults.size();
|
|
|
|
{
|
|
|
|
m_data->m_firstRayRigidPairIndexPerRay->resize(numRays);
|
|
|
|
m_data->m_numRayRigidPairsPerRay->resize(numRays);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
m_data->m_gpuNumRayRigidPairs->resize(1);
|
|
|
|
m_data->m_gpuRayRigidPairs->resize(numRays * 16);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
//run kernel
|
|
|
|
const bool USE_BRUTE_FORCE_RAYCAST = false;
|
2019-01-03 13:26:51 +00:00
|
|
|
if (USE_BRUTE_FORCE_RAYCAST)
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("raycast launch1D");
|
|
|
|
|
2019-01-03 13:26:51 +00:00
|
|
|
b3LauncherCL launcher(m_data->m_q, m_data->m_raytraceKernel, "m_raytraceKernel");
|
2017-08-01 12:30:58 +00:00
|
|
|
int numRays = rays.size();
|
|
|
|
launcher.setConst(numRays);
|
|
|
|
|
|
|
|
launcher.setBuffer(m_data->m_gpuRays->getBufferCL());
|
|
|
|
launcher.setBuffer(m_data->m_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());
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
launcher.launch1D(numRays);
|
|
|
|
clFinish(m_data->m_q);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 13:26:51 +00:00
|
|
|
m_data->m_plbvh->build(broadphase->getAllAabbsGPU(), broadphase->getSmallAabbIndicesGPU(), broadphase->getLargeAabbIndicesGPU());
|
2017-08-01 12:30:58 +00:00
|
|
|
|
|
|
|
m_data->m_plbvh->testRaysAgainstBvhAabbs(*m_data->m_gpuRays, *m_data->m_gpuNumRayRigidPairs, *m_data->m_gpuRayRigidPairs);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
int numRayRigidPairs = -1;
|
|
|
|
m_data->m_gpuNumRayRigidPairs->copyToHostPointer(&numRayRigidPairs, 1);
|
2019-01-03 13:26:51 +00:00
|
|
|
if (numRayRigidPairs > m_data->m_gpuRayRigidPairs->size())
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
numRayRigidPairs = m_data->m_gpuRayRigidPairs->size();
|
|
|
|
m_data->m_gpuNumRayRigidPairs->copyFromHostPointer(&numRayRigidPairs, 1);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
m_data->m_gpuRayRigidPairs->resize(numRayRigidPairs); //Radix sort needs b3OpenCLArray::size() to be correct
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
//Sort ray-rigid pairs by ray index
|
|
|
|
{
|
|
|
|
B3_PROFILE("sort ray-rigid pairs");
|
2019-01-03 13:26:51 +00:00
|
|
|
m_data->m_radixSorter->execute(*reinterpret_cast<b3OpenCLArray<b3SortData>*>(m_data->m_gpuRayRigidPairs));
|
2017-08-01 12:30:58 +00:00
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
//detect start,count of each ray pair
|
|
|
|
{
|
|
|
|
B3_PROFILE("detect ray-rigid pair index ranges");
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("reset ray-rigid pair index ranges");
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
m_data->m_fill->execute(*m_data->m_firstRayRigidPairIndexPerRay, numRayRigidPairs, numRays); //atomic_min used to find first index
|
2017-08-01 12:30:58 +00:00
|
|
|
m_data->m_fill->execute(*m_data->m_numRayRigidPairsPerRay, 0, numRays);
|
|
|
|
clFinish(m_data->m_q);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
b3BufferInfoCL bufferInfo[] =
|
|
|
|
{
|
|
|
|
b3BufferInfoCL(m_data->m_gpuRayRigidPairs->getBufferCL()),
|
|
|
|
|
|
|
|
b3BufferInfoCL(m_data->m_firstRayRigidPairIndexPerRay->getBufferCL()),
|
|
|
|
b3BufferInfoCL(m_data->m_numRayRigidPairsPerRay->getBufferCL())};
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
b3LauncherCL launcher(m_data->m_q, m_data->m_findRayRigidPairIndexRanges, "m_findRayRigidPairIndexRanges");
|
2019-01-03 13:26:51 +00:00
|
|
|
launcher.setBuffers(bufferInfo, sizeof(bufferInfo) / sizeof(b3BufferInfoCL));
|
2017-08-01 12:30:58 +00:00
|
|
|
launcher.setConst(numRayRigidPairs);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
launcher.launch1D(numRayRigidPairs);
|
|
|
|
clFinish(m_data->m_q);
|
|
|
|
}
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
{
|
|
|
|
B3_PROFILE("ray-rigid intersection");
|
2019-01-03 13:26:51 +00:00
|
|
|
|
|
|
|
b3BufferInfoCL bufferInfo[] =
|
|
|
|
{
|
|
|
|
b3BufferInfoCL(m_data->m_gpuRays->getBufferCL()),
|
|
|
|
b3BufferInfoCL(m_data->m_gpuHitResults->getBufferCL()),
|
|
|
|
b3BufferInfoCL(m_data->m_firstRayRigidPairIndexPerRay->getBufferCL()),
|
|
|
|
b3BufferInfoCL(m_data->m_numRayRigidPairsPerRay->getBufferCL()),
|
|
|
|
|
|
|
|
b3BufferInfoCL(narrowphaseData->m_bodyBufferGPU->getBufferCL()),
|
|
|
|
b3BufferInfoCL(narrowphaseData->m_collidablesGPU->getBufferCL()),
|
|
|
|
b3BufferInfoCL(narrowphaseData->m_convexFacesGPU->getBufferCL()),
|
|
|
|
b3BufferInfoCL(narrowphaseData->m_convexPolyhedraGPU->getBufferCL()),
|
|
|
|
|
|
|
|
b3BufferInfoCL(m_data->m_gpuRayRigidPairs->getBufferCL())};
|
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
b3LauncherCL launcher(m_data->m_q, m_data->m_raytracePairsKernel, "m_raytracePairsKernel");
|
2019-01-03 13:26:51 +00:00
|
|
|
launcher.setBuffers(bufferInfo, sizeof(bufferInfo) / sizeof(b3BufferInfoCL));
|
2017-08-01 12:30:58 +00:00
|
|
|
launcher.setConst(numRays);
|
2019-01-03 13:26:51 +00:00
|
|
|
|
2017-08-01 12:30:58 +00:00
|
|
|
launcher.launch1D(numRays);
|
|
|
|
clFinish(m_data->m_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//copy results
|
|
|
|
{
|
|
|
|
B3_PROFILE("raycast copyToHost");
|
|
|
|
m_data->m_gpuHitResults->copyToHost(hitResults);
|
|
|
|
}
|
|
|
|
}
|