From a17e06e1bd1b4b74450388791b50a8071a8de6e1 Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Thu, 23 Feb 2023 14:17:02 -0700
Subject: [PATCH 1/6] build_usd.py: wrap the TBB_ROOT parameter value in double
 quotes when building Embree

This ensures that slash characters are properly escaped on Windows.
---
 build_scripts/build_usd.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py
index e5a80b36c4..b99fc2af95 100644
--- a/build_scripts/build_usd.py
+++ b/build_scripts/build_usd.py
@@ -1609,7 +1609,7 @@ def InstallMaterialX(context, force, buildArgs):
 def InstallEmbree(context, force, buildArgs):
     with CurrentWorkingDirectory(DownloadURL(EMBREE_URL, context, force)):
         extraArgs = [
-            '-DTBB_ROOT={instDir}'.format(instDir=context.instDir),
+            '-DTBB_ROOT="{instDir}"'.format(instDir=context.instDir),
             '-DEMBREE_TUTORIALS=OFF',
             '-DEMBREE_ISPC_SUPPORT=OFF'
         ]

From 9a4fe6c8744125bcb4bf31bd60a8491976aae0ef Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Thu, 23 Feb 2023 12:20:39 -0700
Subject: [PATCH 2/6] FindEmbree.cmake: add support for finding Embree versions
 3 or 4

---
 cmake/modules/FindEmbree.cmake | 41 +++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/cmake/modules/FindEmbree.cmake b/cmake/modules/FindEmbree.cmake
index cd52f6b7f5..4c4ff1cdb2 100644
--- a/cmake/modules/FindEmbree.cmake
+++ b/cmake/modules/FindEmbree.cmake
@@ -19,12 +19,30 @@
 #
 #=============================================================================
 
+find_path(EMBREE_INCLUDE_DIR
+    embree4/rtcore.h
+    embree3/rtcore.h
+HINTS
+    "${EMBREE_LOCATION}/include"
+    "$ENV{EMBREE_LOCATION}/include"
+DOC
+    "Embree headers path"
+)
+
+if (EMBREE_INCLUDE_DIR AND EXISTS "${EMBREE_INCLUDE_DIR}/embree4/rtcore.h")
+    set(EMBREE_VERSIONED_LIBRARY_NAME "embree4")
+    set(EMBREE_VERSION_HEADER_FILE_NAME "rtcore_config.h")
+else()
+    set(EMBREE_VERSIONED_LIBRARY_NAME "embree3")
+    set(EMBREE_VERSION_HEADER_FILE_NAME "rtcore_version.h")
+endif()
+
 if (APPLE)
-    set (EMBREE_LIB_NAME libembree3.dylib)
+    set (EMBREE_LIB_NAME "lib${EMBREE_VERSIONED_LIBRARY_NAME}.dylib")
 elseif (UNIX)
-    set (EMBREE_LIB_NAME libembree3.so)
+    set (EMBREE_LIB_NAME "lib${EMBREE_VERSIONED_LIBRARY_NAME}.so")
 elseif (WIN32)
-    set (EMBREE_LIB_NAME embree3.lib)
+    set (EMBREE_LIB_NAME "${EMBREE_VERSIONED_LIBRARY_NAME}.lib")
 endif()
 
 find_library(EMBREE_LIBRARY
@@ -38,21 +56,14 @@ find_library(EMBREE_LIBRARY
         "Embree library path"
 )
 
-find_path(EMBREE_INCLUDE_DIR
-    embree3/rtcore.h
-HINTS
-    "${EMBREE_LOCATION}/include"
-    "$ENV{EMBREE_LOCATION}/include"
-DOC
-    "Embree headers path"
-)
+set(EMBREE_VERSION_HEADER_FILE_PATH "${EMBREE_INCLUDE_DIR}/${EMBREE_VERSIONED_LIBRARY_NAME}/${EMBREE_VERSION_HEADER_FILE_NAME}")
 
-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_VERSION_HEADER_FILE_PATH}")
+    file(STRINGS "${EMBREE_VERSION_HEADER_FILE_PATH}" 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_VERSION_HEADER_FILE_PATH}" 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_VERSION_HEADER_FILE_PATH}" TMP REGEX "^#define RTC_VERSION_PATCH.*$")
     string(REGEX MATCHALL "[0-9]+" PATCH ${TMP})
 
     set (EMBREE_VERSION ${MAJOR}.${MINOR}.${PATCH})

