[Bf-blender-cvs] [08e719910bf] cycles_hydra: Cycles: Add Hydra render delegate

Patrick Mours noreply at git.blender.org
Tue Mar 22 14:13:36 CET 2022


Commit: 08e719910bf2065ef0603cba8cc43ea236b2d090
Author: Patrick Mours
Date:   Mon Mar 21 10:58:51 2022 +0100
Branches: cycles_hydra
https://developer.blender.org/rB08e719910bf2065ef0603cba8cc43ea236b2d090

Cycles: Add Hydra render delegate

This patch adds a [Hydra](https://graphics.pixar.com/usd/release/glossary.html#usdglossary-hydra) render delegate to Cycles, allowing Cycles to be used for rendering in applications that provide a Hydra viewport (e.g. USDView or NVIDIA Omniverse Kit). The implementation was written from scratch against Cycles X, for integration into the Blender repository to make it possible to continue developing it in step with the rest of Cycles. For this purpose it follows the style of the rest of the [...]

Supported features:
- CPU/CUDA/OptiX/HIP/Metal support
- Camera Settings
- Render Settings (automatically queried from Cycles via node type system)
- Basic AOVs (color, depth, normal, primId, instanceId)
- Lights (Disk, Distant, Dome, Rect, Sphere)
- Meshes
- Geom Subsets
- Subdivision Surfaces (using native Cycles support)
- Custom Primvars (converted to Cycles attributes)
- Cycles Materials (can be exported to USD using the [universal-scene-description branch of Blender](https://developer.blender.org/diffusion/B/history/universal-scene-description/))
- USD Preview Surface Materials
- Curves
- Point Clouds
- OpenVDB Volumes

Still missing features:
- Motion Blur
- Custom AOVs
- ...

Since Hydra render delegates need to be built against the exact USD version and other dependencies as the target application is using, this is intended to be built separate from Blender (`WITH_BLENDER=0` CMake option) and with support for library versions different from what Blender is using. As such the CMake build scripts for Windows had to be modified slightly, so that the Cycles Hydra render delegate can e.g. be built with MSVC 2017 again even though Blender requires MSVC 2019 now, an [...]

This also includes an optimization for Hydra viewports that display the result using OpenGL, in which case the texture can be kept entirely on the GPU (see display_driver.cpp). Unfortunately this is a bit difficult since Hydra doesn't give any control over the OpenGL context created by an application, so the only way to make it available to Cycles (which is rendering on a separate thread) without disturbing the target application is to create a second OpenGL context that is sharing resour [...]

---

**To build:**

1. [Set up a Blender build environment](https://wiki.blender.org/wiki/Building_Blender) as usual but download and apply this patch to the Git repository (Download Raw Diff on the right via `Save Link As` and then run `git apply patch.diff` with the downloaded file in your local repository after syncing to latest master branch).
2. Set these CMake variables:
```
WITH_BLENDER=0
WITH_CYCLES_HYDRA_RENDER_DELEGATE=1
USD_INCLUDE_DIRS=<path to your USD build>/include
USD_LIBRARY_DIR=<path to your USD build>/lib
USD_LIBRARY_PREFIX=<optional, if e.g. USD libs are called "usd_hd.lib", set to "usd_">
```
3. Continue following the usual Blender build instructions. After building the INSTALL target, the output directory contains the `hdCycles` shared library and associated resource files which can be loaded as a USD plugin.

**To execute:**

4. Copy `hdCycles.dll`/`hdCycles.a` and the `hdCycles` directory from the output directory to the USD plugin directory of the target application, or point a `PXR_PLUGINPATH_NAME` environment variable to the output directory.
5. Launch the target application, it should now automatically detect the Cycles Hydra render delegate.

Differential Revision: https://developer.blender.org/D14398

===================================================================

M	CMakeLists.txt
M	build_files/cmake/Modules/FindUSD.cmake
M	build_files/cmake/macros.cmake
M	build_files/cmake/platform/platform_win32.cmake
M	intern/cycles/CMakeLists.txt
M	intern/cycles/device/CMakeLists.txt
A	intern/cycles/hydra/CMakeLists.txt
A	intern/cycles/hydra/attribute.cpp
A	intern/cycles/hydra/attribute.h
A	intern/cycles/hydra/camera.cpp
A	intern/cycles/hydra/camera.h
A	intern/cycles/hydra/config.h
A	intern/cycles/hydra/curves.cpp
A	intern/cycles/hydra/curves.h
A	intern/cycles/hydra/display_driver.cpp
A	intern/cycles/hydra/display_driver.h
A	intern/cycles/hydra/field.cpp
A	intern/cycles/hydra/field.h
A	intern/cycles/hydra/geometry.h
A	intern/cycles/hydra/geometry.inl
A	intern/cycles/hydra/instancer.cpp
A	intern/cycles/hydra/instancer.h
A	intern/cycles/hydra/light.cpp
A	intern/cycles/hydra/light.h
A	intern/cycles/hydra/material.cpp
A	intern/cycles/hydra/material.h
A	intern/cycles/hydra/mesh.cpp
A	intern/cycles/hydra/mesh.h
A	intern/cycles/hydra/node_util.cpp
A	intern/cycles/hydra/node_util.h
A	intern/cycles/hydra/output_driver.cpp
A	intern/cycles/hydra/output_driver.h
A	intern/cycles/hydra/plugInfo.json
A	intern/cycles/hydra/plugin.cpp
A	intern/cycles/hydra/plugin.h
A	intern/cycles/hydra/pointcloud.cpp
A	intern/cycles/hydra/pointcloud.h
A	intern/cycles/hydra/render_buffer.cpp
A	intern/cycles/hydra/render_buffer.h
A	intern/cycles/hydra/render_delegate.cpp
A	intern/cycles/hydra/render_delegate.h
A	intern/cycles/hydra/render_pass.cpp
A	intern/cycles/hydra/render_pass.h
A	intern/cycles/hydra/resources/plugInfo.json
A	intern/cycles/hydra/session.cpp
A	intern/cycles/hydra/session.h
A	intern/cycles/hydra/volume.cpp
A	intern/cycles/hydra/volume.h
M	intern/cycles/integrator/render_scheduler.cpp
M	intern/cycles/kernel/svm/vertex_color.h
M	intern/cycles/scene/integrator.cpp
M	intern/cycles/scene/mesh.cpp
M	intern/cycles/scene/mesh.h
M	intern/cycles/session/session.h
M	intern/cycles/util/tbb.h

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04cedcc6722..d6625a3d5b3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -408,6 +408,8 @@ option(WITH_CYCLES_DEBUG             "Build Cycles with options useful for debug
 option(WITH_CYCLES_STANDALONE        "Build Cycles standalone application" OFF)
 option(WITH_CYCLES_STANDALONE_GUI    "Build Cycles standalone with GUI" OFF)
 
+option(WITH_CYCLES_HYDRA_RENDER_DELEGATE "Build Cycles Hydra render delegate" OFF)
+
 option(WITH_CYCLES_DEBUG_NAN         "Build Cycles with additional asserts for detecting NaNs and invalid values" OFF)
 option(WITH_CYCLES_NATIVE_ONLY       "Build Cycles with native kernel only (which fits current CPU, use for development only)" OFF)
 option(WITH_CYCLES_KERNEL_ASAN       "Build Cycles kernels with address sanitizer when WITH_COMPILER_ASAN is on, even if it's very slow" OFF)
@@ -729,9 +731,10 @@ endif()
 #-----------------------------------------------------------------------------
 # Check for conflicting/unsupported configurations
 
-if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE)
+if(NOT WITH_BLENDER AND NOT WITH_CYCLES_STANDALONE AND NOT WITH_CYCLES_HYDRA_RENDER_DELEGATE)
   message(FATAL_ERROR
     "At least one of WITH_BLENDER or WITH_CYCLES_STANDALONE "
+    "or WITH_CYCLES_HYDRA_RENDER_DELEGATE "
     "must be enabled, nothing to do!"
   )
 endif()
@@ -1884,14 +1887,13 @@ if(WITH_BLENDER)
   # source after intern and extern to gather all
   # internal and external library information first, for test linking
   add_subdirectory(source)
-elseif(WITH_CYCLES_STANDALONE)
+elseif(WITH_CYCLES_STANDALONE OR WITH_CYCLES_HYDRA_RENDER_DELEGATE)
   add_subdirectory(intern/glew-mx)
   add_subdirectory(intern/guardedalloc)
   add_subdirectory(intern/libc_compat)
   add_subdirectory(intern/sky)
 
   add_subdirectory(intern/cycles)
-  add_subdirectory(extern/clew)
   if(WITH_CYCLES_LOGGING)
     if(NOT WITH_SYSTEM_GFLAGS)
       add_subdirectory(extern/gflags)
diff --git a/build_files/cmake/Modules/FindUSD.cmake b/build_files/cmake/Modules/FindUSD.cmake
index 840fa2d538f..c8c1f043b63 100644
--- a/build_files/cmake/Modules/FindUSD.cmake
+++ b/build_files/cmake/Modules/FindUSD.cmake
@@ -17,50 +17,60 @@ IF(NOT USD_ROOT_DIR AND NOT $ENV{USD_ROOT_DIR} STREQUAL "")
   SET(USD_ROOT_DIR $ENV{USD_ROOT_DIR})
 ENDIF()
 
-SET(_usd_SEARCH_DIRS
-  ${USD_ROOT_DIR}
-  /opt/lib/usd
-)
+find_package(pxr REQUIRED OFF)
 
-FIND_PATH(USD_INCLUDE_DIR
-  NAMES
-    pxr/usd/usd/api.h
-  HINTS
-    ${_usd_SEARCH_DIRS}
-  PATH_SUFFIXES
-    include
-  DOC "Universal Scene Description (USD) header files"
-)
+if (NOT pxr_FOUND)
 
-FIND_LIBRARY(USD_LIBRARY
-  NAMES
-    usd_m usd_ms
-  NAMES_PER_DIR
-  HINTS
-    ${_usd_SEARCH_DIRS}
-  PATH_SUFFIXES
-    lib64 lib lib/static
-  DOC "Universal Scene Description (USD) monolithic library"
-)
+  SET(_usd_SEARCH_DIRS
+    ${USD_ROOT_DIR}
+    /opt/lib/usd
+  )
 
-IF(${USD_LIBRARY_NOTFOUND})
-  set(USD_FOUND FALSE)
-ELSE()
-  # handle the QUIETLY and REQUIRED arguments and set USD_FOUND to TRUE if
-  # all listed variables are TRUE
-  INCLUDE(FindPackageHandleStandardArgs)
-  FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR)
+  FIND_PATH(USD_INCLUDE_DIR
+    NAMES
+      pxr/usd/usd/api.h
+    HINTS
+      ${_usd_SEARCH_DIRS}
+    PATH_SUFFIXES
+      include
+    DOC "Universal Scene Description (USD) header files"
+  )
+
+  FIND_LIBRARY(USD_LIBRARY
+    NAMES
+      usd_m usd_ms
+    NAMES_PER_DIR
+    HINTS
+      ${_usd_SEARCH_DIRS}
+    PATH_SUFFIXES
+      lib64 lib lib/static
+    DOC "Universal Scene Description (USD) monolithic library"
+  )
 
-  IF(USD_FOUND)
-    get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)
-    SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR})
-    set(USD_LIBRARIES ${USD_LIBRARY})
+  IF(${USD_LIBRARY_NOTFOUND})
+    set(USD_FOUND FALSE)
+  ELSE()
+    # handle the QUIETLY and REQUIRED arguments and set USD_FOUND to TRUE if
+    # all listed variables are TRUE
+    INCLUDE(FindPackageHandleStandardArgs)
+    FIND_PACKAGE_HANDLE_STANDARD_ARGS(USD DEFAULT_MSG USD_LIBRARY USD_INCLUDE_DIR)
+
+    IF(USD_FOUND)
+      get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)
+      SET(USD_INCLUDE_DIRS ${USD_INCLUDE_DIR})
+      set(USD_LIBRARIES ${USD_LIBRARY})
+    ENDIF()
   ENDIF()
