[Bf-blender-cvs] [a2b52dc5716] master: Cycles: add Optix device backend

Patrick Mours noreply at git.blender.org
Fri Sep 13 11:55:12 CEST 2019


Commit: a2b52dc5716a97e5413acbd6eefc9ce3788b6456
Author: Patrick Mours
Date:   Thu Sep 12 14:50:06 2019 +0200
Branches: master
https://developer.blender.org/rBa2b52dc5716a97e5413acbd6eefc9ce3788b6456

Cycles: add Optix device backend

This uses hardware-accelerated raytracing on NVIDIA RTX graphics cards.

It is still currently experimental. Most features are supported, but a few
are still missing like baking, branched path tracing and using CPU memory.
https://wiki.blender.org/wiki/Reference/Release_Notes/2.81/Cycles#NVIDIA_RTX

For building with Optix support, the Optix SDK must be installed. See here for
build instructions:
https://wiki.blender.org/wiki/Building_Blender/CUDA

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

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

M	CMakeLists.txt
M	build_files/buildbot/slave_compile.py
A	build_files/cmake/Modules/FindOptiX.cmake
M	build_files/cmake/config/blender_lite.cmake
M	build_files/cmake/config/blender_release.cmake
M	intern/cycles/CMakeLists.txt
M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_device.cpp
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
A	intern/cycles/bvh/bvh_optix.cpp
A	intern/cycles/bvh/bvh_optix.h
M	intern/cycles/device/CMakeLists.txt
M	intern/cycles/device/device.cpp
M	intern/cycles/device/device.h
M	intern/cycles/device/device_cuda.cpp
M	intern/cycles/device/device_intern.h
M	intern/cycles/device/device_multi.cpp
A	intern/cycles/device/device_optix.cpp
M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/render/mesh.cpp
M	intern/cycles/util/util_debug.cpp
M	intern/cycles/util/util_debug.h

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad705821596..258e79b7d4a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -426,6 +426,7 @@ mark_as_advanced(WITH_CYCLES_DEBUG)
 mark_as_advanced(WITH_CYCLES_NATIVE_ONLY)
 
 option(WITH_CYCLES_DEVICE_CUDA              "Enable Cycles CUDA compute support" ON)
+option(WITH_CYCLES_DEVICE_OPTIX             "Enable Cycles OptiX support" OFF)
 option(WITH_CYCLES_DEVICE_OPENCL            "Enable Cycles OpenCL compute support" ON)
 option(WITH_CYCLES_NETWORK              "Enable Cycles compute over network support (EXPERIMENTAL and unfinished)" OFF)
 mark_as_advanced(WITH_CYCLES_DEVICE_CUDA)
diff --git a/build_files/buildbot/slave_compile.py b/build_files/buildbot/slave_compile.py
index 84667e663f6..0da0ead819f 100644
--- a/build_files/buildbot/slave_compile.py
+++ b/build_files/buildbot/slave_compile.py
@@ -34,6 +34,9 @@ def get_cmake_options(builder):
     elif builder.platform == 'linux':
         config_file = "build_files/buildbot/config/blender_linux.cmake"
 
+    optix_sdk_dir = os.path.join(builder.blender_dir, '..', '..', 'NVIDIA-Optix-SDK')
+    options.append('-DOPTIX_ROOT_DIR:PATH=' + optix_sdk_dir)
+
     options.append("-C" + os.path.join(builder.blender_dir, config_file))
     options.append("-DCMAKE_INSTALL_PREFIX=%s" % (builder.install_dir))
 