From 68fc6db207bfc85e4f7846ac2e526a856d8307c4 Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Thu, 16 Feb 2023 16:37:11 -0700
Subject: [PATCH 3/6] 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. RTCIntersectContext was
renamed to RTCRayQueryContext, but it was also made part of the optional
RTCIntersectArguments parameter to rtcIntersect and rtcOccluded functions.
Since the context is not used by hdEmbree, it no longer needs to be provided.
---
 pxr/imaging/plugin/hdEmbree/CMakeLists.txt           | 6 ++++++
 pxr/imaging/plugin/hdEmbree/context.h                | 6 +++++-
 pxr/imaging/plugin/hdEmbree/mesh.h                   | 9 +++++++--
 pxr/imaging/plugin/hdEmbree/meshSamplers.h           | 9 +++++++--
 pxr/imaging/plugin/hdEmbree/pch.h                    | 6 ++++++
 pxr/imaging/plugin/hdEmbree/renderDelegate.h         | 7 ++++++-
 pxr/imaging/plugin/hdEmbree/renderParam.h            | 6 +++++-
 pxr/imaging/plugin/hdEmbree/renderer.cpp             | 8 ++++++++
 pxr/imaging/plugin/hdEmbree/renderer.h               | 9 +++++++--
 pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp | 7 ++++++-
 10 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/pxr/imaging/plugin/hdEmbree/CMakeLists.txt b/pxr/imaging/plugin/hdEmbree/CMakeLists.txt
index 43aa0826e5..ef98ef8f67 100644
--- a/pxr/imaging/plugin/hdEmbree/CMakeLists.txt
+++ b/pxr/imaging/plugin/hdEmbree/CMakeLists.txt
@@ -11,6 +11,12 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT})
     return()
 endif()
 
