Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: How many times shader executes?

  1. #1
    Newbie Newbie
    Join Date
    Feb 2016
    Posts
    2

    How many times shader executes?

    Hi All,
    I'm a new to OpenGL and I have a question.
    For a program that uses vertex, geometry and fragment shader to finally renders 3 line strips and each line strip has 5 vertices.
    I guess their execution number as below:
    Vertex shader executes 3 X 5 = 15 times.
    Geometry shader executes only 3 times.
    Fragment shader executes as many as the involved pixels count.

    Actually, I'm not sure about my answer, could you correct me please?

    Cheers,
    Nai

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,975
    Quote Originally Posted by Alharbi View Post
    I'm a new to OpenGL and I have a question.
    For a program that uses vertex, geometry and fragment shader to finally renders 3 line strips and each line strip has 5 vertices.
    I guess their execution number as below:
    Vertex shader executes 3 X 5 = 15 times.
    Geometry shader executes only 3 times.
    Fragment shader executes as many as the involved pixels count.

    Actually, I'm not sure about my answer, could you correct me please?
    If there are 15 distinct vertices, then the vertex shader will execute 15 times. If you use glDrawElements() and some of the indices are repeated (meaning that vertices are re-used), the vertex shader may only be executed once for each repeated vertex or it may be executed as many times as the vertex is repeated, or somewhere in between.

    The geometry shader is invoked once for each point, line or triangle. So for a line strip with 5 vertices, it will be invoked 4 times, once for each line segment. For 3 such strips, it will be invoked 3x4=12 times.

    The fragment shader is executed at least once per rendered fragment. If multisampling is used, it may be executed once per fragment or once per sample, depending upon whether the shader references gl_SamplePosition. The fragment shader may also be executed for fragments which aren't rendered but whose values are required to compute derivatives (either explicitly via dFdx/dFdy or implicitly via texture() etc).

  3. #3
    Newbie Newbie
    Join Date
    Feb 2016
    Posts
    2

    Really helpful!

    Quote Originally Posted by GClements View Post
    If there are 15 distinct vertices, then the vertex shader will execute 15 times. If you use glDrawElements() and some of the indices are repeated (meaning that vertices are re-used), the vertex shader may only be executed once for each repeated vertex or it may be executed as many times as the vertex is repeated, or somewhere in between.

    The geometry shader is invoked once for each point, line or triangle. So for a line strip with 5 vertices, it will be invoked 4 times, once for each line segment. For 3 such strips, it will be invoked 3x4=12 times.

    The fragment shader is executed at least once per rendered fragment. If multisampling is used, it may be executed once per fragment or once per sample, depending upon whether the shader references gl_SamplePosition. The fragment shader may also be executed for fragments which aren't rendered but whose values are required to compute derivatives (either explicitly via dFdx/dFdy or implicitly via texture() etc).
    I was away from my computer. So i'm sorry my reply was late.
    Just to say: Thank you for your clear and helpful explanation.

    Cheers,
    Nai

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •