Respect the result type during constant folding.
Previously, expressions like `(1.0 + myConstHalfVar)` would create a FloatLiteral node of type `$floatLiteral`, instead of `half`. This could cause an assertion if the IRNode containing that FloatLiteral value was strict about types. Example assertion: http://screen/5x9XXhxygRgk9rz Change-Id: I42bf8285790d7939f07a6597e222bb6ac96d709b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402781 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
parent
e4c4322da6
commit
e26dcf5eae
@ -409,9 +409,9 @@ std::unique_ptr<Expression> ConstantFolder::Simplify(const Context& context,
|
||||
// precision to calculate the results and hope the result makes sense.
|
||||
// TODO(skia:10932): detect and handle integer overflow properly.
|
||||
using SKSL_UINT = uint64_t;
|
||||
#define RESULT(t, op) t ## Literal::Make(context, offset, leftVal op rightVal)
|
||||
#define URESULT(t, op) t ## Literal::Make(context, offset, (SKSL_UINT) leftVal op \
|
||||
(SKSL_UINT) rightVal)
|
||||
#define RESULT(t, op) t ## Literal::Make(offset, leftVal op rightVal, &resultType)
|
||||
#define URESULT(t, op) t ## Literal::Make(offset, (SKSL_UINT)(leftVal) op \
|
||||
(SKSL_UINT)(rightVal), &resultType)
|
||||
if (left->is<IntLiteral>() && right->is<IntLiteral>()) {
|
||||
SKSL_INT leftVal = left->as<IntLiteral>().value();
|
||||
SKSL_INT rightVal = right->as<IntLiteral>().value();
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
: INHERITED(offset, kExpressionKind, type)
|
||||
, fValue(value) {}
|
||||
|
||||
// Makes a literal of $intLiteral type.
|
||||
// Makes a literal of $floatLiteral type.
|
||||
static std::unique_ptr<FloatLiteral> Make(const Context& context, int offset, float value) {
|
||||
return std::make_unique<FloatLiteral>(offset, value, context.fTypes.fFloatLiteral.get());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user