diff options
author | Sv. Lockal <lockalsash@gmail.com> | 2014-01-11 20:47:30 +0400 |
---|---|---|
committer | Sv. Lockal <lockalsash@gmail.com> | 2014-01-11 20:47:30 +0400 |
commit | b886c26d1f70d512b4f68975142372e3bee81c89 (patch) | |
tree | db3bfb844f50b37ff1c60bbd8cbeecee82cfc746 /intern | |
parent | 5fc2fe9fad1a99d19ffaf4220fe139f8d324ba59 (diff) |
Cycles: mix hair minimum width code with SSE intersection code
Gives 6.5% speedup for hair.blend from testsuite.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D197
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/kernel_bvh_traversal.h | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/intern/cycles/kernel/kernel_bvh_traversal.h b/intern/cycles/kernel/kernel_bvh_traversal.h index 8f69083575b..a78e72ec12c 100644 --- a/intern/cycles/kernel/kernel_bvh_traversal.h +++ b/intern/cycles/kernel/kernel_bvh_traversal.h @@ -69,7 +69,7 @@ ccl_device bool BVH_FUNCTION_NAME isect->u = 0.0f; isect->v = 0.0f; -#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if defined(__KERNEL_SSE2__) const shuffle_swap_t shuf_identity = shuffle_swap_identity(); const shuffle_swap_t shuf_swap = shuffle_swap_swap(); @@ -101,7 +101,7 @@ ccl_device bool BVH_FUNCTION_NAME bool traverseChild0, traverseChild1; int nodeAddrChild1; -#if !defined(__KERNEL_SSE2__) || FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if !defined(__KERNEL_SSE2__) /* Intersect two child bounding boxes, non-SSE version */ float t = isect->t; @@ -159,15 +159,36 @@ ccl_device bool BVH_FUNCTION_NAME /* Intersect two child bounding boxes, SSE3 version adapted from Embree */ /* fetch node data */ - __m128 *bvh_nodes = (__m128*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE; - float4 cnodes = ((float4*)bvh_nodes)[3]; + const __m128 *bvh_nodes = (__m128*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE; + const float4 cnodes = ((float4*)bvh_nodes)[3]; /* intersect ray against child nodes */ const __m128 tminmaxx = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[0], shufflex), Psplat[0]), idirsplat[0]); const __m128 tminmaxy = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[1], shuffley), Psplat[1]), idirsplat[1]); const __m128 tminmaxz = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[2], shufflez), Psplat[2]), idirsplat[2]); - const __m128 tminmax = _mm_xor_ps(_mm_max_ps(_mm_max_ps(tminmaxx, tminmaxy), _mm_max_ps(tminmaxz, tsplat)), _mm_castsi128_ps(pn)); + /* calculate { c0min, c1min, -c0max, -c1max} */ + __m128 minmax = _mm_max_ps(_mm_max_ps(tminmaxx, tminmaxy), _mm_max_ps(tminmaxz, tsplat)); + const __m128 tminmax = _mm_xor_ps(minmax, _mm_castsi128_ps(pn)); + +#if FEATURE(BVH_HAIR_MINIMUM_WIDTH) + if(difl != 0.0f) { + float4 *tminmaxview = (float4*)&tminmax; + float &c0min = tminmaxview->x, &c1min = tminmaxview->y; + float &c0max = tminmaxview->z, &c1max = tminmaxview->w; + + float hdiff = 1.0f + difl; + float ldiff = 1.0f - difl; + if(__float_as_int(cnodes.z) & PATH_RAY_CURVE) { + c0min = max(ldiff * c0min, c0min - extmax); + c0max = min(hdiff * c0max, c0max + extmax); + } + if(__float_as_int(cnodes.w) & PATH_RAY_CURVE) { + c1min = max(ldiff * c1min, c1min - extmax); + c1max = min(hdiff * c1max, c1max + extmax); + } + } +#endif const __m128 lrhit = _mm_cmple_ps(tminmax, shuffle_swap(tminmax, shuf_swap)); /* decide which nodes to traverse next */ @@ -186,7 +207,7 @@ ccl_device bool BVH_FUNCTION_NAME if(traverseChild0 && traverseChild1) { /* both children were intersected, push the farther one */ -#if !defined(__KERNEL_SSE2__) || FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if !defined(__KERNEL_SSE2__) bool closestChild1 = (c1min < c0min); #else union { __m128 m128; float v[4]; } uminmax; @@ -255,7 +276,7 @@ ccl_device bool BVH_FUNCTION_NAME hit = bvh_triangle_intersect(kg, isect, P, idir, visibility, object, primAddr); /* shadow ray early termination */ -#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if defined(__KERNEL_SSE2__) if(hit) { if(visibility == PATH_RAY_SHADOW_OPAQUE) return true; @@ -281,7 +302,7 @@ ccl_device bool BVH_FUNCTION_NAME bvh_instance_push(kg, object, ray, &P, &idir, &isect->t, tmax); #endif -#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if defined(__KERNEL_SSE2__) Psplat[0] = _mm_set_ps1(P.x); Psplat[1] = _mm_set_ps1(P.y); Psplat[2] = _mm_set_ps1(P.z); @@ -317,7 +338,7 @@ ccl_device bool BVH_FUNCTION_NAME bvh_instance_pop(kg, object, ray, &P, &idir, &isect->t, tmax); #endif -#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH) +#if defined(__KERNEL_SSE2__) Psplat[0] = _mm_set_ps1(P.x); Psplat[1] = _mm_set_ps1(P.y); Psplat[2] = _mm_set_ps1(P.z); |