+
+  UNSET(_usd_SEARCH_DIRS)
+
+ELSE()
+    SET(USD_FOUND ON)
+    SET(USD_INCLUDE_DIR ${PXR_INCLUDE_DIRS})
+    SET(USD_LIBRARIES ${PXR_LIBRARIES})
 ENDIF()
 
 MARK_AS_ADVANCED(
   USD_INCLUDE_DIR
   USD_LIBRARY_DIR
 )
-
-UNSET(_usd_SEARCH_DIRS)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index bf3e56922c9..5508e8f2104 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -879,7 +879,7 @@ function(delayed_install
   destination)
 
   foreach(f ${files})
-    if(IS_ABSOLUTE ${f})
+    if(IS_ABSOLUTE ${f} OR "${base}" STREQUAL "")
       set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${f})
     else()
       set_property(GLOBAL APPEND PROPERTY DELAYED_INSTALL_FILES ${base}/${f})
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index e2e49ca0bcd..ec0c83195e9 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -39,7 +39,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
     set(WITH_WINDOWS_STRIPPED_PDB OFF)
   endif()
 else()
-  if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.28.29921) # MSVC 2019 16.9.16
+  if(WITH_BLENDER AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.28.29921) # MSVC 2019 16.9.16
     message(FATAL_ERROR "Compiler is unsupported, MSVC 2019 16.9.16 or newer is required for building blender.")
   endif()
 endif()
