forked from bartvdbraak/blender
Cycles: mix hair minimum width code with SSE intersection code
Gives 6.5% speedup for hair.blend from testsuite. This commit was previously reverted, but should work ok now. Patch by Sv. Lockal.
This commit is contained in:
parent
afadaaf8e0
commit
78f23ce9fc
@ -69,7 +69,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
isect->u = 0.0f;
|
isect->u = 0.0f;
|
||||||
isect->v = 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_identity = shuffle_swap_identity();
|
||||||
const shuffle_swap_t shuf_swap = shuffle_swap_swap();
|
const shuffle_swap_t shuf_swap = shuffle_swap_swap();
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
bool traverseChild0, traverseChild1;
|
bool traverseChild0, traverseChild1;
|
||||||
int nodeAddrChild1;
|
int nodeAddrChild1;
|
||||||
|
|
||||||
#if !defined(__KERNEL_SSE2__) || FEATURE(BVH_HAIR_MINIMUM_WIDTH)
|
#if !defined(__KERNEL_SSE2__)
|
||||||
/* Intersect two child bounding boxes, non-SSE version */
|
/* Intersect two child bounding boxes, non-SSE version */
|
||||||
float t = isect->t;
|
float t = isect->t;
|
||||||
|
|
||||||
@ -154,15 +154,37 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
/* Intersect two child bounding boxes, SSE3 version adapted from Embree */
|
/* Intersect two child bounding boxes, SSE3 version adapted from Embree */
|
||||||
|
|
||||||
/* fetch node data */
|
/* fetch node data */
|
||||||
__m128 *bvh_nodes = (__m128*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
|
const __m128 *bvh_nodes = (__m128*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
|
||||||
float4 cnodes = ((float4*)bvh_nodes)[3];
|
const float4 cnodes = ((float4*)bvh_nodes)[3];
|
||||||
|
|
||||||
/* intersect ray against child nodes */
|
/* intersect ray against child nodes */
|
||||||
const __m128 tminmaxx = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[0], shufflexyz[0]), Psplat[0]), idirsplat[0]);
|
const __m128 tminmaxx = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[0], shufflexyz[0]), Psplat[0]), idirsplat[0]);
|
||||||
const __m128 tminmaxy = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[1], shufflexyz[1]), Psplat[1]), idirsplat[1]);
|
const __m128 tminmaxy = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[1], shufflexyz[1]), Psplat[1]), idirsplat[1]);
|
||||||
const __m128 tminmaxz = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[2], shufflexyz[2]), Psplat[2]), idirsplat[2]);
|
const __m128 tminmaxz = _mm_mul_ps(_mm_sub_ps(shuffle_swap(bvh_nodes[2], shufflexyz[2]), Psplat[2]), idirsplat[2]);
|
||||||
|
|
||||||
const __m128 tminmax = _mm_xor_ps(_mm_max_ps(_mm_max_ps(tminmaxx, tminmaxy), _mm_max_ps(tminmaxz, tsplat)), 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, 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<2, 3, 0, 1>(tminmax));
|
const __m128 lrhit = _mm_cmple_ps(tminmax, shuffle<2, 3, 0, 1>(tminmax));
|
||||||
|
|
||||||
/* decide which nodes to traverse next */
|
/* decide which nodes to traverse next */
|
||||||
@ -181,7 +203,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
|
|
||||||
if(traverseChild0 && traverseChild1) {
|
if(traverseChild0 && traverseChild1) {
|
||||||
/* both children were intersected, push the farther one */
|
/* 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);
|
bool closestChild1 = (c1min < c0min);
|
||||||
#else
|
#else
|
||||||
union { __m128 m128; float v[4]; } uminmax;
|
union { __m128 m128; float v[4]; } uminmax;
|
||||||
@ -250,7 +272,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
hit = bvh_triangle_intersect(kg, isect, P, idir, visibility, object, primAddr);
|
hit = bvh_triangle_intersect(kg, isect, P, idir, visibility, object, primAddr);
|
||||||
|
|
||||||
/* shadow ray early termination */
|
/* shadow ray early termination */
|
||||||
#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH)
|
#if defined(__KERNEL_SSE2__)
|
||||||
if(hit) {
|
if(hit) {
|
||||||
if(visibility == PATH_RAY_SHADOW_OPAQUE)
|
if(visibility == PATH_RAY_SHADOW_OPAQUE)
|
||||||
return true;
|
return true;
|
||||||
@ -276,7 +298,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
bvh_instance_push(kg, object, ray, &P, &idir, &isect->t, tmax);
|
bvh_instance_push(kg, object, ray, &P, &idir, &isect->t, tmax);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH)
|
#if defined(__KERNEL_SSE2__)
|
||||||
Psplat[0] = _mm_set_ps1(P.x);
|
Psplat[0] = _mm_set_ps1(P.x);
|
||||||
Psplat[1] = _mm_set_ps1(P.y);
|
Psplat[1] = _mm_set_ps1(P.y);
|
||||||
Psplat[2] = _mm_set_ps1(P.z);
|
Psplat[2] = _mm_set_ps1(P.z);
|
||||||
@ -306,7 +328,7 @@ ccl_device bool BVH_FUNCTION_NAME
|
|||||||
bvh_instance_pop(kg, object, ray, &P, &idir, &isect->t, tmax);
|
bvh_instance_pop(kg, object, ray, &P, &idir, &isect->t, tmax);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__KERNEL_SSE2__) && !FEATURE(BVH_HAIR_MINIMUM_WIDTH)
|
#if defined(__KERNEL_SSE2__)
|
||||||
Psplat[0] = _mm_set_ps1(P.x);
|
Psplat[0] = _mm_set_ps1(P.x);
|
||||||
Psplat[1] = _mm_set_ps1(P.y);
|
Psplat[1] = _mm_set_ps1(P.y);
|
||||||
Psplat[2] = _mm_set_ps1(P.z);
|
Psplat[2] = _mm_set_ps1(P.z);
|
||||||
|
Loading…
Reference in New Issue
Block a user