KhronosGroup / OpenGL-API

OpenGL and OpenGL ES API Issue Tracker
34 stars 5 forks source link

[OpenGL] 4.6: SPIR-V cannot correctly declare interpolation on variables. #10

Closed NicolBolas closed 6 years ago

NicolBolas commented 7 years ago

When discussing a vertex property's interpolation, the specification consistently talks about the vertex processing stage's output variable declaration:

If a vertex, tessellation or geometry shader is active, user-defined output variables may be flatshaded by using the flat qualifier when declaring the output

The noperspective and flat keywords used to declare shader outputs affect how they are interpolated.

However, in the SPIR-V validation section, it says this:

The Flat, NoPerspective, Sample, and Centroid decorations must not be used on variables with storage class other than Input or on variables used in the interface of non-fragment shader entry points.

This means that only fragment shader inputs can have these decorations. So, how can SPIR-V satisfy the rule above: "the noperspective and flat keywords used to declare shader outputs affect how they are interpolated?" It can't declare those keywords on outputs of any kind, let alone on Vertex Processing stages.

It seems likely that this is some form of confusion. GLSL 4.30 says this, as part of its list of changes from 4.20:

Allow mismatches in interpolation and auxiliary qualification across stages.

Now in GLSL 4.30, the text in section 4.5, Interpolation Qualifiers never actually changed from the 4.20 version. This was explicitly a bug (10990) that was fixed in GLSL 4.40.

So, it is clear that interpolation qualifiers across stages are not supposed to need to match. But the OpenGL specification never got updated with that. The GL specs have always talked about the vertex stage outputs' qualifiers, not the fragment shader qualifiers.

Until now, GLSL could still provide those qualifiers, so this wasn't strictly a problem: you just has to specify them in non-fragment shader places. But since SPIR-V cannot specify them outside of the fragment shader, and the OpenGL specification doesn't actually care what the fragment shader's interpolation qualifiers are... we have a problem.

pdaniell-nv commented 7 years ago

Discussed in the OpenGL WG meeting on Friday. We agreed that only the fragment shader input qualifiers are required to determine interpolation. The GLSL spec will be clarified to say this.

For the API spec, we need to update this:

11.1.3.10 Shader Outputs A vertex shader can write to user-defined output variables. These values are expected to be interpolated across the primitive it outputs, unless they are specified to be flat shaded.

To say something like:

11.1.3.10 Shader Outputs A vertex shader can write to user-defined output variables. Interpolation of these values across the primitive is determined by the fragment shader input variable interpolation qualifier.

@oddhack can you make this change?

oddhack commented 6 years ago

This will be fixed in the next spec update, coming soon.

@pdaniell-nv the ES spec doesn't talk about SPIR yet, but should we make this same fix there anyway in anticipation? If so this can be reopened against me with appropriate label changes.