Skip to content

Commit

Permalink
Upgrade to embree 4 (#43)
Browse files Browse the repository at this point in the history
* Upgrade to embree 4

* Replace all embree 3 occurences

* Copy grid file for examples

* Add test badge and enable ray masking per default in embree 4

* Bump minor version
  • Loading branch information
tobre1 authored Mar 2, 2024
1 parent 0cc162d commit 47319fa
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: 🧪 Run Tests

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
Expand Down
44 changes: 31 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(
ViennaRay
LANGUAGES CXX
VERSION 2.0.0)
VERSION 2.0.1)

# --------------------------------------------------------------------------------------------------------
# Library options
Expand All @@ -22,10 +22,22 @@ option(VIENNARAY_BUILD_TESTS "Build tests" OFF)

include("cmake/openmp.cmake")

find_package(embree 3 QUIET)
set(VIENNARAY_EMBREE_VERSION 4)
find_package(embree ${VIENNARAY_EMBREE_VERSION} QUIET)
set(VIENNARAY_SYSTEM_EMBREE ${embree_FOUND})
if(VIENNARAY_SYSTEM_EMBREE)
message(STATUS "[ViennaRay] Found embree 4 system installation")
else(VIENNARAY_SYSTEM_EMBREE)
# look for embree 3
find_package(embree 3 QUIET)
set(VIENNARAY_SYSTEM_EMBREE ${embree_FOUND})
if(VIENNARAY_SYSTEM_EMBREE)
message(STATUS "[ViennaRay] Found embree 3 system installation")
set(VIENNARAY_EMBREE_VERSION 3)
endif()
endif()

if (NOT VIENNARAY_SYSTEM_EMBREE)
if(NOT VIENNARAY_SYSTEM_EMBREE)
message(STATUS "[ViennaRay] Using remote embree")
endif()

