glsl: make use of glsl_type::is_double()
[mesa.git] / src / compiler / glsl / ast_to_hir.cpp
index 72706d054e5ce4c47788f1b744d9390872bb2893..4bff9e979bfa730830906140b207133a50d84d74 100644 (file)
@@ -445,9 +445,9 @@ arithmetic_result_type(ir_rvalue * &value_a, ir_rvalue * &value_b,
     */
    assert(type_a->is_matrix() || type_b->is_matrix());
    assert(type_a->base_type == GLSL_TYPE_FLOAT ||
-          type_a->base_type == GLSL_TYPE_DOUBLE);
+          type_a->is_double());
    assert(type_b->base_type == GLSL_TYPE_FLOAT ||
-          type_b->base_type == GLSL_TYPE_DOUBLE);
+          type_b->is_double());
 
    /*   "* The operator is add (+), subtract (-), or divide (/), and the
     *      operands are matrices with the same number of rows and the same
@@ -1487,8 +1487,7 @@ ast_expression::do_hir(exec_list *instructions,
        * in a scalar boolean.  See page 57 of the GLSL 1.50 spec.
        */
       assert(type->is_error()
-             || ((type->base_type == GLSL_TYPE_BOOL)
-                 && type->is_scalar()));
+             || (type->is_boolean() && type->is_scalar()));
 
       result = new(ctx) ir_expression(operations[this->oper], type,
                                       op[0], op[1]);
