Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MR test #290

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/rgl/api/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ typedef enum : int32_t
*/
typedef enum : int32_t
{
RGL_RETURN_TYPE_FIRST = 0,
RGL_RETURN_TYPE_LAST = 1,
RGL_RETURN_TYPE_NOT_DIVERGENT = 0,
RGL_RETURN_TYPE_FIRST = 1,
RGL_RETURN_TYPE_LAST = 2,
} rgl_return_type_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/RaytraceRequestContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct RaytraceRequestContext
float nearNonHitDistance;
float farNonHitDistance;

const Mat3x4f* rays;
const Mat3x4f* raysWorld;
size_t rayCount;

Mat3x4f rayOriginToWorld;
Expand Down
12 changes: 7 additions & 5 deletions src/gpu/nodeKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ __global__ void kFilterGroundPoints(size_t pointCount, const Vec3f sensor_up_vec
}

__global__ void kProcessBeamSamplesFirstLast(size_t beamCount, int samplesPerBeam, MultiReturnPointers beamSamples,
MultiReturnPointers first, MultiReturnPointers last)
MultiReturnPointers first, MultiReturnPointers last, const Mat3x4f* beamsWorld)
{
LIMIT(beamCount);

Expand All @@ -244,14 +244,16 @@ __global__ void kProcessBeamSamplesFirstLast(size_t beamCount, int samplesPerBea
lastIdx = sampleIdx;
}
}
Vec3f beamOrigin = beamsWorld[beamIdx] * Vec3f{0, 0, 0};
Vec3f beamDir = ((beamsWorld[beamIdx] * Vec3f{0, 0, 1}) - beamOrigin).normalized();
bool isHit = firstIdx >= 0; // Note that firstHit >= 0 implies lastHit >= 0
first.isHit[beamIdx] = isHit;
last.isHit[beamIdx] = isHit;
if (isHit) {
first.xyz[beamIdx] = beamSamples.xyz[beamIdx * samplesPerBeam + firstIdx];
first.distance[beamIdx] = beamSamples.distance[beamIdx * samplesPerBeam + firstIdx];
last.xyz[beamIdx] = beamSamples.xyz[beamIdx * samplesPerBeam + lastIdx];
last.distance[beamIdx] = beamSamples.distance[beamIdx * samplesPerBeam + lastIdx];
first.xyz[beamIdx] = beamOrigin + beamDir * first.distance[beamIdx];
last.xyz[beamIdx] = beamOrigin + beamDir * last.distance[beamIdx];
}
}

Expand Down Expand Up @@ -329,7 +331,7 @@ void gpuRadarComputeEnergy(cudaStream_t stream, size_t count, float rayAzimuthSt
}

void gpuProcessBeamSamplesFirstLast(cudaStream_t stream, size_t beamCount, int samplesPerBeam, MultiReturnPointers beamSamples,
MultiReturnPointers first, MultiReturnPointers last)
MultiReturnPointers first, MultiReturnPointers last, const Mat3x4f* beamsWorld)
{
run(kProcessBeamSamplesFirstLast, stream, beamCount, samplesPerBeam, beamSamples, first, last);
run(kProcessBeamSamplesFirstLast, stream, beamCount, samplesPerBeam, beamSamples, first, last, beamsWorld);
}
2 changes: 1 addition & 1 deletion src/gpu/nodeKernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ void gpuRadarComputeEnergy(cudaStream_t stream, size_t count, float rayAzimuthSt
const Field<DISTANCE_F32>::type* hitDist, const Field<NORMAL_VEC3_F32>::type* hitNorm,
const Field<XYZ_VEC3_F32>::type* hitPos, Vector<3, thrust::complex<float>>* outBUBRFactor);
void gpuProcessBeamSamplesFirstLast(cudaStream_t stream, size_t beamCount, int samplesPerBeam, MultiReturnPointers beamSamples,
MultiReturnPointers first, MultiReturnPointers last);
MultiReturnPointers first, MultiReturnPointers last, const Mat3x4f* beamWorld);
13 changes: 8 additions & 5 deletions src/gpu/optixPrograms.cu
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C" __global__ void __raygen__()
return;
}