+if (EMBREE_VERSION VERSION_GREATER_EQUAL 4.0.0)
+    add_definitions(-DPXR_EMBREE_MAJOR_VERSION=4)
+else()
+    add_definitions(-DPXR_EMBREE_MAJOR_VERSION=3)
+endif()
+
 pxr_plugin(hdEmbree
    LIBRARIES
         plug
diff --git a/pxr/imaging/plugin/hdEmbree/context.h b/pxr/imaging/plugin/hdEmbree/context.h
index 4165adb1e6..7e5c099b74 100644
--- a/pxr/imaging/plugin/hdEmbree/context.h
+++ b/pxr/imaging/plugin/hdEmbree/context.h
@@ -14,7 +14,11 @@
 #include "pxr/base/gf/matrix4f.h"
 #include "pxr/base/vt/array.h"
 
-#include <embree3/rtcore.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+#else
+    #include <embree3/rtcore.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 
 PXR_NAMESPACE_OPEN_SCOPE
 
diff --git a/pxr/imaging/plugin/hdEmbree/mesh.h b/pxr/imaging/plugin/hdEmbree/mesh.h
index bbb006302f..a6f71f110f 100644
--- a/pxr/imaging/plugin/hdEmbree/mesh.h
+++ b/pxr/imaging/plugin/hdEmbree/mesh.h
@@ -15,8 +15,13 @@
 
 #include "pxr/imaging/plugin/hdEmbree/meshSamplers.h"
 
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_ray.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+    #include <embree4/rtcore_ray.h>
+#else
+    #include <embree3/rtcore.h>
+    #include <embree3/rtcore_ray.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 
 PXR_NAMESPACE_OPEN_SCOPE
 
diff --git a/pxr/imaging/plugin/hdEmbree/meshSamplers.h b/pxr/imaging/plugin/hdEmbree/meshSamplers.h
index c32c35fffa..51459a2ed4 100644
--- a/pxr/imaging/plugin/hdEmbree/meshSamplers.h
+++ b/pxr/imaging/plugin/hdEmbree/meshSamplers.h
@@ -12,8 +12,13 @@
 #include "pxr/imaging/hd/meshUtil.h"
 #include "pxr/base/vt/types.h"
 
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_geometry.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+    #include <embree4/rtcore_geometry.h>
+#else
+    #include <embree3/rtcore.h>
+    #include <embree3/rtcore_geometry.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 
 #include <bitset>
 
diff --git a/pxr/imaging/plugin/hdEmbree/pch.h b/pxr/imaging/plugin/hdEmbree/pch.h
index 9f613dd069..fc5fdcbb35 100644
--- a/pxr/imaging/plugin/hdEmbree/pch.h
+++ b/pxr/imaging/plugin/hdEmbree/pch.h
@@ -76,9 +76,15 @@
 #include <unordered_set>
 #include <utility>
 #include <vector>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+#include <embree4/rtcore.h>
+#include <embree4/rtcore_geometry.h>
+#include <embree4/rtcore_ray.h>
+#else
 #include <embree3/rtcore.h>
 #include <embree3/rtcore_geometry.h>
 #include <embree3/rtcore_ray.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 #ifdef PXR_PYTHON_SUPPORT_ENABLED
 #include "pxr/base/tf/pySafePython.h"
 #endif // PXR_PYTHON_SUPPORT_ENABLED
diff --git a/pxr/imaging/plugin/hdEmbree/renderDelegate.h b/pxr/imaging/plugin/hdEmbree/renderDelegate.h
index 1d8694daa6..826d020e04 100644
--- a/pxr/imaging/plugin/hdEmbree/renderDelegate.h
+++ b/pxr/imaging/plugin/hdEmbree/renderDelegate.h
@@ -13,8 +13,13 @@
 #include "pxr/imaging/plugin/hdEmbree/renderer.h"
 #include "pxr/base/tf/staticTokens.h"
 
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+#else
+    #include <embree3/rtcore.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+
 #include <mutex>
-#include <embree3/rtcore.h>
 
 PXR_NAMESPACE_OPEN_SCOPE
 
diff --git a/pxr/imaging/plugin/hdEmbree/renderParam.h b/pxr/imaging/plugin/hdEmbree/renderParam.h
index 206a7458bc..af94ef10a4 100644
--- a/pxr/imaging/plugin/hdEmbree/renderParam.h
+++ b/pxr/imaging/plugin/hdEmbree/renderParam.h
@@ -11,7 +11,11 @@
 #include "pxr/imaging/hd/renderDelegate.h"
 #include "pxr/imaging/hd/renderThread.h"
 
-#include <embree3/rtcore.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+#else
+    #include <embree3/rtcore.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 
 PXR_NAMESPACE_OPEN_SCOPE
 
diff --git a/pxr/imaging/plugin/hdEmbree/renderer.cpp b/pxr/imaging/plugin/hdEmbree/renderer.cpp
index 88d5e79093..86b5c003d8 100644
--- a/pxr/imaging/plugin/hdEmbree/renderer.cpp
+++ b/pxr/imaging/plugin/hdEmbree/renderer.cpp
@@ -667,9 +667,13 @@ HdEmbreeRenderer::_TraceRay(unsigned int x, unsigned int y,
     rayHit.ray.flags = 0;
     _PopulateRayHit(&rayHit, origin, dir, 0.0f);
     {
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+      rtcIntersect1(_scene, &rayHit);
+#else
       RTCIntersectContext context;
       rtcInitIntersectContext(&context);
       rtcIntersect1(_scene, &context, &rayHit);
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
       //
       // there is something odd about how this is used in Embree. Is it reversed
       // here and then when it it used in
@@ -1005,9 +1009,13 @@ HdEmbreeRenderer::_ComputeAmbientOcclusion(GfVec3f const& position,
         shadow.flags = 0;
         _PopulateRay(&shadow, position, shadowDir, 0.001f);
         {
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+          rtcOccluded1(_scene, &shadow);
+#else
           RTCIntersectContext context;
           rtcInitIntersectContext(&context);
           rtcOccluded1(_scene,&context,&shadow);
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
         }
 
         // 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 2da9880848..913b83eccc 100644
--- a/pxr/imaging/plugin/hdEmbree/renderer.h
+++ b/pxr/imaging/plugin/hdEmbree/renderer.h
@@ -15,8 +15,13 @@
 #include "pxr/base/gf/matrix4d.h"
 #include "pxr/base/gf/rect2i.h"
 
-#include <embree3/rtcore.h>
-#include <embree3/rtcore_ray.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+    #include <embree4/rtcore_ray.h>
+#else
+    #include <embree3/rtcore.h>
+    #include <embree3/rtcore_ray.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
 
 #include <random>
 #include <atomic>
diff --git a/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp b/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
index 02c2ca69f8..45370dfed0 100644
--- a/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
+++ b/pxr/imaging/plugin/hdEmbree/testenv/testHdEmbree.cpp
@@ -23,7 +23,12 @@
 
 #include "pxr/base/tf/errorMark.h"
 
-#include <embree3/rtcore.h>
+#if defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+    #include <embree4/rtcore.h>
+#else
+    #include <embree3/rtcore.h>
+#endif // defined(PXR_EMBREE_MAJOR_VERSION) && PXR_EMBREE_MAJOR_VERSION >= 4
+
 #include <iostream>
 
 PXR_NAMESPACE_USING_DIRECTIVE

From edfa4698ac06cc700a948773cc55172f21278118 Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Wed, 24 Jul 2024 10:07:44 -0400
Subject: [PATCH 4/6] build_usd.py: update Embree URLs to reflect new home in
 the RenderKit GitHub organization

---
 build_scripts/build_usd.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py
index b99fc2af95..b70fcf5bdd 100644
--- a/build_scripts/build_usd.py
+++ b/build_scripts/build_usd.py
@@ -1602,9 +1602,9 @@ def InstallMaterialX(context, force, buildArgs):
 # For MacOS we use version 3.13.3 to include a fix from Intel
 # to build on Apple Silicon.
 if MacOS():
-    EMBREE_URL = "https://github.com/embree/embree/archive/v3.13.3.zip"
+    EMBREE_URL = "https://github.com/RenderKit/embree/archive/v3.13.3.zip"
 else:
-    EMBREE_URL = "https://github.com/embree/embree/archive/v3.2.2.zip"
+    EMBREE_URL = "https://github.com/RenderKit/embree/archive/v3.2.2.zip"
 
 def InstallEmbree(context, force, buildArgs):
     with CurrentWorkingDirectory(DownloadURL(EMBREE_URL, context, force)):

From 459b102b9da9f308cedd2d76fabeb67c6a583ba7 Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Thu, 23 Feb 2023 12:25:24 -0700
Subject: [PATCH 5/6] build_usd.py: add an option to choose Embree 3 or Embree
 4

The new --embree-major-version option can be given to build_usd.py to select
between Embree 3 or Embree 4. By default, Embree 3 is still used, preserving
the existing behavior.
---
 build_scripts/build_usd.py | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py
index b70fcf5bdd..2c918b6493 100644
--- a/build_scripts/build_usd.py
+++ b/build_scripts/build_usd.py
@@ -1599,14 +1599,19 @@ def InstallMaterialX(context, force, buildArgs):
 
 ############################################################
 # Embree
-# For MacOS we use version 3.13.3 to include a fix from Intel
-# to build on Apple Silicon.
-if MacOS():
-    EMBREE_URL = "https://github.com/RenderKit/embree/archive/v3.13.3.zip"
-else:
-    EMBREE_URL = "https://github.com/RenderKit/embree/archive/v3.2.2.zip"
+
+EMBREE_DEFAULT_MAJOR_VERSION = 3
 
 def InstallEmbree(context, force, buildArgs):
+    if context.embreeMajorVersion >= 4:
+        EMBREE_URL = "https://github.com/RenderKit/embree/archive/refs/tags/v4.4.0.zip"
+    elif MacOS():
+        # For MacOS we use version 3.13.3 to include a fix from Intel
+        # to build on Apple Silicon.
+        EMBREE_URL = "https://github.com/RenderKit/embree/archive/refs/tags/v3.13.3.zip"
+    else:
+        EMBREE_URL = "https://github.com/RenderKit/embree/archive/refs/tags/v3.2.2.zip"
+
     with CurrentWorkingDirectory(DownloadURL(EMBREE_URL, context, force)):
         extraArgs = [
             '-DTBB_ROOT="{instDir}"'.format(instDir=context.instDir),
@@ -1623,7 +1628,9 @@ def InstallEmbree(context, force, buildArgs):
 
         RunCMake(context, force, extraArgs)
 
-EMBREE = Dependency("Embree", InstallEmbree, "include/embree3/rtcore.h")
+EMBREE = Dependency("Embree", InstallEmbree,
+                    "include/embree3/rtcore.h",
+                    "include/embree4/rtcore.h")
 
 ############################################################
 # AnimX
@@ -2152,6 +2159,12 @@ def InstallUSD(context, force, buildArgs):
                       help="Build Embree sample imaging plugin")
 subgroup.add_argument("--no-embree", dest="build_embree", action="store_false",
                       help="Do not build Embree sample imaging plugin (default)")
+group.add_argument("--embree-major-version",
+                   default=EMBREE_DEFAULT_MAJOR_VERSION, type=int,
+                   choices=[3, 4],
+                   help=(
+                       "The major version of Embree to build "
+                       "(default: {})").format(EMBREE_DEFAULT_MAJOR_VERSION))
 subgroup = group.add_mutually_exclusive_group()
 subgroup.add_argument("--prman", dest="build_prman", action="store_true",
                       default=False,
@@ -2379,6 +2392,7 @@ def __init__(self, args):
 
         # - Imaging plugins
         self.buildEmbree = self.buildImaging and args.build_embree
+        self.embreeMajorVersion = args.embree_major_version
         self.buildPrman = self.buildImaging and args.build_prman
         self.prmanLocation = (os.path.abspath(args.prman_location)
                                if args.prman_location else None)                               
@@ -2696,6 +2710,7 @@ def _JoinVersion(v):
       OpenImageIO support:      {buildOIIO} 
       OpenColorIO support:      {buildOCIO} 
       Embree support:           {buildEmbree}
+        Embree major version:   {embreeMajorVersion}
       PRMan support:            {buildPrman}
       Vulkan support:           {enableVulkan}
     UsdImaging                  {buildUsdImaging}
@@ -2762,6 +2777,8 @@ def FormatBuildArguments(buildArgs):
     buildOIIO=("On" if context.buildOIIO else "Off"),
     buildOCIO=("On" if context.buildOCIO else "Off"),
     buildEmbree=("On" if context.buildEmbree else "Off"),
+    embreeMajorVersion=(context.embreeMajorVersion if context.buildEmbree
+                        else "N/A"),
     buildPrman=("On" if context.buildPrman else "Off"),
     buildUsdImaging=("On" if context.buildUsdImaging else "Off"),
     buildUsdview=("On" if context.buildUsdview else "Off"),

From 560c88f5d4775a6cd83d4407d1fff863472a988f Mon Sep 17 00:00:00 2001
From: Matt Johnson <matt.johnson@epicgames.com>
Date: Wed, 24 Jul 2024 10:17:27 -0400
Subject: [PATCH 6/6] build_usd.py: allow oneTBB and Embree to be used together
 when Embree 4.x or later is selected

---
 build_scripts/build_usd.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py
index 2c918b6493..61902abe68 100644
--- a/build_scripts/build_usd.py
+++ b/build_scripts/build_usd.py
@@ -2513,9 +2513,10 @@ def ForceBuildDependency(self, dep):
     PrintError("Draco plugin can not be enabled for monolithic build on Windows")
     sys.exit(1)
 
-# The versions of Embree we currently support do not support oneTBB.
-if context.buildOneTBB and context.buildEmbree:
-    PrintError("Embree support cannot be enabled when building against oneTBB")
+# When building with both oneTBB and Embree, a 4.x version of Embree must be
+# used.
+if context.buildOneTBB and (context.buildEmbree and context.embreeMajorVersion < 4):
+    PrintError("Embree 4.x or later must be selected when building against oneTBB")
     sys.exit(1)
 
 # Windows ARM64 requires oneTBB. Since oneTBB is a non-standard option for the
