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/src/osgText/Text.cpp

    r8093 r8868  
    641641        } 
    642642 
    643         if (!_rotation.zeroRotation() ) 
    644         { 
    645             matrix.postMult(osg::Matrix::rotate(_rotation)); 
    646         } 
     643        matrix.postMultRotate(_rotation); 
    647644 
    648645        if (_characterSizeMode!=OBJECT_COORDS) 
    649646        { 
    650647 
    651             osg::Matrix M(rotate_matrix*osg::Matrix::translate(_position)*atc._modelview); 
     648            osg::Matrix M(rotate_matrix); 
     649            M.postMultTranslate(_position); 
     650            M.postMult(atc._modelview); 
    652651            osg::Matrix& P = atc._projection; 
    653652             
     
    694693                if (P10<0) 
    695694                   scale_font_vert=-scale_font_vert; 
    696                 matrix.postMult(osg::Matrix::scale(scale_font_hori, scale_font_vert,1.0f)); 
     695                matrix.postMultScale(osg::Vec3f(scale_font_hori, scale_font_vert,1.0f)); 
    697696            } 
    698697            else if (pixelSizeVert>getFontHeight()) 
    699698            { 
    700699                float scale_font = getFontHeight()/pixelSizeVert; 
    701                 matrix.postMult(osg::Matrix::scale(scale_font, scale_font,1.0f)); 
     700                matrix.postMultScale(osg::Vec3f(scale_font, scale_font,1.0f)); 
    702701            } 
    703702 
     
    709708        } 
    710709 
    711         matrix.postMult(osg::Matrix::translate(_position)); 
     710        matrix.postMultTranslate(_position); 
    712711    } 
    713712    else if (!_rotation.zeroRotation()) 
    714713    { 
    715         matrix.makeTranslate(-_offset); 
    716         matrix.postMult(osg::Matrix::rotate(_rotation)); 
    717         matrix.postMult(osg::Matrix::translate(_position)); 
     714        matrix.makeRotate(_rotation); 
     715        matrix.preMultTranslate(-_offset); 
     716        matrix.postMultTranslate(_position); 
    718717    } 
    719718    else