GLSL icon indicating copy to clipboard operation
GLSL copied to clipboard

Can built-in varyings be redeclared with different types?

Open ReinUsesLisp opened this issue 4 years ago • 2 comments

In other words, is the following code legal in a VTG stage?

out gl_PerVertex {
    vec2 gl_Position;
};

Some implementations allow it while others don't. After reading the GLSL specification there is not wording that forbids these redeclarations. glslang forbids it.

To answer the question: "why would anyone do that?" The output type is meaningful for transform feedbacks and the implementation that allows this takes the type in mind.

ReinUsesLisp avatar Mar 09 '20 23:03 ReinUsesLisp

The spec says:

The gl_PerVertex block can be redeclared in a shader to explicitly indicate what subset of the fixed pipeline interface will be used. This is necessary to establish the interface between multiple programs. This establishes the output interface the shader will use with the subsequent pipeline stage. It must be a subset of the built-in members of gl_PerVertex.

I think "a subset of the built-in members of gl_PerVertex" disallows this case because vec2 gl_Position is not a member of default gl_PerVertex block.

amdrexu avatar Mar 10 '20 05:03 amdrexu

Agreed with @amdrexu. While I can see the ambiguity in how it is written, the intent was to subset the list of members, not subset the type of a member.

FYI, glslang emits this for the OP example:

ERROR: 0:...: 'gl_Position' : cannot redeclare block member with a different type

Recommendation change;

must be a subset of the built-in members

to something more like

must be a member list that subsets the list of built-in members

and add

The types of the members themselves cannot be changed.

johnkslang avatar Mar 25 '20 14:03 johnkslang