SPIR-V array constructors

Bug: skia:
Change-Id: I88c896e126c764fc07a7e5a5adace1651070a494
Reviewed-on: https://skia-review.googlesource.com/24243
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 8c606ae..c07a6db 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1760,6 +1760,24 @@
     return result;
 }
 
+SpvId SPIRVCodeGenerator::writeArrayConstructor(const Constructor& c, OutputStream& out) {
+    ASSERT(c.fType.kind() == Type::kArray_Kind);
+    // go ahead and write the arguments so we don't try to write new instructions in the middle of
+    // an instruction
+    std::vector<SpvId> arguments;
+    for (size_t i = 0; i < c.fArguments.size(); i++) {
+        arguments.push_back(this->writeExpression(*c.fArguments[i], out));
+    }
+    SpvId result = this->nextId();
+    this->writeOpCode(SpvOpCompositeConstruct, 3 + (int32_t) c.fArguments.size(), out);
+    this->writeWord(this->getType(c.fType), out);
+    this->writeWord(result, out);
+    for (SpvId id : arguments) {
+        this->writeWord(id, out);
+    }
+    return result;
+}
+
 SpvId SPIRVCodeGenerator::writeConstructor(const Constructor& c, OutputStream& out) {
     if (c.fType == *fContext.fFloat_Type) {
         return this->writeFloatConstructor(c, out);
@@ -1773,6 +1791,8 @@
             return this->writeVectorConstructor(c, out);
         case Type::kMatrix_Kind:
             return this->writeMatrixConstructor(c, out);
+        case Type::kArray_Kind:
+            return this->writeArrayConstructor(c, out);
         default:
             ABORT("unsupported constructor: %s", c.description().c_str());
     }
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h
index 4500abb..5db4bb4 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.h
+++ b/src/sksl/SkSLSPIRVCodeGenerator.h
@@ -173,6 +173,8 @@
 
     SpvId writeVectorConstructor(const Constructor& c, OutputStream& out);
 
+    SpvId writeArrayConstructor(const Constructor& c, OutputStream& out);
+
     SpvId writeConstructor(const Constructor& c, OutputStream& out);
 
     SpvId writeFieldAccess(const FieldAccess& f, OutputStream& out);