glsl: Inherrit type of declared variable from initializer
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 8 Dec 2010 00:27:22 +0000 (16:27 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 8 Dec 2010 00:36:44 +0000 (16:36 -0800)
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.

src/glsl/ast_to_hir.cpp

index 4b9b07fbf612f9b00dc2479e471b12e545ededde..82b3f2e0ea99ba9088d37105b1d3d357382a25cb 100644 (file)
@@ -2228,6 +2228,24 @@ ast_declarator_list::hir(exec_list *instructions,
            if (this->type->qualifier.flags.q.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.flags.q.uniform)