Mesa (staging/19.1): glsl: disallow incompatible matrices multiplication

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Sep 30 08:43:06 UTC 2019


Module: Mesa
Branch: staging/19.1
Commit: a36ea3f864e416e8600e8ff4c7b70158556e3fa9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a36ea3f864e416e8600e8ff4c7b70158556e3fa9

Author: Andrii Simiklit <andrii.simiklit at globallogic.com>
Date:   Tue Sep 10 17:00:32 2019 +0300

glsl: disallow incompatible matrices multiplication

glsl 4.4 spec section '5.9 expressions':
"The operator is multiply (*), where both operands are matrices or one operand is a vector and the
 other a matrix. A right vector operand is treated as a column vector and a left vector operand as a
 row vector. In all these cases, it is required that the number of columns of the left operand is equal
 to the number of rows of the right operand. Then, the multiply (*) operation does a linear
 algebraic multiply, yielding an object that has the same number of rows as the left operand and the
 same number of columns as the right operand. Section 5.10 “Vector and Matrix Operations”
 explains in more detail how vectors and matrices are operated on."

This fix disallows a multiplication of incompatible matrices like:
mat4x3(..) * mat4x3(..)
mat4x2(..) * mat4x2(..)
mat3x2(..) * mat3x2(..)
....

CC: <mesa-stable at lists.freedesktop.org>
Reviewed-by: Eric Anholt <eric at anholt.net>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111664
Signed-off-by: Andrii Simiklit <andrii.simiklit at globallogic.com>
(cherry picked from commit b32bb888c70576bf7e48f22703028eb1a43da651)

---

 src/compiler/glsl_types.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 8e5087e2e1a..97f2f205603 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -1311,9 +1311,7 @@ glsl_type::get_function_instance(const glsl_type *return_type,
 const glsl_type *
 glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
 {
-   if (type_a == type_b) {
-      return type_a;
-   } else if (type_a->is_matrix() && type_b->is_matrix()) {
+   if (type_a->is_matrix() && type_b->is_matrix()) {
       /* 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
@@ -1333,6 +1331,8 @@ glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
 
          return type;
       }
+   } else if (type_a == type_b) {
+      return type_a;
    } else if (type_a->is_matrix()) {
       /* A is a matrix and B is a column vector.  Columns of A must match
        * rows of B.  Given the other previously tested constraints, this




More information about the mesa-commit mailing list