Why Tesellation control shader is invoked many times?

176 views Asked by At

My question is that all of Tesellation Control Shader Invocation produce the same result, why OPENGL has to call this shader many times for each patch. For example: My Tesellation Control Shader calculates control points for the Bezier Surface. It take an array of three vertices, which is aggregated earlier from Vertex Shaders.

// attributes of the input CPs
in vec3 WorldPos_CS_in[]; 

My patch size is 3, so Tesellation Control Shader is called three times for the same input, save for gl_invocatinoID, and then all of them produce the same following control points:

struct OutputPatch                                                                               
{                                                                                                
vec3 WorldPos_B030;                                                                          
vec3 WorldPos_B021;                                                                          
vec3 WorldPos_B012;                                                                          
vec3 WorldPos_B003;                                                                          
vec3 WorldPos_B102;                                                                          
vec3 WorldPos_B201;                                                                          
vec3 WorldPos_B300;                                                                          
vec3 WorldPos_B210;                                                                          
vec3 WorldPos_B120;                                                                          
vec3 WorldPos_B111;                                                                          
vec3 Normal[3];                                                                              
vec2 TexCoord[3];                                                                            
};                                                                                               

// attributes of the output CPs                                                                  
out patch OutputPatch oPatch; 

And, also the same information which help OpenGL divide this patch into tesellation coordinates:

 // Calculate the tessellation levels       
 gl_TessLevelOuter[0] = gTessellationLevel; 
 gl_TessLevelOuter[1] = gTessellationLevel; 
 gl_TessLevelOuter[2] = gTessellationLevel; 
 gl_TessLevelInner[0] = gTessellationLevel; 

It is clear that all of Tes Control Shader do same job. Does it waste resources? Why Tesellation Control Shader should be called for one time for each patch?

1

There are 1 answers

0
Hugh Fisher On

Well the control shader invocations don't produce exactly the same result, because the control point output is obviously different for each. But that's being pedantic.

In your program, and in all of mine so far, yes the control shader is doing exactly the same thing for every control point and the tessellation level doesn't change.

But suppose you have the shader generating new attributes for each control point, a texture normal or something? Then the shader would generate different results for each. It's nice to have the extra flexibility if you need it.

Modern GPUs try to do as much as possible in parallel. The older geometry shaders have one invocation generating multiple outputs. It's more efficient, not less, on modern GPUs to have multiple invocations each generating one output.