Mat3x4f ray = ctx.rays[rayIdx];
Mat3x4f ray = ctx.raysWorld[rayIdx];
const Mat3x4f rayLocal =
ctx.rayOriginToWorld.inverse() *
ray; // TODO(prybicki): instead of computing inverse, we should pass rays in local CF and then transform them to world CF.
Expand Down Expand Up @@ -137,12 +137,16 @@ extern "C" __global__ void __closesthit__()
// Hitpoint
Vec3f hitObject = Vec3f((1 - u - v) * A + u * B + v * C);
const Vec3f hitWorldRaytraced = optixTransformPointFromObjectToWorldSpace(hitObject);
const float distance = (hitWorldRaytraced - beamSampleOrigin).length();
const Vector<3, double> hwrd = hitWorldRaytraced;
const Vector<3, double> hso = beamSampleOrigin;
const double distance = (hwrd - hso).length();
const Vec3f hitWorldSeenBySensor = [&]() {
if (!ctx.doApplyDistortion) {
return hitWorldRaytraced;
}
Mat3x4f undistortedRay = ctx.rays[beamIdx] * makeBeamSampleRayTransform(ctx.beamHalfDivergence, circleIdx, vertexIdx);
Mat3x4f sampleRayTf = beamSampleRayIdx == 0 ? Mat3x4f::identity() :
makeBeamSampleRayTransform(ctx.beamHalfDivergence, circleIdx, vertexIdx);
Mat3x4f undistortedRay = ctx.raysWorld[beamIdx] * sampleRayTf;
Vec3f undistortedOrigin = undistortedRay * Vec3f{0, 0, 0};
Vec3f undistortedDir = undistortedRay * Vec3f{0, 0, 1} - undistortedOrigin;
return undistortedOrigin + undistortedDir * distance;
Expand Down Expand Up @@ -186,7 +190,6 @@ extern "C" __global__ void __closesthit__()

// Save sub-sampling results
ctx.mrSamples.isHit[mrSamplesIdx] = true;
ctx.mrSamples.xyz[mrSamplesIdx] = hitWorldSeenBySensor;
ctx.mrSamples.distance[mrSamplesIdx] = distance;
if (beamSampleRayIdx != 0) {
return;
Expand Down Expand Up @@ -267,7 +270,7 @@ __device__ Mat3x4f makeBeamSampleRayTransform(float halfDivergenceAngleRad, unsi

__device__ void saveNonHitRayResult(float nonHitDistance)
{
Mat3x4f ray = ctx.rays[optixGetLaunchIndex().x];
Mat3x4f ray = ctx.raysWorld[optixGetLaunchIndex().x];
Vec3f origin = ray * Vec3f{0, 0, 0};
Vec3f dir = ray * Vec3f{0, 0, 1} - origin;
Vec3f displacement = dir.normalized() * nonHitDistance;
Expand Down
3 changes: 3 additions & 0 deletions src/graph/NodesCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ struct MultiReturnSwitchNode : IPointsNodeSingleInput
// Data getters
IAnyArray::ConstPtr getFieldData(rgl_field_t field) override
{
if (returnType == RGL_RETURN_TYPE_NOT_DIVERGENT) {
return rtxInput->getFieldData(field);
}
return rtxInput->getFieldDataMultiReturn(field, returnType);
}

Expand Down
12 changes: 7 additions & 5 deletions src/graph/RaytraceNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void RaytraceNode::enqueueExecImpl()
.doApplyDistortion = doApplyDistortion,
.nearNonHitDistance = nearNonHitDistance,
.farNonHitDistance = farNonHitDistance,
.rays = raysPtr,
.raysWorld = raysPtr,
.rayCount = raysNode->getRayCount(),
.rayOriginToWorld = raysNode->getCumulativeRayTransfrom(),
.rayRanges = rayRanges.has_value() ? (*rayRanges)->asSubclass<DeviceAsyncArray>()->getReadPtr() :
Expand Down Expand Up @@ -133,8 +133,10 @@ void RaytraceNode::enqueueExecImpl()
CHECK_OPTIX(optixLaunch(Optix::getOrCreate().pipeline, getStreamHandle(), pipelineArgsPtr, pipelineArgsSize, &sceneSBT,
launchDims.x, launchDims.y, launchDims.y));

gpuProcessBeamSamplesFirstLast(getStreamHandle(), raysNode->getRayCount(), MULTI_RETURN_BEAM_SAMPLES,
mrSamples.getPointers(), mrFirst.getPointers(), mrLast.getPointers());
if (beamHalfDivergence > 0.0f) {
gpuProcessBeamSamplesFirstLast(getStreamHandle(), raysNode->getRayCount(), MULTI_RETURN_BEAM_SAMPLES,
mrSamples.getPointers(), mrFirst.getPointers(), mrLast.getPointers(), raysPtr);
}
}

IAnyArray::ConstPtr RaytraceNode::getFieldDataMultiReturn(rgl_field_t field, rgl_return_type_t type)
Expand All @@ -144,15 +146,15 @@ IAnyArray::ConstPtr RaytraceNode::getFieldDataMultiReturn(rgl_field_t field, rgl
case XYZ_VEC3_F32: return mrFirst.xyz;
case DISTANCE_F32: return mrFirst.distance;
case IS_HIT_I32: return mrFirst.isHit;
default: throw InvalidPipeline(fmt::format("Multi-Return not supported for this field ({})", toString(field)));
default: return getFieldData(field);
}
}
if (type == RGL_RETURN_TYPE_LAST) {
switch (field) {
case XYZ_VEC3_F32: return mrLast.xyz;
case DISTANCE_F32: return mrLast.distance;
case IS_HIT_I32: return mrLast.isHit;
default: throw InvalidPipeline(fmt::format("Multi-Return not supported for this field ({})", toString(field)));
default: return getFieldData(field);
}
}
throw InvalidPipeline(fmt::format("Unknown multi-return type ({})", type));
Expand Down
1 change: 1 addition & 0 deletions test/include/helpers/geometryData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <rgl/api/core.h>

static constexpr float CUBE_HALF_EDGE = 1.0;
static constexpr float CUBE_EDGE = 2.0;

static rgl_vec3f cubeVertices[] = {
{-1, -1, -1}, // 0
Expand Down
4 changes: 2 additions & 2 deletions test/include/helpers/testPointCloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class TestPointCloud
}

template<rgl_field_t T>
std::vector<typename Field<T>::type> getFieldValues()
std::vector<typename Field<T>::type> getFieldValues() const
{
int fieldIndex = std::find(fields.begin(), fields.end(), T) - fields.begin();

Expand All @@ -252,7 +252,7 @@ class TestPointCloud

for (int i = 0; i < getPointCount(); i++) {
fieldValues.emplace_back(
*reinterpret_cast<typename Field<T>::type*>(data.data() + i * getPointByteSize() + offset));
*reinterpret_cast<const typename Field<T>::type*>(data.data() + i * getPointByteSize() + offset));
}

return fieldValues;
Expand Down
Loading
Loading