Skip to content

Commit 683fc0b

Browse files
committed
hdEmbree: add support for building against Embree versions 3 or 4
This supports upgrading Embree to a major version 4 release, so it includes handling for the change in file paths between "embree3" and "embree4" and also accounts for a small change in API in version 4 where RTCIntersectContext was removed.
1 parent 91e2bf9 commit 683fc0b

File tree

10 files changed

+63
-10
lines changed

10 files changed

+63
-10
lines changed

pxr/imaging/plugin/hdEmbree/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT})
1111
return()
1212
endif()
1313

14+
if (EMBREE_VERSION VERSION_GREATER_EQUAL 4.0.0)
15+
add_definitions(-DEMBREE_MAJOR_VERSION=4)
16+
else()
17+
add_definitions(-DEMBREE_MAJOR_VERSION=3)
18+
endif()
19+
1420
pxr_plugin(hdEmbree
1521
LIBRARIES
1622
plug

pxr/imaging/plugin/hdEmbree/context.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
#include "pxr/base/gf/matrix4f.h"
3232
#include "pxr/base/vt/array.h"
3333

34-
#include <embree3/rtcore.h>
34+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
35+
#include <embree4/rtcore.h>
36+
#else
37+
#include <embree3/rtcore.h>
38+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
3539

3640
PXR_NAMESPACE_OPEN_SCOPE
3741

pxr/imaging/plugin/hdEmbree/mesh.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232

3333
#include "pxr/imaging/plugin/hdEmbree/meshSamplers.h"
3434

35-
#include <embree3/rtcore.h>
36-
#include <embree3/rtcore_ray.h>
35+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
36+
#include <embree4/rtcore.h>
37+
#include <embree4/rtcore_ray.h>
38+
#else
39+
#include <embree3/rtcore.h>
40+
#include <embree3/rtcore_ray.h>
41+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
3742

3843
PXR_NAMESPACE_OPEN_SCOPE
3944

pxr/imaging/plugin/hdEmbree/meshSamplers.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@
2929
#include "pxr/imaging/hd/meshUtil.h"
3030
#include "pxr/base/vt/types.h"
3131

32-
#include <embree3/rtcore.h>
33-
#include <embree3/rtcore_geometry.h>
32+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
33+
#include <embree4/rtcore.h>
34+
#include <embree4/rtcore_geometry.h>
35+
#else
36+
#include <embree3/rtcore.h>
37+
#include <embree3/rtcore_geometry.h>
38+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
3439

3540
#include <bitset>
3641

pxr/imaging/plugin/hdEmbree/pch.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,15 @@
151151
#include <boost/unordered_map.hpp>
152152
#include <boost/utility/enable_if.hpp>
153153
#include <boost/weak_ptr.hpp>
154+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
155+
#include <embree4/rtcore.h>
156+
#include <embree4/rtcore_geometry.h>
157+
#include <embree4/rtcore_ray.h>
158+
#else
154159
#include <embree3/rtcore.h>
155160
#include <embree3/rtcore_geometry.h>
156161
#include <embree3/rtcore_ray.h>
162+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
157163
#include <tbb/atomic.h>
158164
#include <tbb/blocked_range.h>
159165
#include <tbb/cache_aligned_allocator.h>

pxr/imaging/plugin/hdEmbree/renderDelegate.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@
3030
#include "pxr/imaging/plugin/hdEmbree/renderer.h"
3131
#include "pxr/base/tf/staticTokens.h"
3232

33+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
34+
#include <embree4/rtcore.h>
35+
#else
36+
#include <embree3/rtcore.h>
37+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
38+
3339
#include <mutex>
34-
#include <embree3/rtcore.h>
3540

3641
PXR_NAMESPACE_OPEN_SCOPE
3742

pxr/imaging/plugin/hdEmbree/renderParam.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include "pxr/imaging/hd/renderDelegate.h"
2929
#include "pxr/imaging/hd/renderThread.h"
3030

31-
#include <embree3/rtcore.h>
31+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
32+
#include <embree4/rtcore.h>
33+
#else
34+
#include <embree3/rtcore.h>
35+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
3236

3337
PXR_NAMESPACE_OPEN_SCOPE
3438

pxr/imaging/plugin/hdEmbree/renderer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,13 @@ HdEmbreeRenderer::_TraceRay(unsigned int x, unsigned int y,
653653
rayHit.ray.flags = 0;
654654
_PopulateRayHit(&rayHit, origin, dir, 0.0f);
655655
{
656+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
657+
rtcIntersect1(_scene, &rayHit);
658+
#else
656659
RTCIntersectContext context;
657660
rtcInitIntersectContext(&context);
658661
rtcIntersect1(_scene, &context, &rayHit);
662+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
659663
//
660664
// there is something odd about how this is used in Embree. Is it reversed
661665
// here and then when it it used in
@@ -995,9 +999,13 @@ HdEmbreeRenderer::_ComputeAmbientOcclusion(GfVec3f const& position,
995999
shadow.flags = 0;
9961000
_PopulateRay(&shadow, position, shadowDir, 0.001f);
9971001
{
1002+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
1003+
rtcOccluded1(_scene, &shadow);
1004+
#else
9981005
RTCIntersectContext context;
9991006
rtcInitIntersectContext(&context);
10001007
rtcOccluded1(_scene,&context,&shadow);
1008+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
10011009
}
10021010

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

pxr/imaging/plugin/hdEmbree/renderer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
#include "pxr/base/gf/matrix4d.h"
3333
#include "pxr/base/gf/rect2i.h"
3434

35-
#include <embree3/rtcore.h>
36-
#include <embree3/rtcore_ray.h>
35+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
36+
#include <embree4/rtcore.h>
37+
#include <embree4/rtcore_ray.h>
38+
#else
39+
#include <embree3/rtcore.h>
40+
#include <embree3/rtcore_ray.h>
41+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
3742

3843
#include <random>
3944
#include <atomic>

pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040

4141
#include "pxr/base/tf/errorMark.h"
4242

43-
#include <embree3/rtcore.h>
43+
#if defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
44+
#include <embree4/rtcore.h>
45+
#else
46+
#include <embree3/rtcore.h>
47+
#endif // defined(EMBREE_MAJOR_VERSION) && EMBREE_MAJOR_VERSION >= 4
48+
4449
#include <iostream>
4550

4651
PXR_NAMESPACE_USING_DIRECTIVE

0 commit comments

Comments
 (0)