Fix #2132: constant matrix constructor from single non-scalar argument
authorJohn Kessenich <cepheus@frii.com>
Wed, 18 Mar 2020 16:27:59 +0000 (10:27 -0600)
committerJohn Kessenich <cepheus@frii.com>
Wed, 18 Mar 2020 16:27:59 +0000 (10:27 -0600)
Test/baseResults/constFold.frag.out
Test/constFold.frag
glslang/MachineIndependent/parseConst.cpp

index 2a48c42..045afc0 100644 (file)
@@ -260,27 +260,27 @@ ERROR: node is still EOpNull!
 0:120                1.000000
 0:120          Constant:
 0:120            3 (const int)
-0:126  Function Definition: foo3( ( global void)
-0:126    Function Parameters: 
-0:128    Sequence
-0:128      Sequence
-0:128        move second child to first child ( temp 3X2 matrix of float)
-0:128          'r32' ( temp 3X2 matrix of float)
-0:128          Constant:
-0:128            43.000000
-0:128            64.000000
-0:128            51.000000
-0:128            76.000000
-0:128            59.000000
-0:128            88.000000
-0:138  Function Definition: foo4( ( global void)
-0:138    Function Parameters: 
-0:140    Sequence
-0:140      Sequence
-0:140        move second child to first child ( temp int)
-0:140          'a' ( temp int)
-0:140          Constant:
-0:140            9 (const int)
+0:129  Function Definition: foo3( ( global void)
+0:129    Function Parameters: 
+0:131    Sequence
+0:131      Sequence
+0:131        move second child to first child ( temp 3X2 matrix of float)
+0:131          'r32' ( temp 3X2 matrix of float)
+0:131          Constant:
+0:131            43.000000
+0:131            64.000000
+0:131            51.000000
+0:131            76.000000
+0:131            59.000000
+0:131            88.000000
+0:141  Function Definition: foo4( ( global void)
+0:141    Function Parameters: 
+0:143    Sequence
+0:143      Sequence
+0:143        move second child to first child ( temp int)
+0:143          'a' ( temp int)
+0:143          Constant:
+0:143            9 (const int)
 0:?   Linker Objects
 0:?     'a' ( const int)
 0:?       1 (const int)
@@ -367,6 +367,29 @@ ERROR: node is still EOpNull!
 0:?       13.000000
 0:?       14.000000
 0:?       15.000000
+0:?     'm22' ( const 2X2 matrix of float)
+0:?       1.000000
+0:?       2.000000
+0:?       3.000000
+0:?       4.000000
+0:?     'mm34' ( const 3X4 matrix of float)
+0:?       7.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       7.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       7.000000
+0:?       0.000000
+0:?     'mv4' ( const 4-component vector of float)
+0:?       1.000000
+0:?       2.000000
+0:?       3.000000
+0:?       4.000000
 0:?     'a0' ( const 3-element array of structure{ global int i,  global float f,  global bool b})
 0:?       3 (const int)
 0:?       2.000000
@@ -635,6 +658,29 @@ ERROR: node is still EOpNull!
 0:?       13.000000
 0:?       14.000000
 0:?       15.000000
+0:?     'm22' ( const 2X2 matrix of float)
+0:?       1.000000
+0:?       2.000000
+0:?       3.000000
+0:?       4.000000
+0:?     'mm34' ( const 3X4 matrix of float)
+0:?       7.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       7.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       0.000000
+0:?       7.000000
+0:?       0.000000
+0:?     'mv4' ( const 4-component vector of float)
+0:?       1.000000
+0:?       2.000000
+0:?       3.000000
+0:?       4.000000
 0:?     'a0' ( const 3-element array of structure{ global int i,  global float f,  global bool b})
 0:?       3 (const int)
 0:?       2.000000
index daecaa2..49373e6 100644 (file)
@@ -122,6 +122,9 @@ void foo2()
 
 const mat2 mm2 = mat2(1.0, 2.0, 3.0, 4.0);\r
 const mat3x2 mm32 = mat3x2(10.0, 11.0, 12.0, 13.0, 14.0, 15.0);\r
+const mat2 m22 = mat2(vec4(1.0, 2.0, 3.0, 4.0));\r
+const mat3x4 mm34 = mat3x4(7.0);\r
+const vec4 mv4 = vec4(m22);\r
 \r
 void foo3()\r
 {\r
index 1a8e6d9..e4f04d9 100644 (file)
@@ -165,17 +165,27 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
                     }
                 }
             } else {
-                // matrix from vector
+                // matrix from vector or scalar
                 int count = 0;
                 const int startIndex = index;
                 int nodeComps = node->getType().computeNumComponents();
                 for (int i = startIndex; i < endIndex; i++) {
                     if (i >= instanceSize)
                         return;
-                    if (i == startIndex || (i - startIndex) % (matrixRows + 1) == 0 )
+                    if (nodeComps == 1) {
+                        // If there is a single scalar parameter to a matrix
+                        // constructor, it is used to initialize all the
+                        // components on the matrix\92s diagonal, with the
+                        // remaining components initialized to 0.0.
+                        if (i == startIndex || (i - startIndex) % (matrixRows + 1) == 0 )
+                            leftUnionArray[i] = rightUnionArray[count];
+                        else
+                            leftUnionArray[i].setDConst(0.0);
+                    } else {
+                        // construct the matrix in column-major order, from
+                        // the components provided, in order
                         leftUnionArray[i] = rightUnionArray[count];
-                    else
-                        leftUnionArray[i].setDConst(0.0);
+                    }
 
                     index++;