[Bf-blender-cvs] [2c5531c0a52] master: Cycles: Added Embree as BVH option for CPU renders.

Stefan Werner noreply at git.blender.org
Wed Nov 7 13:04:54 CET 2018


Commit: 2c5531c0a521119a2f5c88b4ba2a67234c537d2b
Author: Stefan Werner
Date:   Wed Nov 7 12:58:12 2018 +0100
Branches: master
https://developer.blender.org/rB2c5531c0a521119a2f5c88b4ba2a67234c537d2b

Cycles: Added Embree as BVH option for CPU renders.

Note that this is turned off by default and must be enabled at build time with the CMake WITH_CYCLES_EMBREE flag.
Embree must be built as a static library with ray masking turned on, the `make deps` scripts have been updated accordingly.
There, Embree is off by default too and must be enabled with the WITH_EMBREE flag.

Using Embree allows for much faster rendering of deformation motion blur while reducing the memory footprint.

TODO: GPU implementation, deduplication of data, leveraging more of Embrees features (e.g. tessellation cache).

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

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

M	CMakeLists.txt
M	build_files/build_environment/CMakeLists.txt
A	build_files/build_environment/cmake/embree.cmake
M	build_files/build_environment/cmake/harvest.cmake
M	build_files/build_environment/cmake/options.cmake
M	build_files/build_environment/cmake/versions.cmake
A	build_files/cmake/Modules/FindEmbree.cmake
M	build_files/cmake/macros.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
A	build_files/cmake/platform/platform_win32_msvc.cmake
M	intern/cycles/CMakeLists.txt
M	intern/cycles/app/CMakeLists.txt
M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_python.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/bvh/CMakeLists.txt
M	intern/cycles/bvh/bvh.cpp
M	intern/cycles/bvh/bvh.h
A	intern/cycles/bvh/bvh_embree.cpp
A	intern/cycles/bvh/bvh_embree.h
M	intern/cycles/bvh/bvh_params.h
M	intern/cycles/cmake/external_libs.cmake
M	intern/cycles/device/device_cpu.cpp
M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/bvh/bvh.h
A	intern/cycles/kernel/bvh/bvh_embree.h
M	intern/cycles/kernel/geom/geom_curve_intersect.h
M	intern/cycles/kernel/geom/geom_object.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/scene.cpp
M	intern/cycles/render/scene.h
M	intern/cycles/util/util_transform.h
M	source/blender/python/intern/CMakeLists.txt

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fc7f3acbbb4..eb8df075380 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -405,6 +405,7 @@ option(WITH_CYCLES					"Enable Cycles Render Engine" ON)
 option(WITH_CYCLES_STANDALONE		"Build Cycles standalone application" OFF)
 option(WITH_CYCLES_STANDALONE_GUI	"Build Cycles standalone with GUI" OFF)
 option(WITH_CYCLES_OSL				"Build Cycles with OSL support" ${_init_CYCLES_OSL})
+option(WITH_CYCLES_EMBREE			"Build Cycles with Embree support" OFF)
 option(WITH_CYCLES_OPENSUBDIV		"Build Cycles with OpenSubdiv support" ${_init_CYCLES_OPENSUBDIV})
 option(WITH_CYCLES_CUDA_BINARIES	"Build Cycles CUDA binaries" OFF)
 option(WITH_CYCLES_CUBIN_COMPILER	"Build cubins with nvrtc based compiler instead of nvcc" OFF)
diff --git a/build_files/build_environment/CMakeLists.txt b/build_files/build_environment/CMakeLists.txt
index 00e486bbb40..8c1d38c0635 100644
--- a/build_files/build_environment/CMakeLists.txt
+++ b/build_files/build_environment/CMakeLists.txt
@@ -97,6 +97,10 @@ if(WITH_WEBP)
 	include(cmake/webp.cmake)
 endif()
 
+if(WITH_EMBREE)
+	include(cmake/embree.cmake)
+endif()
+
 if(WIN32)
 	# HMD branch deps
 	include(cmake/hidapi.cmake)
