Usually I don’t complain about the specification. It is as it is, and we can do nothing about it. But when I have to explain it to somebody else then I come to some difficulties being unable to defend some points in the specification. The main topic of today’s agenda is tessellation shaders. I would like to hear your opinions why the specification for the tessellation shaders is written like it is.
1. The problem of indexing output array gl_out in the tessellation control shader (TCS).
The tessellation control shader is invoked for each vertex of the output patch! Each invocation can read the attributes of any vertex in the input or output patches, but can only write per-vertex attributes for the corresponding output patch vertex. … Tessellation control shaders must use the input variable gl_InvocationID as the vertex number index when writing to per-vertex output variables.
So, we all have to write gl_out[gl_InvocationID].gl_Position = … all the time, instead of just gl_out.gl_Position = … Why the spec allows indexing but just for a single value? In my opinion gl_out should not be seen as an array from within TCS.
2. The problem of gl_out array length.
The intrinsically declared tessellation control output array gl_out will also be sized by any output layout declaration. Hence, the expression gl_out.length() will return the output patch vertex count specified in a previous output layout qualifier. For outputs declared without an array size, including intrinsically declared outputs (i.e., gl_out), a layout must be must be declared before any use of the method length() or other array use requires its size be known. It is a compile-time error if the output patch vertex count specified in an output layout qualifier does not match the array size specified in any output variable declaration in the same shader.
Why anyone should call function to read a constant value defined in the same program unit? Removing the array will also remove the problem with the length.
3. The problem of defining tessellation primitive generator (TPG) functioning by the subsequent stage.
A layout qualifier in the tessellation evaluation shader (TES) defines: primitive mode, spacing, direction and point-mode. All this is required by TPG to do its job. Why it is not defined in the TCS, where it logically should be?
4. The problem of writing patch out variables.
While tessellation control shader invocations may read any per-vertex and per-patch output variable and write any per-patch output variable, reading or writing output variables also written by other invocations has ordering hazards discussed below.
It is overseen in many tutorials that only a single invocation of TCS should write patch out variables. Maybe GLSL compiler should cast an exception if those writings are not enclosed in some if(gl_InvocationID==…)-statement.
There are probably other problems in the TS spec, but those are the most apparent ones. If you have an explanation for any of them, please share with me.