diff --git a/build_files/cmake/Modules/FindOptiX.cmake b/build_files/cmake/Modules/FindOptiX.cmake
new file mode 100644
index 00000000000..56fd2fd1396
--- /dev/null
+++ b/build_files/cmake/Modules/FindOptiX.cmake
@@ -0,0 +1,57 @@
+# - Find OptiX library
+# Find the native OptiX includes and library
+# This module defines
+#  OPTIX_INCLUDE_DIRS, where to find optix.h, Set when
+#                         OPTIX_INCLUDE_DIR is found.
+#  OPTIX_ROOT_DIR, The base directory to search for OptiX.
+#                     This can also be an environment variable.
+#  OPTIX_FOUND, If false, do not try to use OptiX.
+
+#=============================================================================
+# Copyright 2019 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 OPTIX_ROOT_DIR was defined in the environment, use it.
+IF(NOT OPTIX_ROOT_DIR AND NOT $ENV{OPTIX_ROOT_DIR} STREQUAL "")
+  SET(OPTIX_ROOT_DIR $ENV{OPTIX_ROOT_DIR})
+ENDIF()
+
+SET(_optix_SEARCH_DIRS
+  ${OPTIX_ROOT_DIR}
+  "$ENV{PROGRAMDATA}/NVIDIA Corporation/OptiX SDK 7.0.0"
+  /usr/local
+  /sw # Fink
+  /opt/local # DarwinPorts
+)
+
+FIND_PATH(OPTIX_INCLUDE_DIR
+  NAMES
+    optix.h
+  HINTS
+    ${_optix_SEARCH_DIRS}
+  PATH_SUFFIXES
+    include
+)
+
+# handle the QUIETLY and REQUIRED arguments and set OPTIX_FOUND to TRUE if
+# all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(OptiX DEFAULT_MSG
+    OPTIX_INCLUDE_DIR)
+
+IF(OPTIX_FOUND)
+  SET(OPTIX_INCLUDE_DIRS ${OPTIX_INCLUDE_DIR})
+ENDIF(OPTIX_FOUND)
+
+MARK_AS_ADVANCED(
+  OPTIX_INCLUDE_DIR
+)
+
+UNSET(_optix_SEARCH_DIRS)
diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake
index e98f4f098bb..37cbfa27972 100644
--- a/build_files/cmake/config/blender_lite.cmake
+++ b/build_files/cmake/config/blender_lite.cmake
@@ -17,6 +17,7 @@ set(WITH_CODEC_FFMPEG        OFF CACHE BOOL "" FORCE)
 set(WITH_CODEC_SNDFILE       OFF CACHE BOOL "" FORCE)
 set(WITH_CYCLES              OFF CACHE BOOL "" FORCE)
 set(WITH_CYCLES_OSL          OFF CACHE BOOL "" FORCE)
+set(WITH_CYCLES_DEVICE_OPTIX OFF CACHE BOOL "" FORCE)
 set(WITH_DRACO               OFF CACHE BOOL "" FORCE)
 set(WITH_FFTW3               OFF CACHE BOOL "" FORCE)
 set(WITH_LIBMV               OFF CACHE BOOL "" FORCE)
diff --git a/build_files/cmake/config/blender_release.cmake b/build_files/cmake/config/blender_release.cmake
index 2d7b167764b..cb338f40a7b 100644
--- a/build_files/cmake/config/blender_release.cmake
+++ b/build_files/cmake/config/blender_release.cmake
@@ -57,6 +57,7 @@ set(WITH_MEM_JEMALLOC          ON  CACHE BOOL "" FORCE)
 set(WITH_CYCLES_CUDA_BINARIES  ON  CACHE BOOL "" FORCE)
 set(WITH_CYCLES_CUBIN_COMPILER OFF CACHE BOOL "" FORCE)
 set(CYCLES_CUDA_BINARIES_ARCH sm_30;sm_35;sm_37;sm_50;sm_52;sm_60;sm_61;sm_70;sm_75 CACHE STRING "" FORCE)
+set(WITH_CYCLES_DEVICE_OPTIX   ON CACHE BOOL "" FORCE)
 
 # platform dependent options
 if(UNIX AND NOT APPLE)
diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 6a3ebd85378..25e8e124885 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -219,6 +219,24 @@ if(WITH_CYCLES_OSL)
   )
 endif()
 