Expand All @@ -43,15 +55,17 @@ set_target_properties(
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_compile_definitions(${PROJECT_NAME}
INTERFACE VIENNARAY_EMBREE_VERSION=${VIENNARAY_EMBREE_VERSION})

if(VIENNARAY_USE_WDIST)
message(STATUS "[ViennaRay] Using weighted distribution of ray weights")
target_compile_definitions(${PROJECT_NAME} PUBLIC VIENNARAY_USE_WDIST)
target_compile_definitions(${PROJECT_NAME} INTERFACE VIENNARAY_USE_WDIST)
endif()

if(EMBREE_RAY_MASK)
if(EMBREE_RAY_MASK OR VIENNARAY_EMBREE_VERSION EQUAL 4)
message(STATUS "[ViennaRay] Using embree ray masking")
target_compile_definitions(${PROJECT_NAME} PUBLIC VIENNARAY_USE_RAY_MASKING)
target_compile_definitions(${PROJECT_NAME} INTERFACE VIENNARAY_USE_RAY_MASKING)
endif()

# --------------------------------------------------------------------------------------------------------
Expand All @@ -73,7 +87,7 @@ CPMAddPackage(
VERSION 1.11.1
GIT_REPOSITORY "https://github.com/TheLartians/PackageProject.cmake")

if (NOT VIENNARAY_SYSTEM_EMBREE)
if(NOT VIENNARAY_SYSTEM_EMBREE)
CPMFindPackage(
NAME TBB
VERSION 2020.0
Expand All @@ -82,12 +96,16 @@ if (NOT VIENNARAY_SYSTEM_EMBREE)
OPTIONS "TBB_TEST OFF" "TBB_STRICT OFF")
endif()

CPMFindPackage(
NAME embree
VERSION 3.0
GIT_TAG v3.13.0
GIT_REPOSITORY "https://github.com/embree/embree"
OPTIONS "EMBREE_TUTORIALS OFF")
if(VIENNARAY_EMBREE_VERSION EQUAL 3)
CPMFindPackage(NAME embree VERSION ${VIENNARAY_EMBREE_VERSION})
else(VIENNARAY_EMBREE_VERSION)
CPMFindPackage(
NAME embree
VERSION ${VIENNARAY_EMBREE_VERSION}
GIT_TAG v4.3.1
GIT_REPOSITORY "https://github.com/embree/embree"
OPTIONS "EMBREE_TUTORIALS OFF")
endif()

find_package(OpenMP REQUIRED)
target_link_libraries(${PROJECT_NAME} INTERFACE OpenMP::OpenMP_CXX embree)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<h1>ViennaRay</h1>

[![🧪 Tests](https://github.com/ViennaTools/ViennaRay/actions/workflows/test.yml/badge.svg)](https://github.com/ViennaTools/ViennaRay/actions/workflows/test.yml)

</div>

ViennaRay is a flux calculation library for topography simulations, based in Intel®'s ray tracing kernel [Embree](https://www.embree.org/). It is designed to provide efficient and high-performance ray tracing, while maintaining a simple and easy to use interface. ViennaRay was developed and optimized for use in conjunction with [ViennaLS](https://github.com/ViennaTools/ViennaLS), which provides the necessary geometry representation. It is however possible to use this as a standalone library, with self-designed geometries.
Expand Down Expand Up @@ -48,6 +50,7 @@ git clone https://github.com/ViennaTools/ViennaRay.git
cd ViennaRay

cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to/your/custom/install/
cmake --build build
cmake --install build
```

Expand All @@ -60,7 +63,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
* Installation with CPM

```cmake
CPMAddPackage("gh:viennatools/[email protected].0")
CPMAddPackage("gh:viennatools/[email protected].1")
```

* With a local installation
Expand All @@ -72,7 +75,7 @@ We recommend using [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) to consum
find_package(TBB REQUIRED)
find_package(OpenMP REQUIRED)
find_package(embree 3 PATHS ${VIENNARAY_PATH})
find_package(embree 4 PATHS ${VIENNARAY_PATH})
find_package(ViennaRay PATHS ${VIENNARAY_PATH})
target_link_libraries(${PROJECT_NAME} PUBLIC ViennaTools::ViennaRay)
Expand Down
4 changes: 3 additions & 1 deletion cmake/embree.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
macro(setup_embree_env TARGET OUTPUT)
if(VIENNARAY_DISABLE_COPY OR NOT MSVC OR VIENNARAY_SYSTEM_EMBREE)
if(VIENNARAY_DISABLE_COPY
OR NOT MSVC
OR VIENNARAY_SYSTEM_EMBREE)
message(STATUS "[ViennaRay] Skipping Embree-Environment setup for ${TARGET}")
else()
message(STATUS "[ViennaRay] Setting up Embree-Environment for ${TARGET}")
Expand Down
1 change: 1 addition & 0 deletions examples/trench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ project(trench LANGUAGES CXX)

add_executable(${PROJECT_NAME} "${PROJECT_NAME}.cpp")
target_link_libraries(${PROJECT_NAME} PRIVATE ViennaRay)
configure_file(trenchGrid3D.dat ${CMAKE_CURRENT_BINARY_DIR}/trenchGrid3D.dat COPYONLY)

add_dependencies(ViennaRay_Examples ${PROJECT_NAME})
1 change: 1 addition & 0 deletions examples/trench2D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ project(trench2D LANGUAGES CXX)

add_executable(${PROJECT_NAME} "${PROJECT_NAME}.cpp")
target_link_libraries(${PROJECT_NAME} PRIVATE ViennaRay)
configure_file(trenchGrid2D.dat ${CMAKE_CURRENT_BINARY_DIR}/trenchGrid2D.dat COPYONLY)

add_dependencies(ViennaRay_Examples ${PROJECT_NAME})
1 change: 0 additions & 1 deletion include/viennaray/rayGeometry.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef RAY_GEOMETRY_HPP
#define RAY_GEOMETRY_HPP

#include <embree3/rtcore.h>
#include <rayMetaGeometry.hpp>
#include <rayUtil.hpp>

Expand Down
4 changes: 4 additions & 0 deletions include/viennaray/rayMetaGeometry.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RAY_METAGEOMETRY_HPP
#define RAY_METAGEOMETRY_HPP

#if VIENNARAY_EMBREE_VERSION < 4
#include <embree3/rtcore.h>
#else
#include <embree4/rtcore.h>
#endif
#include <rayUtil.hpp>

template <typename NumericType, int D> class rayMetaGeometry {
Expand Down
4 changes: 4 additions & 0 deletions include/viennaray/raySource.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef RAY_SOURCE_HPP
#define RAY_SOURCE_HPP

#if VIENNARAY_EMBREE_VERSION < 4
#include <embree3/rtcore.h>
#else
#include <embree4/rtcore.h>
#endif
#include <rayPreCompileMacros.hpp>
#include <rayRNG.hpp>
#include <rayUtil.hpp>
Expand Down
1 change: 0 additions & 1 deletion include/viennaray/rayTrace.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef RAY_TRACE_HPP
#define RAY_TRACE_HPP

#include <embree3/rtcore.h>
#include <rayBoundary.hpp>
#include <rayGeometry.hpp>
#include <rayHitCounter.hpp>
Expand Down
7 changes: 7 additions & 0 deletions include/viennaray/rayTraceKernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ template <typename NumericType, int D> class rayTraceKernel {
// probabilistic weight
const NumericType initialRayWeight = 1.;

#if VIENNARAY_EMBREE_VERSION < 4
auto rtcContext = RTCIntersectContext{};
rtcInitIntersectContext(&rtcContext);
#endif

[[maybe_unused]] size_t progressCount = 0;

Expand Down Expand Up @@ -150,7 +152,12 @@ template <typename NumericType, int D> class rayTraceKernel {
// source

// Run the intersection
#if VIENNARAY_EMBREE_VERSION < 4
rtcIntersect1(rtcScene, &rtcContext, &rayHit);
#else
rtcIntersect1(rtcScene, &rayHit);
#endif

++totaltraces;

/* -------- No hit -------- */
Expand Down
4 changes: 2 additions & 2 deletions include/viennaray/rayUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace rayInternal {
constexpr double PI = 3.14159265358979323846;

template <int D>
constexpr double DiskFactor =
0.5 * (D == 3 ? 1.7320508 : 1.41421356237) * (1 + 1e-5);
constexpr double DiskFactor = 0.5 * (D == 3 ? 1.7320508 : 1.41421356237) *
(1 + 1e-5);

/* ------------- Vector operation functions ------------- */
template <typename NumericType>
Expand Down
1 change: 0 additions & 1 deletion tests/boundaryHit/boundaryHit.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayBoundary.hpp>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>
Expand Down
1 change: 0 additions & 1 deletion tests/boundaryHit2D/boundaryHit2D.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayBoundary.hpp>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>
Expand Down
1 change: 0 additions & 1 deletion tests/buildBoundary/buildBoundary.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayTestAsserts.hpp>
#include <rayTrace.hpp>

Expand Down
1 change: 0 additions & 1 deletion tests/buildBoundary2D/buildBoundary2D.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayTestAsserts.hpp>
#include <rayTrace.hpp>

Expand Down
1 change: 0 additions & 1 deletion tests/createGeometry/createGeometry.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>

Expand Down
1 change: 0 additions & 1 deletion tests/createRay/createRay.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayGeometry.hpp>
#include <rayRNG.hpp>
#include <raySourceGrid.hpp>
Expand Down
11 changes: 10 additions & 1 deletion tests/intersectionTest/intersectionTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayBoundary.hpp>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>
Expand Down Expand Up @@ -51,8 +50,10 @@ int main() {
auto geometryID = rtcAttachGeometry(rtcscene, rtcgeometry);
rtcJoinCommitScene(rtcscene);

#if VIENNARAY_EMBREE_VERSION < 4
auto rtccontext = RTCIntersectContext{};
rtcInitIntersectContext(&rtccontext);
#endif
RAYTEST_ASSERT(rtcGetDeviceError(rtcDevice) == RTC_ERROR_NONE)

{
Expand All @@ -79,7 +80,11 @@ int main() {
rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;

#if VIENNARAY_EMBREE_VERSION < 4
rtcIntersect1(rtcscene, &rtccontext, &rayhit);
#else
rtcIntersect1(rtcscene, &rayhit);
#endif

RAYTEST_ASSERT(rayhit.hit.geomID == geometryID)
RAYTEST_ASSERT(rayhit.hit.primID == 840)
Expand Down Expand Up @@ -110,7 +115,11 @@ int main() {
rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;

#if VIENNARAY_EMBREE_VERSION < 4
rtcIntersect1(rtcscene, &rtccontext, &rayhit);
#else
rtcIntersect1(rtcscene, &rayhit);
#endif

RAYTEST_ASSERT(rayhit.hit.geomID == boundaryID)
RAYTEST_ASSERT(rayhit.hit.primID == 7)
Expand Down
1 change: 0 additions & 1 deletion tests/pointNeighborhood/pointNeighborhood.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>
#include <rayUtil.hpp>
Expand Down
1 change: 0 additions & 1 deletion tests/pointNeighborhood2D/pointNeighborhood2D.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <embree3/rtcore.h>
#include <rayGeometry.hpp>
#include <rayTestAsserts.hpp>

Expand Down

0 comments on commit 47319fa

Please sign in to comment.