diff --git a/src/sksl/SkSLConstantFolder.cpp b/src/sksl/SkSLConstantFolder.cpp index bd760c554c..7105065969 100644 --- a/src/sksl/SkSLConstantFolder.cpp +++ b/src/sksl/SkSLConstantFolder.cpp @@ -517,8 +517,9 @@ std::unique_ptr ConstantFolder::Simplify(const Context& context, return nullptr; } - // Perform constant folding on pairs of matrices. - if (leftType.isMatrix() && rightType.isMatrix()) { + // Perform constant folding on pairs of matrices or arrays. + if ((leftType.isMatrix() && rightType.isMatrix()) || + (leftType.isArray() && rightType.isArray())) { bool equality; switch (op.kind()) { case Token::Kind::TK_EQEQ: diff --git a/src/sksl/ir/SkSLConstructor.cpp b/src/sksl/ir/SkSLConstructor.cpp index 8b09f4eedb..55e0218678 100644 --- a/src/sksl/ir/SkSLConstructor.cpp +++ b/src/sksl/ir/SkSLConstructor.cpp @@ -294,6 +294,17 @@ Expression::ComparisonResult Constructor::compareConstant(const Expression& othe return ComparisonResult::kEqual; } + if (myType.isArray()) { + SkASSERT(myType.columns() == c.type().columns()); + for (int col = 0; col < myType.columns(); col++) { + ComparisonResult check = this->arguments()[col]->compareConstant(*c.arguments()[col]); + if (check != ComparisonResult::kEqual) { + return check; + } + } + return ComparisonResult::kEqual; + } + SkDEBUGFAILF("compareConstant unexpected type: %s", myType.description().c_str()); return ComparisonResult::kUnknown; } diff --git a/tests/sksl/folding/ArrayFolding.glsl b/tests/sksl/folding/ArrayFolding.glsl index 6265fdb2e2..42ff795045 100644 --- a/tests/sksl/folding/ArrayFolding.glsl +++ b/tests/sksl/folding/ArrayFolding.glsl @@ -3,7 +3,5 @@ out vec4 sk_FragColor; uniform vec4 colorRed; uniform vec4 colorGreen; vec4 main() { - const int _0_x[3] = int[3](1, 2, 3); - const int _2_y[3] = int[3](1, 2, 4); - return _0_x != _2_y && !(_0_x == _2_y) ? colorGreen : colorRed; + return true ? colorGreen : colorRed; }