Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1483 - in trunk: Core/Math Interface Model/Primitives


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1483 - in trunk: Core/Math Interface Model/Primitives
  • Date: Tue, 17 Jul 2007 14:55:54 -0600 (MDT)

Author: boulos
Date: Tue Jul 17 14:55:53 2007
New Revision: 1483

Modified:
   trunk/Core/Math/CheapRNG.h
   trunk/Interface/Primitive.cc
   trunk/Interface/Primitive.h
   trunk/Interface/RandomNumberGenerator.cc
   trunk/Interface/RandomNumberGenerator.h
   trunk/Model/Primitives/Parallelogram.cc
Log:
Core/Math/CheapRNG.h
 Adding nextIntPacket with SSE implementation.  SSE implementation has
not yet been tested.

Interface/Primitive.cc
Interface/Primitive.h
 Adding getRandomPoints interface to get a set of random points of 
Packet size at once (to amortize virtual function calls and allow for
vectorization using SSE)

Interface/RandomNumberGenerator.cc
Interface/RandomNumberGenerator.h
 Adding packet versions of random number generation.

Model/Lights/AreaLight.cc
 Beginning to use packet interface for light sampling.  Need to add
SSE version and make underlying primitives (Parallelogram for example)
use the packet sampling interface.


Modified: trunk/Core/Math/CheapRNG.h
==============================================================================
--- trunk/Core/Math/CheapRNG.h  (original)
+++ trunk/Core/Math/CheapRNG.h  Tue Jul 17 14:55:53 2007
@@ -53,8 +53,10 @@
 // properties of integer multiplication.
 
 // For the Real type
-#include <MantaTypes.h> 
+#include <MantaTypes.h>
 #include <Interface/RandomNumberGenerator.h>
+#include <MantaSSE.h>
+#include <Core/Math/SSEDefs.h>
 
 namespace Manta {
 
@@ -65,22 +67,49 @@
     // members.
     typedef unsigned int uint32;
   protected:
-    
+
     char padding0 [128];
     uint32 val;
+#ifdef MANTA_SSE
+    __m128i val_sse;
+#endif
     char padding1 [128];
   public:
     // Your seed value is up to the fates.  You should call seed.
     CheapRNG() {}
     static void create(RandomNumberGenerator*& rng ) { rng = new CheapRNG(); 
}
-      
+
     virtual void seed(unsigned int seed_val) {
       val = seed_val;
+#ifdef MANTA_SSE
+      // TODO(boulos): Find a better way to seed this.  Normally you
+      // could just call nextInt() but all that will do for this RNG
+      // is make the sequences out of sync by one iteration... So you
+      // want offsets.
+      val_sse = _mm_set_epi32(seed_val,
+                              seed_val * 12345,
+                              seed_val * 12345 * 12345,
+                              seed_val * 12345 * 12345 * 12345);
+#endif
     }
 
     virtual unsigned int nextInt() {
       val = 1664525*val + 1013904223;
       return val;
+    }
+
+    virtual void nextIntPacket(Packet<unsigned int>& results) {
+#ifdef MANTA_SSE
+      for (int i = 0; i < Packet<unsigned int>::MaxSize; i++) {
+        val_sse = _mm_add_epi32(_mm_set1_epi32(1013904223),
+                                _mm_mullo_epi32(val_sse, 
_mm_set1_epi32(1664525)));
+        _mm_store_si128((__m128i*)&results.data[i], val_sse);
+      }
+#else
+      for (int i = 0; i < Packet<unsigned int>::MaxSize; i++) {
+        results.set(i, nextInt());
+      }
+#endif
     }
   }; // end class CheapRNG
 

Modified: trunk/Interface/Primitive.cc
==============================================================================
--- trunk/Interface/Primitive.cc        (original)
+++ trunk/Interface/Primitive.cc        Tue Jul 17 14:55:53 2007
@@ -20,3 +20,19 @@
   throw SCIRun::InternalError("Unimplemented getRandomPoint for Primitive",
                               __FILE__, __LINE__);
 }
+
+void Primitive::getRandomPoints(Packet<Vector>& points,
+                                Packet<Vector>& normals,
+                                Packet<Real>& pdfs,
+                                const RenderContext& context) const {
+  for (int i = 0; i < Packet<Vector>::MaxSize; i++) {
+    Vector point;
+    Vector normal;
+    Real pdf;
+    getRandomPoint(point, normal, pdf, context);
+
+    points.set(i, point);
+    normals.set(i, normal);
+    pdfs.set(i, pdf);
+  }
+}

