forked from bartvdbraak/blender
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.
This commit is contained in:
parent
da66a2c871
commit
4f2583ee13
@ -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,
|
||||
|
@ -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. */
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user