OSDN Git Service

Non square matrices related fixes
authorAlexis Hetu <sugoi@google.com>
Wed, 15 Jul 2015 20:55:56 +0000 (16:55 -0400)
committerAlexis Hétu <sugoi@google.com>
Thu, 16 Jul 2015 19:08:26 +0000 (19:08 +0000)
- Implemented proper VariableRegisterCount (we were using row
  count instead of column count to get the number of registers)
  and VariableRegisterSize.
- Matrix to matrix copies now clear the correct rows of the
  destination matrix when needed
- Added registerSize helper function to type to help clarify
  this for matrices.
- Added missing member initializations in TType constructor

Change-Id: Ic880815515c7d12ad12e44f1392aa6892caa953f
Reviewed-on: https://swiftshader-review.googlesource.com/3718
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/OpenGL/compiler/OutputASM.cpp
src/OpenGL/compiler/SymbolTable.cpp
src/OpenGL/compiler/Types.h
src/OpenGL/compiler/intermediate.h
src/OpenGL/libGLESv2/Program.cpp
src/OpenGL/libGLESv2/utilities.cpp
src/OpenGL/libGLESv2/utilities.h

index 4fb4126..428be87 100644 (file)
@@ -964,11 +964,12 @@ namespace glsl
                        if(visit == PostVisit)\r
                        {\r
                                TIntermTyped *arg0 = arg[0]->getAsTyped();\r
-                               const int dim = result->getNominalSize();\r
+                               const int outCols = result->getNominalSize();\r
+                               const int outRows = result->getSecondarySize();\r
 \r
                                if(arg0->isScalar() && arg.size() == 1)   // Construct scale matrix\r
                                {\r
-                                       for(int i = 0; i < dim; i++)\r
+                                       for(int i = 0; i < outCols; i++)\r
                                        {\r
                                                Instruction *init = emit(sw::Shader::OPCODE_MOV, result, &zero);\r
                                                init->dst.index += i;\r
@@ -980,9 +981,12 @@ namespace glsl
                                }\r
                                else if(arg0->isMatrix())\r
                                {\r
-                                       for(int i = 0; i < dim; i++)\r
+                                       const int inCols = arg0->getNominalSize();\r
+                                       const int inRows = arg0->getSecondarySize();\r
+\r
+                                       for(int i = 0; i < outCols; i++)\r
                                        {\r
-                                               if(dim > dim2(arg0))\r
+                                               if(i >= inCols || outRows > inRows)\r
                                                {\r
                                                        // Initialize to identity matrix\r
                                                        Constant col((i == 0 ? 1.0f : 0.0f), (i == 1 ? 1.0f : 0.0f), (i == 2 ? 1.0f : 0.0f), (i == 3 ? 1.0f : 0.0f));\r
@@ -990,11 +994,11 @@ namespace glsl
                                                        mov->dst.index += i;\r
                                                }\r
 \r
-                                               if(i < dim2(arg0))\r
+                                               if(i < inCols)\r
                                                {\r
                                                        Instruction *mov = emitCast(result, arg0);\r
                                                        mov->dst.index += i;\r
-                                                       mov->dst.mask = 0xF >> (4 - dim2(arg0));\r
+                                                       mov->dst.mask = 0xF >> (4 - inRows);\r
                                                        argument(mov->src[0], arg0, i);\r
                                                }\r
                                        }\r
@@ -1018,9 +1022,9 @@ namespace glsl
                                                        mov->src[0].swizzle = (readSwizzle(argi, size) << (row * 2)) + 0x55 * element;\r
 \r
                                                        int end = row + size - element;\r
-                                                       column = end >= dim ? column + 1 : column;\r
-                                                       element = element + dim - row;\r
-                                                       row = end >= dim ? 0 : end;\r
+                                                       column = end >= outRows ? column + 1 : column;\r
+                                                       element = element + outRows - row;\r
+                                                       row = end >= outRows ? 0 : end;\r
                                                }\r
                                        }\r
                                }\r
@@ -1461,7 +1465,7 @@ namespace glsl
                }\r
                else if(type.isMatrix())\r
                {\r
-                       return registers * type.getSecondarySize();\r
+                       return registers * type.registerSize();\r
                }\r
                \r
                UNREACHABLE(0);\r
@@ -1477,7 +1481,7 @@ namespace glsl
                                return registerSize(*((*(type.getStruct()->fields().begin()))->type()), 0);\r
                        }\r
 \r
-                       return type.isMatrix() ? type.getSecondarySize() : type.getNominalSize();\r
+                       return type.registerSize();\r
                }\r
 \r
                if(type.isArray() && registers >= type.elementRegisterCount())\r
