Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1463 - trunk/Model/Groups


Chronological Thread 
  • From: thiago@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1463 - trunk/Model/Groups
  • Date: Tue, 10 Jul 2007 20:16:29 -0600 (MDT)

Author: thiago
Date: Tue Jul 10 20:16:28 2007
New Revision: 1463

Modified:
   trunk/Model/Groups/DynBVH.cc
   trunk/Model/Groups/DynBVH.h
Log:
Quick hack for parallelizing the bounding box update (refit) to 2 threads. 
For 5 minutes worth of coding, this is a nice speedup. But it needs to be 
completly rewritten later so that it scales better and to more than 2 threads.


Modified: trunk/Model/Groups/DynBVH.cc
==============================================================================
--- trunk/Model/Groups/DynBVH.cc        (original)
+++ trunk/Model/Groups/DynBVH.cc        Tue Jul 10 20:16:28 2007
@@ -14,7 +14,7 @@
 const float BVH_C_trav = 10.f;
 
 #ifdef MANTA_SSE
-#define USE_DYNBVH_PORTS 0
+#define USE_DYNBVH_PORTS 1
 #else
 #define USE_DYNBVH_PORTS 0
 #endif
@@ -430,7 +430,7 @@
 
 void DynBVH::rebuild(Group *group, int proc, int numProcs)
 {
-  if (proc > 0) return; //TODO: make this parallel (at least some of it).
+  //  if (proc > 0) return; //TODO: make this parallel (at least some of it).
 
   //for now we rebuild if the number of primitives is different and
   //update otherwise. This of course isn't always best, so if someone
@@ -439,9 +439,10 @@
 
   if(currGroup && currGroup->getSize() == group->getSize()) {
     currGroup = group;
-    updateBounds(context, 0);
+    parallelUpdateBounds(context, proc, numProcs);
   }
   else {
+    if (proc > 0) return;
 
     cerr << "\nDynBVH::preprocess START\n";
     double start = SCIRun::Time::currentSeconds();
@@ -521,6 +522,32 @@
         printf("DynBVH Build Complete\n");
     }
 
+}
+
+void DynBVH::parallelUpdateBounds(const PreprocessContext& context, 
+                                  int proc, int numProcs)
+{
+  //XXXX this is super naive hackish code! FIXME!
+  if (numProcs == 1)
+    updateBounds(context, 0);
+  else {
+    BVHNode& node = nodes[0];
+    int left_son = node.child;
+    int right_son = left_son + 1;
+    if (proc == 0) {
+      updateBounds(context, left_son);
+      const BVHNode& left_node = nodes[left_son];    
+      node.bounds = left_node.bounds;
+    }
+    else if (proc == 1)
+      updateBounds(context, right_son);
+    else return;
+    
+    barrier.wait(2);
+
+    const BVHNode& right_node = nodes[right_son];
+    node.bounds.extendByBox(right_node.bounds);
+  }
 }
 
 void DynBVH::updateBounds(const PreprocessContext& context, int ID)

Modified: trunk/Model/Groups/DynBVH.h
==============================================================================
--- trunk/Model/Groups/DynBVH.h (original)
+++ trunk/Model/Groups/DynBVH.h Tue Jul 10 20:16:28 2007
@@ -5,6 +5,8 @@
 #include <Core/Geometry/BBox.h>
 #include <Interface/RayPacket.h>
 #include <Interface/AccelerationStructure.h>
+#include <Core/Thread/Barrier.h>
+#include <SCIRun/Core/Thread/Mutex.h>
 
 namespace Manta
 {
@@ -58,9 +60,11 @@
         vector<int> object_ids;
         int num_nodes;
         Group* currGroup;
+        SCIRun::Barrier barrier;
+
 
     public:
-        DynBVH() : currGroup(NULL)
+      DynBVH() : currGroup(NULL), barrier("DynBVH barrier")
         {}
 
         void preprocess(const PreprocessContext&);
@@ -93,6 +97,8 @@
                    int nodeID, int objectBegin, int objectEnd,
                    int &nextFree, int depth = 0);
 
+        void parallelUpdateBounds(const PreprocessContext& context, 
+                                  int proc, int numProcs);
         void updateBounds(const PreprocessContext& context, int ID = 0);
 
 




  • [MANTA] r1463 - trunk/Model/Groups, thiago, 07/10/2007

Archive powered by MHonArc 2.6.16.

Top of page