@@ -252,6 +252,12 @@ if(NOT DEFINED LIBDIR)
   elseif(MSVC_VERSION GREATER 1919)
     message(STATUS "Visual Studio 2019 detected.")
     set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
+  elseif(MSVC_VERSION GREATER 1909)
+    message(STATUS "Visual Studio 2017 detected.")
+    set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
+  elseif(MSVC_VERSION EQUAL 1900)
+    message(STATUS "Visual Studio 2015 detected.")
+    set(LIBDIR ${CMAKE_SOURCE_DIR}/../lib/${LIBDIR_BASE}_vc15)
   endif()
 else()
   message(STATUS "Using pre-compiled LIBDIR: ${LIBDIR}")
@@ -403,10 +409,10 @@ if(WITH_CODEC_FFMPEG)
 endif()
 
 if(WITH_IMAGE_OPENEXR)
-  set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
-  set(OPENEXR_VERSION "2.1")
   windows_find_package(OPENEXR REQUIRED)
   if(NOT OPENEXR_FOUND)
+    set(OPENEXR_ROOT_DIR ${LIBDIR}/openexr)
+    set(OPENEXR_VERSION "2.1")
     warn_hardcoded_paths(OpenEXR)
     set(OPENEXR ${LIBDIR}/openexr)
     set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include)
