OSDN Git Service

Fix nonsquare matrix construction from scalar
authorChris Forbes <chrisforbes@google.com>
Fri, 21 Sep 2018 18:30:15 +0000 (11:30 -0700)
committerChris Forbes <chrisforbes@google.com>
Fri, 21 Sep 2018 19:35:45 +0000 (19:35 +0000)
Matrix is laid out in column-major order, so the stride between elements
on the main diagonal is #rows + 1, not #columns + 1.

Bug: b/116263076
Change-Id: I00994b663bc4229e24f8ae1b7fa518caa0e7ea71
Reviewed-on: https://swiftshader-review.googlesource.com/20768
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
src/OpenGL/compiler/parseConst.cpp

index c3e0b0c..26af408 100644 (file)
@@ -30,7 +30,7 @@ public:
                  infoSink(sink),
                  size(0),
                  isMatrix(false),
-                 matrixSize(0) {
+                 matrixRows(0) {
        }
 
        bool error;
@@ -53,7 +53,7 @@ protected:
        TInfoSink& infoSink;
        size_t size; // size of the constructor ( 4 for vec4)
        bool isMatrix;
-       int matrixSize; // dimension of the matrix (nominal size and not the instance size)
+       int matrixRows; // number of rows in the matrix (nominal size and not the instance size)
 };
 
 //
@@ -124,7 +124,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
 
                if (node->getType().isMatrix()) {
                        isMatrix = true;
-                       matrixSize = node->getType().getNominalSize();
+                       matrixRows = node->getType().getSecondarySize();
                }
        }
 
@@ -142,7 +142,7 @@ bool TConstTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
                constructorType = EOpNull;
                size = 0;
                isMatrix = false;
-               matrixSize = 0;
+               matrixRows = 0;
        }
        return false;
 }
@@ -203,7 +203,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
                        for(size_t i = index; i < totalSize; i++) {
                                if (i >= instanceSize)
                                        return;
-                               if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 )
+                               if (element - i == 0 || (i - element) % (matrixRows + 1) == 0 )
                                        leftUnionArray[i].cast(basicType, rightUnionArray[0]);
                                else
                                        leftUnionArray[i].setFConst(0.0f);