OSDN Git Service

Implement constructing vectors from matrices and matrices from scalars.
authorNicolas Capens <capn@google.com>
Fri, 13 Jun 2014 21:13:17 +0000 (17:13 -0400)
committerNicolas Capens <nicolascapens@google.com>
Sun, 15 Jun 2014 23:38:38 +0000 (23:38 +0000)
BUG=15415045

Change-Id: I97355dab2890bcf3c1bf39d149960e53e4fed325
Reviewed-on: https://swiftshader-review.googlesource.com/1115
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
src/GLES2/compiler/OutputASM.cpp

index 3a8aaec..4f5b62e 100644 (file)
@@ -618,7 +618,7 @@ namespace sh
                case EOpAbs:              if(visit == PostVisit) emit(sw::Shader::OPCODE_ABS, result, arg); break;\r
                case EOpSign:             if(visit == PostVisit) emit(sw::Shader::OPCODE_SGN, result, arg); break;\r
                case EOpFloor:            if(visit == PostVisit) emit(sw::Shader::OPCODE_FLOOR, result, arg); break;\r
-               case EOpCeil:             if(visit == PostVisit) emit(sw::Shader::OPCODE_CEIL, result, arg, result);    break;\r
+               case EOpCeil:             if(visit == PostVisit) emit(sw::Shader::OPCODE_CEIL, result, arg, result); break;\r
                case EOpFract:            if(visit == PostVisit) emit(sw::Shader::OPCODE_FRC, result, arg); break;\r
                case EOpLength:           if(visit == PostVisit) emit(sw::Shader::OPCODE_LEN(dim(arg)), result, arg); break;\r
                case EOpNormalize:        if(visit == PostVisit) emit(sw::Shader::OPCODE_NRM(dim(arg)), result, arg); break;\r
@@ -640,6 +640,8 @@ namespace sh
                        return false;\r
                }\r
 \r
+               Constant zero(0.0f, 0.0f, 0.0f, 0.0f);\r
+\r
                TIntermTyped *result = node;\r
                const TType &resultType = node->getType();\r
                TIntermSequence &arg = node->getSequence();\r
@@ -648,7 +650,7 @@ namespace sh
                switch(node->getOp())\r
                {\r
                case EOpSequence:           break;\r
-               case EOpDeclaration:            break;\r
+               case EOpDeclaration:        break;\r
                case EOpPrototype:          break;\r
                case EOpComma:\r
                        if(visit == PostVisit)\r
@@ -862,13 +864,30 @@ namespace sh
                                {\r
                                        TIntermTyped *argi = arg[i]->getAsTyped();\r
                                        int size = argi->getNominalSize();\r
-                                       ASSERT(!argi->isMatrix());\r
 \r
-                                       Instruction *mov = emitCast(result, argi);\r
-                                       mov->dst.mask = (0xF << component) & 0xF;\r
-                                       mov->src[0].swizzle = readSwizzle(argi, size) << (component * 2);\r
+                                       if(!argi->isMatrix())\r
+                                       {\r
+                                               Instruction *mov = emitCast(result, argi);\r
+                                               mov->dst.mask = (0xF << component) & 0xF;\r
+                                               mov->src[0].swizzle = readSwizzle(argi, size) << (component * 2);\r
+\r
+                                               component += size;\r
+                                       }\r
+                                       else   // Matrix\r
+                                       {\r
+                                               int column = 0;\r
+\r
+                                               while(component < resultType.getNominalSize())\r
+                                               {\r
+                                                       Instruction *mov = emitCast(result, argi);\r
+                                                       mov->dst.mask = (0xF << component) & 0xF;\r
+                                                       mov->src[0].index += column;\r
+                                                       mov->src[0].swizzle = readSwizzle(argi, size) << (component * 2);\r
 \r
-                                       component += size;\r
+                                                       column++;\r
+                                                       component += size;\r
+                                               }\r
+                                       }\r
                                }\r
                        }\r
                        break;\r
@@ -880,7 +899,19 @@ namespace sh
                                TIntermTyped *arg0 = arg[0]->getAsTyped();\r
                                const int dim = result->getNominalSize();\r
 \r
-                               if(arg0->isMatrix())\r
+                               if(arg0->isScalar() && arg.size() == 1)   // Construct scale matrix\r
+                               {\r
+                                       for(int i = 0; i < dim; i++)\r
+                                       {\r
+                                               Instruction *init = emit(sw::Shader::OPCODE_MOV, result, &zero);\r
+                                               init->dst.index += i;\r
+                                               Instruction *mov = emitCast(result, arg0);\r
+                                               mov->dst.index += i;\r
+                                               mov->dst.mask = 1 << i;\r
+                                               ASSERT(mov->src[0].swizzle == 0x00);\r
+                                       }\r
+                               }\r
+                               else if(arg0->isMatrix())\r
                                {\r
                                        for(int i = 0; i < dim; i++)\r
                                        {\r