[Mesa-dev] [PATCH] glsl/linker: Check the subroutine associated functions names

Ian Romanick idr at freedesktop.org
Fri Oct 5 13:52:19 UTC 2018


On 10/03/2018 01:39 AM, Vadym Shovkoplias wrote:
> From Section 6.1.2 (Subroutines) of the GLSL 4.00 specification
> 
>     "A program will fail to compile or link if any shader
>      or stage contains two or more functions with the same
>      name if the name is associated with a subroutine type."
> 
> Fixes:
>     * no-overloads.vert
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108109
> Signed-off-by: Vadym Shovkoplias <vadym.shovkoplias at globallogic.com>
> ---
>  src/compiler/glsl/linker.cpp | 40 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index 3fde7e78d3..aca5488a1e 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -4639,6 +4639,45 @@ link_assign_subroutine_types(struct gl_shader_program *prog)
>     }
>  }
>  
> +static void
> +verify_subroutine_associated_funcs(struct gl_shader_program *prog)
> +{
> +   unsigned mask = prog->data->linked_stages;
> +   while (mask) {
> +      const int i = u_bit_scan(&mask);
> +      gl_program *p = prog->_LinkedShaders[i]->Program;
> +      glsl_symbol_table *symbols = prog->_LinkedShaders[i]->symbols;
> +
> +      /*
> +       * From OpenGL ES Shading Language 4.00 specification
> +       * (6.1.2 Subroutines):
> +       *     "A program will fail to compile or link if any shader
> +       *     or stage contains two or more functions with the same
> +       *     name if the name is associated with a subroutine type."
> +       */

There is no such thing as the "OpenGL ES Shading Language 4.00
specification", and there are is no subroutine support in GLSL ES.  I'm
assuming you actually meant, "GLSL 4.00".

For future reference, please use the canonical format for spec quotations:

      /* Section 6.1.2 (Subroutines) of the GLSL 4.00 spec says:
       *
       *    A program will fail to compile or link if any shader
       *    or stage contains two or more functions with the same
       *    name if the name is associated with a subroutine type.
       */

Some people, myself included, use grep to find spec quotations in the
code.  Using the canonical format helps those people find things.  This
especially matters when later versions of the spec have bug fixes that
require use to change the behavior of the compiler.

> +      for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
> +         unsigned definitions = 0;
> +         char *name = p->sh.SubroutineFunctions[j].name;
> +         ir_function *fn = symbols->get_function(name);
> +
> +         /* Calculate number of function definitions with the same name */
> +         foreach_in_list(ir_function_signature, sig, &fn->signatures) {
> +            if (sig->is_defined) {
> +               if (++definitions > 1) {
> +                  linker_error(prog, "%s shader contains two or more function "
> +                        "definitions with name `%s', which is "
> +                        "associated with a subroutine type.\n",
> +                        _mesa_shader_stage_to_string(i),
> +                        fn->name);
> +                  return;
> +               }
> +            }
> +         }
> +      }
> +   }
> +}
> +
> +
>  static void
>  set_always_active_io(exec_list *ir, ir_variable_mode io_mode)
>  {
> @@ -5024,6 +5063,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
>  
>     check_explicit_uniform_locations(ctx, prog);
>     link_assign_subroutine_types(prog);
> +   verify_subroutine_associated_funcs(prog);
>  
>     if (!prog->data->LinkStatus)
>        goto done;
> 



More information about the mesa-dev mailing list