Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1046 - in trunk: . Interface Model/Backgrounds Model/Materials Model/Primitives Model/Textures StandAlone
- Date: Mon, 8 May 2006 15:33:48 -0600 (MDT)
Author: sparker
Date: Mon May 8 15:33:32 2006
New Revision: 1046
Added:
trunk/Interface/Packet.h
trunk/Interface/RayPacket.cc
Modified:
trunk/Interface/CMakeLists.txt
trunk/Interface/RayPacket.h
trunk/Interface/Texture.h
trunk/Model/Backgrounds/TextureBackground.cc
trunk/Model/Materials/AmbientOcclusion.cc
trunk/Model/Materials/Dielectric.cc
trunk/Model/Materials/Flat.cc
trunk/Model/Materials/Lambertian.cc
trunk/Model/Materials/MaterialTable.cc
trunk/Model/Materials/MetalMaterial.cc
trunk/Model/Materials/NDotL.cc
trunk/Model/Materials/Phong.cc
trunk/Model/Materials/Transparent.cc
trunk/Model/Primitives/Parallelogram.cc
trunk/Model/Textures/CheckerTexture.h
trunk/Model/Textures/Constant.h
trunk/Model/Textures/NormalTexture.cc
trunk/Model/Textures/NormalTexture.h
trunk/Model/Textures/TriVerTexture.cc
trunk/Model/Textures/TriVerTexture.h
trunk/StandAlone/manta.cc
trunk/TODO
Log:
Verticalize texturing
SSE parallelogram
Start SSE in Phong
Modified: trunk/Interface/CMakeLists.txt
==============================================================================
--- trunk/Interface/CMakeLists.txt (original)
+++ trunk/Interface/CMakeLists.txt Mon May 8 15:33:32 2006
@@ -33,6 +33,7 @@
Primitive.h
Primitive.cc
RayPacket.h
+ RayPacket.cc
Renderer.h
Renderer.cc
RenderParameters.h
Added: trunk/Interface/Packet.h
==============================================================================
--- (empty file)
+++ trunk/Interface/Packet.h Mon May 8 15:33:32 2006
@@ -0,0 +1,45 @@
+
+#ifndef Manta_Interface_Packet_h
+#define Manta_Interface_Packet_h
+
+#include <RayPacketParameters.h>
+#include <Core/Color/Color.h>
+#include <Core/Util/Align.h>
+
+namespace Manta {
+ template<typename ValueType>
+ class MANTA_ALIGN(16) Packet {
+ public:
+ enum {
+ MaxSize = RAYPACKET_MAXSIZE
+ };
+ MANTA_ALIGN(16) ValueType data[MaxSize];
+ const ValueType& get(int idx) const {
+ return data[idx];
+ }
+ ValueType get(int idx) {
+ return data[idx];
+ }
+ void set(int idx, ValueType value) {
+ data[idx] = value;
+ }
+ };
+ template<>
+ class MANTA_ALIGN(16) Packet<Color> {
+ public:
+ enum {
+ MaxSize = RAYPACKET_MAXSIZE
+ };
+ MANTA_ALIGN(16) Color::ComponentType
colordata[Color::NumComponents][MaxSize];
+ Color get(int idx) const {
+ return Color(RGB(colordata[0][idx], colordata[1][idx],
colordata[2][idx]));
+ }
+ void set(int idx, const Color& value) {
+ colordata[0][idx] = value[0];
+ colordata[1][idx] = value[1];
+ colordata[2][idx] = value[2];
+ }
+ };
+}
+
+#endif
Added: trunk/Interface/RayPacket.cc
==============================================================================
--- (empty file)
+++ trunk/Interface/RayPacket.cc Mon May 8 15:33:32 2006
@@ -0,0 +1,81 @@
+
+#include <Interface/RayPacket.h>
+#include <MantaSSE.h>
+
+using namespace Manta;
+
+void RayPacket::actualNormalizeDirections()
+{
+ if(flags & NormalizedDirections)
+ return;
+
+ if(flags & HaveHitRecords){
+ for(int i=rayBegin;i<rayEnd;i++){
+ Real sum = 0;
+ for(int j=0;j<3;j++)
+ sum += data->direction[j][i] * data->direction[j][i];
+ Real length = SCIRun::Sqrt(sum);
+ if(data->hitMatl[i] != 0)
+ data->minT[i] *= length;
+ Real scale = 1/length;
+ for(int j=0;j<3;j++)
+ data->direction[j][i] *= scale;
+ }
+ } else {
+#ifdef MANTA_SSE
+ int b = (rayBegin + 3) & (~3);
+ int e = rayEnd & (~3);
+ if(b == e){
+ for(int i=rayBegin;i<rayEnd;i++){
+ Real sum = 0;
+ for(int j=0;j<3;j++)
+ sum += data->direction[j][i] * data->direction[j][i];
+ Real scale = 1/SCIRun::Sqrt(sum);
+ for(int j=0;j<3;j++)
+ data->direction[j][i] *= scale;
+ }
+ } else {
+ int i = rayBegin;
+ for(;i<b;i++){
+ Real sum = 0;
+ for(int j=0;j<3;j++)
+ sum += data->direction[j][i] * data->direction[j][i];
+ Real scale = 1/SCIRun::Sqrt(sum);
+ for(int j=0;j<3;j++)
+ data->direction[j][i] *= scale;
+ }
+ for(;i<e;i+=4){
+ __m128 xd = _mm_load_ps(&data->direction[0][i]);
+ __m128 yd = _mm_load_ps(&data->direction[1][i]);
+ __m128 zd = _mm_load_ps(&data->direction[2][i]);
+ __m128 sum = _mm_add_ps(_mm_add_ps(_mm_mul_ps(xd, xd),
_mm_mul_ps(yd, yd)), _mm_mul_ps(zd, zd));
+ __m128 scale = _mm_rsqrt_ps(sum);
+ // Do one newton-raphson iteration to get the accuracy we need
+ scale = _mm_mul_ps(_mm_mul_ps(scale, _mm_sub_ps(_mm_set1_ps(3.f),
_mm_mul_ps(sum, _mm_mul_ps(scale, scale)))), _mm_set1_ps(0.5f));
+ _mm_store_ps(&data->direction[0][i], _mm_mul_ps(xd, scale));
+ _mm_store_ps(&data->direction[1][i], _mm_mul_ps(yd, scale));
+ _mm_store_ps(&data->direction[2][i], _mm_mul_ps(zd, scale));
+ }
+ for(;i<rayEnd;i++){
+ Real sum = 0;
+ for(int j=0;j<3;j++)
+ sum += data->direction[j][i] * data->direction[j][i];
+ Real scale = 1/SCIRun::Sqrt(sum);
+ for(int j=0;j<3;j++)
+ data->direction[j][i] *= scale;
+ }
+ }
+#else
+ for(int i=rayBegin;i<rayEnd;i++){
+ Real sum = 0;
+ for(int j=0;j<3;j++)
+ sum += data->direction[j][i] * data->direction[j][i];
+ Real scale = 1/SCIRun::Sqrt(sum);
+ for(int j=0;j<3;j++)
+ data->direction[j][i] *= scale;
+ }
+#endif
+ }
+ flags |= NormalizedDirections;
+ flags &= ~HaveInverseDirections;
+}
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon May 8 15:33:32 2006
@@ -270,30 +270,7 @@
if(flags & NormalizedDirections)
return;
- if(flags & HaveHitRecords){
- for(int i=rayBegin;i<rayEnd;i++){
- Real sum = 0;
- for(int j=0;j<3;j++)
- sum += data->direction[j][i] * data->direction[j][i];
- Real length = SCIRun::Sqrt(sum);
- if(data->hitMatl[i] != 0)
- data->minT[i] *= length;
- Real scale = 1/length;
- for(int j=0;j<3;j++)
- data->direction[j][i] *= scale;
- }
- } else {
- for(int i=rayBegin;i<rayEnd;i++){
- Real sum = 0;
- for(int j=0;j<3;j++)
- sum += data->direction[j][i] * data->direction[j][i];
- Real scale = 1/SCIRun::Sqrt(sum);
- for(int j=0;j<3;j++)
- data->direction[j][i] *= scale;
- }
- }
- flags |= NormalizedDirections;
- flags &= ~HaveInverseDirections;
+ actualNormalizeDirections();
}
void computeInverseDirections()
{
@@ -570,6 +547,8 @@
}
private:
+ void actualNormalizeDirections();
+
// Prevent accidental copying of RayPackets
RayPacket(const RayPacket&);
RayPacket& operator=(const RayPacket&);
Modified: trunk/Interface/Texture.h
==============================================================================
--- trunk/Interface/Texture.h (original)
+++ trunk/Interface/Texture.h Mon May 8 15:33:32 2006
@@ -2,6 +2,8 @@
#ifndef Manta_Interface_Texture_h
#define Manta_Interface_Texture_h
+#include <Interface/Packet.h>
+
namespace Manta {
class RayPacket;
class RenderContext;
@@ -11,8 +13,7 @@
Texture();
virtual ~Texture();
- virtual void mapValues(const RenderContext& context, RayPacket& rays,
- ValueType results[]) const = 0;
+ virtual void mapValues(Packet<ValueType>& results, const RenderContext&
context, RayPacket& rays) const = 0;
private:
Texture(const Texture&);
Texture& operator=(const Texture&);
Modified: trunk/Model/Backgrounds/TextureBackground.cc
==============================================================================
--- trunk/Model/Backgrounds/TextureBackground.cc (original)
+++ trunk/Model/Backgrounds/TextureBackground.cc Mon May 8 15:33:32
2006
@@ -88,12 +88,12 @@
rays.setFlag(RayPacket::HaveHitPositions);
// Now get the colors from the texture.
- Color bg_color[RayPacket::MaxSize];
- colortex->mapValues(context, rays, bg_color);
+ Packet<Color> bg_color;
+ colortex->mapValues(bg_color, context, rays);
// Copy the colors over.
for(int i=rays.begin();i<rays.end();i++){
- rays.setColor(i, bg_color[i]);
+ rays.setColor(i, bg_color.get(i));
}
}
Modified: trunk/Model/Materials/AmbientOcclusion.cc
==============================================================================
--- trunk/Model/Materials/AmbientOcclusion.cc (original)
+++ trunk/Model/Materials/AmbientOcclusion.cc Mon May 8 15:33:32 2006
@@ -144,14 +144,14 @@
} while(!done);
// Compute diffuse colors
- Color diffuse[RayPacket::MaxSize];
- colortex->mapValues(context, rays, diffuse);
+ Packet<Color> diffuse;
+ colortex->mapValues(diffuse, context, rays);
// Sum up diffuse/specular contributions
for(int i = rays.begin(); i < rays.end(); i++){
Color result;
for(int j=0;j<Color::NumComponents;j++)
- result[j] = diffuse[i][j] * total[j][i];
+ result[j] = diffuse.colordata[j][i] * total[j][i];
rays.setColor(i, result);
}
}
Modified: trunk/Model/Materials/Dielectric.cc
==============================================================================
--- trunk/Model/Materials/Dielectric.cc (original)
+++ trunk/Model/Materials/Dielectric.cc Mon May 8 15:33:32 2006
@@ -66,13 +66,13 @@
rays.normalizeDirections();
rays.computeNormals(context);
- Real n_values[RayPacket::MaxSize];
- Real nt_values[RayPacket::MaxSize];
- Color sigma_a_values[RayPacket::MaxSize];
-
- n->mapValues(context, rays, n_values);
- nt->mapValues(context, rays, nt_values);
- sigma_a->mapValues(context, rays, sigma_a_values);
+ Packet<Real> n_values;
+ Packet<Real> nt_values;
+ Packet<Color> sigma_a_values;
+
+ n->mapValues(n_values, context, rays);
+ nt->mapValues(nt_values, context, rays);
+ sigma_a->mapValues(sigma_a_values, context, rays);
RayPacketData reflected_data;
RayPacketData refracted_data;
@@ -104,13 +104,13 @@
bool was_incoming = ( n_dot_v < 0 );
Color beers_color;
if ( was_incoming ) {
- eta_tmp_inv = nt_values[i]/n_values[i];
+ eta_tmp_inv = nt_values.data[i]/n_values.data[i];
n_dot_v = -n_dot_v;
beers_color = Color::white();
} else {
normal = -normal;
- eta_tmp_inv = n_values[i]/nt_values[i];
- beers_color = sigma_a_values[i].Pow(rays.getMinT(i));
+ eta_tmp_inv = n_values.data[i]/nt_values.data[i];
+ beers_color = sigma_a_values.get(i).Pow(rays.getMinT(i));
}
Real cosine_sq = 1 + (n_dot_v*n_dot_v - 1) * (eta_tmp_inv*eta_tmp_inv);
@@ -132,7 +132,7 @@
Real k = 1 - cosine;
k*=(k*k)*(k*k);
- Real r0 = (n_values[i] - nt_values[i]) / (n_values[i] + nt_values[i]);
+ Real r0 = (n_values.data[i] - nt_values.data[i]) / (n_values.data[i] +
nt_values.data[i]);
r0 *= r0;
Real R = r0*(1-k) + k;
Modified: trunk/Model/Materials/Flat.cc
==============================================================================
--- trunk/Model/Materials/Flat.cc (original)
+++ trunk/Model/Materials/Flat.cc Mon May 8 15:33:32 2006
@@ -59,10 +59,10 @@
{
// Compute colors
- Color colors[RayPacket::MaxSize];
- colortex->mapValues(context, rays, colors);
+ Packet<Color> colors;
+ colortex->mapValues(colors, context, rays);
// Copy the colors into the ray packet.
for(int i=rays.begin();i<rays.end();i++)
- rays.setColor( i, colors[i] );
+ rays.setColor( i, colors.get(i) );
}
Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Mon May 8 15:33:32 2006
@@ -34,8 +34,8 @@
rays.computeNormals(context);
// Compute colors
- Color diffuse[RayPacket::MaxSize];
- colortex->mapValues(context, rays, diffuse);
+ Packet<Color> diffuse;
+ colortex->mapValues(diffuse, context, rays);
// Compute ambient contributions for all rays
ColorArray totalLight;
@@ -84,7 +84,7 @@
for(int i = rays.begin(); i < rays.end(); i++){
Color result;
for(int j=0;j<Color::NumComponents;j++)
- result[j] = totalLight[j][i] * diffuse[i][j];
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
rays.setColor(i, result);
}
Modified: trunk/Model/Materials/MaterialTable.cc
==============================================================================
--- trunk/Model/Materials/MaterialTable.cc (original)
+++ trunk/Model/Materials/MaterialTable.cc Mon May 8 15:33:32 2006
@@ -58,16 +58,16 @@
void MaterialTable::shade(const RenderContext& context, RayPacket& rays)
const {
// Determine material id's.
- int id[RayPacket::MaxSize];
- id_texture->mapValues( context, rays, id );
+ Packet<int> id;
+ id_texture->mapValues( id, context, rays );
// Shade continuous subpackets of matching materials.
for(int i = rays.begin();i<rays.end();){
- const Material *hit_matl = material_table[ id[i] ].material;
+ const Material *hit_matl = material_table[ id.data[i] ].material;
int end = i+1;
while(end < rays.end() && rays.wasHit(end) &&
- material_table[id[end]].material == hit_matl)
+ material_table[id.data[end]].material == hit_matl)
end++;
// Shade the subpacket of rays.
Modified: trunk/Model/Materials/MetalMaterial.cc
==============================================================================
--- trunk/Model/Materials/MetalMaterial.cc (original)
+++ trunk/Model/Materials/MetalMaterial.cc Mon May 8 15:33:32 2006
@@ -35,8 +35,8 @@
if(rays.getDepth() < context.scene->getRenderParameters().maxDepth) {
rays.normalizeDirections();
rays.computeNormals(context);
- Color specular[RayPacket::MaxSize];
- specular_reflectance->mapValues(context, rays, specular);
+ Packet<Color> specular;
+ specular_reflectance->mapValues(specular, context, rays);
rays.computeHitPositions();
RayPacketData rdata;
@@ -63,7 +63,7 @@
// don't do things like multiply all the colors by a double,
// thus promoting those expressions when we don't need to.
ColorComponent kc = (ColorComponent)k;
- Color R = specular[i] * (1-kc) + Color::white()*kc;
+ Color R = specular.get(i) * (1-kc) + Color::white()*kc;
rays.setColor(i, R * refl_rays.getColor(i));
}
Modified: trunk/Model/Materials/NDotL.cc
==============================================================================
--- trunk/Model/Materials/NDotL.cc (original)
+++ trunk/Model/Materials/NDotL.cc Mon May 8 15:33:32 2006
@@ -67,8 +67,8 @@
{
rays.computeNormals(context);
// Compute colors
- Color colors[RayPacket::MaxSize];
- colortex->mapValues(context, rays, colors);
+ Packet<Color> colors;
+ colortex->mapValues(colors, context, rays);
// Copy the colors into the ray packet.
for(int i=rays.begin();i<rays.end();i++)
@@ -78,6 +78,6 @@
if (cosine < 0)
cosine = 0;
//rays.setColor( i, colors[i] * cosine );
- rays.setColor(i, colors[i]);
+ rays.setColor(i, colors.get(i));
}
}
Modified: trunk/Model/Materials/Phong.cc
==============================================================================
--- trunk/Model/Materials/Phong.cc (original)
+++ trunk/Model/Materials/Phong.cc Mon May 8 15:33:32 2006
@@ -41,6 +41,7 @@
#include <Model/Textures/Constant.h>
#include <Core/Util/NotFinished.h>
#include <Core/Color/ColorSpace_fancy.h>
+#include <MantaSSE.h>
using namespace Manta;
@@ -83,10 +84,10 @@
rays.normalizeDirections();
// Compute colors
- Color diffuse[RayPacket::MaxSize];
- diffusetex->mapValues(context, rays, diffuse);
- Color specular[RayPacket::MaxSize];
- speculartex->mapValues(context, rays, specular);
+ Packet<Color> diffuse;
+ diffusetex->mapValues(diffuse, context, rays);
+ Packet<Color> specular;
+ speculartex->mapValues(specular, context, rays);
// Compute normals
rays.computeNormals(context);
@@ -150,17 +151,50 @@
} while(!done);
// Sum up diffuse/specular contributions
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i = rays.begin(); i < rays.end(); i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = specularLight[j][i] * specular.colordata[j][i] +
ambientAndDiffuseLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = specularLight[j][i] * specular.colordata[j][i] +
ambientAndDiffuseLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ RayPacketData* data = rays.data;
+ for(;i<e;i+=4){
+ _mm_store_ps(&data->color[0][i],
_mm_add_ps(_mm_mul_ps(_mm_load_ps(&specularLight[0][i]),
_mm_load_ps(&specular.colordata[0][i])),
_mm_mul_ps(_mm_load_ps(&ambientAndDiffuseLight[0][i]),
_mm_load_ps(&diffuse.colordata[0][i]))));
+ _mm_store_ps(&data->color[1][i],
_mm_add_ps(_mm_mul_ps(_mm_load_ps(&specularLight[1][i]),
_mm_load_ps(&specular.colordata[1][i])),
_mm_mul_ps(_mm_load_ps(&ambientAndDiffuseLight[1][i]),
_mm_load_ps(&diffuse.colordata[1][i]))));
+ _mm_store_ps(&data->color[2][i],
_mm_add_ps(_mm_mul_ps(_mm_load_ps(&specularLight[2][i]),
_mm_load_ps(&specular.colordata[2][i])),
_mm_mul_ps(_mm_load_ps(&ambientAndDiffuseLight[2][i]),
_mm_load_ps(&diffuse.colordata[2][i]))));
+ }
+ for(;i<rays.rayEnd;i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = specularLight[j][i] * specular.colordata[j][i] +
ambientAndDiffuseLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ }
+#else
for(int i = rays.begin(); i < rays.end(); i++){
Color result;
for(int j=0;j<Color::NumComponents;j++)
- result[j] = specularLight[j][i] * specular[i][j] +
ambientAndDiffuseLight[j][i] * diffuse[i][j];
+ result[j] = specularLight[j][i] * specular.colordata[j][i] +
ambientAndDiffuseLight[j][i] * diffuse.colordata[j][i];
rays.setColor(i, result);
}
+#endif
// Compute reflections
if(do_refl && rays.getDepth() <
context.scene->getRenderParameters().maxDepth){
- ColorComponent refl[RayPacket::MaxSize];
- refltex->mapValues(context, rays, refl);
+ Packet<ColorComponent> refl;
+ refltex->mapValues(refl, context, rays);
rays.computeHitPositions();
RayPacketData rdata;
@@ -170,11 +204,11 @@
Vector refl_dir = (rays.getDirection(i) -
rays.getNormal(i)*(2*Dot(rays.getNormal(i),
rays.getDirection(i) )));
refl_rays.setRay(i, rays.getHitPosition(i), refl_dir);
- refl_rays.setImportance(i, rays.getImportance(i) * refl[i]);
+ refl_rays.setImportance(i, rays.getImportance(i) * refl.data[i]);
}
refl_rays.resetHits();
context.renderer->traceRays(context, refl_rays);
for(int i=rays.begin();i<rays.end();i++)
- rays.setColor(i, rays.getColor(i) + refl_rays.getColor(i) * refl[i]);
+ rays.setColor(i, rays.getColor(i) + refl_rays.getColor(i) *
refl.data[i]);
}
}
Modified: trunk/Model/Materials/Transparent.cc
==============================================================================
--- trunk/Model/Materials/Transparent.cc (original)
+++ trunk/Model/Materials/Transparent.cc Mon May 8 15:33:32 2006
@@ -65,8 +65,8 @@
rays.computeHitPositions();
// Compute colors
- Color diffuse[RayPacket::MaxSize];
- color->mapValues(context, rays, diffuse);
+ Packet<Color> diffuse;
+ color->mapValues(diffuse, context, rays);
// Compute ambient contributions for all rays
ColorArray totalLight;
@@ -115,15 +115,15 @@
for(int i = rays.begin(); i < rays.end(); i++){
Color result;
for(int j=0;j<Color::NumComponents;j++) {
- result[j] = totalLight[j][i] * diffuse[i][j];
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
}
rays.setColor( i, result );
}
// Check to see what the alpha value is for this location.
- ColorComponent alpha_values[RayPacket::MaxSize];
- alpha->mapValues( context, rays, alpha_values );
+ Packet<ColorComponent> alpha_values;
+ alpha->mapValues( alpha_values, context, rays );
RayPacketData secondaryData;
RayPacket secondaryRays(secondaryData, RayPacket::UnknownShape, 0, 0,
rays.getDepth(), 0);
@@ -132,7 +132,7 @@
// Shoot a secondary ray for all 1.0 alpha values.
int size = 0;
for (int i=rays.begin();i<rays.end();++i) {
- if (alpha_values[i] < (ColorComponent)1.0) {
+ if (alpha_values.data[i] < (ColorComponent)1.0) {
secondaryRays.setOrigin ( size, rays.getHitPosition( i ) );
secondaryRays.setDirection( size, rays.getDirection ( i ) );
map[size] = i;
@@ -152,8 +152,8 @@
// Blend the secondary ray color based on the alpha.
rays.setColor( map[i],
- (second*((ColorComponent)1.0-alpha_values[map[i]])) +
- (first*(alpha_values[map[i]])));
+ (second*((ColorComponent)1.0-alpha_values.data[map[i]])) +
+ (first*(alpha_values.data[map[i]])));
}
}
Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc (original)
+++ trunk/Model/Primitives/Parallelogram.cc Mon May 8 15:33:32 2006
@@ -3,6 +3,7 @@
#include <Interface/RayPacket.h>
#include <Core/Geometry/BBox.h>
#include <Core/Math/MiscMath.h>
+#include <MantaSSE.h>
using namespace Manta;
using SCIRun::Abs;
@@ -49,13 +50,115 @@
// affect this value. You should be doing this dot product against
// normalized vectors anyway.
rays.normalizeDirections();
- if(rays.getFlag(RayPacket::ConstantOrigin) && rays.end()-rays.begin() > 1){
+ if(rays.getFlag(RayPacket::ConstantOrigin)){
Real num = d-Dot(normal, rays.getOrigin(0));
Vector a(rays.getOrigin(0)-anchor);
Real o1 = Dot(a, v1);
Real o2 = Dot(a, v2);
- int i = rays.begin();
- do {
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i = rays.begin(); i < rays.end(); i++){
+ Real dt=Dot(rays.getDirection(i), normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Real t=num/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector vi(rays.getDirection(i)*t);
+ Real a1 = Dot(v1, vi)+o1;
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi)+o2;
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ Real dt=Dot(rays.getDirection(i), normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Real t=num/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector vi(rays.getDirection(i)*t);
+ Real a1 = Dot(v1, vi)+o1;
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi)+o2;
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ RayPacketData* data = rays.data;
+ __m128 normalx = _mm_set1_ps(normal[0]);
+ __m128 normaly = _mm_set1_ps(normal[1]);
+ __m128 normalz = _mm_set1_ps(normal[2]);
+ __m128 vec_o1 = _mm_set1_ps(o1);
+ __m128 vec_o2 = _mm_set1_ps(o2);
+ __m128 vec_num = _mm_set1_ps(num);
+ for(;i<e;i+=4){
+ __m128 dx = _mm_load_ps(&data->direction[0][i]);
+ __m128 dy = _mm_load_ps(&data->direction[1][i]);
+ __m128 dz = _mm_load_ps(&data->direction[2][i]);
+ __m128 dt = _mm_add_ps(_mm_add_ps(_mm_mul_ps(dx, normalx),
_mm_mul_ps(dy, normaly)), _mm_mul_ps(dz, normalz));
+
+ //if(Abs(dt) < (Real)1.e-6)
+ //continue;
+ __m128 t = _mm_div_ps(vec_num, dt);
+ __m128 hit = _mm_and_ps(_mm_cmplt_ps(t, _mm_load_ps(&data->minT[i])),
+ _mm_cmpgt_ps(t, _mm_set1_ps(T_EPSILON)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ __m128 vix = _mm_mul_ps(dx, t);
+ __m128 viy = _mm_mul_ps(dy, t);
+ __m128 viz = _mm_mul_ps(dz, t);
+ __m128 a1 = _mm_add_ps(_mm_add_ps(_mm_add_ps(_mm_mul_ps(vix,
_mm_set1_ps(v1[0])), _mm_mul_ps(viy, _mm_set1_ps(v1[1]))), _mm_mul_ps(viz,
_mm_set1_ps(v1[2]))), vec_o1);
+ __m128 zero = _mm_setzero_ps();
+ __m128 one = _mm_set1_ps(1.0f);
+ hit = _mm_and_ps(hit, _mm_and_ps(_mm_cmpge_ps(a1, zero),
_mm_cmple_ps(a1, one)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ __m128 a2 = _mm_add_ps(_mm_add_ps(_mm_add_ps(_mm_mul_ps(vix,
_mm_set1_ps(v2[0])), _mm_mul_ps(viy, _mm_set1_ps(v2[1]))), _mm_mul_ps(viz,
_mm_set1_ps(v2[2]))), vec_o2);
+ hit = _mm_and_ps(hit, _mm_and_ps(_mm_cmpge_ps(a2, zero),
_mm_cmple_ps(a2, one)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ _mm_maskmoveu_si128((__m128i)t, (__m128i)hit, (char*)&data->minT[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)getMaterial()),
(__m128i)hit, (char*)&data->hitMatl[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)this), (__m128i)hit,
(char*)&data->hitPrim[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)getTexCoordMapper()),
(__m128i)hit, (char*)&data->hitTex[i]);
+ }
+ for(;i<rays.rayEnd;i++){
+ Real dt=Dot(rays.getDirection(i), normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Real t=num/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector vi(rays.getDirection(i)*t);
+ Real a1 = Dot(v1, vi)+o1;
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi)+o2;
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ }
+#else
+ for(int i = rays.begin(); i < rays.end(); i++){
Real dt=Dot(rays.getDirection(i), normal);
if(Abs(dt) < (Real)1.e-6)
continue;
@@ -72,10 +175,129 @@
if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
- } while(++i < rays.end());
+ }
+#endif
} else {
- int i = rays.begin();
- do {
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i=rays.rayBegin;i<rays.rayEnd;i++){
+ Vector dir = rays.getDirection(i);
+ Real dt=Dot(dir, normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Vector origin = rays.getOrigin(i);
+ Real t=(d-Dot(normal, origin))/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector p(origin+dir*t);
+ Vector vi(p-anchor);
+ Real a1 = Dot(v1, vi);
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi);
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ Vector dir = rays.getDirection(i);
+ Real dt=Dot(dir, normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Vector origin = rays.getOrigin(i);
+ Real t=(d-Dot(normal, origin))/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector p(origin+dir*t);
+ Vector vi(p-anchor);
+ Real a1 = Dot(v1, vi);
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi);
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ RayPacketData* data = rays.data;
+ __m128 normalx = _mm_set1_ps(normal[0]);
+ __m128 normaly = _mm_set1_ps(normal[1]);
+ __m128 normalz = _mm_set1_ps(normal[2]);
+ for(;i<e;i+=4){
+ __m128 dx = _mm_load_ps(&data->direction[0][i]);
+ __m128 dy = _mm_load_ps(&data->direction[1][i]);
+ __m128 dz = _mm_load_ps(&data->direction[2][i]);
+ __m128 dt = _mm_add_ps(_mm_add_ps(_mm_mul_ps(dx, normalx),
_mm_mul_ps(dy, normaly)), _mm_mul_ps(dz, normalz));
+
+ //if(Abs(dt) < (Real)1.e-6)
+ //continue;
+ __m128 ox = _mm_load_ps(&data->origin[0][i]);
+ __m128 oy = _mm_load_ps(&data->origin[1][i]);
+ __m128 oz = _mm_load_ps(&data->origin[2][i]);
+ __m128 dot = _mm_add_ps(_mm_add_ps(_mm_mul_ps(ox, normalx),
_mm_mul_ps(oy, normaly)), _mm_mul_ps(oz, normalz));
+ __m128 t = _mm_div_ps(_mm_sub_ps(_mm_set1_ps(d), dot), dt);
+
+ __m128 hit = _mm_and_ps(_mm_cmplt_ps(t, _mm_load_ps(&data->minT[i])),
+ _mm_cmpgt_ps(t, _mm_set1_ps(T_EPSILON)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ __m128 px = _mm_add_ps(ox, _mm_mul_ps(dx, t));
+ __m128 py = _mm_add_ps(oy, _mm_mul_ps(dy, t));
+ __m128 pz = _mm_add_ps(oz, _mm_mul_ps(dz, t));
+
+ __m128 vix = _mm_sub_ps(px, _mm_set1_ps(anchor[0]));
+ __m128 viy = _mm_sub_ps(py, _mm_set1_ps(anchor[1]));
+ __m128 viz = _mm_sub_ps(pz, _mm_set1_ps(anchor[2]));
+
+ __m128 a1 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(vix,
_mm_set1_ps(v1[0])), _mm_mul_ps(viy, _mm_set1_ps(v1[1]))), _mm_mul_ps(viz,
_mm_set1_ps(v1[2])));
+ __m128 zero = _mm_setzero_ps();
+ __m128 one = _mm_set1_ps(1.0f);
+ hit = _mm_and_ps(hit, _mm_and_ps(_mm_cmpge_ps(a1, zero),
_mm_cmple_ps(a1, one)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ __m128 a2 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(vix,
_mm_set1_ps(v2[0])), _mm_mul_ps(viy, _mm_set1_ps(v2[1]))), _mm_mul_ps(viz,
_mm_set1_ps(v2[2])));
+ hit = _mm_and_ps(hit, _mm_and_ps(_mm_cmpge_ps(a2, zero),
_mm_cmple_ps(a2, one)));
+ if(_mm_movemask_ps(hit) == 0)
+ continue;
+
+ _mm_maskmoveu_si128((__m128i)t, (__m128i)hit, (char*)&data->minT[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)getMaterial()),
(__m128i)hit, (char*)&data->hitMatl[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)this), (__m128i)hit,
(char*)&data->hitPrim[i]);
+ _mm_maskmoveu_si128(_mm_set1_epi32((int)getTexCoordMapper()),
(__m128i)hit, (char*)&data->hitTex[i]);
+ }
+ for(;i<rays.rayEnd;i++){
+ Vector dir = rays.getDirection(i);
+ Real dt=Dot(dir, normal);
+ if(Abs(dt) < (Real)1.e-6)
+ continue;
+ Vector origin = rays.getOrigin(i);
+ Real t=(d-Dot(normal, origin))/dt;
+ if(t>rays.getMinT(i))
+ continue;
+ Vector p(origin+dir*t);
+ Vector vi(p-anchor);
+ Real a1 = Dot(v1, vi);
+ if (a1 < 0 || a1 > 1)
+ continue;
+ Real a2 = Dot(v2, vi);
+ if (a2 < 0 || a2 > 1)
+ continue;
+
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
+ rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
+ }
+ }
+#else
+ for(int i = rays.begin(); i < rays.end(); i++){
Vector dir = rays.getDirection(i);
Real dt=Dot(dir, normal);
if(Abs(dt) < (Real)1.e-6)
@@ -95,7 +317,8 @@
if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
- } while(++i < rays.end());
+ }
+#endif
}
}
Modified: trunk/Model/Textures/CheckerTexture.h
==============================================================================
--- trunk/Model/Textures/CheckerTexture.h (original)
+++ trunk/Model/Textures/CheckerTexture.h Mon May 8 15:33:32 2006
@@ -17,8 +17,7 @@
const Vector& v1, const Vector& v2);
virtual ~CheckerTexture();
- virtual void mapValues(const RenderContext& context, RayPacket& rays,
- ValueType results[]) const;
+ virtual void mapValues(Packet<ValueType>&, const RenderContext& context,
RayPacket& rays) const;
private:
CheckerTexture(const CheckerTexture&);
CheckerTexture& operator=(const CheckerTexture&);
@@ -50,9 +49,8 @@
}
template<class ValueType>
- void CheckerTexture<ValueType>::mapValues(const RenderContext& context,
- RayPacket& rays,
- ValueType results[]) const
+ void CheckerTexture<ValueType>::mapValues(Packet<ValueType>& results,
const RenderContext& context,
+ RayPacket& rays) const
{
if(need_w)
rays.computeTextureCoordinates3(context);
@@ -68,7 +66,7 @@
int i1 = (int)vv1;
int i2 = (int)vv2;
int which = (i1+i2)%2;
- results[i] = values[which];
+ results.set(i, values[which]);
}
}
Modified: trunk/Model/Textures/Constant.h
==============================================================================
--- trunk/Model/Textures/Constant.h (original)
+++ trunk/Model/Textures/Constant.h Mon May 8 15:33:32 2006
@@ -14,12 +14,11 @@
Constant(const ValueType& value);
virtual ~Constant();
- virtual void mapValues(const RenderContext& context, RayPacket& rays,
- ValueType results[]) const;
+ virtual void mapValues(Packet<ValueType>& results, const RenderContext&
context, RayPacket& rays) const;
ValueType getValue() const { return value; }
- void setValue( const ValueType value_ ) { value = value_; }
-
+ void setValue( const ValueType value_ ) { value = value_; }
+
private:
Constant(const Constant&);
Constant& operator=(const Constant&);
@@ -39,12 +38,11 @@
}
template<class ValueType>
- void Constant<ValueType>::mapValues(const RenderContext&,
- RayPacket& rays,
- ValueType results[]) const
+ void Constant<ValueType>::mapValues(Packet<ValueType>& results, const
RenderContext&,
+ RayPacket& rays) const
{
for(int i=rays.begin();i<rays.end();i++)
- results[i] = value;
+ results.set(i, value);
}
}
Modified: trunk/Model/Textures/NormalTexture.cc
==============================================================================
--- trunk/Model/Textures/NormalTexture.cc (original)
+++ trunk/Model/Textures/NormalTexture.cc Mon May 8 15:33:32 2006
@@ -147,14 +147,14 @@
}
template<class ScratchPadInfo, class ValueType>
-void WireframeTexture<ScratchPadInfo,ValueType>::mapValues(const
RenderContext &context, RayPacket& rays, ValueType results[]) const {
+void
WireframeTexture<ScratchPadInfo,ValueType>::mapValues(Packet<ValueType>&
results, const RenderContext &context, RayPacket& rays) const {
// Compute the normal for each ray.
rays.computeNormals( context );
// Lookup dependent texture values.
- ValueType texture_values[RayPacket::MaxSize];
- texture->mapValues( context, rays, texture_values );
+ Packet<ValueType> texture_values;
+ texture->mapValues( texture_values, context, rays );
// Iterate over the packet and set the colors.
for (int i=rays.begin();i<rays.end();++i) {
@@ -164,13 +164,13 @@
getBarycentricCoords( rays, i, a, b, c );
if ((a < 0.05) || (b < 0.05) || (c < 0.05)) {
- results[i] = wire_value;
+ results.set(i, wire_value);
}
else {
- results[i] = texture_values[i];
+ results.set(i, texture_values.get(i));
}
- }
+ }
}
Modified: trunk/Model/Textures/NormalTexture.h
==============================================================================
--- trunk/Model/Textures/NormalTexture.h (original)
+++ trunk/Model/Textures/NormalTexture.h Mon May 8 15:33:32 2006
@@ -64,7 +64,7 @@
WireframeTexture( const ValueType &color_, const ValueType &wire_value_
);
virtual ~WireframeTexture() { }
- virtual void mapValues(const RenderContext&, RayPacket& rays, ValueType
results[]) const;
+ virtual void mapValues(Packet<ValueType>& results, const RenderContext&,
RayPacket& rays) const;
private:
///////////////////////////////////////////////////////////////////////////
Modified: trunk/Model/Textures/TriVerTexture.cc
==============================================================================
--- trunk/Model/Textures/TriVerTexture.cc (original)
+++ trunk/Model/Textures/TriVerTexture.cc Mon May 8 15:33:32 2006
@@ -11,9 +11,8 @@
{
}
- void TriVerTexture::mapValues(const RenderContext& context,
- RayPacket& rays,
- Color results[]) const
+ void TriVerTexture::mapValues(Packet<Color>& results, const RenderContext&
context,
+ RayPacket& rays) const
{
rays.computeTextureCoordinates3( context );
@@ -22,8 +21,8 @@
Triangle::TriangleHit& th = rays.scratchpad<Triangle::TriangleHit>(i);
const VertexColoredTriangle* vct =
static_cast<const VertexColoredTriangle*>(rays.getHitPrimitive(i));
- results[i] = vct->getVertexColor(0)*(1 - th.a - th.b) +
- vct->getVertexColor(1)*th.a + vct->getVertexColor(2)*th.b;
+ results.set(i, vct->getVertexColor(0)*(1 - th.a - th.b) +
+ vct->getVertexColor(1)*th.a + vct->getVertexColor(2)*th.b);
}
}
}
Modified: trunk/Model/Textures/TriVerTexture.h
==============================================================================
--- trunk/Model/Textures/TriVerTexture.h (original)
+++ trunk/Model/Textures/TriVerTexture.h Mon May 8 15:33:32 2006
@@ -16,8 +16,7 @@
TriVerTexture();
virtual ~TriVerTexture();
- virtual void mapValues(const RenderContext& context, RayPacket& rays,
- Color results[]) const;
+ virtual void mapValues(Packet<Color>& result, const RenderContext&
context, RayPacket& rays) const;
private:
TriVerTexture(const TriVerTexture&);
Modified: trunk/StandAlone/manta.cc
==============================================================================
--- trunk/StandAlone/manta.cc (original)
+++ trunk/StandAlone/manta.cc Mon May 8 15:33:32 2006
@@ -326,19 +326,21 @@
}
} else if(arg == "-scene"){
- if(rtrt->haveScene())
- cerr << "WARNING: multiple scenes
specified, will use last one\n";
- string scene;
- if(!getStringArg(i, args, scene))
- usage(rtrt);
- if(!rtrt->readScene(scene)){
- cerr << "Error reading scene: " <<
scene << '\n';
- throw IllegalArgument( "-scene", i,
args );
- }
+ if(rtrt->haveScene())
+ cerr << "WARNING: multiple scenes specified, will use last one\n";
+ string scene;
+ if(!getStringArg(i, args, scene))
+ usage(rtrt);
+ if(!rtrt->readScene(scene)){
+ cerr << "Error reading scene: " << scene << '\n';
+ throw IllegalArgument( "-scene", i, args );
+ }
}
else if (arg == "-stack") {
if (!getStringArg(i,args,stack_file))
usage(rtrt);
+ } else {
+ usage(rtrt);
}
}
Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Mon May 8 15:33:32 2006
@@ -1,3 +1,34 @@
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i = rays.begin(); i < rays.end(); i++){
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ }
+ RayPacketData* data = rays.data;
+ for(;i<e;i+=4){
+ }
+ for(;i<rays.rayEnd;i++){
+ }
+ }
+#else
+ for(int i = rays.begin(); i < rays.end(); i++){
+ }
+#endif
+
+
+namespace std {
+ std::ostream& operator<< (std::ostream& os, __m128 d)
+ {
+ float* data = (float*)&d;
+ cerr << '[' << data[0] << ", " << data[1] << ", " << data[2] << ", " <<
data[3] << ']';;
+ }
+}
+
+
Point/Vector:
- double-check const-correctness
- [MANTA] r1046 - in trunk: . Interface Model/Backgrounds Model/Materials Model/Primitives Model/Textures StandAlone, sparker, 05/08/2006
Archive powered by MHonArc 2.6.16.