Skip to content

Commit cac37c7

Browse files
authored
Upgrade embree to 4.3.1 (isl-org#6665)
* Replace reference of rtcIntersect1M to rtcIntersect1 * Change RTCRayHit mask default value and enable filter callbacks
1 parent aba7214 commit cac37c7

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

3rdparty/embree/embree.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ endif()
6969
ExternalProject_Add(
7070
ext_embree
7171
PREFIX embree
72-
URL https://github.com/embree/embree/archive/refs/tags/v3.13.3.tar.gz
73-
URL_HASH SHA256=74ec785afb8f14d28ea5e0773544572c8df2e899caccdfc88509f1bfff58716f
72+
URL https://github.com/embree/embree/archive/refs/tags/v4.3.1.tar.gz
73+
URL_HASH SHA256=824edcbb7a8cd393c5bdb7a16738487b21ecc4e1d004ac9f761e934f97bb02a4
7474
DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/embree"
7575
UPDATE_COMMAND ""
7676
CMAKE_ARGS
@@ -88,7 +88,7 @@ ExternalProject_Add(
8888
-DEMBREE_TASKING_SYSTEM=INTERNAL
8989
${WIN_CMAKE_ARGS}
9090
BUILD_BYPRODUCTS
91-
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree3${CMAKE_STATIC_LIBRARY_SUFFIX}
91+
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}embree4${CMAKE_STATIC_LIBRARY_SUFFIX}
9292
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}simd${CMAKE_STATIC_LIBRARY_SUFFIX}
9393
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lexers${CMAKE_STATIC_LIBRARY_SUFFIX}
9494
<INSTALL_DIR>/${Open3D_INSTALL_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}sys${CMAKE_STATIC_LIBRARY_SUFFIX}
@@ -100,4 +100,4 @@ ExternalProject_Add(
100100
ExternalProject_Get_Property(ext_embree INSTALL_DIR)
101101
set(EMBREE_INCLUDE_DIRS ${INSTALL_DIR}/include/ ${INSTALL_DIR}/src/ext_embree/) # "/" is critical.
102102
set(EMBREE_LIB_DIR ${INSTALL_DIR}/${Open3D_INSTALL_LIB_DIR})
103-
set(EMBREE_LIBRARIES embree3 ${ISA_LIBS} simd lexers sys math tasking)
103+
set(EMBREE_LIBRARIES embree4 ${ISA_LIBS} simd lexers sys math tasking)

cpp/open3d/t/geometry/RaycastingScene.cpp

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "open3d/t/geometry/RaycastingScene.h"
1313

1414
// This header is in the embree src dir (embree/src/ext_embree/..).
15-
#include <embree3/rtcore.h>
15+
#include <embree4/rtcore.h>
1616
#include <tbb/parallel_for.h>
1717

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

6363
struct CountIntersectionsContext {
64-
RTCIntersectContext context;
64+
RTCRayQueryContext context;
6565
std::vector<std::tuple<uint32_t, uint32_t, float>>*
6666
previous_geom_prim_ID_tfar;
6767
int* intersections;
@@ -111,7 +111,7 @@ void CountIntersectionsFunc(const RTCFilterFunctionNArguments* args) {
111111
}
112112

113113
struct ListIntersectionsContext {
114-
RTCIntersectContext context;
114+
RTCRayQueryContext context;
115115
std::vector<std::tuple<uint32_t, uint32_t, float>>*
116116
previous_geom_prim_ID_tfar;
117117
unsigned int* ray_ids;
@@ -360,9 +360,6 @@ struct RaycastingScene::Impl {
360360
const int nthreads) {
361361
CommitScene();
362362

363-
struct RTCIntersectContext context;
364-
rtcInitIntersectContext(&context);
365-
366363
auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
367364
std::vector<RTCRayHit> rayhits(range.size());
368365

@@ -387,15 +384,14 @@ struct RaycastingScene::Impl {
387384
} else {
388385
rh.ray.tfar = std::numeric_limits<float>::infinity();
389386
}
390-
rh.ray.mask = 0;
387+
rh.ray.mask = -1;
391388
rh.ray.id = i - range.begin();
392389
rh.ray.flags = 0;
393390
rh.hit.geomID = RTC_INVALID_GEOMETRY_ID;
394391
rh.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
395-
}
396392

397-
rtcIntersect1M(scene_, &context, &rayhits[0], range.size(),
398-
sizeof(RTCRayHit));
393+
rtcIntersect1(scene_, &rh);
394+
}
399395

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

449-
struct RTCIntersectContext context;
450-
rtcInitIntersectContext(&context);
445+
struct RTCRayQueryContext context;
446+
rtcInitRayQueryContext(&context);
447+
448+
RTCOccludedArguments args;
449+
rtcInitOccludedArguments(&args);
450+
args.context = &context;
451451

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

470-
rtcOccluded1M(scene_, &context, &rayvec[0], range.size(),
471-
sizeof(RTCRay));
469+
rtcOccluded1(scene_, &ray, &args);
470+
}
472471

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

510509
CountIntersectionsContext context;
511-
rtcInitIntersectContext(&context.context);
512-
context.context.filter = CountIntersectionsFunc;
510+
rtcInitRayQueryContext(&context.context);
513511
context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar;
514512
context.intersections = intersections;
515513

514+
RTCIntersectArguments args;
515+
rtcInitIntersectArguments(&args);
516+
args.filter = CountIntersectionsFunc;
517+
args.context = &context.context;
518+
516519
auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
517520
std::vector<RTCRayHit> rayhits(range.size());
518521

@@ -527,14 +530,14 @@ struct RaycastingScene::Impl {
527530
rh->ray.dir_z = r[5];
528531
rh->ray.tnear = 0;
529532
rh->ray.tfar = std::numeric_limits<float>::infinity();
530-
rh->ray.mask = 0;
533+
rh->ray.mask = -1;
531534
rh->ray.flags = 0;
532535
rh->ray.id = i;
533536
rh->hit.geomID = RTC_INVALID_GEOMETRY_ID;
534537
rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
538+
539+
rtcIntersect1(scene_, rh, &args);
535540
}
536-
rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(),
537-
sizeof(RTCRayHit));
538541
};
539542

