Mesa (master): glsl: Fix write mask in matrix-from-matrix constructors.

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Sep 2 01:58:37 UTC 2010


Module: Mesa
Branch: master
Commit: 39605587951aed546c14febcc26e5a479bf8d807
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=39605587951aed546c14febcc26e5a479bf8d807

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Sep  1 16:10:01 2010 -0700

glsl: Fix write mask in matrix-from-matrix constructors.

If the matrix being constructed was larger than the source matrix, it
would overwrite the lower-right part of the matrix with the wrong
values, rather than leaving it as the identity matrix.

For example, constructing a mat4 from a mat2 should only use a writemask
of "xy" when copying from the source, but was using "xyzw".

Fixes the code generated by piglit test constructor-23.vert.

---

 src/glsl/ast_function.cpp |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index f639b8a..1fa2fab 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -833,14 +833,16 @@ emit_inline_matrix_constructor(const glsl_type *type,
 	 new(ctx) ir_assignment(rhs_var_ref, first_param, NULL);
       instructions->push_tail(inst);
 
+      const unsigned last_row = MIN2(src_matrix->type->vector_elements,
+				     var->type->vector_elements);
+      const unsigned last_col = MIN2(src_matrix->type->matrix_columns,
+				     var->type->matrix_columns);
 
       unsigned swiz[4] = { 0, 0, 0, 0 };
       for (unsigned i = 1; i < src_matrix->type->vector_elements; i++)
 	 swiz[i] = i;
 
-      const unsigned last_col = MIN2(src_matrix->type->matrix_columns,
-				     var->type->matrix_columns);
-      const unsigned write_mask = (1U << var->type->vector_elements) - 1;
+      const unsigned write_mask = (1U << last_row) - 1;
 
       for (unsigned i = 0; i < last_col; i++) {
 	 ir_dereference *const lhs =




More information about the mesa-commit mailing list