SkRuntimeEffect: Implement and test matrixCompMult intrinsic
Bug: skia:10913
Change-Id: I430e5eb3fecb0f15775db03699819194d44271b6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347958
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index 5d1ba3e..0eb047f 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -421,6 +421,8 @@
this->write("-");
}
name = "dfdy";
+ } else if (name == "matrixCompMult") {
+ this->writeMatrixCompMult();
}
}
@@ -555,6 +557,25 @@
return name;
}
+static constexpr char kMatrixCompMult[] = R"(
+template <int C, int R>
+matrix<float, C, R> matrixCompMult(matrix<float, C, R> a, matrix<float, C, R> b) {
+ matrix<float, C, R> result;
+ for (int c = 0; c < C; ++c) {
+ result[c] = a[c] * b[c];
+ }
+ return result;
+}
+)";
+
+void MetalCodeGenerator::writeMatrixCompMult() {
+ String name = "matrixCompMult";
+ if (fWrittenIntrinsics.find(name) == fWrittenIntrinsics.end()) {
+ fWrittenIntrinsics.insert(name);
+ fExtraFunctions.writeText(kMatrixCompMult);
+ }
+}
+
String MetalCodeGenerator::getTempVariable(const Type& type) {
String tempVar = "_skTemp" + to_string(fVarCount++);
this->fFunctionHeader += " " + this->typeName(type) + " " + tempVar + ";\n";