[Bf-blender-cvs] [53932f1f068] master: Cycles: add Optix support in the kernel

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


Commit: 53932f1f068501bfb095c407a7777a964dc5ec1c
Author: Patrick Mours
Date:   Thu Sep 12 14:46:47 2019 +0200
Branches: master
https://developer.blender.org/rB53932f1f068501bfb095c407a7777a964dc5ec1c

Cycles: add Optix support in the kernel

This adds all the kernel side changes for the Optix backend.

Ref D5363

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

M	intern/cycles/kernel/bvh/bvh.h
M	intern/cycles/kernel/geom/geom_curve_intersect.h
A	intern/cycles/kernel/kernel_compat_optix.h
M	intern/cycles/kernel/kernel_globals.h
M	intern/cycles/kernel/kernel_path.h
M	intern/cycles/kernel/kernel_shader.h
M	intern/cycles/kernel/kernel_shadow.h
M	intern/cycles/kernel/kernel_subsurface.h
M	intern/cycles/kernel/kernel_types.h
A	intern/cycles/kernel/kernels/optix/kernel_optix.cu

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

diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h
index 162b2fb5cdb..d0bc1fe4b36 100644
--- a/intern/cycles/kernel/bvh/bvh.h
+++ b/intern/cycles/kernel/bvh/bvh.h
@@ -33,136 +33,140 @@ CCL_NAMESPACE_BEGIN
 
 #include "kernel/bvh/bvh_types.h"
 
+#ifndef __KERNEL_OPTIX__
+
 /* Common QBVH functions. */
-#ifdef __QBVH__
-#  include "kernel/bvh/qbvh_nodes.h"
-#  ifdef __KERNEL_AVX2__
-#    include "kernel/bvh/obvh_nodes.h"
+#  ifdef __QBVH__
+#    include "kernel/bvh/qbvh_nodes.h"
+#    ifdef __KERNEL_AVX2__
+#      include "kernel/bvh/obvh_nodes.h"
+#    endif
 #  endif
-#endif
 
 /* Regular BVH traversal */
 
-#include "kernel/bvh/bvh_nodes.h"
+#  include "kernel/bvh/bvh_nodes.h"
 
-#define BVH_FUNCTION_NAME bvh_intersect
-#define BVH_FUNCTION_FEATURES 0
-#include "kernel/bvh/bvh_traversal.h"
-
-#if defined(__INSTANCING__)
-#  define BVH_FUNCTION_NAME bvh_intersect_instancing
-#  define BVH_FUNCTION_FEATURES BVH_INSTANCING
+#  define BVH_FUNCTION_NAME bvh_intersect
+#  define BVH_FUNCTION_FEATURES 0
 #  include "kernel/bvh/bvh_traversal.h"
-#endif
 
-#if defined(__HAIR__)
-#  define BVH_FUNCTION_NAME bvh_intersect_hair
-#  define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
-#  include "kernel/bvh/bvh_traversal.h"
-#endif
+#  if defined(__INSTANCING__)
+#    define BVH_FUNCTION_NAME bvh_intersect_instancing
+#    define BVH_FUNCTION_FEATURES BVH_INSTANCING
+#    include "kernel/bvh/bvh_traversal.h"
+#  endif
 
-#if defined(__OBJECT_MOTION__)
-#  define BVH_FUNCTION_NAME bvh_intersect_motion
-#  define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
-#  include "kernel/bvh/bvh_traversal.h"
-#endif
+#  if defined(__HAIR__)
+#    define BVH_FUNCTION_NAME bvh_intersect_hair
+#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
+#    include "kernel/bvh/bvh_traversal.h"
+#  endif
 
-#if defined(__HAIR__) && defined(__OBJECT_MOTION__)
-#  define BVH_FUNCTION_NAME bvh_intersect_hair_motion
-#  define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
-#  include "kernel/bvh/bvh_traversal.h"
-#endif
+#  if defined(__OBJECT_MOTION__)
+#    define BVH_FUNCTION_NAME bvh_intersect_motion
+#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
+#    include "kernel/bvh/bvh_traversal.h"
+#  endif
 
-/* Subsurface scattering BVH traversal */
+#  if defined(__HAIR__) && defined(__OBJECT_MOTION__)
+#    define BVH_FUNCTION_NAME bvh_intersect_hair_motion
+#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
+#    include "kernel/bvh/bvh_traversal.h"
+#  endif
 
-#if defined(__BVH_LOCAL__)
-#  define BVH_FUNCTION_NAME bvh_intersect_local
-#  define BVH_FUNCTION_FEATURES BVH_HAIR
-#  include "kernel/bvh/bvh_local.h"
+/* Subsurface scattering BVH traversal */
 
