Mesa (7.9): glsl: Inherrit type of declared variable from initializer

Ian Romanick idr at kemper.freedesktop.org
Fri Dec 17 22:54:20 UTC 2010


Module: Mesa
Branch: 7.9
Commit: 2b4277dcf32a88d72fd4e89f3be61e7298c71637
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2b4277dcf32a88d72fd4e89f3be61e7298c71637

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Dec  7 16:27:22 2010 -0800

glsl: Inherrit type of declared variable from initializer

Types of declared variables and their initializer must match excatly
except for unsized arrays.  Previously the type inherritance for
unsized arrays happened implicitly in the emitted assignment.
However, this assignment is never emitted for uniforms.  Now that type
is explicitly copied unconditionally.

Fixes piglit test array-compare-04.vert (bugzilla #32035) and
glsl-array-uniform-length (bugzilla #31985).

NOTE: This is a candidate for the 7.9 branch.
(cherry picked from commit b0fc5103cbc9116806a9888f747baed4b8166246)

---

 src/glsl/ast_to_hir.cpp |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 3e9a4db..74d6308 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2039,6 +2039,24 @@ ast_declarator_list::hir(exec_list *instructions,
 	    if (this->type->qualifier.constant)
 	       var->read_only = false;
 
+	    /* If the declared variable is an unsized array, it must inherrit
+	     * its full type from the initializer.  A declaration such as
+	     *
+	     *     uniform float a[] = float[](1.0, 2.0, 3.0, 3.0);
+	     *
+	     * becomes
+	     *
+	     *     uniform float a[4] = float[](1.0, 2.0, 3.0, 3.0);
+	     *
+	     * The assignment generated in the if-statement (below) will also
+	     * automatically handle this case for non-uniforms.
+	     *
+	     * If the declared variable is not an array, the types must
+	     * already match exactly.  As a result, the type assignment
+	     * here can be done unconditionally.
+	     */
+	    var->type = rhs->type;
+
 	    /* Never emit code to initialize a uniform.
 	     */
 	    if (!this->type->qualifier.uniform)




More information about the mesa-commit mailing list