Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r874 - trunk/Model/Groups
- Date: Sun, 29 Jan 2006 02:17:10 -0700 (MST)
Author: abe
Date: Sun Jan 29 02:17:10 2006
New Revision: 874
Modified:
trunk/Model/Groups/SSEKDTree.cc
Log:
The sse kdtree traversal is now faster than the original traversal on my dual
xeon.
M Model/Groups/SSEKDTree.cc
Modified: trunk/Model/Groups/SSEKDTree.cc
==============================================================================
--- trunk/Model/Groups/SSEKDTree.cc (original)
+++ trunk/Model/Groups/SSEKDTree.cc Sun Jan 29 02:17:10 2006
@@ -151,7 +151,7 @@
subPacket.resetFlag( RayPacket::HaveSigns );
subPacket.computeSigns();
- assert( subPacket.getFlag( RayPacket::ConstantSigns ) );
+ //assert( subPacket.getFlag( RayPacket::ConstantSigns ) );
///////////////////////////////////////////////////////////////////////////
// Make sure that the traversal packet starts with an index that is
@@ -175,7 +175,7 @@
// Compute min and max distance for the kdtree.
for (int
p=p_start;(p<TraversalPacketSize)&&((which+p)<subPacket.end());++p) {
- assert(getMaterial());
+ // assert(getMaterial());
// Intersect the ray with the bounding box for the group.
valid_mask[p] = Intersection::intersectAaBox( bbox,
@@ -200,7 +200,7 @@
if (any(valid_mask)) {
// Make sure that the vector operations won't overflow the ray
packet.
- assert( (which+TraversalPacketSize) <= RayPacket::MaxSize );
+ // assert( (which+TraversalPacketSize) <= RayPacket::MaxSize );
// Intersect the subpacket with the tree.
intersect_node( context, valid_mask, subPacket, which, p_start,
minDist, maxDist );
@@ -287,7 +287,12 @@
_mm_load_ps( &rays.getInverseDirection(which,0) ),
_mm_load_ps( &rays.getInverseDirection(which,1) ),
_mm_load_ps( &rays.getInverseDirection(which,2) ) };
-
+
+
+ // Load the min t value for the rays.
+ __m128 min_t = _mm_load_ps( &rays.getMinT(which) );
+ static const __m128 t_epsilon = _mm_set1_ps( T_EPSILON );
+
// Process nodes on the stack.
while (stack_index) {
@@ -296,21 +301,12 @@
KDTreeNode *node = stack[stack_index].node;
// Copy t_near and t_far from the stack.
- __m128 t_near = stack[stack_index].t_near4;
- __m128 t_far = stack[stack_index].t_far4;
+ __m128 t_near = _mm_max_ps( stack[stack_index].t_near4, t_epsilon );
+ __m128 t_far = _mm_min_ps( stack[stack_index].t_far4, min_t );
// Obtain the active mask for this subtree.
__m128 active_mask = stack[stack_index].mask;
-#if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "P " << stack_index << " ";
- std::cerr << "\t"; M128_DEBUG(rays,active_mask);
- std::cerr << "\t"; M128_DEBUG(rays,t_near);
- std::cerr << "\t"; M128_DEBUG(rays,t_far);
- }
-#endif
-
// Pop stack.
stack_index--;
@@ -324,7 +320,7 @@
const __m128 split = _mm_set1_ps( node->split() );
// Identify near_index and far_index.
- assert( rays.getFlag( RayPacket::ConstantSigns ) );
+ // assert( rays.getFlag( RayPacket::ConstantSigns ) );
const int near_index = rays.getSign(which+p_start,axis);
const int far_index = (1 - near_index);
@@ -346,9 +342,6 @@
/////////////////////////////////////////////////////////////////////////
// Classify the case.
- // Mask cmp_result;
- // set_lte( cmp_result, t_split, t_near );
-// #if 0
__m128 cmp_result = _mm_cmple_ps( t_split, t_near );
if (SSE_ALL( active_mask, cmp_result)) {
@@ -364,7 +357,6 @@
continue;
}
- // set_gte( cmp_result, t_split, t_far );
cmp_result = _mm_cmpge_ps( t_split, t_far );
if (SSE_ALL( active_mask, cmp_result)) {
@@ -379,16 +371,12 @@
// No stack operations.
continue;
}
-// #endif
+
/////////////////////////////////////////////////////////////////////////
// Otherwise:
// Case III "Both" -- Push far node on stack.
-#if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "C\n";
- }
-#endif
+
// Check to make sure some rays hit the far child.
cmp_result = _mm_and_ps( active_mask,
_mm_cmple_ps( t_split, t_far ) );
@@ -400,21 +388,7 @@
// Copy t_split and t_far to the stack.
stack[stack_index].t_near4 = t_split;
stack[stack_index].t_far4 = t_far;
-#if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "\tPush node: " << stack_index << " ";
- M128_DEBUG(rays,stack[stack_index].mask);
- }
-#endif
- }
-#if 0
- else {
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "\tPush node: <skipped> ";
- M128_DEBUG(rays,cmp_result);
- }
}
-#endif
// Check to make sure something hits the near node.
cmp_result = _mm_and_ps( active_mask,
@@ -427,24 +401,10 @@
// Copy t_split to t_far.
t_far = t_split;
-#if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "\tNear node: ";
- M128_DEBUG(rays,active_mask);
- }
-#endif
}
else {
node = 0;
-#if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "\tNear node: <skipped> ";
- M128_DEBUG(rays,cmp_result);
- }
-#endif
}
-
-
}
///////////////////////////////////////////////////////////////////////////
@@ -455,14 +415,6 @@
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
// Intersect the rays with a list of triangles.
-
-# if 0
- if (rays.getFlag( RayPacket::DebugPacket )) {
- std::cerr << "Leaf Intersect: " << active << "\n";
- std::cerr << " leaf: "; M128_DEBUG(rays,active_mask);
- std::cerr << " leaf: "; M128_DEBUG(rays,live_mask);
- }
-#endif
IntersectPacket intersect_packet;
intersect_packet.active_mask4 = active_mask;
@@ -485,17 +437,19 @@
}
}
+ // Update min_t after performing intersections.
+ min_t = _mm_load_ps( &rays.getMinT(which) );
+
/////////////////////////////////////////////////////////////////////////
// Interpolate normals for successful hits.
// normal = (n1 * u) + (n2 * v) + (n0 * (1 - u - v));
for (int p=0;p<TraversalPacketSize;++p) {
-
// Note that hit_mask[p] is only set to true when a hit occurs and
// active_mask[p] is true.
if (intersect_packet.hit_mask[p]) {
- assert( intersect_packet.hit_index[p] < tris->getLen() );
+ // assert( intersect_packet.hit_index[p] < tris->getLen() );
// Interpolate between the three vertices.
Vectorf &n0 = normals[intersect_packet.hit_index[p]][0];
@@ -513,14 +467,12 @@
scratch_pad.b = v;
}
}
+
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Check to see if the hit is inside the current cell.
-// # if 0
-
- __m128 min_t = _mm_load_ps( &rays.getMinT(which) );
// Only turn off active rays which terminate in the current node.
static const __m128 nan = _mm_set1_ps( (float)0xffffffff );
@@ -529,13 +481,11 @@
_mm_sub_ps ( nan, active_mask )));
// Check to see if any rays are active any longer.
- // if (none(active_mask)) {
if (_mm_movemask_ps( live_mask ) == 0) {
-
+
// Done with this packet.
break;
}
-// #endif
}
}
- [MANTA] r874 - trunk/Model/Groups, abe, 01/29/2006
Archive powered by MHonArc 2.6.16.