PDA

View Full Version : How many times shader executes?



Alharbi
02-26-2016, 02:54 PM
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

GClements
02-26-2016, 05:14 PM
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).

Alharbi
02-28-2016, 04:18 AM
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