Skip to content

Commit

Permalink
Revert "Upgrade embree to 4.3.1 (isl-org#6665)"
Browse files Browse the repository at this point in the history
This reverts commit cac37c7.
  • Loading branch information
sitic committed Mar 23, 2024
1 parent 43308b2 commit b243578
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 41 deletions.
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/v4.3.1.tar.gz
URL_HASH SHA256=824edcbb7a8cd393c5bdb7a16738487b21ecc4e1d004ac9f761e934f97bb02a4
URL https://github.com/embree/embree/archive/refs/tags/v3.13.3.tar.gz
URL_HASH SHA256=74ec785afb8f14d28ea5e0773544572c8df2e899caccdfc88509f1bfff58716f
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}embree4${CMAKE_STATIC_LIBRARY_SUFFIX}
<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}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 embree4 ${ISA_LIBS} simd lexers sys math tasking)
set(EMBREE_LIBRARIES embree3 ${ISA_LIBS} simd lexers sys math tasking)
66 changes: 29 additions & 37 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 <embree4/rtcore.h>
#include <embree3/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 {
RTCRayQueryContext context;
RTCIntersectContext 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 {
RTCRayQueryContext context;
RTCIntersectContext context;
std::vector<std::tuple<uint32_t, uint32_t, float>>*
previous_geom_prim_ID_tfar;
unsigned int* ray_ids;
Expand Down Expand Up @@ -360,6 +360,9 @@ 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 @@ -384,15 +387,16 @@ struct RaycastingScene::Impl {
} else {
rh.ray.tfar = std::numeric_limits<float>::infinity();
}
rh.ray.mask = -1;
rh.ray.mask = 0;
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;

rtcIntersect1(scene_, &rh);
}

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

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

struct RTCRayQueryContext context;
rtcInitRayQueryContext(&context);

RTCOccludedArguments args;
rtcInitOccludedArguments(&args);
args.context = &context;
struct RTCIntersectContext context;
rtcInitIntersectContext(&context);

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

rtcOccluded1(scene_, &ray, &args);
}

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

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

CountIntersectionsContext context;
rtcInitRayQueryContext(&context.context);
rtcInitIntersectContext(&context.context);
context.context.filter = CountIntersectionsFunc;
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 @@ -530,14 +527,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 = -1;
rh->ray.mask = 0;
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 @@ -582,7 +579,8 @@ struct RaycastingScene::Impl {
0.f));

ListIntersectionsContext context;
rtcInitRayQueryContext(&context.context);
rtcInitIntersectContext(&context.context);
context.context.filter = ListIntersectionsFunc;
context.previous_geom_prim_ID_tfar = &previous_geom_prim_ID_tfar;
context.ray_ids = ray_ids;
context.geometry_ids = geometry_ids;
Expand All @@ -592,11 +590,6 @@ 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 @@ -611,14 +604,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 = -1;
rh->ray.mask = 0;
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 @@ -702,9 +695,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_FILTER_FUNCTION_IN_ARGUMENTS);
rtcSetSceneFlags(
impl_->scene_,
RTC_SCENE_FLAG_ROBUST | RTC_SCENE_FLAG_CONTEXT_FILTER_FUNCTION);

impl_->devprop_join_commit = rtcGetDeviceProperty(
impl_->device_, RTC_DEVICE_PROPERTY_JOIN_COMMIT_SUPPORTED);
Expand Down Expand Up @@ -753,7 +746,6 @@ 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

0 comments on commit b243578

Please sign in to comment.