From e2d8aa36f7c820ce15c2c5cfad93aaed4dae0fad Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:02:32 -0500 Subject: [PATCH 1/8] Adding wrapper headers to support embree 3 and 4. --- CMakeLists.txt | 18 ++++++++++++++++-- include/double-down/MOABRay.h | 5 ++--- include/double-down/RTI.hpp | 8 ++++---- include/double-down/embree3.hpp | 17 +++++++++++++++++ include/double-down/embree4.hpp | 3 +++ include/double-down/embree_interface.hpp | 14 ++++++++++++++ include/double-down/primitives.hpp | 4 ++-- include/double-down/ray.h | 5 ++--- src/RTI.cpp | 17 +++++------------ test/CMakeLists.txt | 2 +- tools/CMakeLists.txt | 1 - 11 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 include/double-down/embree3.hpp create mode 100644 include/double-down/embree4.hpp create mode 100644 include/double-down/embree_interface.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1325ac1..174fc5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,12 +33,19 @@ MESSAGE ( STATUS "MOAB_INCLUDE_DIRS is " ${MOAB_INCLUDE_DIRS} ) INCLUDE_DIRECTORIES( ${MOAB_INCLUDE_DIRS} ) # Embree -FIND_PACKAGE (embree 3.6.1 REQUIRED HINTS ${EMBREE_DIR}) +FIND_PACKAGE(embree 3.6.1 HINTS ${EMBREE_DIR} QUIET) + +if (NOT ${embree_FOUND}) +FIND_PACKAGE (embree REQUIRED HINTS ${EMBREE_DIR}) +endif() + if (NOT ${EMBREE_VERSION} VERSION_GREATER 3.6.0) message(FATAL_ERROR "Double-down requires Embree v3.6.1 or higher.") endif() +# set embree version + # Set install locations set( DD_BINARY_INSTALL_LOCATION "${CMAKE_INSTALL_PREFIX}/tools" ) set( DD_INCLUDE_INSTALL_LOCATION "${CMAKE_INSTALL_PREFIX}/include/double_down" ) @@ -57,11 +64,18 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # add library -add_library( dd SHARED "src/RTI.cpp" "src/primitives.cpp" "src/MOABRay.cpp" "src/MOABDirectAccess.cpp") +add_library(dd SHARED "src/RTI.cpp" "src/primitives.cpp" "src/MOABRay.cpp" "src/MOABDirectAccess.cpp") target_include_directories(dd PRIVATE ${CMAKE_SOURCE_DIR}/include) set_target_properties(dd PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE) set_target_properties(dd PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib ) +# pass precompile definition depending on embree version +if (${EMBREE_VERSION} VERSION_GREATER_EQUAL 4.0.0) + target_compile_definitions(dd PUBLIC EMBREE4) +else() + target_compile_definitions(dd PUBLIC EMBREE3) +endif() + target_include_directories( dd INTERFACE "${CMAKE_INSTALL_PREFIX}/include" ${EMBREE_INCLUDE_DIRS}) target_link_libraries( dd ${MOAB_LIBRARIES} ${EMBREE_LIBRARY} ) set_target_properties(dd PROPERTIES INSTALL_RPATH "${MOAB_LIBRARY_DIRS};${EMBREE_LIBRARY_DIR}") diff --git a/include/double-down/MOABRay.h b/include/double-down/MOABRay.h index ec1d67e..0fd717b 100644 --- a/include/double-down/MOABRay.h +++ b/include/double-down/MOABRay.h @@ -1,15 +1,14 @@ #ifndef DD_RAY_FUNCS_H #define DD_RAY_FUNCS_H -// Embree -#include "embree3/rtcore.h" - // MOAB #include "moab/GeomQueryTool.hpp" // Double-down #include "ray.h" +#include "double-down/embree_interface.hpp" + using namespace double_down; /*! Extension of the single/double precision ray hit to include MOAB handles */ diff --git a/include/double-down/RTI.hpp b/include/double-down/RTI.hpp index 16c2778..de5a539 100644 --- a/include/double-down/RTI.hpp +++ b/include/double-down/RTI.hpp @@ -1,8 +1,8 @@ #ifndef DD_RTI_H #define DD_RTI_H -#include "embree3/rtcore.h" -#include "embree3/rtcore_ray.h" +#include +#include #include "moab/Core.hpp" #include "moab/GeomQueryTool.hpp" @@ -12,8 +12,8 @@ #include "MOABRay.h" #include "MOABDirectAccess.h" -#include -#include +#include "embree_interface.hpp" + namespace double_down { diff --git a/include/double-down/embree3.hpp b/include/double-down/embree3.hpp new file mode 100644 index 0000000..a847db6 --- /dev/null +++ b/include/double-down/embree3.hpp @@ -0,0 +1,17 @@ + +#include "embree3/rtcore.h" + +#ifndef DD_EMBREE_WRAPPERS +#define DD_EMBREE_WRAPPERS + +// provide a function signature that matches the one in embree > v4. +// the context is created internally +inline void rtcIntersect1(RTCScene scene, RTCRayHit* rayhit) { + { + RTCIntersectContext context; + rtcInitIntersectContext(&context); + rtcIntersect1(scene, &context, rayhit); + } +} + +#endif // include guard \ No newline at end of file diff --git a/include/double-down/embree4.hpp b/include/double-down/embree4.hpp new file mode 100644 index 0000000..7fd372d --- /dev/null +++ b/include/double-down/embree4.hpp @@ -0,0 +1,3 @@ + +#include "embree4/rtcore.h" +#include "embree4/rtcore_ray.h" \ No newline at end of file diff --git a/include/double-down/embree_interface.hpp b/include/double-down/embree_interface.hpp new file mode 100644 index 0000000..14fdaba --- /dev/null +++ b/include/double-down/embree_interface.hpp @@ -0,0 +1,14 @@ + +#ifdef EMBREE4 + +#include "double-down/embree4.hpp" + +#elif defined(EMBREE3) + +#include "double-down/embree3.hpp" + +#else + +#error "No embree version provided to compiler" + +#endif \ No newline at end of file diff --git a/include/double-down/primitives.hpp b/include/double-down/primitives.hpp index 8ad44bc..9fb16f6 100644 --- a/include/double-down/primitives.hpp +++ b/include/double-down/primitives.hpp @@ -4,8 +4,6 @@ #include -// Embree -#include "embree3/rtcore.h" // MOAB #include "moab/Core.hpp" @@ -15,6 +13,8 @@ #include "ray.h" #include "MOABDirectAccess.h" +// Embree +#include "double-down/embree_interface.hpp" namespace double_down { /*! Structure with triangle information used in Embree */ diff --git a/include/double-down/ray.h b/include/double-down/ray.h index c6b8fce..2b44ac4 100644 --- a/include/double-down/ray.h +++ b/include/double-down/ray.h @@ -2,12 +2,11 @@ #ifndef DD_RAY_H #define DD_RAY_H -// Embree -#include "embree3/rtcore_ray.h" - // Double-down #include "Vec3da.h" +#include "double-down/embree_interface.hpp" + namespace double_down { enum RayFireType { RF, PIV, ACCUM }; diff --git a/src/RTI.cpp b/src/RTI.cpp index ccb5b95..06de3e5 100644 --- a/src/RTI.cpp +++ b/src/RTI.cpp @@ -8,6 +8,7 @@ // Double-down #include "double-down/RTI.hpp" #include "double-down/constants.h" +#include "double-down/embree_wrapper.hpp" namespace double_down { @@ -584,9 +585,7 @@ void RayTracingInterface::shutdown() { void RayTracingInterface::fire(moab::EntityHandle volume, RTCDRayHit &rayhit) { { - RTCIntersectContext context; - rtcInitIntersectContext(&context); - rtcIntersect1(scene_map[volume],&context,(RTCRayHit*)&rayhit); + rtcIntersect1(scene_map[volume], (RTCRayHit*)&rayhit); rayhit.hit.Ng_x = -rayhit.hit.Ng_x; rayhit.hit.Ng_y = -rayhit.hit.Ng_y; rayhit.hit.Ng_z = -rayhit.hit.Ng_z; @@ -740,9 +739,7 @@ RayTracingInterface::point_in_volume(const moab::EntityHandle volume, // fire ray { - RTCIntersectContext context; - rtcInitIntersectContext(&context); - rtcIntersect1(scene,&context,(RTCRayHit*)&mbrayhit); + rtcIntersect1(scene,(RTCRayHit*)&mbrayhit); // triangle normal conventions are the flipped in Embree compared to MOAB // TODO: reverse the initial triangle normals so we don't have to do these ops here. mbhit.Ng_x = -mbhit.Ng_x; @@ -890,9 +887,7 @@ RayTracingInterface::ray_fire(const moab::EntityHandle volume, // fire ray { - RTCIntersectContext context; - rtcInitIntersectContext(&context); - rtcIntersect1(scene,&context,(RTCRayHit*)&rayhit); + rtcIntersect1(scene, (RTCRayHit*)&rayhit); mbhit.Ng_x = -mbhit.Ng_x; mbhit.Ng_y = -mbhit.Ng_y; mbhit.Ng_z = -mbhit.Ng_z; @@ -917,9 +912,7 @@ RayTracingInterface::ray_fire(const moab::EntityHandle volume, // fire ray in negative direction if (overlap_thickness > 0.0) { - RTCIntersectContext context; - rtcInitIntersectContext(&context); - rtcIntersect1(scene,&context,(RTCRayHit*)&neg_ray); + rtcIntersect1(scene,(RTCRayHit*)&neg_ray); neg_hit.Ng_x = -neg_hit.Ng_x; neg_hit.Ng_y = -neg_hit.Ng_y; neg_hit.Ng_z = -neg_hit.Ng_z; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4420f7e..7d911bd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(test_mb test_mb.cpp test_utils.cpp) target_include_directories(test_mb PUBLIC ${MOAB_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/) -target_link_libraries(test_mb ${MOAB_LIBRARIES}) +target_link_libraries(test_mb ${MOAB_LIBRARIES} dd) set_target_properties(test_mb PROPERTIES BUILD_RPATH "${MOAB_LIBRARY_DIRS}") set_target_properties(test_mb PROPERTIES BUILD_RPATH_USE_LINK_PATH TRUE) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 35cacb1..a8273d0 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -2,7 +2,6 @@ add_executable(ray_fire ray_fire.cpp) target_include_directories(ray_fire PUBLIC ${MOAB_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include/) target_link_libraries(ray_fire ${MOAB_LIBRARIES} ${EMBREE_LIBRARY} dd) -target_link_libraries(ray_fire ${EMBREE_LIBRARY}) install(TARGETS ray_fire DESTINATION ${DD_BINARY_INSTALL_LOCATION}) add_executable(closest_to_location closest_to_location.cpp) From fbfab9980849647f379afd73424021c80423fdb0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:03:51 -0500 Subject: [PATCH 2/8] Explaining series of find_package calls --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 174fc5e..314934b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,13 +33,13 @@ MESSAGE ( STATUS "MOAB_INCLUDE_DIRS is " ${MOAB_INCLUDE_DIRS} ) INCLUDE_DIRECTORIES( ${MOAB_INCLUDE_DIRS} ) # Embree +# this series of calls is needed to support the way that Embree indicates +# compatible versions in 3 and 4 (version 4 does it correctly, but 3 does not) FIND_PACKAGE(embree 3.6.1 HINTS ${EMBREE_DIR} QUIET) - if (NOT ${embree_FOUND}) FIND_PACKAGE (embree REQUIRED HINTS ${EMBREE_DIR}) endif() - if (NOT ${EMBREE_VERSION} VERSION_GREATER 3.6.0) message(FATAL_ERROR "Double-down requires Embree v3.6.1 or higher.") endif() From 71586bbdb7e6d8673a222c85f6388cad15c8301b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:07:51 -0500 Subject: [PATCH 3/8] Updating CI to test against multiple Embree versions --- .github/workflows/ci.yml | 5 ++++- ci/embree-install.sh | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1ffeea..6189583 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,9 @@ env: DISPLAY: 99.0 jobs: + strategty: + matrix: + embree_version: ['3.6.1', '4.0.0'] build: runs-on: ubuntu-latest @@ -46,7 +49,7 @@ jobs: - name: Embree Build shell: bash - run: $GITHUB_WORKSPACE/ci/embree-install.sh + run: $GITHUB_WORKSPACE/ci/embree-install.sh ${embree_version} - name: Configure CMake # Use a bash shell so we can use the same syntax for environment variable diff --git a/ci/embree-install.sh b/ci/embree-install.sh index ff0f8e4..9c69607 100755 --- a/ci/embree-install.sh +++ b/ci/embree-install.sh @@ -2,7 +2,7 @@ set -ex # Embree Variables -EMBREE_TAG='v3.6.1' +EMBREE_TAG='v${1}' EMBREE_REPO='https://github.com/embree/embree' EMBREE_INSTALL_DIR=$HOME/EMBREE/ From 442d83be424d7c28b9830c34bc7c6c55ab7d1457 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:09:08 -0500 Subject: [PATCH 4/8] Correcting stages? --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6189583..003988e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,11 +23,11 @@ env: DISPLAY: 99.0 jobs: - strategty: - matrix: - embree_version: ['3.6.1', '4.0.0'] build: runs-on: ubuntu-latest + strategy: + matrix: + embree_version: ['3.6.1', '4.0.0'] steps: - uses: actions/checkout@v2 From 576c97ebdbfdab56fc913f7a4c7d1b1f3a5df4af Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:30:41 -0500 Subject: [PATCH 5/8] Updating embree install script --- ci/embree-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/embree-install.sh b/ci/embree-install.sh index 9c69607..e5fb1ac 100755 --- a/ci/embree-install.sh +++ b/ci/embree-install.sh @@ -1,8 +1,8 @@ #!/bin/bash set -ex -# Embree Variables -EMBREE_TAG='v${1}' +# Embree Variables -- use first argument to script as version number +EMBREE_TAG="v${1}" EMBREE_REPO='https://github.com/embree/embree' EMBREE_INSTALL_DIR=$HOME/EMBREE/ From 37d0e04a6b87ee654c13398b7509ade42d5aa024 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 12:42:23 -0500 Subject: [PATCH 6/8] Using matrix varible properly --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 003988e..dba0e55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: - name: Embree Build shell: bash - run: $GITHUB_WORKSPACE/ci/embree-install.sh ${embree_version} + run: $GITHUB_WORKSPACE/ci/embree-install.sh ${{ matrix.embree_version }} - name: Configure CMake # Use a bash shell so we can use the same syntax for environment variable From 65d1f9c2008297cc768a6e8c93f2b20c9a741251 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 13:10:24 -0500 Subject: [PATCH 7/8] Removing bad include --- src/RTI.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/RTI.cpp b/src/RTI.cpp index 06de3e5..2281d93 100644 --- a/src/RTI.cpp +++ b/src/RTI.cpp @@ -8,8 +8,6 @@ // Double-down #include "double-down/RTI.hpp" #include "double-down/constants.h" -#include "double-down/embree_wrapper.hpp" - namespace double_down { From 7ced70ea5c8b640e21257537f46bbe2b2f974c62 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 12 Apr 2023 15:33:28 -0500 Subject: [PATCH 8/8] Testing against latest release of Embree in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dba0e55..9f5a1dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - embree_version: ['3.6.1', '4.0.0'] + embree_version: ['3.6.1', '4.0.1'] steps: - uses: actions/checkout@v2