glsl: Fix program interface queries relating to interface blocks.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 17 Dec 2016 01:03:15 +0000 (17:03 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 19 Dec 2016 23:43:09 +0000 (15:43 -0800)
commit4c4d9e4f032d5753034361ee70aa88d16d3a04b4
tree25c1a9b5c83423ecb8b9c8301052d6463ba84b84
parentad6d1d70ad55e317765d2212353d4a3387d5cbeb
glsl: Fix program interface queries relating to interface blocks.

This fixes 555 dEQP tests (using the nougat-cts-dev branch), Piglit's
arb_program_interface_query/arb_program_interface_query-resource-query,
and GL45-CTS.program_interface_query.separate-programs-{tess-control,
tess-eval,geometry}.  Only one dEQP program interface failure remains.

I would have liked to split this up into several distinct changes, but
I wasn't sure how to do that given thet tangled nature of these issues.

So, the issues:

   * We need to treat interface blocks declared as an array of instances
     as a single block - removing the outer array.  The resource list
     entry's name should not include the array length.  Properties such
     as GL_ARRAY_SIZE should refer to the variable inside the block, not
     the interface block's array properties.

   * We need to do this prefixing even for structure variables.

   * We need to do this for built-ins (such as gl_PerVertex.gl_Position).

   * After interface array unwrapping, any variable which is an array
     should have [0] appended.  It doesn't matter if it's a TCS/TES/GS
     input or TCS output - that looked like an attempt to unwrap for
     per-vertex variables, but that didn't consider per-patch variables,
     and as far as I can tell there's nothing to justify this.

Several Mesa developers have suggested that Issue 16 contradicts the
main specification, but I believe that it doesn't - the main spec just
isn't terribly clear.  The main ARB_program_interface query spec says:

  "* For an active interface block not declared as an array of block
     instances, a single entry will be generated, using the block name from
     the shader source.

   * For an active interface block declared as an array of instances,
     separate entries will be generated for each active instance.  The name
     of the instance is formed by concatenating the block name, the "["
     character, an integer identifying the instance number, and the "]"
     character."

Issue 16 says that built-ins should be named "gl_PerVertex.gl_Position",
but several people suggested the second bullet above means that it
should be named "gl_PerVertex[array length].gl_Position".

There are two important things to note.  Those bullet points say
"an active interface block", while the others say "variable" or "active
shader storage block member".  They also don't mention applying the
rules recursively (unlike the other bullets).  Both suggest that
these rules apply to blocks themselves, not members of blocks.

In fact, for GL_UNIFORM_BLOCK queries, we do have "block[0]",
"block[1]", ... resource list entries - so those rules are real,
and actually used.  So if they don't apply to block members, then how
should members be named?  Unfortunately, I don't see any rules outside
of issue 16 - where the rationale is very unclear.  I hope to clarify
the spec in the future.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/compiler/glsl/linker.cpp
src/mesa/main/shader_query.cpp