Modified: trunk/Interface/Primitive.h
==============================================================================
--- trunk/Interface/Primitive.h (original)
+++ trunk/Interface/Primitive.h Tue Jul 17 14:55:53 2007
@@ -3,6 +3,7 @@
 #define Manta_Interface_Primitive_h
 
 #include <Interface/Object.h>
+#include <Interface/Packet.h>
 #include <MantaTypes.h>
 
 namespace Manta {
@@ -24,6 +25,11 @@
                                 Vector& normal,
                                 Real& pdf,
                                 const RenderContext& context) const;
+
+    virtual void getRandomPoints(Packet<Vector>& points,
+                                 Packet<Vector>& normals,
+                                 Packet<Real>& pdfs,
+                                 const RenderContext& context) const;
   private:
     Primitive(const Primitive&);
     Primitive& operator=(const Primitive&);

Modified: trunk/Interface/RandomNumberGenerator.cc
==============================================================================
--- trunk/Interface/RandomNumberGenerator.cc    (original)
+++ trunk/Interface/RandomNumberGenerator.cc    Tue Jul 17 14:55:53 2007
@@ -11,9 +11,33 @@
   }
 
   template<>
+  void RandomNumberGenerator::nextPacket(Packet<float>& results) {
+#ifdef MANTA_SSE
+    Packet<unsigned int> uints;
+    nextIntPacket(uints);
+    for (int i = 0; i < Packet<float>::MaxSize; i+= 4) {
+      _mm_store_ps(&results.data[i],
+                   
_mm_mul_ps(_mm_cvtepi32_ps(_mm_load_si128((__m128i*)&uints.data[i])),
+                              _mm_set1_ps((float)(1./4294967296.))));
+    }
+#else
+    for (int i = 0; i < Packet::MaxSize; i++) {
+      results.set(i, nextFloat());
+    }
+#endif
+  }
+
+  template<>
   double RandomNumberGenerator::next<double>()
   {
     return nextDouble();
+  }
+
+  template<>
+  void RandomNumberGenerator::nextPacket(Packet<double>& results) {
+    for (int i = 0; i < Packet<double>::MaxSize; i++) {
+      results.set(i, nextDouble());
+    }
   }
 
 } // end namespace Manta

Modified: trunk/Interface/RandomNumberGenerator.h
==============================================================================
--- trunk/Interface/RandomNumberGenerator.h     (original)
+++ trunk/Interface/RandomNumberGenerator.h     Tue Jul 17 14:55:53 2007
@@ -33,17 +33,23 @@
  */
 
 #include <MantaSSE.h>
+#include <Interface/Packet.h>
 
 namespace Manta {
   class RandomNumberGenerator {
   public:
     virtual ~RandomNumberGenerator() {}
-    
+
     virtual void seed(unsigned int val) = 0;
 
     // result = [0, 4294967295(UINT_MAX)]
     virtual unsigned int nextInt() = 0;
 
+    virtual void nextIntPacket(Packet<unsigned int>& results) {
+      for (int i = 0; i < Packet<unsigned int>::MaxSize; i++) {
+        results.set(i, nextInt());
+      }
+    }
     // All the floating point interface return numbers in the range of
     // [0, 1).
 
@@ -52,6 +58,9 @@
     template<class T>
     T next() { return 0; }
 
+    template<class T>
+    void nextPacket(Packet<T>& results) { return; }
+
     virtual double nextDouble() {
       return ( (double)nextInt() * (1./4294967296.) );
     }
@@ -65,10 +74,14 @@
   // defined symbols.
   template<>
   float RandomNumberGenerator::next<float>();
+  template<>
+  void RandomNumberGenerator::nextPacket(Packet<float>& results);
 
   template<>
   double RandomNumberGenerator::next<double>();
-  
+  template<>
+  void RandomNumberGenerator::nextPacket(Packet<double>& results);
+
 } // end namespace Manta
 
 #endif // #ifndef Manta_Interface_RandomNumberGenerator_h

Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc     (original)
+++ trunk/Model/Primitives/Parallelogram.cc     Tue Jul 17 14:55:53 2007
@@ -555,3 +555,5 @@
            context.rng->next<Real>() * v2_unscaled);
   normal = this->normal;
 }
+
+




  • [MANTA] r1483 - in trunk: Core/Math Interface Model/Primitives, boulos, 07/17/2007

Archive powered by MHonArc 2.6.16.

Top of page