Vertex shader slower than fixed function pipeline?

Started by
21 comments, last by Eric Lengyel 18 years ago
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?
Advertisement


Frankly, I dont care about the ATI vs Nvidia arguement. Can anyone shed some light as to the origional question?
Did you try removing the glFinish()? It is usually not neccesary. Use glFlush() instead.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"


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).
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?
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

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!


BTW, average milliseconds per frame stay consistance with the above results also.


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.
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)?
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!

This topic is closed to new replies.

Advertisement