@@ -462,15 +468,17 @@ if(WITH_PYTHON)
 endif()
 
 if(WITH_BOOST)
-  if(WITH_CYCLES AND WITH_CYCLES_OSL)
+  if(WITH_CYCLES_OSL)
     set(boost_extra_libs wave)
   endif()
-  if(WITH_INTERNATIONAL)
-    list(APPEND boost_extra_libs locale)
+  if(WITH_BLENDER)
+    if(WITH_INTERNATIONAL)
+      list(APPEND boost_extra_libs locale)
+    endif()
+    set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
+    set(Boost_USE_MULTITHREADED ON) # suffix -mt
+    set(Boost_USE_STATIC_LIBS ON) # suffix -s
   endif()
-  set(Boost_USE_STATIC_RUNTIME ON) # prefix lib
-  set(Boost_USE_MULTITHREADED ON) # suffix -mt
-  set(Boost_USE_STATIC_LIBS ON) # suffix -s
   if(WITH_WINDOWS_FIND_MODULES)
     find_package(Boost COMPONENTS date_time filesystem thread regex system ${boost_extra_libs})
   endif()
@@ -505,7 +513,7 @@ if(WITH_BOOST)
       debug ${BOOST_LIBPATH}/libboost_thread-${BOOST_DEBUG_POSTFIX}
       debug ${BOOST_LIBPATH}/libboost_chrono-${BOOST_DEBUG_POSTFIX}
     )
