[opengtl-commits] [333] pixel coordinates are given as a vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 333
Author: cyrille
Date: 2008-08-31 16:32:05 +0200 (Sun, 31 Aug 2008)
Log Message:
-----------
pixel coordinates are given as a vector
Modified Paths:
--------------
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
trunk/OpenGTL/OpenShiva/tests/convolution/copy.shiva
trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva
trunk/OpenGTL/OpenShiva/tests/vectors/operations.shiva
trunk/OpenGTL/TODO
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -87,8 +87,9 @@
//------------------- StructAccessorExpression -------------------//
-StructAccessorExpression::StructAccessorExpression(AccessorExpression* _parent, int _index) : m_parent(_parent), m_index(_index)
+StructAccessorExpression::StructAccessorExpression(AccessorExpression* _parent, unsigned int _index) : m_parent(_parent), m_index(_index)
{
+ GTL_ASSERT( m_index < m_parent->type()->structDataMembers()->size());
}
StructAccessorExpression::~StructAccessorExpression()
Modified: trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AST/AccessorExpression.h 2008-08-31 14:32:05 UTC (rev 333)
@@ -47,7 +47,7 @@
};
class StructAccessorExpression : public AccessorExpression {
public:
- StructAccessorExpression(AccessorExpression* _parent, int _index);
+ StructAccessorExpression(AccessorExpression* _parent, unsigned int _index);
~StructAccessorExpression();
virtual bool isConstant() const;
virtual const GTLCore::Type* type() const;
@@ -57,7 +57,7 @@
virtual bool allocatedInMemory() const { return m_parent->allocatedInMemory(); }
private:
AccessorExpression * m_parent;
- int m_index;
+ unsigned int m_index;
};
class ArrayAccessorExpression : public AccessorExpression {
public:
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CodeGenerator_p.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -150,18 +150,15 @@
{
GTL_DEBUG("Convert value to a vector");
// Create a vector
- llvm::Value* result = new llvm::AllocaInst( _targetType->d->type(), integerToConstant(1), "", _currentBlock);
- llvm::Value* resultLoad = new llvm::LoadInst( result, "", _currentBlock);
+ llvm::Value* resultLoad = llvm::ConstantVector::get( static_cast<const llvm::VectorType*>(_targetType->d->type()), std::vector<llvm::Constant*>() );
llvm::Value* vecElt = convertValueTo( _currentBlock, _value, _valueType, _targetType->embeddedType() );
// Affect the same value to each element of the vector
for(int i = 0; i < _targetType->vectorSize(); ++i)
{
- llvm::InsertElementInst::Create( resultLoad, vecElt, i, "", _currentBlock );
+ resultLoad = llvm::InsertElementInst::Create( resultLoad, vecElt, i, "", _currentBlock );
}
- // store back
- new llvm::StoreInst( resultLoad, result, "", _currentBlock);
GTL_DEBUG("Done");
- return result;
+ return resultLoad;
}
GTL_DEBUG("Create cast instruction");
GTL_DEBUG( *_value << " to " << *_targetType );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -75,7 +75,7 @@
Optimiser::Private::Private() : m_passManager(0)
{
- setLevel( 2 );
+ setLevel( 0 );
}
Optimiser::Private::~Private()
Modified: trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/ParserBase_p.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -171,7 +171,15 @@
return new AST::FunctionMemberAccessorExpression(_expression, sfm, arguments);
}
} else {
- return parseMemberArrayExpression( new AST::StructAccessorExpression( _expression , _expression->type()->d->memberToIndex( name ) ), _constantExpression);
+ int index = _expression->type()->d->memberToIndex( name );
+ if( index == -1 )
+ {
+ reportError("Unknown member: '" + name + "' for structure " + _expression->type()->structName(), d->currentToken );
+ delete _expression;
+ return 0;
+ } else {
+ return parseMemberArrayExpression( new AST::StructAccessorExpression( _expression , index ), _constantExpression);
+ }
}
}
} else if( d->currentToken.type == Token::STARTBOXBRACKET )
Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -50,20 +50,20 @@
return it->second;
}
-const GTLCore::Type* TypeManager::getArray( const GTLCore::Type* _type) const
+const GTLCore::Type* TypeManager::getArray( const GTLCore::Type* _type)
{
GTL_ASSERT( _type );
- std::map< const GTLCore::Type*, const GTLCore::Type*>::const_iterator it = d->knownArrays.find( _type );
- if( it == d->knownArrays.end())
+ std::map< const GTLCore::Type*, const GTLCore::Type*>::const_iterator it = TypeManager::Private::knownArrays.find( _type );
+ if( it == TypeManager::Private::knownArrays.end())
{
GTLCore::Type* at = new GTLCore::Type( _type );
- d->knownArrays[ _type] = at;
+ TypeManager::Private::knownArrays[ _type] = at;
return at;
}
return it->second;
}
-const GTLCore::Type* TypeManager::getArray( const GTLCore::Type* _type, int _levelsCount) const
+const GTLCore::Type* TypeManager::getArray( const GTLCore::Type* _type, int _levelsCount)
{
GTL_ASSERT( _type );
const GTLCore::Type* type = _type;
@@ -74,12 +74,12 @@
return type;
}
-const GTLCore::Type* TypeManager::getVector( const GTLCore::Type* _type, int _size ) const
+const GTLCore::Type* TypeManager::getVector( const GTLCore::Type* _type, int _size )
{
GTL_ASSERT( _type );
std::map< const GTLCore::Type*, std::map< int, const GTLCore::Type* > >::const_iterator it
- = d->knownVectors.find( _type );
- const GTLCore::Type*& type = d->knownVectors[ _type ][ _size ];
+ = TypeManager::Private::knownVectors.find( _type );
+ const GTLCore::Type*& type = TypeManager::Private::knownVectors[ _type ][ _size ];
if( type == 0 )
{
type = new GTLCore::Type( _size, _type );
Modified: trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenGTL/GTLCore/TypeManager.h 2008-08-31 14:32:05 UTC (rev 333)
@@ -39,7 +39,7 @@
* @param type the type of the elements in the array
* @return the array type
*/
- const GTLCore::Type* getArray( const GTLCore::Type* type) const;
+ static const GTLCore::Type* getArray( const GTLCore::Type* type);
/**
* Create an array of array.
* @param _type the base type of an array
@@ -52,8 +52,13 @@
* getArray( GTLCore::Type::Integer32, 2 ) == getArray( getArray( GTLCore::Type::Integer32 );
* @endcode
*/
- const GTLCore::Type* getArray( const GTLCore::Type* _type, int _levelsCount) const;
- const GTLCore::Type* getVector( const GTLCore::Type* _type, int _size ) const;
+ static const GTLCore::Type* getArray( const GTLCore::Type* _type, int _levelsCount);
+ /**
+ * @param _type the type of the elements of the vector
+ * @param _size number of elements of the vector
+ * @return the vector type that contains \a _type
+ */
+ static const GTLCore::Type* getVector( const GTLCore::Type* _type, int _size );
private:
struct Private;
Private* const d;
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -22,6 +22,7 @@
#include <vector>
#include <llvm/CallingConv.h>
+#include <llvm/Constants.h>
#include <llvm/Constant.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Function.h>
@@ -149,22 +150,21 @@
return _currentBlock;
}
-void CodeGenerator::setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _iVal, llvm::Value* _jVal )
+void CodeGenerator::setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel, llvm::Value* _iVal, const GTLCore::Type* _iValType, llvm::Value* _jVal, const GTLCore::Type* _jValType )
{
+ SHIVA_DEBUG("setPixelCoordinates");
+ // Create the coord vector
+ llvm::Value* result = llvm::ConstantVector::get( static_cast<const llvm::VectorType*>( GTLCore::TypeManager::getVector( GTLCore::Type::Float, 2)->d->type()), std::vector<llvm::Constant*>() );
+ SHIVA_DEBUG(*result << " " << *_iVal << " " << *_jVal);
+ result = llvm::InsertElementInst::Create( result, GTLCore::CodeGenerator::convertValueTo( _currentBlock, _iVal, _iValType, GTLCore::Type::Float), (unsigned int)0, "", _currentBlock );
+ result = llvm::InsertElementInst::Create( result, GTLCore::CodeGenerator::convertValueTo( _currentBlock, _jVal, _iValType, GTLCore::Type::Float), 1, "", _currentBlock );
+
std::vector<llvm::Value*> indexes;
indexes.push_back( _gc.codeGenerator()->integerToConstant(0));
- indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_X));
- new llvm::StoreInst(
- _gc.codeGenerator()->convertValueTo( _currentBlock, _iVal, GTLCore::Type::Integer32, GTLCore::Type::Float ),
+ indexes.push_back( _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_COORD));
+ new llvm::StoreInst( result,
llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock ),
- "",
- _currentBlock );
- indexes[1] = _gc.codeGenerator()->integerToConstant(PixelWrap::INDEX_Y);
- new llvm::StoreInst(
- _gc.codeGenerator()->convertValueTo( _currentBlock, _jVal, GTLCore::Type::Integer32, GTLCore::Type::Float ),
- llvm::GetElementPtrInst::Create( _pixel, indexes.begin(), indexes.end(), "", _currentBlock ),
- "",
- _currentBlock );
+ "", _currentBlock );
}
llvm::Function* CodeGenerator::generateEvaluatePixeles( const std::vector<const GTLCore::Type*>& _inputTypes, const GTLCore::Type* _outputType, Kernel* _kernel, GTLCore::ModuleData* _moduleData, int _channels)
@@ -277,7 +277,7 @@
llvm::Value* iVal = incI->get( generationContext, firstBlockILoop );
// Set the coordinates of the pixel
- setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(), iVal, jVal );
+ setPixelCoordinates( generationContext, firstBlockILoop, resultVar->pointer(), iVal, GTLCore::Type::Integer32, jVal, GTLCore::Type::Integer32 );
// Call evaluatePixel
llvm::Function* llvmEPFunction = ePFunction->d->data->function( countArguments );
@@ -617,7 +617,7 @@
currentBlock = memToPixel( generationContext, currentBlock,
callImageWrapData( generationContext, currentBlock, _imageType, arg_self, x_i, y_i ),
px_var, arg_self );
- setPixelCoordinates( generationContext, currentBlock, px_var, x_f, y_f );
+ setPixelCoordinates( generationContext, currentBlock, px_var, x_f, GTLCore::Type::Float, y_f, GTLCore::Type::Float );
llvm::ReturnInst::Create( px_var, currentBlock);
return func;
}
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CodeGenerator_p.h 2008-08-31 14:32:05 UTC (rev 333)
@@ -70,7 +70,7 @@
static llvm::Function* createMemCpyFunction( llvm::Module* _module );
static llvm::Value* accessPixelDataAsU8Ptr( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _pixel);
static llvm::Value* callMemcpy( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _src, llvm::Value* _n );
- static void setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _iVal, llvm::Value* _jVal );
+ static void setPixelCoordinates( GTLCore::GenerationContext& _gc, llvm::BasicBlock* _currentBlock, llvm::Value* _dst, llvm::Value* _iVal, const GTLCore::Type* _iValType, llvm::Value* _jVal, const GTLCore::Type* _jValType );
/**
* Call a "virtual" member of a structure, aka, a member with a pointer.
*/
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Wrapper_p.cpp 2008-08-31 14:32:05 UTC (rev 333)
@@ -126,8 +126,7 @@
std::vector<GTLCore::Type::StructDataMember> pixelDataMembers;
pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "data", vecType ) );
- pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "x", GTLCore::Type::Float ) );
- pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "y", GTLCore::Type::Float) );
+ pixelDataMembers.push_back( GTLCore::Type::StructDataMember( "coord", _typeManager->getVector( GTLCore::Type::Float, 2 ) ) );
const GTLCore::Type* type = _typeManager->d->createStructure( "pixel" + _suffix, pixelDataMembers );
type->d->setVisitor( PixelVisitor::instance() );
Modified: trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/wrappers/PixelWrap_p.h 2008-08-31 14:32:05 UTC (rev 333)
@@ -27,12 +27,10 @@
//---------------------- WARNING ----------------------//
struct PixelWrap {
void* data;
- float x;
- float y;
+ void* coord;
enum PixelIndexes {
INDEX_DATA = 0,
- INDEX_X = 1,
- INDEX_Y = 2
+ INDEX_COORD = 1
};
};
Modified: trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/blur.shiva 2008-08-31 14:32:05 UTC (rev 333)
@@ -2,9 +2,6 @@
{
void evaluatePixel(image img, out pixel result)
{
- float2 point1;
- point1[0] = result.x;
- point1[1] = result.y;
- result = ( img.sampleNearest( point1 ) + img.sampleNearest( point1 - 1.0 ) + img.sampleNearest( point1 + 1.0 ) ) / 3.0;
+ result = ( img.sampleNearest( result.coord ) + img.sampleNearest( result.coord - 1.0 ) + img.sampleNearest( result.coord + 1.0 ) ) / 3.0;
}
}
Modified: trunk/OpenGTL/OpenShiva/tests/convolution/copy.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/convolution/copy.shiva 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/tests/convolution/copy.shiva 2008-08-31 14:32:05 UTC (rev 333)
@@ -2,9 +2,6 @@
{
void evaluatePixel(image img, out pixel result)
{
- float2 point;
- point[0] = result.x;
- point[1] = result.y;
- result = img.sampleNearest( point );
+ result = img.sampleNearest( result.coord );
}
}
Modified: trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/Gradient.shiva 2008-08-31 14:32:05 UTC (rev 333)
@@ -2,6 +2,10 @@
{
void evaluatePixel(out pixel result)
{
- result[0] = 0.5*( result.x / 200 + result.y / 300 );
+ float v = 150.0;
+ float2 point = result.coord;
+ result[0] = 0.5*( point[0] / 200 + point[1] / 300 );
+
+// result[0] = 0.5*( result.coord[0] / 200 + result.coord[1] / 300 );
}
}
Modified: trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/tests/imagegenerators/MandelbrotSet.shiva 2008-08-31 14:32:05 UTC (rev 333)
@@ -8,9 +8,9 @@
float scale = 1 / 400.0;
int max_iteration = 25;
// Do it
- float x = (result.x - xaxis) * scale;
+ float x = (result.coord[0] - xaxis) * scale;
float x0 = x;
- float y = (result.y - yaxis) * scale;
+ float y = (result.coord[1] - yaxis) * scale;
float y0 = y;
int iteration = 0;
Modified: trunk/OpenGTL/OpenShiva/tests/vectors/operations.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/vectors/operations.shiva 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/OpenShiva/tests/vectors/operations.shiva 2008-08-31 14:32:05 UTC (rev 333)
@@ -24,6 +24,13 @@
v3 = v / v2;
if( v3[0] != 0.5 ) ++count;
if( v3[1] != (-1.0 / 3.0) ) ++count;
+ float2 v4 = v2 + 1.0;
+ if( v4[0] != 5.0 ) ++count;
+ if( v4[1] != 4.0 ) ++count;
+ float v6 = 1.0;
+ float2 v5 = v2 - v6;
+ if( v5[0] != 3.0 ) ++count;
+ if( v5[1] != 2.0 ) ++count;
return count;
}
}
Modified: trunk/OpenGTL/TODO
===================================================================
--- trunk/OpenGTL/TODO 2008-08-31 09:19:41 UTC (rev 332)
+++ trunk/OpenGTL/TODO 2008-08-31 14:32:05 UTC (rev 333)
@@ -3,6 +3,9 @@
* array/structure leak in return function (when assigne to a member or an index of an array) (<= might be fixed)
* remove all DEPRECATED functions
+Known bugs:
+ * sounds like you can have two variables of the same name
+
Important TODO
* access to vector using specific vector instructions
* AccessorExpression are leaked