Show
Ignore:
Timestamp:
09/17/08 18:14:28 (6 years ago)
Author:
robert
Message:

From Mathias Froehlich, "This is a generic optimization that does not depend on any cpu or instruction
set.

The optimization is based on the observation that matrix matrix multiplication
with a dense matrix 4x4 is 43 Operations whereas multiplication with a
transform, or scale matrix is only 4
2 operations. Which is a gain of a
*FACTOR*4* for these special cases.
The change implements these special cases, provides a unit test for these
implementation and converts uses of the expensiver dense matrix matrix
routine with the specialized versions.

Depending on the transform nodes in the scenegraph this change gives a
noticable improovement.
For example the osgforest code using the MatrixTransform? is about 20% slower
than the same codepath using the PositionAttitudeTransform? instead of the
MatrixTransform? with this patch applied.

If I remember right, the sse type optimizations did *not* provide a factor 4
improovement. Also these changes are totally independent of any cpu or
instruction set architecture. So I would prefer to have this current kind of
change instead of some hand coded and cpu dependent assembly stuff. If we
need that hand tuned stuff, these can go on top of this changes which must
provide than hand optimized additional variants for the specialized versions
to give a even better result in the end.

An other change included here is a change to rotation matrix from quaterion
code. There is a sqrt call which couold be optimized away. Since we divide in
effect by sqrt(length)*sqrt(length) which is just length ...
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osg/AnimationPath

    r8768 r8868  
    9292            inline void getMatrix(Matrixf& matrix) const 
    9393            { 
    94                 matrix.makeScale(_scale); 
    95                 matrix.postMult(osg::Matrixf::rotate(_rotation)); 
    96                 matrix.postMult(osg::Matrixf::translate(_position)); 
     94                matrix.makeRotate(_rotation); 
     95                matrix.preMultScale(_scale); 
     96                matrix.postMultTranslate(_position); 
    9797            } 
    9898 
    9999            inline void getMatrix(Matrixd& matrix) const 
    100100            { 
    101                 matrix.makeScale(_scale); 
    102                 matrix.postMult(osg::Matrixd::rotate(_rotation)); 
    103                 matrix.postMult(osg::Matrixd::translate(_position)); 
     101                matrix.makeRotate(_rotation); 
     102                matrix.preMultScale(_scale); 
     103                matrix.postMultTranslate(_position); 
    104104            } 
    105105 
    106106            inline void getInverse(Matrixf& matrix) const 
    107107            { 
    108                 matrix.makeScale(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z()); 
    109                 matrix.preMult(osg::Matrixf::rotate(_rotation.inverse())); 
    110                 matrix.preMult(osg::Matrixf::translate(-_position)); 
     108                matrix.makeRotate(_rotation.inverse()); 
     109                matrix.postMultScale(osg::Vec3d(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z())); 
     110                matrix.preMultTranslate(-_position); 
    111111            } 
    112112 
    113113            inline void getInverse(Matrixd& matrix) const 
    114114            { 
    115                 matrix.makeScale(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z()); 
    116                 matrix.preMult(osg::Matrixd::rotate(_rotation.inverse())); 
    117                 matrix.preMult(osg::Matrixd::translate(-_position)); 
     115                matrix.makeRotate(_rotation.inverse()); 
     116                matrix.postMultScale(osg::Vec3d(1.0/_scale.x(),1.0/_scale.y(),1.0/_scale.z())); 
     117                matrix.preMultTranslate(-_position); 
    118118            } 
    119119