-    if(WITH_CYCLES AND WITH_CYCLES_OSL)
+    if(WITH_CYCLES_OSL)
       set(BOOST_LIBRARIES ${BOOST_LIBRARIES}
         optimized ${BOOST_LIBPATH}/libboost_wave-${BOOST_POSTFIX}
         debug ${BOOST_LIBPATH}/libboost_wave-${BOOST_DEBUG_POSTFIX})
@@ -624,21 +632,23 @@ if(WITH_IMAGE_OPENJPEG)
 endif()
 
 if(WITH_OPENSUBDIV)
-  set(OPENSUBDIV_INCLUDE_DIRS ${LIBDIR}/opensubdiv/include)
-  set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
-  set(OPENSUBDIV_LIBRARIES
-    optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
-    optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
-    debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
-    debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
-  )
-  set(OPENSUBDIV_HAS_OPENMP TRUE)
-  set(OPENSUBDIV_HAS_TBB FALSE)
-  set(OPENSUBDIV_HAS_OPENCL TRUE)
-  set(OPENSUBDIV_HAS_CUDA FALSE)
-  set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
-  set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
   windows_find_package(OpenSubdiv)
+  if (NOT OpenSubdiv_FOUND)
+    set(OPENSUBDIV_INCLUDE_DIRS ${LIBDIR}/opensubdiv/include)
+    set(OPENSUBDIV_LIBPATH ${LIBDIR}/opensubdiv/lib)
+    set(OPENSUBDIV_LIBRARIES
+      optimized ${OPENSUBDIV_LIBPATH}/osdCPU.lib
+      optimized ${OPENSUBDIV_LIBPATH}/osdGPU.lib
+      debug ${OPENSUBDIV_LIBPATH}/osdCPU_d.lib
+      debug ${OPENSUBDIV_LIBPATH}/osdGPU_d.lib
+    )
+    set(OPENSUBDIV_HAS_OPENMP TRUE)
+    set(OPENSUBDIV_HAS_TBB FALSE)
+    set(OPENSUBDIV_HAS_OPENCL TRUE)
+    set(OPENSUBDIV_HAS_CUDA FALSE)
+    set(OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK TRUE)
+    set(OPENSUBDIV_HAS_GLSL_COMPUTE TRUE)
+  endif()
 endif()
 
 if(WITH_SDL)
@@ -659,12 +669,15 @@ if(WITH_SYSTEM_AUDASPACE)
 endif()
 
 if(WITH_TBB)
-  set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
-  set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
-  set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
-  if(WITH_TBB_MALLOC_PROXY)
-    set(TBB_MALLOC_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbbmalloc.lib debug ${LIBDIR}/tbb/lib/tbbmalloc_debug.lib)
-    add_definitions(-DWITH_TBB_MALLOC)
+  windows_find_package(TBB)
+  if (NOT TBB_FOUND)
+    set(TBB_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbb.lib debug ${LIBDIR}/tbb/lib/tbb_debug.lib)
+    set(TBB_INCLUDE_DIR ${LIBDIR}/tbb/include)
+    set(TBB_INCLUDE_DIRS ${TBB_INCLUDE_DIR})
+    if(WITH_TBB_MALLOC_PROXY)
+      set(TBB_MALLOC_LIBRARIES optimized ${LIBDIR}/tbb/lib/tbbmalloc.lib debug ${LIBDIR}/tbb/lib/tbbmalloc_debug.lib)
+      add_definitions(-DWITH_TBB_MALLOC)
+    endif()
   endif()
 endif()
 
@@ -693,7 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list