-#  if defined(__OBJECT_MOTION__)
-#    define BVH_FUNCTION_NAME bvh_intersect_local_motion
-#    define BVH_FUNCTION_FEATURES BVH_MOTION | BVH_HAIR
+#  if defined(__BVH_LOCAL__)
+#    define BVH_FUNCTION_NAME bvh_intersect_local
+#    define BVH_FUNCTION_FEATURES BVH_HAIR
 #    include "kernel/bvh/bvh_local.h"
-#  endif
-#endif /* __BVH_LOCAL__ */
-
-/* Volume BVH traversal */
 
-#if defined(__VOLUME__)
-#  define BVH_FUNCTION_NAME bvh_intersect_volume
-#  define BVH_FUNCTION_FEATURES BVH_HAIR
-#  include "kernel/bvh/bvh_volume.h"
+#    if defined(__OBJECT_MOTION__)
+#      define BVH_FUNCTION_NAME bvh_intersect_local_motion
+#      define BVH_FUNCTION_FEATURES BVH_MOTION | BVH_HAIR
+#      include "kernel/bvh/bvh_local.h"
+#    endif
+#  endif /* __BVH_LOCAL__ */
 
-#  if defined(__INSTANCING__)
-#    define BVH_FUNCTION_NAME bvh_intersect_volume_instancing
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
-#    include "kernel/bvh/bvh_volume.h"
-#  endif
+/* Volume BVH traversal */
 
-#  if defined(__OBJECT_MOTION__)
-#    define BVH_FUNCTION_NAME bvh_intersect_volume_motion
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
+#  if defined(__VOLUME__)
+#    define BVH_FUNCTION_NAME bvh_intersect_volume
+#    define BVH_FUNCTION_FEATURES BVH_HAIR
 #    include "kernel/bvh/bvh_volume.h"
-#  endif
-#endif /* __VOLUME__ */
-
-/* Record all intersections - Shadow BVH traversal */
 
-#if defined(__SHADOW_RECORD_ALL__)
-#  define BVH_FUNCTION_NAME bvh_intersect_shadow_all
-#  define BVH_FUNCTION_FEATURES 0
-#  include "kernel/bvh/bvh_shadow_all.h"
+#    if defined(__INSTANCING__)
+#      define BVH_FUNCTION_NAME bvh_intersect_volume_instancing
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
+#      include "kernel/bvh/bvh_volume.h"
+#    endif
 
-#  if defined(__INSTANCING__)
-#    define BVH_FUNCTION_NAME bvh_intersect_shadow_all_instancing
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING
-#    include "kernel/bvh/bvh_shadow_all.h"
-#  endif
+#    if defined(__OBJECT_MOTION__)
+#      define BVH_FUNCTION_NAME bvh_intersect_volume_motion
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
+#      include "kernel/bvh/bvh_volume.h"
+#    endif
+#  endif /* __VOLUME__ */
 
-#  if defined(__HAIR__)
-#    define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
-#    include "kernel/bvh/bvh_shadow_all.h"
-#  endif
+/* Record all intersections - Shadow BVH traversal */
 
-#  if defined(__OBJECT_MOTION__)
-#    define BVH_FUNCTION_NAME bvh_intersect_shadow_all_motion
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
+#  if defined(__SHADOW_RECORD_ALL__)
+#    define BVH_FUNCTION_NAME bvh_intersect_shadow_all
+#    define BVH_FUNCTION_FEATURES 0
 #    include "kernel/bvh/bvh_shadow_all.h"
-#  endif
 
-#  if defined(__HAIR__) && defined(__OBJECT_MOTION__)
-#    define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair_motion
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
-#    include "kernel/bvh/bvh_shadow_all.h"
-#  endif
-#endif /* __SHADOW_RECORD_ALL__ */
+#    if defined(__INSTANCING__)
+#      define BVH_FUNCTION_NAME bvh_intersect_shadow_all_instancing
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING
+#      include "kernel/bvh/bvh_shadow_all.h"
+#    endif
+
+#    if defined(__HAIR__)
+#      define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
+#      include "kernel/bvh/bvh_shadow_all.h"
+#    endif
+
+#    if defined(__OBJECT_MOTION__)
+#      define BVH_FUNCTION_NAME bvh_intersect_shadow_all_motion
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION
+#      include "kernel/bvh/bvh_shadow_all.h"
+#    endif
+
+#    if defined(__HAIR__) && defined(__OBJECT_MOTION__)
+#      define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair_motion
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR | BVH_MOTION
+#      include "kernel/bvh/bvh_shadow_all.h"
+#    endif
+#  endif /* __SHADOW_RECORD_ALL__ */
 
 /* Record all intersections - Volume BVH traversal  */
 
