Disable constant-variable substitution when optimization is off.
When optimization is disabled, I did not expect to see arithmetic like
`color * ONE` disappear (even though it's just a constant fold):
const vec4 ONE = half4(1);
vec4 x = color * ONE;
Change-Id: Id24a632712591c73a904b90e5efdba092d846c0e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382477
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLConstantFolder.cpp b/src/sksl/SkSLConstantFolder.cpp
index 1f0ec47..c397cab 100644
--- a/src/sksl/SkSLConstantFolder.cpp
+++ b/src/sksl/SkSLConstantFolder.cpp
@@ -312,9 +312,16 @@
Operator op,
const Expression& rightExpr,
const Type& resultType) {
- // Replace constant variables with trivial initial-values.
- const Expression* left = GetConstantValueForVariable(leftExpr);
- const Expression* right = GetConstantValueForVariable(rightExpr);
+ // When optimization is enabled, replace constant variables with trivial initial-values.
+ const Expression* left;
+ const Expression* right;
+ if (context.fConfig->fSettings.fOptimize) {
+ left = GetConstantValueForVariable(leftExpr);
+ right = GetConstantValueForVariable(rightExpr);
+ } else {
+ left = &leftExpr;
+ right = &rightExpr;
+ }
// If this is the comma operator, the left side is evaluated but not otherwise used in any way.
// So if the left side has no side effects, it can just be eliminated entirely.