[Bf-blender-cvs] [3df90de6c22] master: Cycles: Add NanoVDB support for rendering volumes

Patrick Mours noreply at git.blender.org
Mon Oct 5 15:04:45 CEST 2020


Commit: 3df90de6c2268bef91d3754f71c7404cfbeeac90
Author: Patrick Mours
Date:   Fri Oct 2 17:40:28 2020 +0200
Branches: master
https://developer.blender.org/rB3df90de6c2268bef91d3754f71c7404cfbeeac90

Cycles: Add NanoVDB support for rendering volumes

NanoVDB is a platform-independent sparse volume data structure that makes it possible to
use OpenVDB volumes on the GPU. This patch uses it for volume rendering in Cycles,
replacing the previous usage of dense 3D textures.

Since it has a big impact on memory usage and performance and changes the OpenVDB
branch used for the rest of Blender as well, this is not enabled by default yet, which will
happen only after 2.82 was branched off. To enable it, build both dependencies and Blender
itself with the "WITH_NANOVDB" CMake option.

Reviewed By: brecht

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

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

M	CMakeLists.txt
M	build_files/build_environment/CMakeLists.txt
M	build_files/build_environment/cmake/harvest.cmake
M	build_files/build_environment/cmake/openvdb.cmake
M	build_files/build_environment/cmake/options.cmake
M	build_files/build_environment/cmake/versions.cmake
A	build_files/build_environment/patches/openvdb_nanovdb.diff
A	build_files/cmake/Modules/FindNanoVDB.cmake
M	build_files/cmake/platform/platform_apple.cmake
M	build_files/cmake/platform/platform_unix.cmake
M	build_files/cmake/platform/platform_win32.cmake
M	intern/cycles/CMakeLists.txt
M	intern/cycles/device/cuda/device_cuda_impl.cpp
M	intern/cycles/device/device_memory.cpp
M	intern/cycles/device/opencl/device_opencl_impl.cpp
M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/kernel_compat_optix.h
M	intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
M	intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
M	intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
M	intern/cycles/render/CMakeLists.txt
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/image_oiio.cpp
M	intern/cycles/render/image_vdb.cpp
M	intern/cycles/render/image_vdb.h
M	intern/cycles/util/util_texture.h

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a7353d0b914..741472128a3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -203,6 +203,7 @@ option(WITH_OPENVDB       "Enable features relying on OpenVDB" ON)
 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" ON)
 option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF)
 mark_as_advanced(WITH_OPENVDB_3_ABI_COMPATIBLE)
+option(WITH_NANOVDB       "Enable usage of NanoVDB data structure for accelerated rendering on the GPU" OFF)
 
 # GHOST Windowing Library Options
 option(WITH_GHOST_DEBUG   "Enable debugging output for the GHOST library" OFF)
@@ -704,6 +705,9 @@ set_and_warn_dependency(WITH_TBB WITH_OPENIMAGEDENOISE  OFF)
 set_and_warn_dependency(WITH_TBB WITH_OPENVDB           OFF)
 set_and_warn_dependency(WITH_TBB WITH_MOD_FLUID         OFF)
 
+# NanoVDB requires OpenVDB to convert the data structure
+set_and_warn_dependency(WITH_OPENVDB WITH_NANOVDB       OFF)
+
 # OpenVDB uses 'half' type from OpenEXR & fails to link without OpenEXR enabled.
 set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENVDB OFF)
 
diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt
index fa2b39fccd8..59c15a03119 100644
--- a/build_files/build_environment/CMakeLists.txt
+++ b/build_files/build_environment/CMakeLists.txt
@@ -117,7 +117,6 @@ if(WIN32)
   include(cmake/yamlcpp.cmake)
   # LCMS is an OCIO dep, but only if you build the apps, leaving it here for convenience
   # include(cmake/lcms.cmake)
-
 endif()
 
 if(NOT WIN32 OR ENABLE_MINGW64)
diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 93e17f33284..1fb56c4d568 100644
--- a/build_files/build_environment/cmake/harvest.cmake
+++ b/build_files/build_environment/cmake/harvest.cmake
@@ -26,6 +26,7 @@ endif()
 message("HARVEST_TARGET = ${HARVEST_TARGET}")
 
 if(WIN32)
+
 if(BUILD_MODE STREQUAL Release)
   add_custom_target(Harvest_Release_Results
     COMMAND # jpeg rename libfile + copy include
@@ -145,6 +146,9 @@ harvest(openjpeg/lib openjpeg/lib "*.a")
 harvest(opensubdiv/include opensubdiv/include "*.h")
 harvest(opensubdiv/lib opensubdiv/lib "*.a")
 harvest(openvdb/include/openvdb openvdb/include/openvdb "*.h")
+if(WITH_NANOVDB)
+  harvest(openvdb/nanovdb nanovdb/include/nanovdb "*.h")
+endif()
 harvest(openvdb/lib openvdb/lib "*.a")
 harvest(xr_openxr_sdk/include/openxr xr_openxr_sdk/include/openxr "*.h")
 harvest(xr_openxr_sdk/lib xr_openxr_sdk/lib "*.a")
diff --git a/build_files/build_environment/cmake/openvdb.cmake b/build_files/build_environment/cmake/openvdb.cmake
index f27d3f408a8..07d0297d5aa 100644
--- a/build_files/build_environment/cmake/openvdb.cmake
+++ b/build_files/build_environment/cmake/openvdb.cmake
@@ -54,6 +54,20 @@ set(OPENVDB_EXTRA_ARGS
   -DOPENVDB_CORE_STATIC=${OPENVDB_STATIC}
   -DOPENVDB_BUILD_BINARIES=Off
   -DCMAKE_DEBUG_POSTFIX=_d
+   # NanoVDB is header-only, so only need the install target
+  -DNANOVDB_BUILD_UNITTESTS=OFF
+  -DNANOVDB_BUILD_EXAMPLES=OFF
+  -DNANOVDB_BUILD_BENCHMARK=OFF
+  -DNANOVDB_BUILD_DOCS=OFF
+  -DNANOVDB_BUILD_TOOLS=OFF
+  -DNANOVDB_CUDA_KEEP_PTX=OFF
+  -DNANOVDB_USE_OPENGL=OFF
+  -DNANOVDB_USE_OPENGL=OFF
+  -DNANOVDB_USE_CUDA=OFF
+  -DNANOVDB_USE_TBB=OFF
+  -DNANOVDB_USE_OPTIX=OFF
+  -DNANOVDB_USE_OPENVDB=OFF
+  -DNANOVDB_ALLOW_FETCHCONTENT=OFF
 )
 
 if(WIN32)
@@ -74,12 +88,18 @@ else()
   )
 endif()
 
+if(WITH_NANOVDB)
+  set(OPENVDB_PATCH_FILE openvdb_nanovdb.diff)
+else()
+  set(OPENVDB_PATCH_FILE openvdb.diff)
+endif()
+
 ExternalProject_Add(openvdb
   URL ${OPENVDB_URI}
   DOWNLOAD_DIR ${DOWNLOAD_DIR}
   URL_HASH MD5=${OPENVDB_HASH}
   PREFIX ${BUILD_DIR}/openvdb
-  PATCH_COMMAND ${PATCH_CMD} -p 1 -d ${BUILD_DIR}/openvdb/src/openvdb < ${PATCH_DIR}/openvdb.diff
+  PATCH_COMMAND ${PATCH_CMD} -p 1 -d ${BUILD_DIR}/openvdb/src/openvdb < ${PATCH_DIR}/${OPENVDB_PATCH_FILE}
   CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/openvdb ${DEFAULT_CMAKE_FLAGS} ${OPENVDB_EXTRA_ARGS}
   INSTALL_DIR ${LIBDIR}/openvdb
 )
@@ -96,11 +116,17 @@ add_dependencies(
 if(WIN32)
   if(BUILD_MODE STREQUAL Release)
     ExternalProject_Add_Step(openvdb after_install
-      COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/openvdb/include ${HARVEST_TARGET}/openvdb/include
+      COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/openvdb/include/openvdb ${HARVEST_TARGET}/openvdb/include/openvdb
       COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/openvdb/lib/openvdb.lib ${HARVEST_TARGET}/openvdb/lib/openvdb.lib
       COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR}/openvdb/bin/openvdb.dll ${HARVEST_TARGET}/openvdb/bin/openvdb.dll
       DEPENDEES install
     )
+    if(WITH_NANOVDB)
+      ExternalProject_Add_Step(openvdb nanovdb_install
+        COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/openvdb/nanovdb ${HARVEST_TARGET}/nanovdb/include/nanovdb
+        DEPENDEES after_install
+      )
+    endif()
   endif()
   if(BUILD_MODE STREQUAL Debug)
     ExternalProject_Add_Step(openvdb after_install
diff --git a/build_files/build_environment/cmake/options.cmake b/build_files/build_environment/cmake/options.cmake
index 29e2ffc7ed8..d6b5762ccbc 100644
--- a/build_files/build_environment/cmake/options.cmake
+++ b/build_files/build_environment/cmake/options.cmake
@@ -21,6 +21,7 @@ if(WIN32)
 endif()
 option(WITH_WEBP "Enable building of oiio with webp support" OFF)
 option(WITH_BOOST_PYTHON "Enable building of boost with python support" OFF)
+option(WITH_NANOVDB "Enable building of OpenVDB with NanoVDB included" OFF)
 set(MAKE_THREADS 1 CACHE STRING "Number of threads to run make with")
 
 if(NOT BUILD_MODE)
diff --git a/build_files/build_environment/cmake/versions.cmake b/build_files/build_environment/cmake/versions.cmake
index 48e37c93d00..244ca6dd49f 100644
--- a/build_files/build_environment/cmake/versions.cmake
+++ b/build_files/build_environment/cmake/versions.cmake
@@ -145,9 +145,15 @@ set(TBB_VERSION 2019_U9)
 set(TBB_URI https://github.com/oneapi-src/oneTBB/archive/${TBB_VERSION}.tar.gz)
 set(TBB_HASH 26263622e9187212ec240dcf01b66207)
 
-set(OPENVDB_VERSION 7.0.0)
-set(OPENVDB_URI https://github.com/dreamworksanimation/openvdb/archive/v${OPENVDB_VERSION}.tar.gz)
-set(OPENVDB_HASH fd6c4f168282f7e0e494d290cd531fa8)
+if(WITH_NANOVDB)
+  set(OPENVDB_GIT_UID e62f7a0bf1e27397223c61ddeaaf57edf111b77f)
+  set(OPENVDB_URI https://github.com/AcademySoftwareFoundation/openvdb/archive/${OPENVDB_GIT_UID}.tar.gz)
+  set(OPENVDB_HASH 90919510bc6ccd630fedc56f748cb199)
+else()
+  set(OPENVDB_VERSION 7.0.0)
+  set(OPENVDB_URI https://github.com/AcademySoftwareFoundation/openvdb/archive/v${OPENVDB_VERSION}.tar.gz)
+  set(OPENVDB_HASH fd6c4f168282f7e0e494d290cd531fa8)
+endif()
 
 set(IDNA_VERSION 2.9)
 set(CHARDET_VERSION 3.0.4)
diff --git a/build_files/build_environment/patches/openvdb_nanovdb.diff b/build_files/build_environment/patches/openvdb_nanovdb.diff
new file mode 100644
index 00000000000..50984e91f37
--- /dev/null
+++ b/build_files/build_environment/patches/openvdb_nanovdb.diff
@@ -0,0 +1,135 @@
+diff -Naur orig/cmake/FindIlmBase.cmake openvdb/cmake/FindIlmBase.cmake
+--- orig/cmake/FindIlmBase.cmake	2019-12-06 12:11:33 -0700
++++ openvdb/cmake/FindIlmBase.cmake	2020-08-12 12:48:44 -0600
+@@ -217,6 +217,8 @@
+     set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
+   endif()
+   list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "${_IlmBase_Version_Suffix}.lib")
++  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "_s.lib")
++  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "_s_d.lib")
+ else()
+   if(ILMBASE_USE_STATIC_LIBS)
+     set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+diff -Naur orig/cmake/FindOpenEXR.cmake openvdb/cmake/FindOpenEXR.cmake
+--- orig/cmake/FindOpenEXR.cmake	2019-12-06 12:11:33 -0700
++++ openvdb/cmake/FindOpenEXR.cmake	2020-08-12 12:48:44 -0600
+@@ -210,6 +210,8 @@
+     set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
+   endif()
+   list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "${_OpenEXR_Version_Suffix}.lib")
++  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "_s.lib")
++  list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES "_s_d.lib")
+ else()
+   if(OPENEXR_USE_STATIC_LIBS)
+     set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+diff -Naur orig/openvdb/openvdb/CMakeLists.txt openvdb/openvdb/openvdb/CMakeLists.txt
+--- orig/openvdb/openvdb/CMakeLists.txt	2019-12-06 12:11:33 -0700
++++ openvdb/openvdb/openvdb/CMakeLists.txt	2020-08-12 14:12:26 -0600
+@@ -105,7 +105,9 @@
+   #        http://boost.2283326.n4.nabble.com/CMake-config-scripts-broken-in-1-70-td4708957.html
+   #        https://github.com/boostorg/boost_install/commit/160c7cb2b2c720e74463865ef0454d4c4cd9ae7c
+   set(BUILD_SHARED_LIBS ON)
+-  set(Boost_USE_STATIC_LIBS OFF)
++  if(NOT WIN32) # blender links boost statically on windows
++    set(Boost_USE_STATIC_LIBS OFF)
++  endif()
+ endif()
+ 
+ find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS iostreams system)
+@@ -193,6 +195,7 @@
+   if(OPENVDB_DISABLE_BOOST_IMPLICIT_LINKING)
+     add_definitions(-DBOOST_ALL_NO_LIB)
+   endif()
++  add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE -DOPENVDB_OPENEXR_STATICLIB)
+ endif()
+ 
+ # @todo Should be target definitions
+@@ -383,7 +386,12 @@
+ # imported targets.
+ 
+ if(OPENVDB_CORE_SHARED)
+-  add_library(openvdb_shared SHARED ${OPENVDB_LIBRARY_SOURCE_FILES})
++  if(WIN32)
++    configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
++    add_library(openvdb_shared SHARED ${OPENVDB_LIBRARY_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
++  else()
++    add_library(openvdb_shared SHARED ${OPENVDB_LIBRARY_SOURCE_FILES})
++  endif()
+ endif()
+ 
+ if(OPENVDB_CORE_STATIC)
+diff -Naur orig/openvdb/openvdb/version.rc.in openvdb/openvdb/openvdb/version.rc.in
+--- orig/openvdb/openvdb/version.rc.in	1969-12-31 17:00:00 -0700
++++ openvdb/openvdb/openvdb/version.rc.in	2020-08-12 14:15:01 -0600
+@@ -0,0 +1,48 @@
++#include <winver.h>
++
++#define VER_FILEVERSION             @OpenVDB_MAJOR_VERSION@, at OpenVDB_MINOR_VERSION@, at OpenVDB_PATCH_VERSION@,0
++#define VER_FILEVERSION_STR         "@OpenVDB_MAJOR_VERSION at .@OpenVDB_MINOR_VERSION at .@OpenVDB_PATCH_VERSION at .0\0"
++
++#define 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list