cleaned up SkSL constant handling

Bug: skia:
Change-Id: I8131c4348f0f91bc2705e493918c4ca2d1f4867b
Reviewed-on: https://skia-review.googlesource.com/95920
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2018-01-17 13:51:52 -05:00 committed by Skia Commit-Bot
parent adbe132878
commit 8f6c2aba63
5 changed files with 27 additions and 6 deletions

View File

@ -291,6 +291,7 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
} }
value = this->coerce(std::move(value), *type); value = this->coerce(std::move(value), *type);
var->fWriteCount = 1; var->fWriteCount = 1;
var->fInitialValue = value.get();
} }
if (storage == Variable::kGlobal_Storage && varDecl.fName == "sk_FragColor" && if (storage == Variable::kGlobal_Storage && varDecl.fName == "sk_FragColor" &&
(*fSymbolTable)[varDecl.fName]) { (*fSymbolTable)[varDecl.fName]) {

View File

@ -146,15 +146,11 @@ struct Constructor : public Expression {
} }
double getFVecComponent(int index) const { double getFVecComponent(int index) const {
const Expression& c = this->getVecComponent(index); return this->getVecComponent(index).getConstantFloat();
ASSERT(c.fKind == Expression::kFloatLiteral_Kind);
return ((FloatLiteral&) c).fValue;
} }
int64_t getIVecComponent(int index) const { int64_t getIVecComponent(int index) const {
const Expression& c = this->getVecComponent(index); return this->getVecComponent(index).getConstantInt();
ASSERT(c.fKind == Expression::kIntLiteral_Kind);
return ((IntLiteral&) c).fValue;
} }
// null return should be interpreted as zero // null return should be interpreted as zero

View File

@ -66,6 +66,22 @@ struct Expression : public IRNode {
ABORT("cannot call compareConstant on this type"); ABORT("cannot call compareConstant on this type");
} }
/**
* For an expression which evaluates to a constant int, returns the value. Otherwise calls
* ABORT.
*/
virtual int64_t getConstantInt() const {
ABORT("not a constant int");
}
/**
* For an expression which evaluates to a constant float, returns the value. Otherwise calls
* ABORT.
*/
virtual double getConstantFloat() const {
ABORT("not a constant float");
}
/** /**
* Returns true if evaluating the expression potentially has side effects. Expressions may never * Returns true if evaluating the expression potentially has side effects. Expressions may never
* return false if they actually have side effects, but it is legal (though suboptimal) to * return false if they actually have side effects, but it is legal (though suboptimal) to

View File

@ -39,6 +39,10 @@ struct FloatLiteral : public Expression {
return fValue == f.fValue; return fValue == f.fValue;
} }
double getConstantFloat() const override {
return fValue;
}
const double fValue; const double fValue;
typedef Expression INHERITED; typedef Expression INHERITED;

View File

@ -47,6 +47,10 @@ struct IntLiteral : public Expression {
return INHERITED::coercionCost(target); return INHERITED::coercionCost(target);
} }
int64_t getConstantInt() const override {
return fValue;
}
const int64_t fValue; const int64_t fValue;
typedef Expression INHERITED; typedef Expression INHERITED;