A trick, Mult matrix in GPU with fixed pipelines

This topic is a trick? no :)

Some times when you need to do matrix multiplication in many S.O. with different compilers or SSE2, 3… 3D Now! and so on you want to optimize matrix multiplication with ASM code. Next is a little trick for to use that in GPU without this ASM and more faster. For example if you want model animation:

float mBone01[16] = { ... }
float mBone02[16] = { ... }
float mResult[16];
 
glMatrixMode  ( GL_MODELVIEW );
glLoadIdentity( );
glLoadMatrix  ( mBone01 );
glMultMatrix  ( mBone02 );
glGetMatrix   ( GL_MODELVIEW, mResult );
This entry was posted in Graphics, Programming. Bookmark the permalink.

4 Responses to A trick, Mult matrix in GPU with fixed pipelines

  1. fjfnaranjo says:

    Mmm, interesting…

    How much faster is this way?

    Does usually have the GPU enought time to do this stuff in a real rendering scenario?

  2. Prompt says:

    I have no metrics, but GPU is more faster than CPU and there is many units for parallel calculation. Normally the people use GPU Vertex Shader skinning, but with this approach you can use for normal matrix multiplications or for example with OpenGL ES 1.1 for iPhone where shaders don’t exist.

  3. tamat says:

    but how do you know this is done in the GPU and not in the driver?

    because I always thought that only the mesh transformation is done in the GPU, all the matrix calculations are done in the CPU because it takes more time to send it to the GPU, solve it, and return it than do it straight in the CPU.

  4. Prompt says:

    It’s true. In OpenGL for PC the implementation is not in client SIDE, but, I’m sure that this functionality is really optimized. Maybe in OpenGL ES, all this operation is in client side. Anyway, is a little stupid trick for to do matrix multiplication without using ASM code. I do all this in CPU and I believe in the compiler! :) (sometimes maybe this is a bad idea :P)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">