Revert "added support for SkSL unpremul function"
This reverts commit ffdc3e668061cff14ea55ba087e9105f2ff219fc.
Reason for revert: breaking Chrome roll
Original change's description:
> added support for SkSL unpremul function
>
> Change-Id: I970f1ad0dd0859448c874498fe02342f8abc3aa3
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/242897
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
TBR=bsalomon@google.com,brianosman@google.com,ethannicholas@google.com
Change-Id: I72dacea82b1f4ea2aa6cd600122a4810657aa32e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/243117
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index 916fa9c..641e4c0 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -32,7 +32,6 @@
fIntrinsicMap[String("lessThanEqual")] = METAL(LessThanEqual);
fIntrinsicMap[String("greaterThan")] = METAL(GreaterThan);
fIntrinsicMap[String("greaterThanEqual")] = METAL(GreaterThanEqual);
- fIntrinsicMap[String("unpremul")] = SPECIAL(Unpremul);
}
void MetalCodeGenerator::write(const char* s) {
@@ -70,51 +69,50 @@
this->writeLine("#extension " + ext.fName + " : enable");
}
-String MetalCodeGenerator::getTypeName(const Type& type) {
+void MetalCodeGenerator::writeType(const Type& type) {
switch (type.kind()) {
case Type::kStruct_Kind:
- return type.name();
+ for (const Type* search : fWrittenStructs) {
+ if (*search == type) {
+ // already written
+ this->write(type.name());
+ return;
+ }
+ }
+ fWrittenStructs.push_back(&type);
+ this->writeLine("struct " + type.name() + " {");
+ fIndentation++;
+ this->writeFields(type.fields(), type.fOffset);
+ fIndentation--;
+ this->write("}");
+ break;
case Type::kVector_Kind:
- return this->getTypeName(type.componentType()) + to_string(type.columns());
+ this->writeType(type.componentType());
+ this->write(to_string(type.columns()));
+ break;
case Type::kMatrix_Kind:
- return this->getTypeName(type.componentType()) + to_string(type.columns()) + "x" +
- to_string(type.rows());
+ this->writeType(type.componentType());
+ this->write(to_string(type.columns()));
+ this->write("x");
+ this->write(to_string(type.rows()));
+ break;
case Type::kSampler_Kind:
- return "texture2d<float>"; // FIXME - support other texture types;
+ this->write("texture2d<float> "); // FIXME - support other texture types;
+ break;
default:
if (type == *fContext.fHalf_Type) {
// FIXME - Currently only supporting floats in MSL to avoid type coercion issues.
- return fContext.fFloat_Type->name();
+ this->write(fContext.fFloat_Type->name());
} else if (type == *fContext.fByte_Type) {
- return "char";
+ this->write("char");
} else if (type == *fContext.fUByte_Type) {
- return "uchar";
+ this->write("uchar");
} else {
- return type.name();
+ this->write(type.name());
}
}
}
-void MetalCodeGenerator::writeType(const Type& type) {
- if (type.kind() == Type::kStruct_Kind) {
- for (const Type* search : fWrittenStructs) {
- if (*search == type) {
- // already written
- this->write(this->getTypeName(type));
- return;
- }
- }
- fWrittenStructs.push_back(&type);
- this->writeLine("struct " + type.name() + " {");
- fIndentation++;
- this->writeFields(type.fields(), type.fOffset);
- fIndentation--;
- this->write("}");
- } else {
- this->write(this->getTypeName(type));
- }
-}
-
void MetalCodeGenerator::writeExpression(const Expression& expr, Precedence parentPrecedence) {
switch (expr.fKind) {
case Expression::kBinary_Kind:
@@ -371,23 +369,6 @@
this->writeExpression(*c.fArguments[1], kSequence_Precedence);
this->write(")))");
break;
- case kUnpremul_SpecialIntrinsic: {
- String tmpVar1 = "unpremul" + to_string(fVarCount++);
- this->fFunctionHeader += String(" ") +
- this->getTypeName(c.fArguments[0]->fType) + " " + tmpVar1 +
- ";";
- String tmpVar2 = "unpremulNonZeroAlpha" + to_string(fVarCount++);
- this->fFunctionHeader += String(" ") +
- this->getTypeName(c.fArguments[0]->fType.componentType()) +
- " " + tmpVar2 + ";";
- this->write("(" + tmpVar1 + " = ");
- this->writeExpression(*c.fArguments[0], kSequence_Precedence);
- this->write(", " + tmpVar2 + " = max(" + tmpVar1 + ".a, " +
- to_string(SKSL_UNPREMUL_MIN) + "), " +
- this->getTypeName(*fContext.fHalf4_Type) + "(" + tmpVar1 +
- ".rgb / " + tmpVar2 + ", " + tmpVar2 + "))");
- return;
- }
default:
ABORT("unsupported special intrinsic kind");
}