Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1803 - in trunk: Engine/PixelSamplers Engine/SampleGenerators Interface


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1803 - in trunk: Engine/PixelSamplers Engine/SampleGenerators Interface
  • Date: Fri, 2 Nov 2007 13:34:51 -0600 (MDT)

Author: boulos
Date: Fri Nov  2 13:34:49 2007
New Revision: 1803

Modified:
   trunk/Engine/PixelSamplers/JitterSampler.cc
   trunk/Engine/SampleGenerators/Stratified2D.cc
   trunk/Engine/SampleGenerators/Stratified2D.h
   trunk/Interface/RayPacket.h
Log:
Interface/RayPacket.h

 Adding region_id to RayPacket for SampleGenerators.

Engine/PixelSamplers/JitterSampler.cc
 
  Setting the JitterSampler to fill in the region_id.


Engine/SampleGenerators/Stratified2D.cc
Engine/SampleGenerators/Stratified2D.h

  A lot of bug fixes and I think this sort of works now...


Modified: trunk/Engine/PixelSamplers/JitterSampler.cc
==============================================================================
--- trunk/Engine/PixelSamplers/JitterSampler.cc (original)
+++ trunk/Engine/PixelSamplers/JitterSampler.cc Fri Nov  2 13:34:49 2007
@@ -187,6 +187,7 @@
     // average, and store the results in the fragment.
     int fx = fragment.getX(frag_index);
     int fy = fragment.getY(frag_index);
