RenderingPipeline

from geometry to pixels

Are Vertex Shaders obsolete?

Ok, obsolete is a bit harsh, but currently a OpenGL shader program needs at least a vertex and a fragment shader (or it is a separable shader program in OpenGL 4.1 but in that case the shader program pipeline object needs a vertex shader). With attribute-less rendering (aka ‘drawing without data’) a vertex shader needs no inputs as it creates the output itself (one vertex position, as it still can’t generate more vertices than one and not less than one). But if we take attribute-less rendering one step further and also think of a practical application we get something like this: The vertex shader does nothing, the geometry shader creates one quad per invocation (without further data e.g. as a screen filling quad or with data from a texture as billboards).

Creating camera facing quads in a geometry shader from a point is not new, but actually this point does not need any valid information at all, the geometry shader can take care of everything. This could look like this:

 

Vertex array object generation (note that no attributes are defined) and drawing of one point:

GLint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
glDrawArrays( GL_POINTS, 0, 1 );

The vertex shader:

#version 330 core
void main() {}

The geometry shader:

#version 330 core
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
 
const vec2 data[4] = vec2[]
(
  vec2(-1.0,  1.0),
  vec2(-1.0, -1.0),
  vec2( 1.0,  1.0),
  vec2( 1.0, -1.0)
);
 
void main() {
  for (int i = 0; i < 4; ++i) {
    gl_Position = vec4( data[i], 0.0, 1.0 );
    EmitVertex();
  }
  EndPrimitive();
}

Note that this vertex shader acually compiles, links and the program works fine (GTX 580, NVidia, Linux). As mentioned, the data for other  quads could come from textures or uniform buffers to do more complex/useful stuff.

While the vertex shader does not do anything, I guess the driver will still set up a core with this program, fire up the vertex fetch and let a NOP run, cache the (undefined output) and set up the geometry shader – all this work would not be necessary if program without vertex shaders would be allowed – as long as any stage of the geometry pipeline is present.

Not using vertex attributes could also be useful if you want to do complex custom vertex fetching, the only thing defined by the application would be the number of shader invocations – if you need even more flexibility you would do the primitive assembly in a geometry shader and you would not be strictly bound to the number of vertices given by the application in the glDrawArrays call – here it’s also obvious that the vertex shader is not needed…

A completely empty vertex shader looks scary and disturbing. So why don’t we (ok, you OpenGL ARB) allow programs without vertex shaders and allow attribute bindings directly to tessellation or geometry shaders (of course always only to the first geometry related shader in a program)? This would also eliminate the need for pure ‘pass thru’ shaders.

, , ,

5 thoughts on “Are Vertex Shaders obsolete?
  • Adil says:

    I double this request :) You put the issue pretty straightforward, yet a solution may be more complex than you can think of first, since the data may not pass as transparent from vertex to geo shaders. I mean, it seems only useful for point primitives as input to geo shader, right?

  • Robert says:

    Adil: In the given example of attribute-less rendering the GS generates one (or more) primitive(s) per invocation. The input type of the incovation is irrelevant.

    But even if you render with data, the main geometry processing might be done in the GS, so the VS would just pass tru data and it might also not be needed.

    Yes, those cases are rare but we could life without a VS…

  • Gökhan says:

    Any known issue on attributeless rendering with seperate shader objects with program pipelines? Because when i use same shaders with normal program i get expected results but when i use program pipeline glDrawArrays get segfault. No compile or linking error occurs when creating program pipelines.

    • Robert says:

      I have not heard of such problems before and afaik attribute less rendering should also work with separable shader objects. If you’re sure the problem does not rely in your code elsewhere (e.g. _having_ an attribute active which you don’t use in your shader without having a large enough buffer bound (as the driver might choose to fetch the (nonexistent data) from the buffers even tho your code will never use them and thus provoke a segfault)), it would be great to tell us which OS, GPU and drivers you are using to potentially warn others who might also run into this problem.
      Attribute less rendering is not used much afaik so bugs in the drivers are possible (so are user errors as they have not much experience with this).

      • Gökhan says:

        I thought that i’m doing something wrong for a nearly whole day but at the end I found out that the problem caused by old driver which is amd catalyst driver version 12.10 at win7 64bit . After updating latest driver problem dissappeared. Thank you for your answer.

Leave a Reply

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

*