glsl/linker: Allow unused in blocks which are not declated on previous stage
authorvadym.shovkoplias <vadim.shovkoplias@gmail.com>
Thu, 23 Aug 2018 10:12:16 +0000 (13:12 +0300)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Mon, 27 Aug 2018 10:13:53 +0000 (12:13 +0200)
>From Section 4.3.4 (Inputs) of the GLSL 1.50 spec:

    "Only the input variables that are actually read need to be written
     by the previous stage; it is allowed to have superfluous
     declarations of input variables."

Fixes:
    * interstage-multiple-shader-objects.shader_test

v2:
  Update comment in ir.h since the usage of "used" field
  has been extended.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101247
Signed-off-by: Vadym Shovkoplias <vadym.shovkoplias@globallogic.com>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/ir.h
src/compiler/glsl/link_interface_blocks.cpp

index 67b38f48eff4126596de69f22a19d853eba7ab41..d05d1998a50739f8937c36d0668f873ddd80a246 100644 (file)
@@ -667,8 +667,8 @@ public:
        * variable has been used.  For example, it is an error to redeclare a
        * variable as invariant after it has been used.
        *
-       * This is only maintained in the ast_to_hir.cpp path, not in
-       * Mesa's fixed function or ARB program paths.
+       * This is maintained in the ast_to_hir.cpp path and during linking,
+       * but not in Mesa's fixed function or ARB program paths.
        */
       unsigned used:1;
 
index e5eca9460e3c6c084832dd1918c2c805c8406693..801fbcd5d9f90c6be8f88e9f35623ebb62c923a7 100644 (file)
@@ -417,9 +417,15 @@ validate_interstage_inout_blocks(struct gl_shader_program *prog,
        * write to any of the pre-defined outputs (e.g. if the vertex shader
        * does not write to gl_Position, etc), which is allowed and results in
        * undefined behavior.
+       *
+       * From Section 4.3.4 (Inputs) of the GLSL 1.50 spec:
+       *
+       *    "Only the input variables that are actually read need to be written
+       *     by the previous stage; it is allowed to have superfluous
+       *     declarations of input variables."
        */
       if (producer_def == NULL &&
-          !is_builtin_gl_in_block(var, consumer->Stage)) {
+          !is_builtin_gl_in_block(var, consumer->Stage) && var->data.used) {
          linker_error(prog, "Input block `%s' is not an output of "
                       "the previous stage\n", var->get_interface_type()->name);
          return;