usd/2266.patch
Benjamin A. Beasley f7dcba95bd Port to Embree 4
2023-02-11 14:57:21 -05:00

217 lines
8.1 KiB
Diff

From 4b6c23d459c602fdac5e0ebc9b7722cbd5475e86 Mon Sep 17 00:00:00 2001
From: "Benjamin A. Beasley" <code@musicinmybrain.net>
Date: Sat, 11 Feb 2023 13:58:42 -0500
Subject: [PATCH] Port to Embree 4.x
---
cmake/modules/FindEmbree.cmake | 16 ++++++++--------
pxr/imaging/plugin/hdEmbree/context.h | 2 +-
pxr/imaging/plugin/hdEmbree/mesh.cpp | 2 +-
pxr/imaging/plugin/hdEmbree/mesh.h | 4 ++--
pxr/imaging/plugin/hdEmbree/meshSamplers.h | 4 ++--
pxr/imaging/plugin/hdEmbree/pch.h | 6 +++---
pxr/imaging/plugin/hdEmbree/renderDelegate.h | 2 +-
pxr/imaging/plugin/hdEmbree/renderParam.h | 2 +-
pxr/imaging/plugin/hdEmbree/renderer.cpp | 8 ++------
pxr/imaging/plugin/hdEmbree/renderer.h | 4 ++--
.../plugin/hdEmbree/testenv/testHdEmbree.cpp | 2 +-
11 files changed, 24 insertions(+), 28 deletions(-)
diff --git a/cmake/modules/FindEmbree.cmake b/cmake/modules/FindEmbree.cmake
index e12639d6d9..ec13d0f5c4 100644
--- a/cmake/modules/FindEmbree.cmake
+++ b/cmake/modules/FindEmbree.cmake
@@ -37,11 +37,11 @@
#=============================================================================
if (APPLE)
- set (EMBREE_LIB_NAME libembree3.dylib)
+ set (EMBREE_LIB_NAME libembree4.dylib)
elseif (UNIX)
- set (EMBREE_LIB_NAME libembree3.so)
+ set (EMBREE_LIB_NAME libembree4.so)
elseif (WIN32)
- set (EMBREE_LIB_NAME embree3.lib)
+ set (EMBREE_LIB_NAME embree4.lib)
endif()
find_library(EMBREE_LIBRARY
@@ -56,7 +56,7 @@ find_library(EMBREE_LIBRARY
)
find_path(EMBREE_INCLUDE_DIR
- embree3/rtcore.h
+ embree4/rtcore.h
HINTS
"${EMBREE_LOCATION}/include"
"$ENV{EMBREE_LOCATION}/include"
@@ -64,12 +64,12 @@ DOC
"Embree headers path"
)
-if (EMBREE_INCLUDE_DIR AND EXISTS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" )
- file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MAJOR.*$")
+if (EMBREE_INCLUDE_DIR AND EXISTS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_version.h" )
+ file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MAJOR.*$")
string(REGEX MATCHALL "[0-9]+" MAJOR ${TMP})
- file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MINOR.*$")
+ file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_MINOR.*$")
string(REGEX MATCHALL "[0-9]+" MINOR ${TMP})
- file(STRINGS "${EMBREE_INCLUDE_DIR}/embree3/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_PATCH.*$")
+ file(STRINGS "${EMBREE_INCLUDE_DIR}/embree4/rtcore_version.h" TMP REGEX "^#define RTC_VERSION_PATCH.*$")
string(REGEX MATCHALL "[0-9]+" PATCH ${TMP})
set (EMBREE_VERSION ${MAJOR}.${MINOR}.${PATCH})
diff --git a/pxr/imaging/plugin/hdEmbree/context.h b/pxr/imaging/plugin/hdEmbree/context.h
index 7af4ab0d27..fb10e8ceff 100644
--- a/pxr/imaging/plugin/hdEmbree/context.h
+++ b/pxr/imaging/plugin/hdEmbree/context.h
@@ -31,7 +31,7 @@
#include "pxr/base/gf/matrix4f.h"
#include "pxr/base/vt/array.h"
-#include <embree3/rtcore.h>
+#include <embree4/rtcore.h>
PXR_NAMESPACE_OPEN_SCOPE
diff --git a/pxr/imaging/plugin/hdEmbree/mesh.cpp b/pxr/imaging/plugin/hdEmbree/mesh.cpp
index e8e001e1cc..fe0f25b7b8 100644
--- a/pxr/imaging/plugin/hdEmbree/mesh.cpp
+++ b/pxr/imaging/plugin/hdEmbree/mesh.cpp
@@ -220,7 +220,7 @@ void HdEmbreeMesh::_EmbreeCullFaces(const RTCFilterFunctionNArguments* args)
default: break;
}
if (cull) {
- // This is how you reject a hit in embree3 instead of setting
+ // This is how you reject a hit in embree3/4 instead of setting
// geomId to invalid on the ray
args->valid[i] = 0;
}
diff --git a/pxr/imaging/plugin/hdEmbree/mesh.h b/pxr/imaging/plugin/hdEmbree/mesh.h
index 4574454368..f83bf5d998 100644
--- a/pxr/imaging/plugin/hdEmbree/mesh.h
+++ b/pxr/imaging/plugin/hdEmbree/mesh.h
@@ -32,8 +32,8 @@
#include "pxr/imaging/plugin/hdEmbree/meshSamplers.h"
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_ray.h>
+#include <embree4/rtcore.h>
+#include <embree4/rtcore_ray.h>
PXR_NAMESPACE_OPEN_SCOPE
diff --git a/pxr/imaging/plugin/hdEmbree/meshSamplers.h b/pxr/imaging/plugin/hdEmbree/meshSamplers.h
index bef6f65959..2b481e5694 100644
--- a/pxr/imaging/plugin/hdEmbree/meshSamplers.h
+++ b/pxr/imaging/plugin/hdEmbree/meshSamplers.h
@@ -29,8 +29,8 @@
#include "pxr/imaging/hd/meshUtil.h"
#include "pxr/base/vt/types.h"
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_geometry.h>
+#include <embree4/rtcore.h>
+#include <embree4/rtcore_geometry.h>
#include <bitset>
diff --git a/pxr/imaging/plugin/hdEmbree/pch.h b/pxr/imaging/plugin/hdEmbree/pch.h
index 7710229804..e8e733bfc4 100644
--- a/pxr/imaging/plugin/hdEmbree/pch.h
+++ b/pxr/imaging/plugin/hdEmbree/pch.h
@@ -151,9 +151,9 @@
#include <boost/unordered_map.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/weak_ptr.hpp>
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_geometry.h>
-#include <embree3/rtcore_ray.h>
+#include <embree4/rtcore.h>
+#include <embree4/rtcore_geometry.h>
+#include <embree4/rtcore_ray.h>
#include <tbb/atomic.h>
#include <tbb/blocked_range.h>
#include <tbb/cache_aligned_allocator.h>
diff --git a/pxr/imaging/plugin/hdEmbree/renderDelegate.h b/pxr/imaging/plugin/hdEmbree/renderDelegate.h
index 20a80487a9..6a6bc9dbf1 100644
--- a/pxr/imaging/plugin/hdEmbree/renderDelegate.h
+++ b/pxr/imaging/plugin/hdEmbree/renderDelegate.h
@@ -31,7 +31,7 @@
#include "pxr/base/tf/staticTokens.h"
#include <mutex>
-#include <embree3/rtcore.h>
+#include <embree4/rtcore.h>
PXR_NAMESPACE_OPEN_SCOPE
diff --git a/pxr/imaging/plugin/hdEmbree/renderParam.h b/pxr/imaging/plugin/hdEmbree/renderParam.h
index ff61000ab5..d3f903e0f3 100644
--- a/pxr/imaging/plugin/hdEmbree/renderParam.h
+++ b/pxr/imaging/plugin/hdEmbree/renderParam.h
@@ -28,7 +28,7 @@
#include "pxr/imaging/hd/renderDelegate.h"
#include "pxr/imaging/hd/renderThread.h"
-#include <embree3/rtcore.h>
+#include <embree4/rtcore.h>
PXR_NAMESPACE_OPEN_SCOPE
diff --git a/pxr/imaging/plugin/hdEmbree/renderer.cpp b/pxr/imaging/plugin/hdEmbree/renderer.cpp
index 20ec78c6aa..72a897120d 100644
--- a/pxr/imaging/plugin/hdEmbree/renderer.cpp
+++ b/pxr/imaging/plugin/hdEmbree/renderer.cpp
@@ -650,9 +650,7 @@ HdEmbreeRenderer::_TraceRay(unsigned int x, unsigned int y,
rayHit.ray.flags = 0;
_PopulateRayHit(&rayHit, origin, dir, 0.0f);
{
- RTCIntersectContext context;
- rtcInitIntersectContext(&context);
- rtcIntersect1(_scene, &context, &rayHit);
+ rtcIntersect1(_scene, &rayHit);
//
// there is something odd about how this is used in Embree. Is it reversed
// here and then when it it used in
@@ -992,9 +990,7 @@ HdEmbreeRenderer::_ComputeAmbientOcclusion(GfVec3f const& position,
shadow.flags = 0;
_PopulateRay(&shadow, position, shadowDir, 0.001f);
{
- RTCIntersectContext context;
- rtcInitIntersectContext(&context);
- rtcOccluded1(_scene,&context,&shadow);
+ rtcOccluded1(_scene,&shadow);
}
// Record this AO ray's contribution to the occlusion factor: a
diff --git a/pxr/imaging/plugin/hdEmbree/renderer.h b/pxr/imaging/plugin/hdEmbree/renderer.h
index 6af8081678..740812fb03 100644
--- a/pxr/imaging/plugin/hdEmbree/renderer.h
+++ b/pxr/imaging/plugin/hdEmbree/renderer.h
@@ -32,8 +32,8 @@
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/rect2i.h"
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_ray.h>
+#include <embree4/rtcore.h>
+#include <embree4/rtcore_ray.h>
#include <random>
#include <atomic>
diff --git a/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp b/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
index c361c678bc..8380aebe72 100644
--- a/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
+++ b/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
@@ -40,7 +40,7 @@
#include "pxr/base/tf/errorMark.h"
-#include <embree3/rtcore.h>
+#include <embree4/rtcore.h>
#include <iostream>
PXR_NAMESPACE_USING_DIRECTIVE