glsl: validate subroutine types match function signature.
authorDave Airlie <airlied@redhat.com>
Fri, 6 May 2016 01:28:40 +0000 (11:28 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 23 May 2016 06:19:56 +0000 (16:19 +1000)
This fixes:
GL43-CTS.shader_subroutine.subroutines_incompatible_with_subroutine_type

It just makes sure the signatures match as well as the return
types.

Reviewed-by: Chris Forbes <chrisforbes@google.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/compiler/glsl/ast_to_hir.cpp

index a524fbdc56fe2eefc5586f87ac08bad847268f0b..434734d09afeea70ada545363c762c84fb930041 100644 (file)
@@ -5522,6 +5522,24 @@ ast_function::hir(exec_list *instructions,
          if (!type) {
             _mesa_glsl_error(& loc, state, "unknown type '%s' in subroutine function definition", decl->identifier);
          }
+
+         for (int i = 0; i < state->num_subroutine_types; i++) {
+            ir_function *fn = state->subroutine_types[i];
+            ir_function_signature *tsig = NULL;
+
+            if (strcmp(fn->name, decl->identifier))
+               continue;
+
+            tsig = fn->matching_signature(state, &sig->parameters,
+                                          false);
+            if (!tsig) {
+               _mesa_glsl_error(& loc, state, "subroutine type mismatch '%s' - signatures do not match\n", decl->identifier);
+            } else {
+               if (tsig->return_type != sig->return_type) {
+                  _mesa_glsl_error(& loc, state, "subroutine type mismatch '%s' - return types do not match\n", decl->identifier);
+               }
+            }
+         }
          f->subroutine_types[idx++] = type;
       }
       state->subroutines = (ir_function **)reralloc(state, state->subroutines,