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

Upgrade embree to 4.3.1 #6665

Merged
merged 6 commits into from
Mar 18, 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
8 changes: 4 additions & 4 deletions 3rdparty/embree/embree.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ endif()
ExternalProject_Add(
ext_embree
PREFIX embree
URL https://github.com/embree/embree/archive/refs/tags/v3.13.3.tar.gz
URL_HASH SHA256=74ec785afb8f14d28ea5e0773544572c8df2e899caccdfc88509f1bfff58716f
URL https://github.com/embree/embree/archive/refs/tags/v4.3.1.tar.gz
URL_HASH SHA256=824edcbb7a8cd393c5bdb7a16738487b21ecc4e1d004ac9f761e934f97bb02a4
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/embree"
UPDATE_COMMAND ""
CMAKE_ARGS
Expand All @@ -88,7 +88,7 @@ ExternalProject_Add(
-DEMBREE_TASKING_SYSTEM=INTERNAL
${WIN_CMAKE_ARGS}
BUILD_BYPRODUCTS
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree3${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree4${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}simd${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lexers${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}sys${CMAKE_STATIC_LIBRARY_SUFFIX}
Expand All @@ -100,4 +100,4 @@ ExternalProject_Add(
ExternalProject_Get_Property(ext_embree INSTALL_DIR)
set(EMBREE_INCLUDE_DIRS ${INSTALL_DIR}/include/ ${INSTALL_DIR}/src/ext_embree/) # "/" is critical.
set(EMBREE_LIB_DIR ${INSTALL_DIR}/${Open3D_INSTALL_LIB_DIR})
set(EMBREE_LIBRARIES embree3 ${ISA_LIBS} simd lexers sys math tasking)
set(EMBREE_LIBRARIES embree4 ${ISA_LIBS} simd lexers sys math tasking)
66 changes: 37 additions & 29 deletions cpp/open3d/t/geometry/RaycastingScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "open3d/t/geometry/RaycastingScene.h"

// This header is in the embree src dir (embree/src/ext_embree/..).
#include <embree3/rtcore.h>
#include <embree4/rtcore.h>
#include <tbb/parallel_for.h>

#include <Eigen/Core>
Expand Down Expand Up @@ -61,7 +61,7 @@ void AssertTensorDtypeLastDimDeviceMinNDim(const open3d::core::Tensor& tensor,
}

struct CountIntersectionsContext {
RTCIntersectContext context;
RTCRayQueryContext context;
std::vector<std::tuple<uint32_t, uint32_t, float>>*
previous_geom_prim_ID_tfar;
int* intersections;
Expand Down Expand Up @@ -111,7 +111,7 @@ void CountIntersectionsFunc(const RTCFilterFunctionNArguments* args) {
}

struct ListIntersectionsContext {
RTCIntersectContext context;
RTCRayQueryContext context;
std::vector<std::tuple<uint32_t, uint32_t, float>>*
previous_geom_prim_ID_tfar;
unsigned int* ray_ids;
Expand Down Expand Up @@ -360,9 +360,6 @@ struct RaycastingScene::Impl {
const int nthreads) {
CommitScene();

struct RTCIntersectContext context;
rtcInitIntersectContext(&context);

auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
std::vector<RTCRayHit> rayhits(range.size());

Expand All @@ -387,15 +384,14 @@ struct RaycastingScene::Impl {
} else {
rh.ray.tfar = std::numeric_limits<float>::infinity();
}
rh.ray.mask = 0;
rh.ray.mask = -1;
rh.ray.id = i - range.begin();
rh.ray.flags = 0;
rh.hit.geomID = RTC_INVALID_GEOMETRY_ID;
rh.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
}

rtcIntersect1M(scene_, &context, &rayhits[0], range.size(),
sizeof(RTCRayHit));
rtcIntersect1(scene_, &rh);
}

for (size_t i = range.begin(); i < range.end(); ++i) {
RTCRayHit rh = rayhits[i - range.begin()];
Expand Down Expand Up @@ -446,8 +442,12 @@ struct RaycastingScene::Impl {
const int nthreads) {
CommitScene();

struct RTCIntersectContext context;
rtcInitIntersectContext(&context);
struct RTCRayQueryContext context;
rtcInitRayQueryContext(&context);

RTCOccludedArguments args;
rtcInitOccludedArguments(&args);
args.context = &context;

auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
std::vector<RTCRay> rayvec(range.size());
Expand All @@ -462,13 +462,12 @@ struct RaycastingScene::Impl {
ray.dir_z = r[5];
ray.tnear = tnear;
ray.tfar = tfar;
ray.mask = 0;
ray.mask = -1;
ray.id = i - range.begin();
ray.flags = 0;
}

rtcOccluded1M(scene_, &context, &rayvec[0], range.size(),
sizeof(RTCRay));
rtcOccluded1(scene_, &ray, &args);
}

for (size_t i = range.begin(); i < range.end(); ++i) {
RTCRay ray = rayvec[i - range.begin()];
Expand Down Expand Up @@ -508,11 +507,15 @@ struct RaycastingScene::Impl {
0.f));

CountIntersectionsContext context;
rtcInitIntersectContext(&context.context);
context.context.filter = CountIntersectionsFunc;
rtcInitRayQueryContext(&context.context);
context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar;
context.intersections = intersections;

RTCIntersectArguments args;
rtcInitIntersectArguments(&args);
args.filter = CountIntersectionsFunc;
args.context = &context.context;

auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
std::vector<RTCRayHit> rayhits(range.size());

Expand All @@ -527,14 +530,14 @@ struct RaycastingScene::Impl {
rh->ray.dir_z = r[5];
rh->ray.tnear = 0;
rh->ray.tfar = std::numeric_limits<float>::infinity();
rh->ray.mask = 0;
rh->ray.mask = -1;
rh->ray.flags = 0;
rh->ray.id = i;
rh->hit.geomID = RTC_INVALID_GEOMETRY_ID;
rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID;

rtcIntersect1(scene_, rh, &args);
}
rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(),
sizeof(RTCRayHit));
};

if (nthreads > 0) {
Expand Down Expand Up @@ -579,8 +582,7 @@ struct RaycastingScene::Impl {
0.f));

ListIntersectionsContext context;
rtcInitIntersectContext(&context.context);
context.context.filter = ListIntersectionsFunc;
rtcInitRayQueryContext(&context.context);
context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar;
context.ray_ids = ray_ids;
context.geometry_ids = geometry_ids;
Expand All @@ -590,6 +592,11 @@ struct RaycastingScene::Impl {
context.cumsum = cumsum;
context.track_intersections = track_intersections;

RTCIntersectArguments args;
rtcInitIntersectArguments(&args);
args.filter = ListIntersectionsFunc;
args.context = &context.context;

auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
std::vector<RTCRayHit> rayhits(range.size());

Expand All @@ -604,14 +611,14 @@ struct RaycastingScene::Impl {
rh->ray.dir_z = r[5];
rh->ray.tnear = 0;
rh->ray.tfar = std::numeric_limits<float>::infinity();
rh->ray.mask = 0;
rh->ray.mask = -1;
rh->ray.flags = 0;
rh->ray.id = i;
rh->hit.geomID = RTC_INVALID_GEOMETRY_ID;
rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID;

rtcIntersect1(scene_, rh, &args);
}
rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(),
sizeof(RTCRayHit));
};

if (nthreads > 0) {
Expand Down Expand Up @@ -695,9 +702,9 @@ RaycastingScene::RaycastingScene(int64_t nthreads)

impl_->scene_ = rtcNewScene(impl_->device_);
// set flag for better accuracy
rtcSetSceneFlags(
impl_->scene_,
RTC_SCENE_FLAG_ROBUST | RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION);
rtcSetSceneFlags(impl_->scene_,
RTC_SCENE_FLAG_ROBUST |
RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS);

impl_->devprop_join_commit = rtcGetDeviceProperty(
impl_->device_, RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED);
Expand Down Expand Up @@ -746,6 +753,7 @@ uint32_t RaycastingScene::AddTriangles(const core::Tensor& vertex_positions,
memcpy(index_buffer, data.GetDataPtr(),
sizeof(uint32_t) * 3 * num_triangles);
}
rtcSetGeometryEnableFilterFunctionFromArguments(geom, true);
rtcCommitGeometry(geom);

uint32_t geom_id = rtcAttachGeometry(impl_->scene_, geom);
Expand Down
Loading