540543
if (nthreads > 0) {
@@ -579,8 +582,7 @@ struct RaycastingScene::Impl {
579582
0.f));
580583

581584
ListIntersectionsContext context;
582-
rtcInitIntersectContext(&context.context);
583-
context.context.filter = ListIntersectionsFunc;
585+
rtcInitRayQueryContext(&context.context);
584586
context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar;
585587
context.ray_ids = ray_ids;
586588
context.geometry_ids = geometry_ids;
@@ -590,6 +592,11 @@ struct RaycastingScene::Impl {
590592
context.cumsum = cumsum;
591593
context.track_intersections = track_intersections;
592594

595+
RTCIntersectArguments args;
596+
rtcInitIntersectArguments(&args);
597+
args.filter = ListIntersectionsFunc;
598+
args.context = &context.context;
599+
593600
auto LoopFn = [&](const tbb::blocked_range<size_t>& range) {
594601
std::vector<RTCRayHit> rayhits(range.size());
595602

@@ -604,14 +611,14 @@ struct RaycastingScene::Impl {
604611
rh->ray.dir_z = r[5];
605612
rh->ray.tnear = 0;
606613
rh->ray.tfar = std::numeric_limits<float>::infinity();
607-
rh->ray.mask = 0;
614+
rh->ray.mask = -1;
608615
rh->ray.flags = 0;
609616
rh->ray.id = i;
610617
rh->hit.geomID = RTC_INVALID_GEOMETRY_ID;
611618
rh->hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
619+
620+
rtcIntersect1(scene_, rh, &args);
612621
}
613-
rtcIntersect1M(scene_, &context.context, &rayhits[0], range.size(),
614-
sizeof(RTCRayHit));
615622
};
616623

617624
if (nthreads > 0) {
@@ -695,9 +702,9 @@ RaycastingScene::RaycastingScene(int64_t nthreads)
695702

696703
impl_->scene_ = rtcNewScene(impl_->device_);
697704
// set flag for better accuracy
698-
rtcSetSceneFlags(
699-
impl_->scene_,
700-
RTC_SCENE_FLAG_ROBUST | RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION);
705+
rtcSetSceneFlags(impl_->scene_,
706+
RTC_SCENE_FLAG_ROBUST |
707+
RTC_SCENE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS);
701708

702709
impl_->devprop_join_commit = rtcGetDeviceProperty(
703710
impl_->device_, RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED);
@@ -746,6 +753,7 @@ uint32_t RaycastingScene::AddTriangles(const core::Tensor& vertex_positions,
746753
memcpy(index_buffer, data.GetDataPtr(),
747754
sizeof(uint32_t) * 3 * num_triangles);
748755
}
756+
rtcSetGeometryEnableFilterFunctionFromArguments(geom, true);
749757
rtcCommitGeometry(geom);
750758

751759
uint32_t geom_id = rtcAttachGeometry(impl_->scene_, geom);

0 commit comments

Comments
 (0)