Cycles: Simplify code around debug stats in BVH traversing
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 27 May 2016 08:55:48 +0000 (10:55 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 27 May 2016 08:55:48 +0000 (10:55 +0200)
intern/cycles/kernel/geom/geom_bvh.h
intern/cycles/kernel/geom/geom_bvh_traversal.h
intern/cycles/kernel/geom/geom_qbvh_traversal.h

index 9eadc97386c7e80b798daad18230fb50e7fa6082..d0eedd3396afdc2bf29889ab08634e5f2df3081d 100644 (file)
@@ -48,6 +48,28 @@ CCL_NAMESPACE_BEGIN
 
 #define BVH_FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0)
 
+/* Debugging heleprs */
+#ifdef __KERNEL_DEBUG__
+#  define BVH_DEBUG_INIT() \
+       do { \
+               isect->num_traversal_steps = 0; \
+               isect->num_traversed_instances = 0; \
+       } while(0)
+#  define BVH_DEBUG_NEXT_STEP() \
+       do { \
+               ++isect->num_traversal_steps; \
+       } while(0)
+#  define BVH_DEBUG_NEXT_INSTANCE() \
+       do { \
+               ++isect->num_traversed_instances; \
+       } while(0)
+#else  /* __KERNEL_DEBUG__ */
+#  define BVH_DEBUG_INIT()
+#  define BVH_DEBUG_NEXT_STEP()
+#  define BVH_DEBUG_NEXT_INSTANCE()
+#endif  /* __KERNEL_DEBUG__ */
+
+
 /* Common QBVH functions. */
 #ifdef __QBVH__
 #  include "geom_qbvh.h"
index 8560612addcc4137cbb150e153a5182275ae281b..ae919ef3f869b08914d9372d9def78de032510a4 100644 (file)
@@ -74,10 +74,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
        isect->prim = PRIM_NONE;
        isect->object = OBJECT_NONE;
 
-#if defined(__KERNEL_DEBUG__)
-       isect->num_traversal_steps = 0;
-       isect->num_traversed_instances = 0;
-#endif
+       BVH_DEBUG_INIT();
 
 #if defined(__KERNEL_SSE2__)
        const shuffle_swap_t shuf_identity = shuffle_swap_identity();
@@ -241,10 +238,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                                --stackPtr;
                                        }
                                }
-
-#if defined(__KERNEL_DEBUG__)
-                               isect->num_traversal_steps++;
-#endif
+                               BVH_DEBUG_NEXT_STEP();
                        }
 
                        /* if node is leaf, fetch triangle list */
@@ -266,9 +260,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                        switch(type & PRIMITIVE_ALL) {
                                                case PRIMITIVE_TRIANGLE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                if(triangle_intersect(kg, &isect_precalc, isect, P, visibility, object, primAddr)) {
                                                                        /* shadow ray early termination */
@@ -287,9 +279,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 #if BVH_FEATURE(BVH_MOTION)
                                                case PRIMITIVE_MOTION_TRIANGLE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#  if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#  endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                if(motion_triangle_intersect(kg, isect, P, dir, ray->time, visibility, object, primAddr)) {
                                                                        /* shadow ray early termination */
@@ -310,9 +300,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                                case PRIMITIVE_CURVE:
                                                case PRIMITIVE_MOTION_CURVE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#  if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#  endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                bool hit;
                                                                if(kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
@@ -364,9 +352,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                                        nodeAddr = kernel_tex_fetch(__object_node, object);
 
-#  if defined(__KERNEL_DEBUG__)
-                                       isect->num_traversed_instances++;
-#  endif
+                                       BVH_DEBUG_NEXT_INSTANCE();
                                }
                        }
 #endif  /* FEATURE(BVH_INSTANCING) */
index ce3bbbdf957168c735eb16f18f0212a304708494..738d08ac6fc9a17bc8795ca84aa1ebb036f09de7 100644 (file)
@@ -78,10 +78,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
        isect->prim = PRIM_NONE;
        isect->object = OBJECT_NONE;
 
-#if defined(__KERNEL_DEBUG__)
-       isect->num_traversal_steps = 0;
-       isect->num_traversed_instances = 0;
-#endif
+       BVH_DEBUG_INIT();
 
        ssef tnear(0.0f), tfar(ray->t);
        sse3f idir4(ssef(idir.x), ssef(idir.y), ssef(idir.z));
@@ -120,9 +117,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                int traverseChild;
                                ssef dist;
 
-#if defined(__KERNEL_DEBUG__)
-                               isect->num_traversal_steps++;
-#endif
+                               BVH_DEBUG_NEXT_STEP();
 
 #if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH)
                                if(difl != 0.0f) {
@@ -295,9 +290,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                        switch(type & PRIMITIVE_ALL) {
                                                case PRIMITIVE_TRIANGLE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                if(triangle_intersect(kg, &isect_precalc, isect, P, visibility, object, primAddr)) {
                                                                        tfar = ssef(isect->t);
@@ -311,9 +304,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 #if BVH_FEATURE(BVH_MOTION)
                                                case PRIMITIVE_MOTION_TRIANGLE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#  if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#  endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                if(motion_triangle_intersect(kg, isect, P, dir, ray->time, visibility, object, primAddr)) {
                                                                        tfar = ssef(isect->t);
@@ -329,9 +320,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                                case PRIMITIVE_CURVE:
                                                case PRIMITIVE_MOTION_CURVE: {
                                                        for(; primAddr < primAddr2; primAddr++) {
-#  if defined(__KERNEL_DEBUG__)
-                                                               isect->num_traversal_steps++;
-#  endif
+                                                               BVH_DEBUG_NEXT_STEP();
                                                                kernel_assert(kernel_tex_fetch(__prim_type, primAddr) == type);
                                                                bool hit;
                                                                if(kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
@@ -381,9 +370,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                                        nodeAddr = kernel_tex_fetch(__object_node, object);
 
-#  if defined(__KERNEL_DEBUG__)
-                                       isect->num_traversed_instances++;
-#  endif
+                                       BVH_DEBUG_NEXT_INSTANCE();
                                }
                        }
 #endif  /* FEATURE(BVH_INSTANCING) */