moved SkSL FloatLiteral data into IRNode
Change-Id: Ic39e3e8169218cfdd0e1eee274858cc421abec7e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320221 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
4b6f37d902
commit
135e237656
@ -29,7 +29,7 @@ public:
|
||||
R"SkSL(half4 inputColor = %s;
|
||||
half3 hsl = inputColor.xyz;
|
||||
half C = (1.0 - abs(2.0 * hsl.z - 1.0)) * hsl.y;
|
||||
half3 p = hsl.xxx + half3(0.0, 0.66666666666666663, 0.33333333333333331);
|
||||
half3 p = hsl.xxx + half3(0.0, 0.66666668653488159, 0.3333333432674408);
|
||||
half3 q = clamp(abs(fract(p) * 6.0 - 3.0) - 1.0, 0.0, 1.0);
|
||||
half3 rgb = (q - 0.5) * C + hsl.z;
|
||||
%s = clamp(half4(rgb, inputColor.w), 0.0, 1.0);
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
fragBuilder->emitFunction(kHalf_GrSLType, "HSLToRGB", 3, HSLToRGB_args,
|
||||
R"SkSL(if (t < 0.0) t += 1.0;
|
||||
if (t > 1.0) t -= 1.0;
|
||||
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));
|
||||
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));
|
||||
)SkSL",
|
||||
&HSLToRGB_name);
|
||||
SkString _sample896 = this->invokeChild(0, args);
|
||||
@ -87,7 +87,7 @@ half4 color = _0_unpremul;
|
||||
} else {
|
||||
h = (color.x - color.y) / d + 4.0;
|
||||
}
|
||||
h *= 0.16666666666666666;
|
||||
h *= 0.1666666716337204;
|
||||
}
|
||||
l = 1.0 + l * -0.5;
|
||||
if (s == 0.0) {
|
||||
@ -95,9 +95,9 @@ half4 color = _0_unpremul;
|
||||
} else {
|
||||
half q = l < 0.5 ? l * (1.0 + s) : (l + s) - l * s;
|
||||
half p = 2.0 * l - q;
|
||||
color.x = %s(p, q, h + 0.33333333333333331);
|
||||
color.x = %s(p, q, h + 0.3333333432674408);
|
||||
color.y = %s(p, q, h);
|
||||
color.z = %s(p, q, h - 0.33333333333333331);
|
||||
color.z = %s(p, q, h - 0.3333333432674408);
|
||||
}
|
||||
}
|
||||
@if (%s) {
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
SkString _sample1173 = this->invokeChild(0, args);
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(half4 c = %s;
|
||||
half4 p = c.y < c.z ? half4(c.zy, -1.0, 0.66666666666666663) : half4(c.yz, 0.0, -0.33333333333333331);
|
||||
half4 p = c.y < c.z ? half4(c.zy, -1.0, 0.66666668653488159) : half4(c.yz, 0.0, -0.3333333432674408);
|
||||
half4 q = c.x < p.x ? half4(p.x, c.x, p.yw) : half4(c.x, p.x, p.yz);
|
||||
|
||||
half pmV = q.x;
|
||||
|
@ -1022,7 +1022,7 @@ static inline uint32_t float_to_bits(float x) {
|
||||
|
||||
void ByteCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
|
||||
this->write(ByteCodeInstruction::kPushImmediate);
|
||||
this->write32(float_to_bits(f.fValue));
|
||||
this->write32(float_to_bits(f.value()));
|
||||
}
|
||||
|
||||
static bool is_generic_type(const Type* type, const Type* generic) {
|
||||
|
@ -650,14 +650,14 @@ static bool try_replace_expression(BasicBlock* b,
|
||||
* 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.
|
||||
*/
|
||||
template <typename T = double>
|
||||
template <typename T = SKSL_FLOAT>
|
||||
static bool is_constant(const Expression& expr, T value) {
|
||||
switch (expr.kind()) {
|
||||
case Expression::Kind::kIntLiteral:
|
||||
return expr.as<IntLiteral>().value() == value;
|
||||
|
||||
case Expression::Kind::kFloatLiteral:
|
||||
return expr.as<FloatLiteral>().fValue == value;
|
||||
return expr.as<FloatLiteral>().value() == value;
|
||||
|
||||
case Expression::Kind::kConstructor: {
|
||||
const Constructor& constructor = expr.as<Constructor>();
|
||||
|
@ -298,7 +298,7 @@ void Dehydrator::write(const Expression* e) {
|
||||
const FloatLiteral& f = e->as<FloatLiteral>();
|
||||
this->writeU8(Rehydrator::kFloatLiteral_Command);
|
||||
FloatIntUnion u;
|
||||
u.fFloat = f.fValue;
|
||||
u.fFloat = f.value();
|
||||
this->writeS32(u.fInt);
|
||||
break;
|
||||
}
|
||||
|
@ -1025,7 +1025,7 @@ void GLSLCodeGenerator::writeIntLiteral(const IntLiteral& i) {
|
||||
}
|
||||
|
||||
void GLSLCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
|
||||
this->write(to_string(f.fValue));
|
||||
this->write(to_string(f.value()));
|
||||
}
|
||||
|
||||
void GLSLCodeGenerator::writeSetting(const Setting& s) {
|
||||
|
@ -1825,8 +1825,8 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
|
||||
}
|
||||
if (left.kind() == Expression::Kind::kFloatLiteral &&
|
||||
right.kind() == Expression::Kind::kFloatLiteral) {
|
||||
double leftVal = left.as<FloatLiteral>().fValue;
|
||||
double rightVal = right.as<FloatLiteral>().fValue;
|
||||
SKSL_FLOAT leftVal = left.as<FloatLiteral>().value();
|
||||
SKSL_FLOAT rightVal = right.as<FloatLiteral>().value();
|
||||
switch (op) {
|
||||
case Token::Kind::TK_PLUS: return RESULT(Float, +);
|
||||
case Token::Kind::TK_MINUS: return RESULT(Float, -);
|
||||
@ -1853,8 +1853,8 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
|
||||
std::vector<std::unique_ptr<Expression>> args;
|
||||
#define RETURN_VEC_COMPONENTWISE_RESULT(op) \
|
||||
for (int i = 0; i < leftType.columns(); i++) { \
|
||||
float value = left.getFVecComponent(i) op \
|
||||
right.getFVecComponent(i); \
|
||||
SKSL_FLOAT value = left.getFVecComponent(i) op \
|
||||
right.getFVecComponent(i); \
|
||||
args.emplace_back(new FloatLiteral(fContext, -1, value)); \
|
||||
} \
|
||||
return std::unique_ptr<Expression>(new Constructor(-1, &leftType, \
|
||||
@ -1876,7 +1876,7 @@ std::unique_ptr<Expression> IRGenerator::constantFold(const Expression& left,
|
||||
fErrors.error(right.fOffset, "division by zero");
|
||||
return nullptr;
|
||||
}
|
||||
float value = left.getFVecComponent(i) / rvalue;
|
||||
SKSL_FLOAT value = left.getFVecComponent(i) / rvalue;
|
||||
args.emplace_back(new FloatLiteral(fContext, -1, value));
|
||||
}
|
||||
return std::unique_ptr<Expression>(new Constructor(-1, &leftType,
|
||||
@ -2227,12 +2227,12 @@ std::unique_ptr<Expression> IRGenerator::convertNumberConstructor(
|
||||
return std::move(args[0]);
|
||||
}
|
||||
if (type.isFloat() && args.size() == 1 && args[0]->is<FloatLiteral>()) {
|
||||
double value = args[0]->as<FloatLiteral>().fValue;
|
||||
SKSL_FLOAT value = args[0]->as<FloatLiteral>().value();
|
||||
return std::make_unique<FloatLiteral>(offset, value, &type);
|
||||
}
|
||||
if (type.isFloat() && args.size() == 1 && args[0]->is<IntLiteral>()) {
|
||||
int64_t value = args[0]->as<IntLiteral>().value();
|
||||
return std::make_unique<FloatLiteral>(offset, (double)value, &type);
|
||||
return std::make_unique<FloatLiteral>(offset, (float)value, &type);
|
||||
}
|
||||
if (args[0]->is<IntLiteral>() && (type == *fContext.fInt_Type ||
|
||||
type == *fContext.fUInt_Type)) {
|
||||
@ -2369,7 +2369,7 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(const ASTNode&
|
||||
}
|
||||
if (base->is<FloatLiteral>()) {
|
||||
return std::make_unique<FloatLiteral>(fContext, base->fOffset,
|
||||
-base->as<FloatLiteral>().fValue);
|
||||
-base->as<FloatLiteral>().value());
|
||||
}
|
||||
if (!baseType.isNumber() && baseType.typeKind() != Type::TypeKind::kVector) {
|
||||
fErrors.error(expression.fOffset,
|
||||
|
@ -919,7 +919,7 @@ void MetalCodeGenerator::writeIntLiteral(const IntLiteral& i) {
|
||||
}
|
||||
|
||||
void MetalCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
|
||||
this->write(to_string(f.fValue));
|
||||
this->write(to_string(f.value()));
|
||||
}
|
||||
|
||||
void MetalCodeGenerator::writeSetting(const Setting& s) {
|
||||
|
@ -2554,8 +2554,8 @@ SpvId SPIRVCodeGenerator::writeFloatLiteral(const FloatLiteral& f) {
|
||||
} else {
|
||||
constantType = ConstantType::kFloat;
|
||||
}
|
||||
float value = (float) f.fValue;
|
||||
std::pair<ConstantValue, ConstantType> key(f.fValue, constantType);
|
||||
float value = (float) f.value();
|
||||
std::pair<ConstantValue, ConstantType> key(f.value(), constantType);
|
||||
auto entry = fNumberConstants.find(key);
|
||||
if (entry == fNumberConstants.end()) {
|
||||
SpvId result = this->nextId();
|
||||
|
@ -47,15 +47,15 @@ union ConstantValue {
|
||||
ConstantValue(int64_t i)
|
||||
: fInt(i) {}
|
||||
|
||||
ConstantValue(double d)
|
||||
: fDouble(d) {}
|
||||
ConstantValue(SKSL_FLOAT f)
|
||||
: fFloat(f) {}
|
||||
|
||||
bool operator==(const ConstantValue& other) const {
|
||||
return fInt == other.fInt;
|
||||
}
|
||||
|
||||
int64_t fInt;
|
||||
double fDouble;
|
||||
SKSL_FLOAT fFloat;
|
||||
};
|
||||
|
||||
enum class ConstantType {
|
||||
|
@ -64,6 +64,10 @@ struct Expression : public IRNode {
|
||||
: INHERITED(offset, (int) Kind::kIntLiteral, data) {
|
||||
}
|
||||
|
||||
Expression(int offset, FloatLiteralData data)
|
||||
: INHERITED(offset, (int) Kind::kFloatLiteral, data) {
|
||||
}
|
||||
|
||||
Expression(int offset, Kind kind, const Type* type)
|
||||
: INHERITED(offset, (int) kind, type) {
|
||||
SkASSERT(kind >= Kind::kFirst && kind <= Kind::kLast);
|
||||
@ -131,7 +135,7 @@ struct Expression : public IRNode {
|
||||
* For an expression which evaluates to a constant float, returns the value. Otherwise calls
|
||||
* ABORT.
|
||||
*/
|
||||
virtual double getConstantFloat() const {
|
||||
virtual SKSL_FLOAT getConstantFloat() const {
|
||||
ABORT("not a constant float");
|
||||
}
|
||||
|
||||
|
@ -19,16 +19,18 @@ namespace SkSL {
|
||||
struct FloatLiteral : public Expression {
|
||||
static constexpr Kind kExpressionKind = Kind::kFloatLiteral;
|
||||
|
||||
FloatLiteral(const Context& context, int offset, double value)
|
||||
: INHERITED(offset, kExpressionKind, context.fFloatLiteral_Type.get())
|
||||
, fValue(value) {}
|
||||
FloatLiteral(const Context& context, int offset, float value)
|
||||
: INHERITED(offset, FloatLiteralData{context.fFloatLiteral_Type.get(), value}) {}
|
||||
|
||||
FloatLiteral(int offset, double value, const Type* type)
|
||||
: INHERITED(offset, kExpressionKind, type)
|
||||
, fValue(value) {}
|
||||
FloatLiteral(int offset, float value, const Type* type)
|
||||
: INHERITED(offset, FloatLiteralData{type, value}) {}
|
||||
|
||||
float value() const {
|
||||
return this->floatLiteralData().fValue;
|
||||
}
|
||||
|
||||
String description() const override {
|
||||
return to_string(fValue);
|
||||
return to_string(this->value());
|
||||
}
|
||||
|
||||
bool hasProperty(Property property) const override {
|
||||
@ -47,19 +49,18 @@ struct FloatLiteral : public Expression {
|
||||
}
|
||||
|
||||
bool compareConstant(const Context& context, const Expression& other) const override {
|
||||
return fValue == other.as<FloatLiteral>().fValue;
|
||||
return this->value() == other.as<FloatLiteral>().value();
|
||||
}
|
||||
|
||||
double getConstantFloat() const override {
|
||||
return fValue;
|
||||
SKSL_FLOAT getConstantFloat() const override {
|
||||
return this->value();
|
||||
}
|
||||
|
||||
std::unique_ptr<Expression> clone() const override {
|
||||
return std::unique_ptr<Expression>(new FloatLiteral(fOffset, fValue, &this->type()));
|
||||
return std::unique_ptr<Expression>(new FloatLiteral(fOffset, this->value(), &this->type()));
|
||||
}
|
||||
|
||||
const double fValue;
|
||||
|
||||
private:
|
||||
using INHERITED = Expression;
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,11 @@ IRNode::IRNode(int offset, int kind, const IntLiteralData& data)
|
||||
, fKind(kind)
|
||||
, fData(data) {}
|
||||
|
||||
IRNode::IRNode(int offset, int kind, const FloatLiteralData& data)
|
||||
: fOffset(offset)
|
||||
, fKind(kind)
|
||||
, fData(data) {}
|
||||
|
||||
IRNode::IRNode(int offset, int kind, const Type* data)
|
||||
: fOffset(offset)
|
||||
, fKind(kind)
|
||||
|
@ -54,6 +54,8 @@ public:
|
||||
return *this->boolLiteralData().fType;
|
||||
case NodeData::Kind::kIntLiteral:
|
||||
return *this->intLiteralData().fType;
|
||||
case NodeData::Kind::kFloatLiteral:
|
||||
return *this->floatLiteralData().fType;
|
||||
case NodeData::Kind::kType:
|
||||
return *this->typeData();
|
||||
case NodeData::Kind::kTypeToken:
|
||||
@ -77,6 +79,11 @@ protected:
|
||||
bool fValue;
|
||||
};
|
||||
|
||||
struct FloatLiteralData {
|
||||
const Type* fType;
|
||||
float fValue;
|
||||
};
|
||||
|
||||
struct IntLiteralData {
|
||||
const Type* fType;
|
||||
int64_t fValue;
|
||||
@ -91,6 +98,7 @@ protected:
|
||||
enum class Kind {
|
||||
kBlock,
|
||||
kBoolLiteral,
|
||||
kFloatLiteral,
|
||||
kIntLiteral,
|
||||
kType,
|
||||
kTypeToken,
|
||||
@ -100,6 +108,7 @@ protected:
|
||||
union Contents {
|
||||
BlockData fBlock;
|
||||
BoolLiteralData fBoolLiteral;
|
||||
FloatLiteralData fFloatLiteral;
|
||||
IntLiteralData fIntLiteral;
|
||||
const Type* fType;
|
||||
TypeTokenData fTypeToken;
|
||||
@ -119,6 +128,11 @@ protected:
|
||||
*(new(&fContents) BoolLiteralData) = data;
|
||||
}
|
||||
|
||||
NodeData(const FloatLiteralData& data)
|
||||
: fKind(Kind::kFloatLiteral) {
|
||||
*(new(&fContents) FloatLiteralData) = data;
|
||||
}
|
||||
|
||||
NodeData(IntLiteralData data)
|
||||
: fKind(Kind::kIntLiteral) {
|
||||
*(new(&fContents) IntLiteralData) = data;
|
||||
@ -148,6 +162,9 @@ protected:
|
||||
case Kind::kBoolLiteral:
|
||||
*(new(&fContents) BoolLiteralData) = other.fContents.fBoolLiteral;
|
||||
break;
|
||||
case Kind::kFloatLiteral:
|
||||
*(new(&fContents) FloatLiteralData) = other.fContents.fFloatLiteral;
|
||||
break;
|
||||
case Kind::kIntLiteral:
|
||||
*(new(&fContents) IntLiteralData) = other.fContents.fIntLiteral;
|
||||
break;
|
||||
@ -174,6 +191,9 @@ protected:
|
||||
case Kind::kBoolLiteral:
|
||||
fContents.fBoolLiteral.~BoolLiteralData();
|
||||
break;
|
||||
case Kind::kFloatLiteral:
|
||||
fContents.fFloatLiteral.~FloatLiteralData();
|
||||
break;
|
||||
case Kind::kIntLiteral:
|
||||
fContents.fIntLiteral.~IntLiteralData();
|
||||
break;
|
||||
@ -193,6 +213,8 @@ protected:
|
||||
|
||||
IRNode(int offset, int kind, const IntLiteralData& data);
|
||||
|
||||
IRNode(int offset, int kind, const FloatLiteralData& data);
|
||||
|
||||
IRNode(int offset, int kind, const Type* data = nullptr);
|
||||
|
||||
IRNode(int offset, int kind, const TypeTokenData& data);
|
||||
@ -253,6 +275,11 @@ protected:
|
||||
return fData.fContents.fBoolLiteral;
|
||||
}
|
||||
|
||||
const FloatLiteralData& floatLiteralData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kFloatLiteral);
|
||||
return fData.fContents.fFloatLiteral;
|
||||
}
|
||||
|
||||
const IntLiteralData& intLiteralData() const {
|
||||
SkASSERT(fData.fKind == NodeData::Kind::kIntLiteral);
|
||||
return fData.fContents.fIntLiteral;
|
||||
|
@ -43,9 +43,9 @@ struct PrefixExpression : public Expression {
|
||||
const DefinitionMap& definitions) override {
|
||||
if (fOperand->kind() == Expression::Kind::kFloatLiteral) {
|
||||
return std::unique_ptr<Expression>(new FloatLiteral(
|
||||
irGenerator.fContext,
|
||||
fOffset,
|
||||
-fOperand->as<FloatLiteral>().fValue));
|
||||
irGenerator.fContext,
|
||||
fOffset,
|
||||
-fOperand->as<FloatLiteral>().value()));
|
||||
|
||||
}
|
||||
return nullptr;
|
||||
|
@ -45,7 +45,7 @@ struct Swizzle : public Expression {
|
||||
value);
|
||||
} else if (type.isFloat()) {
|
||||
SkASSERT(fComponents.size() == 1);
|
||||
double value = constructor.getFVecComponent(fComponents[0]);
|
||||
SKSL_FLOAT value = constructor.getFVecComponent(fComponents[0]);
|
||||
return std::make_unique<FloatLiteral>(irGenerator.fContext, constructor.fOffset,
|
||||
value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user