-#if defined(__VOLUME_RECORD_ALL__)
-#  define BVH_FUNCTION_NAME bvh_intersect_volume_all
-#  define BVH_FUNCTION_FEATURES BVH_HAIR
-#  include "kernel/bvh/bvh_volume_all.h"
-
-#  if defined(__INSTANCING__)
-#    define BVH_FUNCTION_NAME bvh_intersect_volume_all_instancing
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
+#  if defined(__VOLUME_RECORD_ALL__)
+#    define BVH_FUNCTION_NAME bvh_intersect_volume_all
+#    define BVH_FUNCTION_FEATURES BVH_HAIR
 #    include "kernel/bvh/bvh_volume_all.h"
-#  endif
 
-#  if defined(__OBJECT_MOTION__)
-#    define BVH_FUNCTION_NAME bvh_intersect_volume_all_motion
-#    define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
-#    include "kernel/bvh/bvh_volume_all.h"
-#  endif
-#endif /* __VOLUME_RECORD_ALL__ */
+#    if defined(__INSTANCING__)
+#      define BVH_FUNCTION_NAME bvh_intersect_volume_all_instancing
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_HAIR
+#      include "kernel/bvh/bvh_volume_all.h"
+#    endif
+
+#    if defined(__OBJECT_MOTION__)
+#      define BVH_FUNCTION_NAME bvh_intersect_volume_all_motion
+#      define BVH_FUNCTION_FEATURES BVH_INSTANCING | BVH_MOTION | BVH_HAIR
+#      include "kernel/bvh/bvh_volume_all.h"
+#    endif
+#  endif /* __VOLUME_RECORD_ALL__ */
+
+#  undef BVH_FEATURE
+#  undef BVH_NAME_JOIN
+#  undef BVH_NAME_EVAL
+#  undef BVH_FUNCTION_FULL_NAME
 
-#undef BVH_FEATURE
-#undef BVH_NAME_JOIN
-#undef BVH_NAME_EVAL
-#undef BVH_FUNCTION_FULL_NAME
+#endif /* __KERNEL_OPTIX__ */
 
 ccl_device_inline bool scene_intersect_valid(const Ray *ray)
 {
@@ -173,8 +177,10 @@ ccl_device_inline bool scene_intersect_valid(const Ray *ray)
    * such cases.
    * From production scenes so far it seems it's enough to test first element
    * only.
+   * Scene intersection may also called with empty rays for conditional trace
+   * calls that evaluate to false, so filter those out.
    */
-  return isfinite_safe(ray->P.x) && isfinite_safe(ray->D.x);
+  return isfinite_safe(ray->P.x) && isfinite_safe(ray->D.x) && len_squared(ray->D) != 0.0f;
 }
 
 ccl_device_intersect bool scene_intersect(KernelGlobals *kg,
@@ -184,10 +190,46 @@ ccl_device_intersect bool scene_intersect(KernelGlobals *kg,
 {
   PROFILING_INIT(kg, PROFILING_INTERSECT);
 
+#ifdef __KERNEL_OPTIX__
+  uint p0 = 0;
+  uint p1 = 0;
+  uint p2 = 0;
+  uint p3 = 0;
+  uint p4 = visibility;
+  uint p5 = PRIMITIVE_NONE;
+
+  optixTrace(scene_intersect_valid(ray) ? kernel_data.bvh.scene : 0,
+             ray->P,
+             ray->D,
+             0.0f,
+             ray->t,
+             ray->time,
+             0xFF,
+             OPTIX_RAY_FLAG_NONE,
+             0,
+             0,
+             0,  // SBT offset for PG_HITD
+             p0,
+             p1,
+             p2,
+             p3,
+             p4,
+             p5);
+
+  isect->t = __uint_as_float(p0);
+  isect->u = __uint_as_float(p1);
+  isect->v = __uint_as_float(p2);
+  isect->prim = p3;
+  isect->object = p4;
+  isect->type = p5;
+
+  return p5 != PRIMITIVE_NONE;
+#else /* __KERNEL_OPTIX__ */
   if (!scene_intersect_valid(ray)) {
     return false;
   }
-#ifdef __EMBREE__
+
+#  ifdef __EMBREE__
   if (kernel_data.bvh.scene) {
     isect->t = ray->t;
     CCLIntersectContext ctx(kg, CCLIntersectContext::R

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list