aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLIRGenerator.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-09-15 11:42:17 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-09-15 18:50:54 +0000
commit05d5a13fea6246648de7e41358ed338d53c85ea2 (patch)
tree695fdbeae1116f8ce813288e47b31c2a99f28f1f /src/sksl/SkSLIRGenerator.cpp
parent49f1f34438d3431f6d7e32847accd2ba96948a73 (diff)
Revert "Revert "Switched highp float to highfloat and mediump float to half.""
This reverts commit 1d816b92bb7cf2258007f3f74ffd143b89f25d01. Bug: skia: Change-Id: I388b5e5e9bf619db48297a80c9a80c039f26c9f1 Reviewed-on: https://skia-review.googlesource.com/46464 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLIRGenerator.cpp')
-rw-r--r--src/sksl/SkSLIRGenerator.cpp65
1 files changed, 44 insertions, 21 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 83ab993c2a..2c6b9e3f5c 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -17,7 +17,6 @@
#include "ast/SkSLASTFloatLiteral.h"
#include "ast/SkSLASTIndexSuffix.h"
#include "ast/SkSLASTIntLiteral.h"
-#include "ast/SkSLASTPrecision.h"
#include "ir/SkSLBinaryExpression.h"
#include "ir/SkSLBoolLiteral.h"
#include "ir/SkSLBreakStatement.h"
@@ -981,8 +980,15 @@ static bool determine_binary_type(const Context& context,
*outResultType = context.fBool_Type.get();
return left.canCoerceTo(*context.fBool_Type) &&
right.canCoerceTo(*context.fBool_Type);
- case Token::STAR: // fall through
case Token::STAREQ:
+ if (left.kind() == Type::kScalar_Kind) {
+ *outLeftType = &left;
+ *outRightType = &left;
+ *outResultType = &left;
+ return right.canCoerceTo(left);
+ }
+ // fall through
+ case Token::STAR:
if (is_matrix_multiply(left, right)) {
// determine final component type
if (determine_binary_type(context, Token::STAR, left.componentType(),
@@ -1022,12 +1028,22 @@ static bool determine_binary_type(const Context& context,
isLogical = false;
validMatrixOrVectorOp = true;
break;
+ case Token::PLUSEQ:
+ case Token::MINUSEQ:
+ case Token::SLASHEQ:
+ case Token::PERCENTEQ:
+ case Token::SHLEQ:
+ case Token::SHREQ:
+ if (left.kind() == Type::kScalar_Kind) {
+ *outLeftType = &left;
+ *outRightType = &left;
+ *outResultType = &left;
+ return right.canCoerceTo(left);
+ }
+ // fall through
case Token::PLUS: // fall through
- case Token::PLUSEQ: // fall through
case Token::MINUS: // fall through
- case Token::MINUSEQ: // fall through
case Token::SLASH: // fall through
- case Token::SLASHEQ: // fall through
isLogical = false;
validMatrixOrVectorOp = true;
break;
@@ -1041,9 +1057,23 @@ static bool determine_binary_type(const Context& context,
validMatrixOrVectorOp = false;
}
bool isVectorOrMatrix = left.kind() == Type::kVector_Kind || left.kind() == Type::kMatrix_Kind;
- // FIXME: incorrect for shift
- if (right.canCoerceTo(left) && (left.kind() == Type::kScalar_Kind ||
- (isVectorOrMatrix && validMatrixOrVectorOp))) {
+ if (left.kind() == Type::kScalar_Kind && right.kind() == Type::kScalar_Kind &&
+ right.canCoerceTo(left)) {
+ if (left.priority() > right.priority()) {
+ *outLeftType = &left;
+ *outRightType = &left;
+ } else {
+ *outLeftType = &right;
+ *outRightType = &right;
+ }
+ if (isLogical) {
+ *outResultType = context.fBool_Type.get();
+ } else {
+ *outResultType = &left;
+ }
+ return true;
+ }
+ if (right.canCoerceTo(left) && isVectorOrMatrix && validMatrixOrVectorOp) {
*outLeftType = &left;
*outRightType = &left;
if (isLogical) {
@@ -1480,18 +1510,17 @@ std::unique_ptr<Expression> IRGenerator::convertNumberConstructor(
to_string((uint64_t) args.size()) + ")");
return nullptr;
}
- if (type.isFloat() && args[0]->fType.isFloat()) {
+ if (type == args[0]->fType) {
return std::move(args[0]);
}
- if (type.isSigned() && args[0]->fType.isSigned()) {
- return std::move(args[0]);
- }
- if (type.isUnsigned() && args[0]->fType.isUnsigned()) {
- return std::move(args[0]);
+ if (type.isFloat() && args.size() == 1 && args[0]->fKind == Expression::kFloatLiteral_Kind) {
+ double value = ((FloatLiteral&) *args[0]).fValue;
+ return std::unique_ptr<Expression>(new FloatLiteral(fContext, offset, value, &type));
}
if (type.isFloat() && args.size() == 1 && args[0]->fKind == Expression::kIntLiteral_Kind) {
int64_t value = ((IntLiteral&) *args[0]).fValue;
- return std::unique_ptr<Expression>(new FloatLiteral(fContext, offset, (double) value));
+ return std::unique_ptr<Expression>(new FloatLiteral(fContext, offset, (double) value,
+ &type));
}
if (args[0]->fKind == Expression::kIntLiteral_Kind && (type == *fContext.fInt_Type ||
type == *fContext.fUInt_Type)) {
@@ -1949,7 +1978,6 @@ void IRGenerator::markWrittenTo(const Expression& expr, bool readWrite) {
void IRGenerator::convertProgram(const char* text,
size_t length,
SymbolTable& types,
- Modifiers::Flag* defaultPrecision,
std::vector<std::unique_ptr<ProgramElement>>* out) {
Parser parser(text, length, types, fErrors);
std::vector<std::unique_ptr<ASTDeclaration>> parsed = parser.file();
@@ -1957,7 +1985,6 @@ void IRGenerator::convertProgram(const char* text,
printf("float type has name: '%s'\n", fContext.fFloat_Type->name().c_str());
return;
}
- *defaultPrecision = Modifiers::kHighp_Flag;
for (size_t i = 0; i < parsed.size(); i++) {
ASTDeclaration& decl = *parsed[i];
switch (decl.fKind) {
@@ -2004,10 +2031,6 @@ void IRGenerator::convertProgram(const char* text,
}
break;
}
- case ASTDeclaration::kPrecision_Kind: {
- *defaultPrecision = ((ASTPrecision&) decl).fPrecision;
- break;
- }
default:
ABORT("unsupported declaration: %s\n", decl.description().c_str());
}