@@ -2633,8 +2632,7 @@ select_gles_precision(unsigned qual_precision,
     *    declare an atomic type with a different precision or to specify the
     *    default precision for an atomic type to be lowp or mediump."
     */
-   if (type->base_type == GLSL_TYPE_ATOMIC_UINT &&
-       precision != ast_precision_high) {
+   if (type->is_atomic_uint() && precision != ast_precision_high) {
       _mesa_glsl_error(loc, state,
                        "atomic_uint can only have highp precision qualifier");
    }
@@ -3303,74 +3301,73 @@ apply_image_qualifier_to_variable(const struct ast_type_qualifier *qual,
 {
    const glsl_type *base_type = var->type->without_array();
 
-   if (base_type->is_image()) {
-      if (var->data.mode != ir_var_uniform &&
-          var->data.mode != ir_var_function_in) {
-         _mesa_glsl_error(loc, state, "image variables may only be declared as "
-                          "function parameters or uniform-qualified "
-                          "global variables");
+   if (!base_type->is_image()) {
+      if (qual->flags.q.read_only ||
+          qual->flags.q.write_only ||
+          qual->flags.q.coherent ||
+          qual->flags.q._volatile ||
+          qual->flags.q.restrict_flag ||
+          qual->flags.q.explicit_image_format) {
+         _mesa_glsl_error(loc, state, "memory qualifiers may only be applied "
+                          "to images");
       }
+      return;
+   }
 
-      var->data.image_read_only |= qual->flags.q.read_only;
-      var->data.image_write_only |= qual->flags.q.write_only;
-      var->data.image_coherent |= qual->flags.q.coherent;
-      var->data.image_volatile |= qual->flags.q._volatile;
-      var->data.image_restrict |= qual->flags.q.restrict_flag;
-      var->data.read_only = true;
+   if (var->data.mode != ir_var_uniform &&
+       var->data.mode != ir_var_function_in) {
+      _mesa_glsl_error(loc, state, "image variables may only be declared as "
+                       "function parameters or uniform-qualified "
+                       "global variables");
+   }
 
-      if (qual->flags.q.explicit_image_format) {
-         if (var->data.mode == ir_var_function_in) {
-            _mesa_glsl_error(loc, state, "format qualifiers cannot be "
-                             "used on image function parameters");
-         }
+   var->data.image_read_only |= qual->flags.q.read_only;
+   var->data.image_write_only |= qual->flags.q.write_only;
+   var->data.image_coherent |= qual->flags.q.coherent;
+   var->data.image_volatile |= qual->flags.q._volatile;
+   var->data.image_restrict |= qual->flags.q.restrict_flag;
+   var->data.read_only = true;
 
-         if (qual->image_base_type != base_type->sampled_type) {
-            _mesa_glsl_error(loc, state, "format qualifier doesn't match the "
-                             "base data type of the image");
-         }
+   if (qual->flags.q.explicit_image_format) {
+      if (var->data.mode == ir_var_function_in) {
+         _mesa_glsl_error(loc, state, "format qualifiers cannot be used on "
+                          "image function parameters");
+      }
 
-         var->data.image_format = qual->image_format;
-      } else {
-         if (var->data.mode == ir_var_uniform) {
-            if (state->es_shader) {
-               _mesa_glsl_error(loc, state, "all image uniforms "
-                                "must have a format layout qualifier");
+      if (qual->image_base_type != base_type->sampled_type) {
+         _mesa_glsl_error(loc, state, "format qualifier doesn't match the base "
+                          "data type of the image");
+      }
 
-            } else if (!qual->flags.q.write_only) {
-               _mesa_glsl_error(loc, state, "image uniforms not qualified with "
-                                "`writeonly' must have a format layout "
-                                "qualifier");
-            }
+      var->data.image_format = qual->image_format;
+   } else {
+      if (var->data.mode == ir_var_uniform) {
+         if (state->es_shader) {
+            _mesa_glsl_error(loc, state, "all image uniforms must have a "
+                             "format layout qualifier");
+         } else if (!qual->flags.q.write_only) {
+            _mesa_glsl_error(loc, state, "image uniforms not qualified with "
+                             "`writeonly' must have a format layout qualifier");
          }
-
-         var->data.image_format = GL_NONE;
       }
+      var->data.image_format = GL_NONE;
+   }
 
-      /* From page 70 of the GLSL ES 3.1 specification:
-       *
-       * "Except for image variables qualified with the format qualifiers
-       *  r32f, r32i, and r32ui, image variables must specify either memory
-       *  qualifier readonly or the memory qualifier writeonly."
-       */
-      if (state->es_shader &&
-          var->data.image_format != GL_R32F &&
-          var->data.image_format != GL_R32I &&
-          var->data.image_format != GL_R32UI &&
-          !var->data.image_read_only &&
-          !var->data.image_write_only) {
-         _mesa_glsl_error(loc, state, "image variables of format other than "
-                          "r32f, r32i or r32ui must be qualified `readonly' or "
-                          "`writeonly'");
-      }
-
-   } else if (qual->flags.q.read_only ||
-              qual->flags.q.write_only ||
-              qual->flags.q.coherent ||
-              qual->flags.q._volatile ||
-              qual->flags.q.restrict_flag ||
-              qual->flags.q.explicit_image_format) {
-      _mesa_glsl_error(loc, state, "memory qualifiers may only be applied to "
-                       "images");
+   /* From page 70 of the GLSL ES 3.1 specification:
+    *
+    * "Except for image variables qualified with the format qualifiers r32f,
+    *  r32i, and r32ui, image variables must specify either memory qualifier
+    *  readonly or the memory qualifier writeonly."
+    */
+   if (state->es_shader &&
+       var->data.image_format != GL_R32F &&
+       var->data.image_format != GL_R32I &&
+       var->data.image_format != GL_R32UI &&
+       !var->data.image_read_only &&
+       !var->data.image_write_only) {
+      _mesa_glsl_error(loc, state, "image variables of format other than r32f, "
+                       "r32i or r32ui must be qualified `readonly' or "
+                       "`writeonly'");
    }
 }
 
@@ -4714,7 +4711,7 @@ ast_declarator_list::hir(exec_list *instructions,
                           "invalid type `%s' in empty declaration",
                           type_name);
       } else {
-         if (decl_type->base_type == GLSL_TYPE_ARRAY) {
+         if (decl_type->is_array()) {
             /* From Section 13.22 (Array Declarations) of the GLSL ES 3.2
              * spec:
              *
@@ -4736,7 +4733,7 @@ ast_declarator_list::hir(exec_list *instructions,
             validate_array_dimensions(decl_type, state, &loc);
          }
 
-         if (decl_type->base_type == GLSL_TYPE_ATOMIC_UINT) {
+         if (decl_type->is_atomic_uint()) {
             /* Empty atomic counter declarations are allowed and useful
              * to set the default offset qualifier.
              */
@@ -4953,7 +4950,7 @@ ast_declarator_list::hir(exec_list *instructions,
                if (state->is_version(120, 300))
                   break;
             case GLSL_TYPE_DOUBLE:
-               if (check_type->base_type == GLSL_TYPE_DOUBLE && (state->is_version(410, 0) || state->ARB_vertex_attrib_64bit_enable))
+               if (check_type->is_double() && (state->is_version(410, 0) || state->ARB_vertex_attrib_64bit_enable))
                   break;
             /* FALLTHROUGH */
             default: