Jump to content
  • Advertisement
Sign in to follow this  
lynedavid

Vertex shader slower than fixed function pipeline?

This topic is 4441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've read that shaders are just as fast as the fixed pipeline but I decided to do my own tests to be sure. I found some interesting results. In short, I have found fragment shaders to be just as fast (if not then a little faster) than the fixed function pipeline. However, vertex shaders seem significantly slower. I have tested with the following code. I used a display list as this removed download bottlenecks from the equation.
        #define ISURFACES 6000

        glFinish();
        double t1 = getTime();

        glslshader->begin();

        static int first=1;
        glBindTexture ( GL_TEXTURE_2D, basetex );
        for (int i=0;i<ISURFACES;i++)
        {

                float quadwidth  = 20.0;
                float tx=0.0;
                float ty=0.0;
                float h = -10.0;
                glPushMatrix();
                glTranslatef(xg,0.0,0.0);

                if (first)
                {
                        glNewList(DL,GL_COMPILE);
                        glPushMatrix();
                        glBegin(GL_QUADS);
                        for (float x = -50.0 ; x < 50.0 ; x+= quadwidth)
                        {
                                tx=0.0;
                                for (float y = -50.0 ; y < 50.0 ; y+= quadwidth)
                                {
                                        glTexCoord2f(tx,ty);
                                        glVertex3f(x,h,y);
                                        glTexCoord2f(tx,ty+0.2);
                                        glVertex3f(x,h,y+quadwidth);
                                        glTexCoord2f(tx+0.2,ty+0.2);
                                        glVertex3f(x+quadwidth,h,y+quadwidth);
                                        glTexCoord2f(tx+0.2,ty);
                                        glVertex3f(x+quadwidth,h,y);
                                        tx+=0.2;
                                }
                                ty+=0.2;
                        }
                        glEnd();
                        glPopMatrix();
                        glEndList();
                        first=0;

                }else
                {
                        glCallList(DL);

                }
                glPopMatrix();
                xg+=100.0;


        }

        glslshader->end();
        glFinish();
        fprintf(stderr,"Time elapsed=%0.2f\n",(getTime() - t1) * 1000.0);



On my GF 6800 Ultra, the above 6000 primatives with the fixed function pipeline took 4 milliseconds to render. On the other hand, to render with a vertex shader enabled took over 10 milliseconds! The glsl shader looks like this (pretty simple):
void main()
{
       gl_TexCoord[0] = gl_MultiTexCoord0;    
       gl_Position = ftransform();

}

I have also tried with CG and ARB assembly shaders. All with the same results. Is there an optimization I am missong here?

Share this post


Link to post
Share on other sites
Advertisement


The glFinish() is only there to take meaningfull post-fill performance timing figures.

However, in this case using glFlush instead of glFinish makes no difference to the outcome (I have tried).

Share this post


Link to post
Share on other sites
Quote:
Original post by lynedavid


The glFinish() is only there to take meaningfull post-fill performance timing figures.

However, in this case using glFlush instead of glFinish makes no difference to the outcome (I have tried).


Why don't you try running it for a few seconds and measure the everage ms/frame?

Share this post


Link to post
Share on other sites

Ok, I removed the glFinish's and took some fps's. Here are the results:

Vertex shader enabled: 65fps
Vertex shader disabled: 170fps.

The gain appears to actually increase with the fixed function pipeline in this test!

Share this post


Link to post
Share on other sites


The test shown in the source code is very vertex intensive. Very little download and fill influence the results.

Approx 300000 polygons are drawn per frame.

Share this post


Link to post
Share on other sites
Does performance increase if you just bind the shader once instead of every frame (assuming your shader's begin() and end() functions bind and unbind the shader)?

Share this post


Link to post
Share on other sites
ok, the real answer here is: it depends on the shader. While its possible to write an efficient shader its also possible to write one which is horribly inefficient. The driver internally builds shaders to implement fixed function T&L (this is true for both NVIDIA and ATI for the last two generations of chips) so the comparison is really between driver-built shaders and user-built shaders.

The driver writers get paid to make sure the fixed function emulation shaders are very fast!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!