Interpreter: Fix vector/matrix equality and inequality

Need to compare all elements, then fold the result to a single bool.

Change-Id: I0ebfaa9d518f29a782701246ada247cb55c01c2e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216607
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLByteCodeGenerator.cpp b/src/sksl/SkSLByteCodeGenerator.cpp
index 9958466..70052b6 100644
--- a/src/sksl/SkSLByteCodeGenerator.cpp
+++ b/src/sksl/SkSLByteCodeGenerator.cpp
@@ -334,6 +334,8 @@
         lvalue->store();
         return;
     }
+    const Type& lType = b.fLeft->fType;
+    const Type& rType = b.fRight->fType;
     Token::Kind op;
     std::unique_ptr<LValue> lvalue;
     if (is_assignment(b.fOperator)) {
@@ -343,27 +345,31 @@
     } else {
         this->writeExpression(*b.fLeft);
         op = b.fOperator;
-        if (b.fLeft->fType.kind() == Type::kScalar_Kind &&
-            b.fRight->fType.kind() == Type::kVector_Kind) {
-            for (int i = b.fRight->fType.columns(); i > 1; --i) {
+        if (lType.kind() == Type::kScalar_Kind &&
+            (rType.kind() == Type::kVector_Kind || rType.kind() == Type::kMatrix_Kind)) {
+            for (int i = SlotCount(rType); i > 1; --i) {
                 this->write(ByteCodeInstruction::kDup);
             }
         }
     }
     this->writeExpression(*b.fRight);
-    if (b.fLeft->fType.kind() == Type::kVector_Kind &&
-        b.fRight->fType.kind() == Type::kScalar_Kind) {
-        for (int i = b.fLeft->fType.columns(); i > 1; --i) {
+    if ((lType.kind() == Type::kVector_Kind || lType.kind() == Type::kMatrix_Kind) &&
+        rType.kind() == Type::kScalar_Kind) {
+        for (int i = SlotCount(lType); i > 1; --i) {
             this->write(ByteCodeInstruction::kDup);
         }
     }
-    int count = SlotCount(b.fType);
+    int count = SkTMax(SlotCount(lType), SlotCount(rType));
     switch (op) {
         case Token::Kind::EQEQ:
             this->writeTypedInstruction(b.fLeft->fType, ByteCodeInstruction::kCompareIEQ,
                                         ByteCodeInstruction::kCompareIEQ,
                                         ByteCodeInstruction::kCompareFEQ,
                                         count);
+            // Collapse to a single bool
+            for (int i = count; i > 1; --i) {
+                this->write(ByteCodeInstruction::kAndB);
+            }
             break;
         case Token::Kind::GT:
             this->writeTypedInstruction(b.fLeft->fType, ByteCodeInstruction::kCompareSGT,
@@ -400,6 +406,10 @@
                                         ByteCodeInstruction::kCompareINEQ,
                                         ByteCodeInstruction::kCompareFNEQ,
                                         count);
+            // Collapse to a single bool
+            for (int i = count; i > 1; --i) {
+                this->write(ByteCodeInstruction::kOrB);
+            }
             break;
         case Token::Kind::PERCENT:
             this->writeTypedInstruction(b.fLeft->fType, ByteCodeInstruction::kRemainderS,