Text archives Help
- From: sparker@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1247 - in trunk: Interface Model/Primitives
- Date: Tue, 5 Dec 2006 23:54:16 -0700 (MST)
Author: sparker
Date: Tue Dec 5 23:54:15 2006
New Revision: 1247
Modified:
trunk/Interface/RayPacket.h
trunk/Model/Primitives/Parallelogram.cc
Log:
Implemented vertical scratchpad interface. Tested it in parallelogram,
but it is currently disabled in favor of depositing the texture coordinates
directly.
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Tue Dec 5 23:54:15 2006
@@ -58,6 +58,9 @@
class MANTA_ALIGN(16) RayPacketData {
public:
enum {
+ // Scratchpads - 8 values of 4 bytes, 4 values of 8 bytes,
+ MaxScratchpad4 = 8,
+ MaxScratchpad8 = 4,
MaxScratchpadSize = SCRATCHPAD_MAXSIZE,
MaxSize = RAYPACKET_MAXSIZE,
#ifdef MANTA_SSE
@@ -105,6 +108,10 @@
int whichEye[MaxSize];
MANTA_ALIGN(16) int signs[3][MaxSize]; // 1=negative, 0=zero, positive
+ // Scratchpad
+ MANTA_ALIGN(16) float scratchpad4[MaxScratchpad4][MaxSize];
+ MANTA_ALIGN(16) double scratchpad8[MaxScratchpad8][MaxSize];
+
// Char-based arrays
char scratchpad_data[MaxSize][MaxScratchpadSize];
};
@@ -774,21 +781,11 @@
actualComputeHitPositions();
}
- // Scratchpad isn't quite "vertical" yet...
+ // This is for the non-vertical scratchpad
template<class T> T& scratchpad(int which) {
-
- // This pragma relates to the following expression being
- // constant (which it is). Since sizeof(T) is evaluated after
- // the preprocessor, we can't get around not doing it here like
- // this.
-
-# if defined(__sgi) && !defined(__GNUC__)
-# pragma set woff 1209
- ASSERT(sizeof(T) <= RayPacketData::MaxScratchpadSize);
-# pragma set woff 1209
-# else
- ASSERT(sizeof(T) <= RayPacketData::MaxScratchpadSize);
-# endif
+ // This trick is from Andrew Kensler. It will trigger a compile
+ // error if the type to be stored in the scratchpad is too big.
+ char unnamed[ ( sizeof( T ) <= RayPacketData::MaxScratchpadSize ) ? 1
: 0 ];
return *(T*)data->scratchpad_data[which];
}
// This will copy the contects of the scratchpad from the incoming
@@ -797,6 +794,18 @@
memcpy( data->scratchpad_data[which],
copy.data->scratchpad_data[which_copy],
RayPacketData::MaxScratchpadSize);
+ }
+ // This is for the vertical scratchpad
+ template<class T> T* getScratchpad(int idx) {
+ char unnamed[ ( sizeof(T) == 4 || sizeof(T) == 8) ? 1 : 0 ];
+ ASSERT(idx >= 0);
+ if(sizeof(T) == 4){
+ ASSERT(idx < MaxScratchpad4);
+ return (T*)data->scratchpad4[idx];
+ } else {
+ ASSERT(idx < MaxScratchpad8);
+ return (T*)data->scratchpad8[idx];
+ }
}
private:
Modified: trunk/Model/Primitives/Parallelogram.cc
==============================================================================
--- trunk/Model/Primitives/Parallelogram.cc (original)
+++ trunk/Model/Primitives/Parallelogram.cc Tue Dec 5 23:54:15 2006
@@ -82,12 +82,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
} else {
int i = rays.rayBegin;
@@ -106,14 +112,24 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
RayPacketData* data = rays.data;
+#if USE_SCRATCHPAD == 2
+ float* scratch1 = rays.getScratchpad<float>(0);
+ float* scratch2 = rays.getScratchpad<float>(1);
+#endif
__m128 normalx = _mm_set1_ps(normal[0]);
__m128 normaly = _mm_set1_ps(normal[1]);
__m128 normalz = _mm_set1_ps(normal[2]);
@@ -162,7 +178,7 @@
rays.hitWithoutTminCheck(i, hit, t, getMaterial(), this,
getTexCoordMapper());
-#if USE_SCRATCHPAD
+#if USE_SCRATCHPAD == 1
// Copy the barycentric coordinates to the scratch pad
MANTA_ALIGN(16) float ra1[4];
MANTA_ALIGN(16) float ra2[4];
@@ -182,16 +198,26 @@
}
}
#else
+#if USE_SCRATCHPAD == 2
+ if (_mm_movemask_ps(hit) == 15) {
+ _mm_store_ps(&scratch1[i], a1);
+ _mm_store_ps(&scratch2[i], a2);
+ } else {
+ maskedStore_ps(hit, (float*)&scratch1[i], a1);
+ maskedStore_ps(hit, (float*)&scratch2[i], a2);
+ }
+#else
if (_mm_movemask_ps(hit) == 15) {
_mm_store_ps(&data->texCoords[0][i], a1);
_mm_store_ps(&data->texCoords[1][i], a2);
_mm_store_ps(&data->texCoords[2][i], _mm_setzero_ps());
} else {
- maskedStore_ps(hit, (float*)&data->texCoords[0][i], a1);
- maskedStore_ps(hit, (float*)&data->texCoords[1][i], a2);
- maskedStore_ps(hit, (float*)&data->texCoords[2][i],
_mm_setzero_ps());
+ maskedStore_ps(hit, &data->texCoords[0][i], a1);
+ maskedStore_ps(hit, &data->texCoords[1][i], a2);
+ maskedStore_ps(hit, &data->texCoords[2][i], _mm_setzero_ps());
}
#endif
+#endif
}
for(;i<rays.rayEnd;i++){
Real dt=Dot(rays.getDirection(i), normal);
@@ -208,12 +234,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
}
#else
@@ -232,12 +264,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
#endif
} else {
@@ -263,12 +301,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
} else {
int i = rays.rayBegin;
@@ -290,14 +334,24 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
RayPacketData* data = rays.data;
+#if USE_SCRATCHPAD == 2
+ float* scratch1 = rays.getScratchpad<float>(0);
+ float* scratch2 = rays.getScratchpad<float>(1);
+#endif
__m128 normalx = _mm_set1_ps(normal[0]);
__m128 normaly = _mm_set1_ps(normal[1]);
__m128 normalz = _mm_set1_ps(normal[2]);
@@ -342,7 +396,7 @@
rays.hitWithoutTminCheck(i, hit, t, getMaterial(), this,
getTexCoordMapper());
-#if USE_SCRATCHPAD
+#if USE_SCRATCHPAD == 1
// Copy the barycentric coordinates to the scratch pad
MANTA_ALIGN(16) float ra1[4];
MANTA_ALIGN(16) float ra2[4];
@@ -362,6 +416,15 @@
}
}
#else
+#if USE_SCRATCHPAD == 2
+ if (_mm_movemask_ps(hit) == 15) {
+ _mm_store_ps(&scratch1[i], a1);
+ _mm_store_ps(&scratch2[i], a2);
+ } else {
+ maskedStore_ps(hit, (float*)&scratch1[i], a1);
+ maskedStore_ps(hit, (float*)&scratch2[i], a2);
+ }
+#else
if (_mm_movemask_ps(hit) == 15) {
_mm_store_ps(&data->texCoords[0][i], a1);
_mm_store_ps(&data->texCoords[1][i], a2);
@@ -372,6 +435,7 @@
maskedStore_ps(hit, (float*)&data->texCoords[2][i],
_mm_setzero_ps());
}
#endif
+#endif
}
for(;i<rays.rayEnd;i++){
Vector dir = rays.getDirection(i);
@@ -391,12 +455,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
}
#else
@@ -418,12 +488,18 @@
if (a2 < 0 || a2 > 1)
continue;
- if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper()))
-#if USE_SCRATCHPAD
+ if(rays.hit(i, t, getMaterial(), this, getTexCoordMapper())){
+#if USE_SCRATCHPAD == 1
rays.scratchpad<Vector>(i) = Vector(a1, a2, 0);
#else
+#if USE_SCRATCHPAD == 2
+ rays.getScratchpad<Real>(0)[i] = a1;
+ rays.getScratchpad<Real>(1)[i] = a2;
+#else
rays.setTexCoords(i, Vector(a1, a2, 0));
#endif
+#endif
+ }
}
#endif
}
@@ -432,10 +508,18 @@
void Parallelogram::computeTexCoords2(const RenderContext&,
RayPacket& rays) const
{
-#if USE_SCRATCHPAD
+#if USE_SCRATCHPAD == 1
for(int i=rays.begin();i<rays.end();i++){
rays.setTexCoords(i, rays.scratchpad<Vector>(i));
}
+#else
+#if USE_SCRATCHPAD == 2
+ float* a1 = rays.getScratchpad<float>(0);
+ float* a2 = rays.getScratchpad<float>(1);
+ for(int i=rays.begin();i<rays.end();i++){
+ rays.setTexCoords(i, Vector(a1[i], a2[i], 0));
+ }
+#endif
#endif
rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
}
@@ -443,10 +527,18 @@
void Parallelogram::computeTexCoords3(const RenderContext&,
RayPacket& rays) const
{
-#if USE_SCRATCHPAD
+#if USE_SCRATCHPAD == 1
for(int i=rays.begin();i<rays.end();i++){
rays.setTexCoords(i, rays.scratchpad<Vector>(i));
}
+#else
+#if USE_SCRATCHPAD == 2
+ float* a1 = rays.getScratchpad<float>(0);
+ float* a2 = rays.getScratchpad<float>(1);
+ for(int i=rays.begin();i<rays.end();i++){
+ rays.setTexCoords(i, Vector(a1[i], a2[i], 0));
+ }
+#endif
#endif
rays.setFlag(RayPacket::HaveTexture2|RayPacket::HaveTexture3);
}
- [MANTA] r1247 - in trunk: Interface Model/Primitives, sparker, 12/05/2006
Archive powered by MHonArc 2.6.16.