diff options
Diffstat (limited to 'ast_to_hir.cpp')
-rw-r--r-- | ast_to_hir.cpp | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/ast_to_hir.cpp b/ast_to_hir.cpp index 1d9df36143..740adb9f43 100644 --- a/ast_to_hir.cpp +++ b/ast_to_hir.cpp @@ -151,10 +151,7 @@ arithmetic_result_type(const struct glsl_type *type_a, * vector." */ if (type_a->is_vector() && type_b->is_vector()) { - if (type_a->vector_elements == type_b->vector_elements) - return type_a; - else - return glsl_error_type; + return (type_a == type_b) ? type_a : glsl_error_type; } /* All of the combinations of <scalar, scalar>, <vector, scalar>, @@ -183,48 +180,42 @@ arithmetic_result_type(const struct glsl_type *type_a, * more detail how vectors and matrices are operated on." */ if (! multiply) { - if (type_a->is_matrix() && type_b->is_matrix() - && (type_a->vector_elements == type_b->vector_elements) - && (type_a->matrix_rows == type_b->matrix_rows)) - return type_a; - else - return glsl_error_type; + return (type_a == type_b) ? type_a : glsl_error_type; } else { if (type_a->is_matrix() && type_b->is_matrix()) { - if (type_a->vector_elements == type_b->matrix_rows) { - char type_name[7]; - const struct glsl_type *t; - - type_name[0] = 'm'; - type_name[1] = 'a'; - type_name[2] = 't'; - - if (type_a->matrix_rows == type_b->vector_elements) { - type_name[3] = '0' + type_a->matrix_rows; - type_name[4] = '\0'; - } else { - type_name[3] = '0' + type_a->matrix_rows; - type_name[4] = 'x'; - type_name[5] = '0' + type_b->vector_elements; - type_name[6] = '\0'; - } - - t = state->symbols->get_type(type_name); - return (t != NULL) ? t : glsl_error_type; + /* Matrix multiply. The columns of A must match the rows of B. Given + * the other previously tested constraints, this means the vector type + * of a row from A must be the same as the vector type of a column from + * B. + */ + if (type_a->row_type() == type_b->column_type()) { + /* The resulting matrix has the number of columns of matrix B and + * the number of rows of matrix A. We get the row count of A by + * looking at the size of a vector that makes up a column. The + * transpose (size of a row) is done for B. + */ + return + glsl_type::get_instance(type_a->base_type, + type_a->column_type()->vector_elements, + type_b->row_type()->vector_elements); } } else if (type_a->is_matrix()) { /* A is a matrix and B is a column vector. Columns of A must match - * rows of B. + * rows of B. Given the other previously tested constraints, this + * means the vector type of a row from A must be the same as the + * vector the type of B. */ - if (type_a->vector_elements == type_b->vector_elements) + if (type_a->row_type() == type_b) return type_b; } else { assert(type_b->is_matrix()); - /* A is a row vector and B is a matrix. Columns of A must match - * rows of B. + /* A is a row vector and B is a matrix. Columns of A must match rows + * of B. Given the other previously tested constraints, this means + * the type of A must be the same as the vector type of a column from + * B. */ - if (type_a->vector_elements == type_b->matrix_rows) + if (type_a == type_b->column_type()) return type_a; } } |