glsl: introduce validate_image_qualifier_for_type() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 26 Apr 2017 16:50:15 +0000 (18:50 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 28 Apr 2017 08:43:13 +0000 (10:43 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/ast_to_hir.cpp

index 425da639c71875aeb09b3d170e8254319317af5c..1159b2cdfbf9552617b782781393d9e58cdb97aa 100644 (file)
@@ -3291,15 +3291,13 @@ apply_explicit_location(const struct ast_type_qualifier *qual,
    }
 }
 
-static void
-apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
-                                  ir_variable *var,
-                                  struct _mesa_glsl_parse_state *state,
-                                  YYLTYPE *loc)
+static bool
+validate_image_qualifier_for_type(struct _mesa_glsl_parse_state *state,
+                                  YYLTYPE *loc,
+                                  const struct ast_type_qualifier *qual,
+                                  const glsl_type *type)
 {
-   const glsl_type *base_type = var->type->without_array();
-
-   if (!base_type->is_image()) {
+   if (!type->is_image()) {
       if (qual->flags.q.read_only ||
           qual->flags.q.write_only ||
           qual->flags.q.coherent ||
@@ -3313,8 +3311,21 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
          _mesa_glsl_error(loc, state, "format layout qualifiers may only be "
                           "applied to images");
       }
-      return;
+      return false;
    }
+   return true;
+}
+
+static void
+apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
+                                  ir_variable *var,
+                                  struct _mesa_glsl_parse_state *state,
+                                  YYLTYPE *loc)
+{
+   const glsl_type *base_type = var->type->without_array();
+
+   if (!validate_image_qualifier_for_type(state, loc, qual, base_type))
+      return;
 
    if (var->data.mode != ir_var_uniform &&
        var->data.mode != ir_var_function_in) {