Commit: 4f2583ee1300157a2f08532509ab3a53ef3a7b47
Author: Sergey Sharybin
Date:   Fri Jan 2 14:58:01 2015 +0500
Branches: master
https://developer.blender.org/rB4f2583ee1300157a2f08532509ab3a53ef3a7b47

Fix T43027: OpenCL kernel compilation broken after QBVH

OpenCL apparently does not support templates, so the idea of generic
function for swapping is a bit of a failure. Now it is either inlined
into the code (in triangle intersection) or has specific implementation
for QBVH.

This is probably even better, because we can't create QBVH-specific
function in util_math anyway.

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

M       intern/cycles/kernel/geom/geom_qbvh.h
M       intern/cycles/kernel/geom/geom_triangle_intersect.h
M       intern/cycles/util/util_math.h

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

diff --git a/intern/cycles/kernel/geom/geom_qbvh.h 
b/intern/cycles/kernel/geom/geom_qbvh.h
index 7a35437..37deaac 100644
--- a/intern/cycles/kernel/geom/geom_qbvh.h
+++ b/intern/cycles/kernel/geom/geom_qbvh.h
@@ -19,14 +19,24 @@ struct QBVHStackItem {
        float dist;
 };
 
-/* TOOD(sergey): Investigate if using instrinsics helps here. */
+/* TOOD(sergey): Investigate if using instrinsics helps for both
+ * stack item swap and float comparison.
+ */
+ccl_device_inline void qbvh_item_swap(QBVHStackItem *__restrict a,
+                                      QBVHStackItem *__restrict b)
+{
+       QBVHStackItem tmp = *a;
+       *a = *b;
+       *b = tmp;
+}
+
 ccl_device_inline void qbvh_stack_sort(QBVHStackItem *__restrict s1,
                                        QBVHStackItem *__restrict s2,
                                        QBVHStackItem *__restrict s3)
 {
-       if(s2->dist < s1->dist) { util_swap(s2, s1); }
-       if(s3->dist < s2->dist) { util_swap(s3, s2); }
-       if(s2->dist < s1->dist) { util_swap(s2, s1); }
+       if(s2->dist < s1->dist) { qbvh_item_swap(s2, s1); }
+       if(s3->dist < s2->dist) { qbvh_item_swap(s3, s2); }
+       if(s2->dist < s1->dist) { qbvh_item_swap(s2, s1); }
 }
 
 ccl_device_inline void qbvh_stack_sort(QBVHStackItem *__restrict s1,
@@ -34,11 +44,11 @@ ccl_device_inline void qbvh_stack_sort(QBVHStackItem 
*__restrict s1,
                                        QBVHStackItem *__restrict s3,
                                        QBVHStackItem *__restrict s4)
 {
-       if(s2->dist < s1->dist) { util_swap(s2, s1); }
-       if(s4->dist < s3->dist) { util_swap(s4, s3); }
-       if(s3->dist < s1->dist) { util_swap(s3, s1); }
-       if(s4->dist < s2->dist) { util_swap(s4, s2); }
-       if(s3->dist < s2->dist) { util_swap(s3, s2); }
+       if(s2->dist < s1->dist) { qbvh_item_swap(s2, s1); }
+       if(s4->dist < s3->dist) { qbvh_item_swap(s4, s3); }
+       if(s3->dist < s1->dist) { qbvh_item_swap(s3, s1); }
+       if(s4->dist < s2->dist) { qbvh_item_swap(s4, s2); }
+       if(s3->dist < s2->dist) { qbvh_item_swap(s3, s2); }
 }
 
 ccl_device_inline int qbvh_node_intersect(KernelGlobals *__restrict kg,
diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h 
b/intern/cycles/kernel/geom/geom_triangle_intersect.h
index 5090d55..cbb9d27 100644
--- a/intern/cycles/kernel/geom/geom_triangle_intersect.h
+++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h
@@ -67,7 +67,9 @@ void triangle_intersect_precalc(float3 dir,
 
        /* Swap kx and ky dimensions to preserve winding direction of 
triangles. */
        if(IDX(dir, kz) < 0.0f) {
-               util_swap(&kx, &ky);
+               float tmp = kx;
+               kx = ky;
+               kx = tmp;
        }
 
        /* Calculate the shear constants. */
diff --git a/intern/cycles/util/util_math.h b/intern/cycles/util/util_math.h
index f445dd8..177a72b 100644
--- a/intern/cycles/util/util_math.h
+++ b/intern/cycles/util/util_math.h
@@ -1486,25 +1486,6 @@ ccl_device_inline int util_max_axis(float3 vec)
        }
 }
 
-/* NOTE: We don't use std::swap here because of number of reasons:
- *
- * - We don't want current context to be polluted with all the templated
- *   functions from stl which might cause some interference about which
- *   function is used.
- *
- * - Different devices in theory might want to use intrinsics to optimize
- *   this function for specific type.
- *
- * - We don't want ot use references because of OpenCL state at this moment.
- */
-template <typename T>
-ccl_device_inline void util_swap(T *__restrict a, T *__restrict b)
-{
-       T c = *a;
-       *a = *b;
-       *b = c;
-}
-
 CCL_NAMESPACE_END
 
 #endif /* __UTIL_MATH_H__ */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to