@@ -2077,7 +2081,7 @@ namespace glsl
                if(var == -1)\r
                {\r
                        var = allocate(varyings, varying);\r
-                       int componentCount = varying->getNominalSize();\r
+                       int componentCount = varying->registerSize();\r
                        int registerCount = varying->totalRegisterCount();\r
 \r
                        if(pixelShader)\r
index ad3488e..7932bd5 100644 (file)
@@ -26,8 +26,9 @@
 int TSymbolTableLevel::uniqueId = 0;
 
 TType::TType(const TPublicType &p) :
-    type(p.type), precision(p.precision), primarySize(p.primarySize), secondarySize(p.secondarySize), qualifier(p.qualifier), array(p.array), arraySize(p.arraySize),
-    maxArraySize(0), arrayInformationType(0), structure(0), deepestStructNesting(0), mangled(0)
+    type(p.type), precision(p.precision), qualifier(p.qualifier), invariant(false), layoutQualifier(TLayoutQualifier::create()),\r
+    primarySize(p.primarySize), secondarySize(p.secondarySize), array(p.array), arraySize(p.arraySize), maxArraySize(0),\r
+    arrayInformationType(0), interfaceBlock(0), structure(0), deepestStructNesting(0), mangled(0)
 {
     if (p.userDef)
     {
index cb2722c..e58c996 100644 (file)
@@ -345,6 +345,11 @@ public:
                }
        }
 
+       int registerSize() const
+       {
+               return isMatrix() ? secondarySize : primarySize;
+       }
+
        bool isMatrix() const { return secondarySize > 1; }
        void setSecondarySize(int s1) { secondarySize = s1; }
        int getSecondarySize() const { return secondarySize; }
index 99d126d..8b72d30 100644 (file)
@@ -321,6 +321,7 @@ public:
 
        int totalRegisterCount() const { return type.totalRegisterCount(); }
        int elementRegisterCount() const { return type.elementRegisterCount(); }
+       int registerSize() const { return type.registerSize(); }
        int getArraySize() const { return type.getArraySize(); }
 
 protected:
index dd4c598..b8ba80b 100644 (file)
@@ -65,7 +65,7 @@ namespace es2
 \r
        int Uniform::registerCount() const\r
        {\r
-               return size() * VariableRowCount(type);\r
+               return size() * VariableRegisterCount(type);\r
        }\r
 \r
        UniformBlock::UniformBlock(const std::string &name, unsigned int elementIndex, unsigned int dataSize) :\r
@@ -1128,8 +1128,8 @@ namespace es2
                                {\r
                                        int in = input->reg;\r
                                        int out = output->reg;\r
-                                       int components = VariableColumnCount(output->type);\r
-                                       int registers = VariableRowCount(output->type) * output->size();\r
+                                       int components = VariableRegisterSize(output->type);\r
+                                       int registers = VariableRegisterCount(output->type) * output->size();\r
 \r
                                        ASSERT(in >= 0);\r
 \r
@@ -1270,7 +1270,7 @@ namespace es2
 \r
                                linkedAttribute[location] = *attribute;\r
 \r
-                               int rows = VariableRowCount(attribute->type);\r
+                               int rows = VariableRegisterCount(attribute->type);\r
 \r
                                if(rows + location > MAX_VERTEX_ATTRIBS)\r
                                {\r
@@ -1292,7 +1292,7 @@ namespace es2
 \r
                        if(location == -1)   // Not set by glBindAttribLocation\r
                        {\r
-                               int rows = VariableRowCount(attribute->type);\r
+                               int rows = VariableRegisterCount(attribute->type);\r
                                int availableIndex = AllocateFirstFreeBits(&usedLocations, rows, MAX_VERTEX_ATTRIBS);\r
 \r
                                if(availableIndex == -1 || availableIndex + rows > MAX_VERTEX_ATTRIBS)\r
@@ -1308,7 +1308,7 @@ namespace es2
                for(int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; )\r
                {\r
                        int index = vertexShader->getSemanticIndex(linkedAttribute[attributeIndex].name);\r
-                       int rows = std::max(VariableRowCount(linkedAttribute[attributeIndex].type), 1);\r
+                       int rows = std::max(VariableRegisterCount(linkedAttribute[attributeIndex].type), 1);\r
 \r
                        for(int r = 0; r < rows; r++)\r
                        {\r
index ea19daf..bdb8e46 100644 (file)
@@ -278,6 +278,19 @@ namespace es2
                return 0;\r
        }\r
 \r
+       int VariableRegisterCount(GLenum type)\r
+       {\r
+               // Number of registers used is the number of columns for matrices or 1 for scalars and vectors\r
+               return (VariableRowCount(type) > 1) ? VariableColumnCount(type) : 1;\r
+       }\r
+\r
+       int VariableRegisterSize(GLenum type)\r
+       {\r
+               // Number of components per register is the number of rows for matrices or columns for scalars and vectors\r
+               int nbRows = VariableRowCount(type);\r
+               return (nbRows > 1) ? nbRows : VariableColumnCount(type);\r
+       }\r
+\r
        int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize)\r
        {\r
                ASSERT(allocationSize <= bitsSize);\r
index baa699f..82f5fa9 100644 (file)
@@ -33,6 +33,8 @@ namespace es2
        bool IsSamplerUniform(GLenum type);\r
        int VariableRowCount(GLenum type);\r
        int VariableColumnCount(GLenum type);\r
+       int VariableRegisterCount(GLenum type);\r
+       int VariableRegisterSize(GLenum type);\r
 \r
        int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);\r
 \r