compiler/types: Add glsl_get_mul_type() and use it in C++
authorCaio Oliveira <caio.oliveira@intel.com>
Fri, 8 Sep 2023 02:50:36 +0000 (19:50 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 25 Oct 2023 01:51:12 +0000 (01:51 +0000)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25129>

src/compiler/glsl_types.cpp
src/compiler/glsl_types.h
src/compiler/glsl_types_impl.h

index 5c8a8fc..66463bf 100644 (file)
@@ -1637,8 +1637,8 @@ glsl_subroutine_type(const char *subroutine_name)
    return t;
 }
 
-const struct glsl_type *
-glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b)
+extern "C" const struct glsl_type *
+glsl_get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b)
 {
    if (type_a->is_matrix() && type_b->is_matrix()) {
       /* Matrix multiply.  The columns of A must match the rows of B.  Given
@@ -1653,10 +1653,10 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
           * transpose (size of a row) is done for B.
           */
          const struct glsl_type *const type =
-            get_instance(type_a->base_type,
-                         type_a->column_type()->vector_elements,
-                         type_b->row_type()->vector_elements);
-         assert(type != error_type);
+            glsl_type::get_instance(type_a->base_type,
+                                    type_a->column_type()->vector_elements,
+                                    type_b->row_type()->vector_elements);
+         assert(type != &glsl_type_builtin_error);
 
          return type;
       }
@@ -1672,10 +1672,10 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
          /* The resulting vector has a number of elements equal to
           * the number of rows of matrix A. */
          const struct glsl_type *const type =
-            get_instance(type_a->base_type,
-                         type_a->column_type()->vector_elements,
-                         1);
-         assert(type != error_type);
+            glsl_type::get_instance(type_a->base_type,
+                                    type_a->column_type()->vector_elements,
+                                    1);
+         assert(type != &glsl_type_builtin_error);
 
          return type;
       }
@@ -1691,16 +1691,16 @@ glsl_type::get_mul_type(const struct glsl_type *type_a, const struct glsl_type *
          /* The resulting vector has a number of elements equal to
           * the number of columns of matrix B. */
          const struct glsl_type *const type =
-            get_instance(type_a->base_type,
-                         type_b->row_type()->vector_elements,
-                         1);
-         assert(type != error_type);
+            glsl_type::get_instance(type_a->base_type,
+                                    type_b->row_type()->vector_elements,
+                                    1);
+         assert(type != &glsl_type_builtin_error);
 
          return type;
       }
    }
 
-   return error_type;
+   return &glsl_type_builtin_error;
 }
 
 
index 3aaf0c1..f685006 100644 (file)
@@ -1552,6 +1552,7 @@ glsl_sampler_type_to_texture(const struct glsl_type *t)
 
 const struct glsl_type *glsl_replace_vector_type(const struct glsl_type *t, unsigned components);
 const struct glsl_type *glsl_channel_type(const struct glsl_type *t);
+const struct glsl_type *glsl_get_mul_type(const struct glsl_type *type_a, const struct glsl_type *type_b);
 
 unsigned glsl_type_get_sampler_count(const struct glsl_type *t);
 unsigned glsl_type_get_texture_count(const struct glsl_type *t);
index 4f5dd00..dd7ad11 100644 (file)
@@ -169,6 +169,7 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
 }
 
 inline const glsl_type *glsl_type::replace_vec3_with_vec4() const { return glsl_type_replace_vec3_with_vec4(this); }
+inline const glsl_type *glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b) { return glsl_get_mul_type(type_a, type_b); }
 
 inline bool
 glsl_type::is_integer_16() const