diff --git a/build_files/build_environment/cmake/embree.cmake b/build_files/build_environment/cmake/embree.cmake
new file mode 100644
index 00000000000..34e5904db5e
--- /dev/null
+++ b/build_files/build_environment/cmake/embree.cmake
@@ -0,0 +1,46 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+# Note the utility apps may use png/tiff/gif system libraries, but the
+# library itself does not depend on them, so should give no problems.
+
+set(EMBREE_EXTRA_ARGS
+	-DEMBREE_ISPC_SUPPORT=OFF
+	-DEMBREE_TUTORIALS=OFF
+	-DEMBREE_STATIC_LIB=ON
+	-DEMBREE_RAY_MASK=ON
+	-DEMBREE_FILTER_FUNCTION=ON
+	-DEMBREE_BACKFACE_CULLING=OFF
+	-DEMBREE_TASKING_SYSTEM=INTERNAL
+	-DEMBREE_MAX_ISA=AVX2
+)
+
+if(WIN32)
+	set(EMBREE_BUILD_DIR ${BUILD_MODE}/)
+else()
+	set(EMBREE_BUILD_DIR)
+endif()
+
+ExternalProject_Add(external_embree
+	URL ${EMBREE_URI}
+	DOWNLOAD_DIR ${DOWNLOAD_DIR}
+	URL_HASH MD5=${EMBREE_HASH}
+	PREFIX ${BUILD_DIR}/embree
+	CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBDIR}/embree ${DEFAULT_CMAKE_FLAGS} ${EMBREE_EXTRA_ARGS}
+	INSTALL_DIR ${LIBDIR}/embree
+)
diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 4ec71bf2ed2..d0d8b4cefb9 100644
--- a/build_files/build_environment/cmake/harvest.cmake
+++ b/build_files/build_environment/cmake/harvest.cmake
@@ -57,7 +57,9 @@ if(BUILD_MODE STREQUAL Release)
 				# hidapi
 				${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/hidapi/ ${HARVEST_TARGET}/hidapi/ &&
 				# webp, straight up copy
-				${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/webp ${HARVEST_TARGET}/webp
+				${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/webp ${HARVEST_TARGET}/webp &&
+				# embree
+				${CMAKE_COMMAND} -E copy_directory ${LIBDIR}/embree ${HARVEST_TARGET}/embree
 		DEPENDS
 	)
 endif()
@@ -191,5 +193,7 @@ harvest(vpx/lib ffmpeg/lib "*.a")
 harvest(webp/lib ffmpeg/lib "*.a")
 harvest(x264/lib ffmpeg/lib "*.a")
 harvest(xvidcore/lib ffmpeg/lib "*.a")
+harvest(embree/include embree/include "*.h")
+harvest(embree/lib embree/lib "*.a")
 
 endif()
diff --git a/build_files/build_environment/cmake/options.cmake b/build_files/build_environment/cmake/options.cmake
index f3125551972..20e9750bed6 100644
--- a/build_files/build_environment/cmake/options.cmake
+++ b/build_files/build_environment/cmake/options.cmake
@@ -20,6 +20,7 @@ if(WIN32)
 	option(ENABLE_MINGW64 "Enable building of ffmpeg/iconv/libsndfile/lapack/fftw3 by installing mingw64" ON)
 endif()
 option(WITH_WEBP "Enable building of oiio with webp support" OFF)
+option(WITH_EMBREE "Enable building of Embree" 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 7bd994c3491..85f59762ef2 100644
--- a/build_files/build_environment/cmake/versions.cmake
+++ b/build_files/build_environment/cmake/versions.cmake
@@ -298,3 +298,7 @@ set(SSL_HASH ebbfc844a8c8cc0ea5dc10b86c9ce97f401837f3fa08c17b2cdadc118253cf99)
 set(SQLITE_VERSION 3.24.0)
 set(SQLITE_URI https://www.sqlite.org/2018/sqlite-src-3240000.zip)
 set(SQLITE_HASH fb558c49ee21a837713c4f1e7e413309aabdd9c7)
+
+set(EMBREE_VERSION 3.2.4)
+set(EMBREE_URI https://github.com/embree/embree/archive/v${EMBREE_VERSION}.zip)
+set(EMBREE_HASH 3d4a1147002ff43939d45140aa9d6fb8)
diff --git a/build_files/cmake/Modules/FindEmbree.cmake b/build_files/cmake/Modules/FindEmbree.cmake
new file mode 100644
index 00000000000..d3ef8c6eb4c
--- /dev/null
+++ b/build_files/cmake/Modules/FindEmbree.cmake
@@ -0,0 +1,108 @@
+# - Find Embree library
+# Find the native Embree includes and library
+# This module defines
+#  EMBREE_INCLUDE_DIRS, where to find rtcore.h, Set when
+#                            EMBREE_INCLUDE_DIR is found.
+#  EMBREE_LIBRARIES, libraries to link against to use Embree.
+#  EMBREE_ROOT_DIR, The base directory to search for Embree.
+#                        This can also be an environment variable.
+#  EMBREEFOUND, If false, do not try to use Embree.
+#
+# also defined, but not for general use are
+#  EMBREE_LIBRARY, where to find the Embree library.
+
+#=============================================================================
+# Copyright 2018 Blender Foundation.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+# If EMBREE_ROOT_DIR was defined in the environment, use it.
+IF(NOT EMBREE_ROOT_DIR AND NOT $ENV{EMBREE_ROOT_DIR} STREQUAL "")
+  SET(EMBREE_ROOT_DIR $ENV{EMBREE_ROOT_DIR})
+ENDIF()
+
+SET(_embree_SEARCH_DIRS
+  ${EMBREE_ROOT_DIR}
+  /usr/local
+  /sw # Fink
+  /opt/local # DarwinPorts
+  /opt/embree
+  /opt/lib/embree
+)
+
+FIND_PATH(EMBREE_INCLUDE_DIR
+  NAMES
+    embree3/rtcore.h
+  HINTS
+    ${_embree_SEARCH_DIRS}
+  PATH_SUFFIXES
+    include
+)
+
+
+SET(_embree_FIND_COMPONENTS
+  embree_avx
+  embree_avx2
+  embree_sse42
+  embree3
+  lexers
+  math
+  simd
+  sys
+  tasking
+)
+
+SET(_embree_LIBRARIES)
+FOREACH(COMPONENT ${_embree_FIND_COMPONENTS})
+  STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+
+  FIND_LIBRARY(EMBREE_${UPPERCOMPONENT}_LIBRARY
+    NAMES
+      ${COMPONENT}
+    HINTS
+      ${_embree_SEARCH_DIRS}
+    PATH_SUFFIXES
+      lib64 lib
+    )
+  LIST(APPEND _embree_LIBRARIES "${EMBREE_${UPPERCOMPONENT}_LIBRARY}")
+ENDFOREACH()
+
+
+FIND_LIBRARY(EMBREE_LIBRARY
+  NAMES
+    libembree3
+  HINTS
+    ${_embree_SEARCH_DIRS}
+  PATH_SUFFIXES
+    lib64 lib
+)
+
+# handle the QUIETLY and REQUIRED arguments and set EMBREE_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(EMBREE DEFAULT_MSG
+    _embree_LIBRARIES EMBREE_INCLUDE_DIR)
+
+IF(EMBREE_FOUND)
+  SET(EMBREE_LIBRARIES ${_embree_LIBRARIES})
+  SET(EMBREE_INCLUDE_DIRS ${EMBREE_INCLUDE_DIR})
+ENDIF(EMBREE_FOUND)
+
+MARK_AS_ADVANCED(
+  EMBREE_INCLUDE_DIR
+)
+
+FOREACH(COMPONENT ${_embree_FIND_COMPONENTS})
+  STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT)
+  MARK_AS_ADVANCED(EMBREE_${UPPERCOMPONENT}_LIBRARY)
+ENDFOREACH()
+
+UNSET(_embree_SEARCH_DIRS)
+UNSET(_embree_FIND_COMPONENTS)
+UNSET(_embree_LIBRARIES)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index acbbdef6dd4..2b4d454a6a7 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -435,6 +435,9 @@ function(setup_liblinks
 	if(WITH_CYCLES_OSL)
 		target_link_libraries(${target} ${OSL_LIBRARIES})
 	endif()
+	if(WITH_CYCLES_EMBREE)
+		target_link_libraries(${target} ${EMBREE_LIBRARIES})
+	endif()
 	if(WITH_BOOST)
 		target_link_libraries(${target} ${BOOST_LIBRARIES})
 		if(Boost_USE_STATIC_LIBS AND Boost_USE_ICU)
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index c7bef56c090..b57c351862f 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -378,6 +378,11 @@ if(WITH_CYCLES_OSL)
 	endif()
 endif()
 
+if(WITH_CYCLES_EMBREE)
+	find_package(Embree 3.2.4 REQUIRED)
+	set(PLATFORM_LINKFLAGS "${PLATFORM_LINKFLAGS} -Xlinker -stack_size -Xlinker 0x100000")
+endif()
+
 if(WITH_OPENMP)
 	execute_process(COMMAND ${CMAKE_C_COMPILER} --version OUTPUT_VARIABLE COMPILER_VENDOR)
 	string(SUBSTRING "${COMPILER_VENDOR}" 0 5 VENDOR_NAME) # truncate output
diff --git a/build_files/cmake/platform/platform_unix.cmake b/build_files/cmake/platform/platform_unix.cmake
index f8643a558ff..688029617ff 100644
--- a/build_files/cmake/platform/platform_unix.cmake
+++ b/build_files/cmake/platform/platform_unix.cmake
@@ -359,6 +359,10 @@ if(WITH_OPENCOLORIO)
 	endif()
 endif()
 
+if(WITH_CYCLES_EMBREE)
+	find_package(Embree 3.2.4 REQUIRED)
+endif()
+
 if(WITH_LLVM)
 	if(EXISTS ${LIBDIR})
 		set(LLVM_STATIC ON)
diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index 440f514b025..1bf04689971 100644
--- a/build_files/cmake/platform/platform_win32.

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list