Allow Metal shaders to return half4 colors.
This allows us to write SkSL shaders which are valid both for use as
Runtime Effect, and for compilation with skslc targeting Metal.
Change-Id: I74e125d81865d4092e657a7d9948d2e72054bda5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357777
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index 24deb17..66fea1ff 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -1904,7 +1904,14 @@
void MetalCodeGenerator::writeReturnStatement(const ReturnStatement& r) {
if (fCurrentFunction && fCurrentFunction->name() == "main") {
if (r.expression()) {
- fErrors.error(r.fOffset, "Metal does not support returning values from main()");
+ if (r.expression()->type() == *fContext.fTypes.fHalf4) {
+ this->write("_out.sk_FragColor = ");
+ this->writeExpression(*r.expression(), kTopLevel_Precedence);
+ this->writeLine(";");
+ } else {
+ fErrors.error(r.fOffset, "Metal does not support returning '" +
+ r.expression()->type().description() + "' from main()");
+ }
}
this->writeReturnStatementFromMain();
return;