Revert "moved SkSL FloatLiteral data into IRNode"

This reverts commit 135e237656.

No-Tree-Checks: true
Change-Id: I7e9dd2148f7b2a8dee1e49a9a9cc593e0d7ceb6e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/321460
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2020-10-01 08:56:53 -04:00
parent 4f09dd47da
commit a0c82f08df
17 changed files with 43 additions and 80 deletions

View File

@ -29,7 +29,7 @@ public:
R"SkSL(half4 inputColor = %s; R"SkSL(half4 inputColor = %s;
half3 hsl = inputColor.xyz; half3 hsl = inputColor.xyz;
half C = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y; half C = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;
half3 p = hsl.xxx + half3(0.0, 0.66666668653488159, 0.3333333432674408); half3 p = hsl.xxx + half3(0.0, 0.66666666666666663, 0.33333333333333331);
half3 q = clamp(abs(fract(p) * 6.0 - 3.0) - 1.0, 0.0, 1.0); half3 q = clamp(abs(fract(p) * 6.0 - 3.0) - 1.0, 0.0, 1.0);
half3 rgb = (q - 0.5) * C + hsl.z; half3 rgb = (q - 0.5) * C + hsl.z;
%s = clamp(half4(rgb, inputColor.w), 0.0, 1.0); %s = clamp(half4(rgb, inputColor.w), 0.0, 1.0);

View File

@ -45,7 +45,7 @@ public:
fragBuilder->emitFunction(kHalf_GrSLType, "HSLToRGB", 3, HSLToRGB_args, fragBuilder->emitFunction(kHalf_GrSLType, "HSLToRGB", 3, HSLToRGB_args,
R"SkSL(if (t < 0.0) t += 1.0; R"SkSL(if (t < 0.0) t += 1.0;
if (t > 1.0) t -= 1.0; if (t > 1.0) t -= 1.0;
return t < 0.1666666716337204 ? p + ((q - p) * 6.0) * t : (t < 0.5 ? q : (t < 0.66666668653488159 ? p + ((q - p) * (0.66666668653488159 - t)) * 6.0 : p)); return t < 0.16666666666666666 ? p + ((q - p) * 6.0) * t : (t < 0.5 ? q : (t < 0.66666666666666663 ? p + ((q - p) * (0.66666666666666663 - t)) * 6.0 : p));
)SkSL", )SkSL",
&HSLToRGB_name); &HSLToRGB_name);
SkString _sample896 = this->invokeChild(0, args); SkString _sample896 = this->invokeChild(0, args);
@ -87,7 +87,7 @@ half4 color = _0_unpremul;
} else { } else {
h = (color.x - color.y) / d + 4.0; h = (color.x - color.y) / d + 4.0;
} }
h *= 0.1666666716337204; h *= 0.16666666666666666;
} }
l = 1.0 + l * -0.5; l = 1.0 + l * -0.5;
if (s == 0.0) { if (s == 0.0) {
@ -95,9 +95,9 @@ half4 color = _0_unpremul;
} else { } else {
half q = l < 0.5 ? l * (1.0 + s) : (l + s) - l * s; half q = l < 0.5 ? l * (1.0 + s) : (l + s) - l * s;
half p = 2.0 * l - q; half p = 2.0 * l - q;
color.x = %s(p, q, h + 0.3333333432674408); color.x = %s(p, q, h + 0.33333333333333331);
color.y = %s(p, q, h); color.y = %s(p, q, h);
color.z = %s(p, q, h - 0.3333333432674408); color.z = %s(p, q, h - 0.33333333333333331);
} }
} }
@if (%s) { @if (%s) {

View File

@ -27,7 +27,7 @@ public:
SkString _sample1173 = this->invokeChild(0, args); SkString _sample1173 = this->invokeChild(0, args);
fragBuilder->codeAppendf( fragBuilder->codeAppendf(
R"SkSL(half4 c = %s; R"SkSL(half4 c = %s;
half4 p = c.y < c.z ? half4(c.zy, -1.0, 0.66666668653488159) : half4(c.yz, 0.0, -0.3333333432674408); half4 p = c.y < c.z ? half4(c.zy, -1.0, 0.66666666666666663) : half4(c.yz, 0.0, -0.33333333333333331);
half4 q = c.x < p.x ? half4(p.x, c.x, p.yw) : half4(c.x, p.x, p.yz); half4 q = c.x < p.x ? half4(p.x, c.x, p.yw) : half4(c.x, p.x, p.yz);
half pmV = q.x; half pmV = q.x;

View File

@ -1022,7 +1022,7 @@ static inline uint32_t float_to_bits(float x) {
void ByteCodeGenerator::writeFloatLiteral(const FloatLiteral& f) { void ByteCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
this->write(ByteCodeInstruction::kPushImmediate); this->write(ByteCodeInstruction::kPushImmediate);
this->write32(float_to_bits(f.value())); this->write32(float_to_bits(f.fValue));
} }
static bool is_generic_type(const Type* type, const Type* generic) { static bool is_generic_type(const Type* type, const Type* generic) {

View File

@ -652,14 +652,14 @@ static bool try_replace_expression(BasicBlock* b,
* Returns true if the expression is a constant numeric literal with the specified value, or a * Returns true if the expression is a constant numeric literal with the specified value, or a
* constant vector with all elements equal to the specified value. * constant vector with all elements equal to the specified value.
*/ */
template <typename T = SKSL_FLOAT> template <typename T = double>
static bool is_constant(const Expression& expr, T value) { static bool is_constant(const Expression& expr, T value) {
switch (expr.kind()) { switch (expr.kind()) {
case Expression::Kind::kIntLiteral: case Expression::Kind::kIntLiteral:
return expr.as<IntLiteral>().value() == value; return expr.as<IntLiteral>().value() == value;
case Expression::Kind::kFloatLiteral: case Expression::Kind::kFloatLiteral:
return expr.as<FloatLiteral>().value() == value; return expr.as<FloatLiteral>().fValue == value;
case Expression::Kind::kConstructor: { case Expression::Kind::kConstructor: {
const Constructor& constructor = expr.as<Constructor>(); const Constructor& constructor = expr.as<Constructor>();

View File

@ -298,7 +298,7 @@ void Dehydrator::write(const Expression* e) {
const FloatLiteral& f = e->as<FloatLiteral>(); const FloatLiteral& f = e->as<FloatLiteral>();
this->writeU8(Rehydrator::kFloatLiteral_Command); this->writeU8(Rehydrator::kFloatLiteral_Command);
FloatIntUnion u; FloatIntUnion u;
u.fFloat = f.value(); u.fFloat = f.fValue;
this->writeS32(u.fInt); this->writeS32(u.fInt);
break; break;
} }

View File

@ -1025,7 +1025,7 @@ void GLSLCodeGenerator::writeIntLiteral(const IntLiteral& i) {
} }
void GLSLCodeGenerator::writeFloatLiteral(const FloatLiteral& f) { void GLSLCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
this->write(to_string(f.value())); this->write(to_string(f.fValue));
} }
void GLSLCodeGenerator::writeSetting(const Setting& s) { void GLSLCodeGenerator::writeSetting(const Setting& s) {

View File

@ -1828,8 +1828,8 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
} }
if (left.kind() == Expression::Kind::kFloatLiteral && if (left.kind() == Expression::Kind::kFloatLiteral &&
right.kind() == Expression::Kind::kFloatLiteral) { right.kind() == Expression::Kind::kFloatLiteral) {
SKSL_FLOAT leftVal = left.as<FloatLiteral>().value(); double leftVal = left.as<FloatLiteral>().fValue;
SKSL_FLOAT rightVal = right.as<FloatLiteral>().value(); double rightVal = right.as<FloatLiteral>().fValue;
switch (op) { switch (op) {
case Token::Kind::TK_PLUS: return RESULT(Float, +); case Token::Kind::TK_PLUS: return RESULT(Float, +);
case Token::Kind::TK_MINUS: return RESULT(Float, -); case Token::Kind::TK_MINUS: return RESULT(Float, -);
@ -1856,8 +1856,8 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
std::vector<std::unique_ptr<Expression>> args; std::vector<std::unique_ptr<Expression>> args;
#define RETURN_VEC_COMPONENTWISE_RESULT(op) \ #define RETURN_VEC_COMPONENTWISE_RESULT(op) \
for (int i = 0; i < leftType.columns(); i++) { \ for (int i = 0; i < leftType.columns(); i++) { \
SKSL_FLOAT value = left.getFVecComponent(i) op \ float value = left.getFVecComponent(i) op \
right.getFVecComponent(i); \ right.getFVecComponent(i); \
args.emplace_back(new FloatLiteral(fContext, -1, value)); \ args.emplace_back(new FloatLiteral(fContext, -1, value)); \
} \ } \
return std::unique_ptr<Expression>(new Constructor(-1, &leftType, \ return std::unique_ptr<Expression>(new Constructor(-1, &leftType, \
@ -1879,7 +1879,7 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
fErrors.error(right.fOffset, "division by zero"); fErrors.error(right.fOffset, "division by zero");
return nullptr; return nullptr;
} }
SKSL_FLOAT value = left.getFVecComponent(i) / rvalue; float value = left.getFVecComponent(i) / rvalue;
args.emplace_back(new FloatLiteral(fContext, -1, value)); args.emplace_back(new FloatLiteral(fContext, -1, value));
} }
return std::unique_ptr<Expression>(new Constructor(-1, &leftType, return std::unique_ptr<Expression>(new Constructor(-1, &leftType,
@ -2231,12 +2231,12 @@ std::unique_ptr<Expression> IRGenerator::convertNumberConstructor(
return std::move(args[0]); return std::move(args[0]);
} }
if (type.isFloat() && args.size() == 1 && args[0]->is<FloatLiteral>()) { if (type.isFloat() && args.size() == 1 && args[0]->is<FloatLiteral>()) {
SKSL_FLOAT value = args[0]->as<FloatLiteral>().value(); double value = args[0]->as<FloatLiteral>().fValue;
return std::make_unique<FloatLiteral>(offset, value, &type); return std::make_unique<FloatLiteral>(offset, value, &type);
} }
if (type.isFloat() && args.size() == 1 && args[0]->is<IntLiteral>()) { if (type.isFloat() && args.size() == 1 && args[0]->is<IntLiteral>()) {
int64_t value = args[0]->as<IntLiteral>().value(); int64_t value = args[0]->as<IntLiteral>().value();
return std::make_unique<FloatLiteral>(offset, (float)value, &type); return std::make_unique<FloatLiteral>(offset, (double)value, &type);
} }
if (args[0]->is<IntLiteral>() && (type == *fContext.fInt_Type || if (args[0]->is<IntLiteral>() && (type == *fContext.fInt_Type ||
type == *fContext.fUInt_Type)) { type == *fContext.fUInt_Type)) {
@ -2373,7 +2373,7 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(const ASTNode&
} }
if (base->is<FloatLiteral>()) { if (base->is<FloatLiteral>()) {
return std::make_unique<FloatLiteral>(fContext, base->fOffset, return std::make_unique<FloatLiteral>(fContext, base->fOffset,
-base->as<FloatLiteral>().value()); -base->as<FloatLiteral>().fValue);
} }
if (!baseType.isNumber() && baseType.typeKind() != Type::TypeKind::kVector) { if (!baseType.isNumber() && baseType.typeKind() != Type::TypeKind::kVector) {
fErrors.error(expression.fOffset, fErrors.error(expression.fOffset,

View File

@ -919,7 +919,7 @@ void MetalCodeGenerator::writeIntLiteral(const IntLiteral& i) {
} }
void MetalCodeGenerator::writeFloatLiteral(const FloatLiteral& f) { void MetalCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
this->write(to_string(f.value())); this->write(to_string(f.fValue));
} }
void MetalCodeGenerator::writeSetting(const Setting& s) { void MetalCodeGenerator::writeSetting(const Setting& s) {

View File

@ -2555,8 +2555,8 @@ SpvId SPIRVCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
} else { } else {
constantType = ConstantType::kFloat; constantType = ConstantType::kFloat;
} }
float value = (float) f.value(); float value = (float) f.fValue;
std::pair<ConstantValue, ConstantType> key(f.value(), constantType); std::pair<ConstantValue, ConstantType> key(f.fValue, constantType);
auto entry = fNumberConstants.find(key); auto entry = fNumberConstants.find(key);
if (entry == fNumberConstants.end()) { if (entry == fNumberConstants.end()) {
SpvId result = this->nextId(); SpvId result = this->nextId();

View File

@ -47,15 +47,15 @@ union ConstantValue {
ConstantValue(int64_t i) ConstantValue(int64_t i)
: fInt(i) {} : fInt(i) {}
ConstantValue(SKSL_FLOAT f) ConstantValue(double d)
: fFloat(f) {} : fDouble(d) {}
bool operator==(const ConstantValue& other) const { bool operator==(const ConstantValue& other) const {
return fInt == other.fInt; return fInt == other.fInt;
} }
int64_t fInt; int64_t fInt;
SKSL_FLOAT fFloat; double fDouble;
}; };
enum class ConstantType { enum class ConstantType {

View File

@ -64,10 +64,6 @@ struct Expression : public IRNode {
: INHERITED(offset, (int) Kind::kIntLiteral, data) { : INHERITED(offset, (int) Kind::kIntLiteral, data) {
} }
Expression(int offset, FloatLiteralData data)
: INHERITED(offset, (int) Kind::kFloatLiteral, data) {
}
Expression(int offset, Kind kind, ExternalValueData data) Expression(int offset, Kind kind, ExternalValueData data)
: INHERITED(offset, (int) kind, data) { : INHERITED(offset, (int) kind, data) {
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast); SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
@ -140,7 +136,7 @@ struct Expression : public IRNode {
* For an expression which evaluates to a constant float, returns the value. Otherwise calls * For an expression which evaluates to a constant float, returns the value. Otherwise calls
* ABORT. * ABORT.
*/ */
virtual SKSL_FLOAT getConstantFloat() const { virtual double getConstantFloat() const {
ABORT("not a constant float"); ABORT("not a constant float");
} }

View File

@ -19,18 +19,16 @@ namespace SkSL {
struct FloatLiteral : public Expression { struct FloatLiteral : public Expression {
static constexpr Kind kExpressionKind = Kind::kFloatLiteral; static constexpr Kind kExpressionKind = Kind::kFloatLiteral;
FloatLiteral(const Context& context, int offset, float value) FloatLiteral(const Context& context, int offset, double value)
: INHERITED(offset, FloatLiteralData{context.fFloatLiteral_Type.get(), value}) {} : INHERITED(offset, kExpressionKind, context.fFloatLiteral_Type.get())
, fValue(value) {}
FloatLiteral(int offset, float value, const Type* type) FloatLiteral(int offset, double value, const Type* type)
: INHERITED(offset, FloatLiteralData{type, value}) {} : INHERITED(offset, kExpressionKind, type)
, fValue(value) {}
float value() const {
return this->floatLiteralData().fValue;
}
String description() const override { String description() const override {
return to_string(this->value()); return to_string(fValue);
} }
bool hasProperty(Property property) const override { bool hasProperty(Property property) const override {
@ -49,18 +47,19 @@ struct FloatLiteral : public Expression {
} }
bool compareConstant(const Context& context, const Expression& other) const override { bool compareConstant(const Context& context, const Expression& other) const override {
return this->value() == other.as<FloatLiteral>().value(); return fValue == other.as<FloatLiteral>().fValue;
} }
SKSL_FLOAT getConstantFloat() const override { double getConstantFloat() const override {
return this->value(); return fValue;
} }
std::unique_ptr<Expression> clone() const override { std::unique_ptr<Expression> clone() const override {
return std::unique_ptr<Expression>(new FloatLiteral(fOffset, this->value(), &this->type())); return std::unique_ptr<Expression>(new FloatLiteral(fOffset, fValue, &this->type()));
} }
private: const double fValue;
using INHERITED = Expression; using INHERITED = Expression;
}; };

View File

@ -38,11 +38,6 @@ IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
, fKind(kind) , fKind(kind)
, fData(data) {} , fData(data) {}
IRNode::IRNode(int offset, int kind, const FloatLiteralData& data)
: fOffset(offset)
, fKind(kind)
, fData(data) {}
IRNode::IRNode(int offset, int kind, const String& data) IRNode::IRNode(int offset, int kind, const String& data)
: fOffset(offset) : fOffset(offset)
, fKind(kind) , fKind(kind)

View File

@ -57,8 +57,6 @@ public:
return *this->externalValueData().fType; return *this->externalValueData().fType;
case NodeData::Kind::kIntLiteral: case NodeData::Kind::kIntLiteral:
return *this->intLiteralData().fType; return *this->intLiteralData().fType;
case NodeData::Kind::kFloatLiteral:
return *this->floatLiteralData().fType;
case NodeData::Kind::kType: case NodeData::Kind::kType:
return *this->typeData(); return *this->typeData();
case NodeData::Kind::kTypeToken: case NodeData::Kind::kTypeToken:
@ -93,11 +91,6 @@ protected:
const ExternalValue* fValue; const ExternalValue* fValue;
}; };
struct FloatLiteralData {
const Type* fType;
float fValue;
};
struct IntLiteralData { struct IntLiteralData {
const Type* fType; const Type* fType;
int64_t fValue; int64_t fValue;
@ -114,7 +107,6 @@ protected:
kBoolLiteral, kBoolLiteral,
kEnum, kEnum,
kExternalValue, kExternalValue,
kFloatLiteral,
kIntLiteral, kIntLiteral,
kString, kString,
kType, kType,
@ -127,7 +119,6 @@ protected:
BoolLiteralData fBoolLiteral; BoolLiteralData fBoolLiteral;
EnumData fEnum; EnumData fEnum;
ExternalValueData fExternalValue; ExternalValueData fExternalValue;
FloatLiteralData fFloatLiteral;
IntLiteralData fIntLiteral; IntLiteralData fIntLiteral;
String fString; String fString;
const Type* fType; const Type* fType;
@ -158,11 +149,6 @@ protected:
*(new(&fContents) ExternalValueData) = data; *(new(&fContents) ExternalValueData) = data;
} }
NodeData(const FloatLiteralData& data)
: fKind(Kind::kFloatLiteral) {
*(new(&fContents) FloatLiteralData) = data;
}
NodeData(IntLiteralData data) NodeData(IntLiteralData data)
: fKind(Kind::kIntLiteral) { : fKind(Kind::kIntLiteral) {
*(new(&fContents) IntLiteralData) = data; *(new(&fContents) IntLiteralData) = data;
@ -203,9 +189,6 @@ protected:
case Kind::kExternalValue: case Kind::kExternalValue:
*(new(&fContents) ExternalValueData) = other.fContents.fExternalValue; *(new(&fContents) ExternalValueData) = other.fContents.fExternalValue;
break; break;
case Kind::kFloatLiteral:
*(new(&fContents) FloatLiteralData) = other.fContents.fFloatLiteral;
break;
case Kind::kIntLiteral: case Kind::kIntLiteral:
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral; *(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
break; break;
@ -241,9 +224,6 @@ protected:
case Kind::kExternalValue: case Kind::kExternalValue:
fContents.fExternalValue.~ExternalValueData(); fContents.fExternalValue.~ExternalValueData();
break; break;
case Kind::kFloatLiteral:
fContents.fFloatLiteral.~FloatLiteralData();
break;
case Kind::kIntLiteral: case Kind::kIntLiteral:
fContents.fIntLiteral.~IntLiteralData(); fContents.fIntLiteral.~IntLiteralData();
break; break;
@ -270,8 +250,6 @@ protected:
IRNode(int offset, int kind, const IntLiteralData& data); IRNode(int offset, int kind, const IntLiteralData& data);
IRNode(int offset, int kind, const FloatLiteralData& data);
IRNode(int offset, int kind, const String& data); IRNode(int offset, int kind, const String& data);
IRNode(int offset, int kind, const Type* data = nullptr); IRNode(int offset, int kind, const Type* data = nullptr);
@ -344,11 +322,6 @@ protected:
return fData.fContents.fExternalValue; return fData.fContents.fExternalValue;
} }
const FloatLiteralData& floatLiteralData() const {
SkASSERT(fData.fKind == NodeData::Kind::kFloatLiteral);
return fData.fContents.fFloatLiteral;
}
const IntLiteralData& intLiteralData() const { const IntLiteralData& intLiteralData() const {
SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral); SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral);
return fData.fContents.fIntLiteral; return fData.fContents.fIntLiteral;

View File

@ -43,9 +43,9 @@ struct PrefixExpression : public Expression {
const DefinitionMap& definitions) override { const DefinitionMap& definitions) override {
if (fOperand->kind() == Expression::Kind::kFloatLiteral) { if (fOperand->kind() == Expression::Kind::kFloatLiteral) {
return std::unique_ptr<Expression>(new FloatLiteral( return std::unique_ptr<Expression>(new FloatLiteral(
irGenerator.fContext, irGenerator.fContext,
fOffset, fOffset,
-fOperand->as<FloatLiteral>().value())); -fOperand->as<FloatLiteral>().fValue));
} }
return nullptr; return nullptr;

View File

@ -45,7 +45,7 @@ struct Swizzle : public Expression {
value); value);
} else if (type.isFloat()) { } else if (type.isFloat()) {
SkASSERT(fComponents.size() == 1); SkASSERT(fComponents.size() == 1);
SKSL_FLOAT value = constructor.getFVecComponent(fComponents[0]); double value = constructor.getFVecComponent(fComponents[0]);
return std::make_unique<FloatLiteral>(irGenerator.fContext, constructor.fOffset, return std::make_unique<FloatLiteral>(irGenerator.fContext, constructor.fOffset,
value); value);
} }