+if(WITH_CYCLES_DEVICE_OPTIX)
+  find_package(OptiX)
+
+  if(OPTIX_FOUND)
+    add_definitions(-DWITH_OPTIX)
+    include_directories(
+      SYSTEM
+      ${OPTIX_INCLUDE_DIR}
+      )
+
+    # Need pre-compiled CUDA binaries in the OptiX device
+    set(WITH_CYCLES_CUDA_BINARIES ON)
+  else()
+    message(STATUS "Optix not found, disabling it from Cycles")
+    set(WITH_CYCLES_DEVICE_OPTIX OFF)
+  endif()
+endif()
+
 if(WITH_CYCLES_EMBREE)
   add_definitions(-DWITH_EMBREE)
   add_definitions(-DEMBREE_STATIC_LIB)
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 93f8f76cd6a..8623b38a271 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -137,6 +137,7 @@ enum_world_mis = (
 enum_device_type = (
     ('CPU', "CPU", "CPU", 0),
     ('CUDA', "CUDA", "CUDA", 1),
+    ('OPTIX', "OptiX", "OptiX", 3),
     ('OPENCL', "OpenCL", "OpenCL", 2)
 )
 
@@ -740,6 +741,8 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
     debug_use_cuda_adaptive_compile: BoolProperty(name="Adaptive Compile", default=False)
     debug_use_cuda_split_kernel: BoolProperty(name="Split Kernel", default=False)
 
+    debug_optix_cuda_streams: IntProperty(name="CUDA Streams", default=1, min=1)
+
     debug_opencl_kernel_type: EnumProperty(
         name="OpenCL Kernel Type",
         default='DEFAULT',
@@ -1400,10 +1403,12 @@ class CyclesPreferences(bpy.types.AddonPreferences):
 
     def get_device_types(self, context):
         import _cycles
-        has_cuda, has_opencl = _cycles.get_device_types()
+        has_cuda, has_optix, has_opencl = _cycles.get_device_types()
         list = [('NONE', "None", "Don't use compute device", 0)]
         if has_cuda:
             list.append(('CUDA', "CUDA", "Use CUDA for GPU acceleration", 1))
+        if has_optix:
+            list.append(('OPTIX', "OptiX", "Use OptiX for GPU acceleration", 3))
         if has_opencl:
             list.append(('OPENCL', "OpenCL", "Use OpenCL for GPU acceleration", 2))
         return list
@@ -1424,7 +1429,7 @@ class CyclesPreferences(bpy.types.AddonPreferences):
 
     def update_device_entries(self, device_list):
         for device in device_list:
-            if not device[1] in {'CUDA', 'OPENCL', 'CPU'}:
+            if not device[1] in {'CUDA', 'OPTIX', 'OPENCL', 'CPU'}:
                 continue
             # Try to find existing Device entry
             entry = self.find_existing_device_entry(device)
@@ -1439,8 +1444,8 @@ class CyclesPreferences(bpy.types.AddonPreferences):
                 # Update name in case it changed
                 entry.name = device[0]
 
-    # Gets all devices types by default.
-    def get_devices(self, compute_device_type=''):
+    # Gets all devices types for a compute device type.
+    def get_devices_for_type(self, compute_device_type):
         import _cycles
         # Layout of the device tuples: (Name, Type, Persistent ID)
         device_list = _cycles.available_devices(compute_device_type)
@@ -1449,20 +1454,23 @@ class CyclesPreferences(bpy.types.AddonPreferences):
         # hold pointers to a resized array.
         self.update_device_entries(device_list)
         # Sort entries into lists
-        cuda_devices = []
-        opencl_devices = []
+        devices = []
         cpu_devices = []
         for device in device_list:
             entry = self.find_existing_device_entry(device)
-            if entry.type == 'CUDA':
-                cuda_devices.append(entry)
-            elif entry.type == 'OPENCL':
-                opencl_devices.append(entry)
+            if entry.type == compute_device_type:
+                devices.append(entry)
             elif entry.type == 'CPU':
                 cpu_devices.append(entry)
         # Extend all GPU devices with CPU.
-        cuda_devices.extend(cpu_devices)
-        opencl_devices.extend(cpu_devices)
+        if compute_device_type in ('CUDA', 'OPENCL'):
+            devices.extend(cpu_devices)
+        return devices
+
+    # For backwards compatibility, only has CUDA and OpenCL.
+    def get_devices(self, compute_device_type=''):
+        cuda_devices = self.get_devices_for_type('CUDA')
+        opencl_devices = self.get_devices_for_type('OPENCL')
         return cuda_devices, opencl_devices
 
     def get_num_gpu_devices(self):
@@ -1498,16 +1506,24 @@ class CyclesPreferences(bpy.types.AddonPreferences):
         for device in devices:
             box.prop(device, "use", text=device.name)
 
+        if device_type == 'OPTIX':
+            col = box.column(align=True)
+            col.label(text="OptiX support is experimental", icon='INFO')
+            col.label(text="Not all Cycles features are supported yet", icon='BLANK1')
+
+
     def draw_impl(self, layout, context):
         row = layout.row()
         row.prop(self, "compute_device_type", expand=True)
 
-        cuda_devices, opencl_devices = self.get_devices(self.compute_device_type)
+        devices = self.get_devices_for_type(self.compute_device_type)
         row = layout.row()
         if self.compute_device_type == 'CUDA':
-            self._draw_devices(row, 'CUDA', cuda_devices)
+            self._draw_devices(row, 'CUDA', devices)
+        elif self.compute_device_type == 'OPTIX':
+            self._draw_devices(row, 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list