Skip to content

Commit 685e9c6

Browse files
mattyjamsmeshula
authored andcommitted
hdEmbree: add support for building against embree4
These changes allow building USD and the `hdEmbree` plugin against the [4.0.0 version of Embree](https://github.com/embree/embree/releases/tag/v4.0.0). The upgrade from 3.x to 4.x of Embree involves a filename change of headers and libraries (`embree3` -> `embree4`), the renaming of the header file that contains the version information from `rtcore_version.h` to `rtcore_config.h`, and for the usage in `hdEmbree`, no longer providing an (unused) context to the `rtcIntersect1()` and `rtcOccluded1()` functions. See the notes for more detail on upgrading from Embree 4 to Embree 4 here: https://github.com/RenderKit/embree/tree/v4.0.0?tab=readme-ov-file#upgrading-from-embree-3-to-embree-4 Closes PixarAnimationStudios#2266 Closes PixarAnimationStudios#2313 (Internal change: 2373054)
1 parent 687aa82 commit 685e9c6

File tree

12 files changed

+41
-36
lines changed

12 files changed

+41
-36
lines changed

VERSIONS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Our test machines have the following software versions installed.
2626
| Ptex | 2.4.2 | 2.4.2 | 2.4.2 |
2727
| Qt for Python | PySide2 5.15.2.1 | PySide6 6.3.1 | PySide2 5.15.2.1 |
2828
| PyOpenGL | 3.1.5 | 3.1.5 | 3.1.5 |
29-
| Embree | 3.2.2 | 3.13.3 | 3.2.2 |
29+
| Embree | 4.3.3 | 4.3.3 | 4.3.3 |
3030
| RenderMan | 25.3 | 25.3 | 25.3 |
3131
| Alembic | 1.8.5 | 1.8.5 | 1.8.5 |
3232
| OpenEXR | 3.1.13 | 3.1.13 | 3.1.13 |

build_scripts/build_usd.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,17 +1573,13 @@ def InstallMaterialX(context, force, buildArgs):
15731573

15741574
############################################################
15751575
# Embree
1576-
# For MacOS we use version 3.13.3 to include a fix from Intel
1577-
# to build on Apple Silicon.
1578-
if MacOS():
1579-
EMBREE_URL = "https://github.com/embree/embree/archive/v3.13.3.zip"
1580-
else:
1581-
EMBREE_URL = "https://github.com/embree/embree/archive/v3.2.2.zip"
15821576

15831577
def InstallEmbree(context, force, buildArgs):
1578+
EMBREE_URL = "https://github.com/RenderKit/embree/archive/refs/tags/v4.3.3.zip"
1579+
15841580
with CurrentWorkingDirectory(DownloadURL(EMBREE_URL, context, force)):
15851581
extraArgs = [
1586-
'-DTBB_ROOT={instDir}'.format(instDir=context.instDir),
1582+
'-DTBB_ROOT="{instDir}"'.format(instDir=context.instDir),
15871583
'-DEMBREE_TUTORIALS=OFF',
15881584
'-DEMBREE_ISPC_SUPPORT=OFF'
15891585
]
@@ -1621,7 +1617,8 @@ def InstallEmbree(context, force, buildArgs):
16211617

16221618
RunCMake(context, force, extraArgs)
16231619

1624-
EMBREE = Dependency("Embree", InstallEmbree, "include/embree3/rtcore.h")
1620+
EMBREE = Dependency("Embree", InstallEmbree,
1621+
"include/embree4/rtcore.h")
16251622

16261623
############################################################
16271624
# AnimX

cmake/modules/FindEmbree.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#=============================================================================
2121

2222
if (APPLE)
23-
set (EMBREE_LIB_NAME libembree3.dylib)
23+
set (EMBREE_LIB_NAME libembree4.dylib)
2424
elseif (UNIX)
25-
set (EMBREE_LIB_NAME libembree3.so)
25+
set (EMBREE_LIB_NAME libembree4.so)
2626
elseif (WIN32)
27-
set (EMBREE_LIB_NAME embree3.lib)
27+
set (EMBREE_LIB_NAME embree4.lib)
2828
endif()
2929

3030
find_library(EMBREE_LIBRARY
@@ -39,20 +39,20 @@ find_library(EMBREE_LIBRARY
3939
)
4040

4141
find_path(EMBREE_INCLUDE_DIR
42-
embree3/rtcore.h
42+
embree4/rtcore.h
4343
HINTS
4444
"${EMBREE_LOCATION}/include"
4545
"$ENV{EMBREE_LOCATION}/include"
4646
DOC
4747
"Embree headers path"
4848
)
4949

50-
if (EMBREE_INCLUDE_DIR AND EXISTS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" )
51-
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MAJOR.*$")
50+
if (EMBREE_INCLUDE_DIR AND EXISTS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_config.h" )
51+
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_config.h" TMP REGEX "^#define RTC_VERSION_MAJOR.*$")
5252
string(REGEX MATCHALL "[0-9]+" MAJOR ${TMP})
53-
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MINOR.*$")
53+
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_config.h" TMP REGEX "^#define RTC_VERSION_MINOR.*$")
5454
string(REGEX MATCHALL "[0-9]+" MINOR ${TMP})
55-
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_PATCH.*$")
55+
file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_config.h" TMP REGEX "^#define RTC_VERSION_PATCH.*$")
5656
string(REGEX MATCHALL "[0-9]+" PATCH ${TMP})
5757

5858
set (EMBREE_VERSION ${MAJOR}.${MINOR}.${PATCH})

pxr/imaging/plugin/hdEmbree/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "pxr/base/gf/matrix4f.h"
1515
#include "pxr/base/vt/array.h"
1616

17-
#include <embree3/rtcore.h>
17+
#include <embree4/rtcore.h>
1818

1919
PXR_NAMESPACE_OPEN_SCOPE
2020

pxr/imaging/plugin/hdEmbree/mesh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "pxr/imaging/plugin/hdEmbree/meshSamplers.h"
1717

18-
#include <embree3/rtcore.h>
19-
#include <embree3/rtcore_ray.h>
18+
#include <embree4/rtcore.h>
19+
#include <embree4/rtcore_ray.h>
2020

2121
PXR_NAMESPACE_OPEN_SCOPE
2222

pxr/imaging/plugin/hdEmbree/meshSamplers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "pxr/imaging/hd/meshUtil.h"
1313
#include "pxr/base/vt/types.h"
1414

15-
#include <embree3/rtcore.h>
16-
#include <embree3/rtcore_geometry.h>
15+
#include <embree4/rtcore.h>
16+
#include <embree4/rtcore_geometry.h>
1717

1818
#include <bitset>
1919

pxr/imaging/plugin/hdEmbree/pch.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
#include <unordered_set>
7777
#include <utility>
7878
#include <vector>
79-
#include <embree3/rtcore.h>
80-
#include <embree3/rtcore_geometry.h>
81-
#include <embree3/rtcore_ray.h>
79+
#include <embree4/rtcore.h>
80+
#include <embree4/rtcore_geometry.h>
81+
#include <embree4/rtcore_ray.h>
8282
#ifdef PXR_PYTHON_SUPPORT_ENABLED
8383
#include "pxr/base/tf/pySafePython.h"
8484
#endif // PXR_PYTHON_SUPPORT_ENABLED

pxr/imaging/plugin/hdEmbree/renderDelegate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include "pxr/imaging/plugin/hdEmbree/renderer.h"
1414
#include "pxr/base/tf/staticTokens.h"
1515

16+
#include <embree4/rtcore.h>
17+
1618
#include <mutex>
17-
#include <embree3/rtcore.h>
1819

1920
PXR_NAMESPACE_OPEN_SCOPE
2021

pxr/imaging/plugin/hdEmbree/renderParam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "pxr/imaging/hd/renderDelegate.h"
1212
#include "pxr/imaging/hd/renderThread.h"
1313

14-
#include <embree3/rtcore.h>
14+
#include <embree4/rtcore.h>
1515

1616
PXR_NAMESPACE_OPEN_SCOPE
1717

pxr/imaging/plugin/hdEmbree/renderer.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,18 @@
2828
// oneTBB as a min spec. This applies the "Work" thread limit to the
2929
// render thread if "Work" is using old TBB, but won't affect other "Work"
3030
// implementations. Note that it may affect Embree TBB usage as well.
31+
//
32+
// Note: The TBB version macro is located in different headers in legacy TBB.
3133
// -------------------------------------------------------------------------
34+
#if __has_include(<tbb/tbb_stddef.h>)
3235
#include <tbb/tbb_stddef.h>
36+
#elif __has_include(<tbb/version.h>)
37+
#include <tbb/version.h>
38+
#endif
39+
40+
#ifndef TBB_INTERFACE_VERSION_MAJOR
41+
#error "TBB version macro TBB_INTERFACE_VERSION_MAJOR not found"
42+
#endif
3343

3444
#if TBB_INTERFACE_VERSION_MAJOR < 12
3545

@@ -709,9 +719,7 @@ HdEmbreeRenderer::_TraceRay(unsigned int x, unsigned int y,
709719
rayHit.ray.flags = 0;
710720
_PopulateRayHit(&rayHit, origin, dir, 0.0f);
711721
{
712-
RTCIntersectContext context;
713-
rtcInitIntersectContext(&context);
714-
rtcIntersect1(_scene, &context, &rayHit);
722+
rtcIntersect1(_scene, &rayHit);
715723
//
716724
// there is something odd about how this is used in Embree. Is it reversed
717725
// here and then when it it used in
@@ -1047,9 +1055,7 @@ HdEmbreeRenderer::_ComputeAmbientOcclusion(GfVec3f const& position,
10471055
shadow.flags = 0;
10481056
_PopulateRay(&shadow, position, shadowDir, 0.001f);
10491057
{
1050-
RTCIntersectContext context;
1051-
rtcInitIntersectContext(&context);
1052-
rtcOccluded1(_scene,&context,&shadow);
1058+
rtcOccluded1(_scene, &shadow);
10531059
}
10541060

10551061
// Record this AO ray's contribution to the occlusion factor: a

0 commit comments

Comments
 (0)