+    int pixel_id = fy * ci.xres + fx;
     // Which sample does this ray packet start at?
 
     for(int xs = 0; xs < nx; xs++) {
@@ -198,6 +199,7 @@
           py = (fy+y_sample)*ci.yscale+ci.yoffset;
           rays.setPixel(sample_count, 0, px, py);
           rays.data->sample_id[sample_count] = xs * ny + ys;
+          rays.data->region_id[sample_count] = pixel_id;
           sample_count++;
 
           if (sample_count == RayPacket::MaxSize) {

Modified: trunk/Engine/SampleGenerators/Stratified2D.cc
==============================================================================
--- trunk/Engine/SampleGenerators/Stratified2D.cc       (original)
+++ trunk/Engine/SampleGenerators/Stratified2D.cc       Fri Nov  2 13:34:49 
2007
@@ -13,7 +13,9 @@
 using SCIRun::Sqrt;
 
 Stratified2D::Stratified2D(unsigned int spp) :
-  spp(spp), thread_samples(0), max_depth(0), num_threads(0), 
current_pixel(0) {
+  spp(spp), thread_samples(0), max_depth(0), num_threads(0),
+  current_region_id(0), current_raw_region_id(0),
+  xres(0), yres(0) {
   sqrt_spp = static_cast<unsigned int>(Sqrt(static_cast<double>(spp)));
   if (sqrt_spp * sqrt_spp != spp) {
     throw SCIRun::InternalError("Stratified2D expects spp to be a perfect 
square",
@@ -21,6 +23,23 @@
   }
   inv_spp = 1.f/static_cast<float>(spp);
   inv_sqrt_spp = 1.f/static_cast<float>(sqrt_spp);
+
+  // Determine the maximum number of active regions at
+  // once. NOTE(boulos): Currently assuming that a Pixel = a Region
+  if (spp > RayPacket::MaxSize) {
+    if (spp % RayPacket::MaxSize == 0) {
+      max_regions = 1;
+    } else {
+      max_regions = 2;
+    }
+  } else {
+    if (RayPacket::MaxSize % spp == 0) {
+      max_regions = RayPacket::MaxSize/spp;
+    } else {
+      // max_regions = Ceil(MaxSize/spp) + 1
+      max_regions = (RayPacket::MaxSize/spp) + 2;
+    }
+  }
 }
 
 Stratified2D::~Stratified2D() {
@@ -36,22 +55,34 @@
 
   if (thread_samples) {
     for (unsigned int i = 0; i < num_threads; i++) {
+      for (unsigned int r = 0; r < max_regions; r++) {
+        delete[] thread_samples[i][r];
+      }
       delete[] thread_samples[i];
     }
     delete[] thread_samples;
   }
 
-  if (current_pixel) {
-    delete[] current_pixel;
+  // TODO(boulos): Handle the false sharing issues here...
+  if (current_region_id) {
+    delete[] current_region_id;
+  }
+  if (current_raw_region_id) {
+    delete[] current_raw_region_id;
   }
 
   num_threads = new_threads;
   max_depth = new_depth;
-  thread_samples = new float*[num_threads];
-  current_pixel = new unsigned int[num_threads];
+  thread_samples = new float**[num_threads];
+  current_region_id = new unsigned int[num_threads];
+  current_raw_region_id = new unsigned int[num_threads];
   for (unsigned int i = 0; i < num_threads; i++) {
-    thread_samples[i] = new float[spp * max_depth];
-    current_pixel[i] = static_cast<unsigned int>(-1);
+    thread_samples[i] = new float*[max_regions];
+    for (unsigned int r = 0; r < max_regions; r++) {
+      thread_samples[i][r] = new float[spp * max_depth];
+    }
+    current_region_id[i] = 0;
+    current_raw_region_id[i] = static_cast<unsigned int>(-1);
   }
 }
 
@@ -65,15 +96,16 @@
 void Stratified2D::buildSamples(RandomNumberGenerator* rng,
                                 unsigned int thread_id,
                                 unsigned int depth) {
+  float* all_samples = 
thread_samples[thread_id][current_region_id[thread_id]];
   if (max_depth - depth > 1) {
     // NOTE(boulos): We only want to generate the even cases
     if (depth % 2 == 0) {
-      float* x_samples = &(thread_samples[thread_id][spp * depth]);
-      float* y_samples = &(thread_samples[thread_id][spp * (depth+1)]);
+      float* x_samples = &(all_samples[spp * depth]);
+      float* y_samples = &(all_samples[spp * (depth+1)]);
       build2DSamples(rng, x_samples, y_samples);
     }
   } else {
-    float* sample_buf = &(thread_samples[thread_id][spp * depth]);
+    float* sample_buf = &(all_samples[spp * depth]);
     build1DSamples(rng, sample_buf);
   }
 }
@@ -154,23 +186,49 @@
   }
 }
 
+unsigned int Stratified2D::computeRegion(const RenderContext& context, 
RayPacket& rays, int i) {
+  // Compute pixel index
+  unsigned int raw_region_id = static_cast<unsigned 
int>(rays.data->region_id[i]);
+
+  if (raw_region_id != current_raw_region_id[context.proc]) {
+    // generate a new region_id
+    //std::cerr << "Generating a new region id because rri != crri (" << 
raw_region_id << ", ";
+    //std::cerr << current_raw_region_id[context.proc] << ")" << std::endl;
+    current_region_id[context.proc]++;
+    current_region_id[context.proc] %= max_regions;
+    current_raw_region_id[context.proc] = raw_region_id;
+    buildSamplesAllDepths(context.rng, context.proc);
+  }
+
+  return current_region_id[context.proc];
+}
+
 void Stratified2D::setupPacket(const RenderContext& context, RayPacket& 
rays) {
   rays.sample_depth = 0;
-  buildSamplesAllDepths(context.rng, context.proc);
+  bool constant_region = true;
+  for (int i = rays.begin(); i < rays.end(); i++) {
+    rays.data->region_id[i] = computeRegion(context, rays, i);
+    constant_region &= (rays.data->region_id[i] == 
rays.data->region_id[rays.begin()]);
+  }
+  if (constant_region)
+    rays.setFlag(RayPacket::ConstantSampleRegion);
 }
 
 void Stratified2D::setupChildPacket(const RenderContext& context, RayPacket& 
parent, RayPacket& child) {
   child.sample_depth = parent.sample_depth;
   for (int i = parent.begin(); i < parent.end(); i++) {
     child.data->sample_id[i] = parent.data->sample_id[i];
+    child.data->region_id[i] = parent.data->region_id[i];
+  }
+  if (parent.getFlag(RayPacket::ConstantSampleRegion)) {
+    child.setFlag(RayPacket::ConstantSampleRegion);
   }
 }
 
 void Stratified2D::nextSeeds(const RenderContext& context, Packet<float>& 
results, RayPacket& rays) {
   if (rays.sample_depth < max_depth) {
-    float* sample_buf = &(thread_samples[context.proc][spp * 
rays.sample_depth]);
     for (int i = rays.begin(); i < rays.end(); i++) {
-      results.set(i, sample_buf[rays.data->sample_id[i]]);
+      results.set(i, 
thread_samples[context.proc][rays.data->region_id[i]][spp * rays.sample_depth 
+ rays.data->sample_id[i]]);
     }
   } else {
     context.rng->nextPacket(results, rays);
@@ -180,10 +238,8 @@
 
 void Stratified2D::nextSeeds(const RenderContext& context, Packet<double>& 
results, RayPacket& rays) {
   if (rays.sample_depth < max_depth) {
-    float* sample_buf = &(thread_samples[context.proc][spp * 
rays.sample_depth]);
     for (int i = rays.begin(); i < rays.end(); i++) {
-
-      results.set(i, 
static_cast<double>(sample_buf[rays.data->sample_id[i]]));
+      results.set(i, 
static_cast<double>(thread_samples[context.proc][rays.data->region_id[i]][spp 
* rays.sample_depth + rays.data->sample_id[i]]));
     }
   } else {
     context.rng->nextPacket(results, rays);

Modified: trunk/Engine/SampleGenerators/Stratified2D.h
==============================================================================
--- trunk/Engine/SampleGenerators/Stratified2D.h        (original)
+++ trunk/Engine/SampleGenerators/Stratified2D.h        Fri Nov  2 13:34:49 
2007
@@ -27,6 +27,8 @@
     void build1DSamples(RandomNumberGenerator* rng,
                         float* sample_buf);
 
+    unsigned int computeRegion(const RenderContext& context, RayPacket& 
rays, int i);
+
     virtual void setupBegin(const SetupContext&, int numChannels);
     virtual void setupDisplayChannel(SetupContext& context);
     virtual void setupFrame(const RenderContext& context);
@@ -41,10 +43,12 @@
     float inv_spp;
     unsigned int sqrt_spp;
     float inv_sqrt_spp;
-    float** thread_samples;
+    float*** thread_samples;
     unsigned int max_depth;
+    unsigned int max_regions;
     unsigned int num_threads;
-    unsigned int* current_pixel; // num_threads wide
+    unsigned int* current_region_id; // num_threads wide
+    unsigned int* current_raw_region_id; // num_threads wide
     unsigned int xres;
     unsigned int yres;
   };

Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Fri Nov  2 13:34:49 2007
@@ -109,8 +109,9 @@
     Color::ComponentType importance[Manta::Color::NumComponents][MaxSize];   
// 1-attenuation, where eye rays have importance == 1
 
     // Int-based arrays
-    int whichEye[MaxSize];
-    int sample_id[MaxSize];
+    MANTA_ALIGN(16) int whichEye[MaxSize];
+    MANTA_ALIGN(16) int sample_id[MaxSize];
+    MANTA_ALIGN(16) int region_id[MaxSize];
     MANTA_ALIGN(16) int signs[3][MaxSize]; // 1=negative, 0=zero, positive
 
     // Scratchpad
@@ -152,6 +153,7 @@
       HaveCornerRays         = 0x00004000,
 
       HaveSurfaceDerivatives = 0x00008000,
+      ConstantSampleRegion   = 0x00010000,
 
       DebugPacket            = 0x80000000,
     };




  • [Manta] r1803 - in trunk: Engine/PixelSamplers Engine/SampleGenerators Interface, boulos, 11/02/2007

Archive powered by MHonArc 2.6.16.

Top of page