diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-01-02 12:58:01 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2015-01-02 12:58:01 +0300 |
commit | 4f2583ee1300157a2f08532509ab3a53ef3a7b47 (patch) | |
tree | 47a106525015bf3c6e09bd584e4933f9d9dd36b1 | |
parent | da66a2c871aee49338cb27747c67a2cb267b7b39 (diff) |
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.
-rw-r--r-- | intern/cycles/kernel/geom/geom_qbvh.h | 28 | ||||
-rw-r--r-- | intern/cycles/kernel/geom/geom_triangle_intersect.h | 4 | ||||
-rw-r--r-- | intern/cycles/util/util_math.h | 19 |
3 files changed, 22 insertions, 29 deletions
diff --git a/intern/cycles/kernel/geom/geom_qbvh.h b/intern/cycles/kernel/geom/geom_qbvh.h index 7a354379bed..37deaac0800 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 5090d553c41..cbb9d27aaf4 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 f445dd8fd7c..177a72bc1c9 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__ */ |