sksl: Add support for 2x2 matrix inversions in Metal

Bug: skia:
Change-Id: I524319ede491be4884c42d89f485ed98cff0cd29
Reviewed-on: https://skia-review.googlesource.com/c/171221
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.h b/src/sksl/SkSLMetalCodeGenerator.h
index bbf930b..1a3a790 100644
--- a/src/sksl/SkSLMetalCodeGenerator.h
+++ b/src/sksl/SkSLMetalCodeGenerator.h
@@ -182,6 +182,8 @@
 
     void writeFunctionCall(const FunctionCall& c);
 
+    void writeInverseHack(const Expression& mat);
+
     void writeSpecialIntrinsic(const FunctionCall& c, SpecialIntrinsic kind);
 
     void writeConstructor(const Constructor& c);
@@ -250,6 +252,7 @@
     const Context& fContext;
     StringStream fHeader;
     String fFunctionHeader;
+    StringStream fExtraFunctions;
     Program::Kind fProgramKind;
     int fVarCount = 0;
     int fIndentation = 0;
@@ -258,6 +261,7 @@
     // more than one or two structs per shader, a simple linear search will be faster than anything
     // fancier.
     std::vector<const Type*> fWrittenStructs;
+    std::set<String> fWrittenIntrinsics;
     // true if we have run into usages of dFdx / dFdy
     bool fFoundDerivatives = false;
     bool fFoundImageDecl = false;