diff options
-rw-r--r-- | src/sksl/ir/SkSLConstructor.h | 11 | ||||
-rw-r--r-- | src/sksl/ir/SkSLSwizzle.h | 6 | ||||
-rw-r--r-- | tests/SkSLGLSLTest.cpp | 13 |
3 files changed, 28 insertions, 2 deletions
diff --git a/src/sksl/ir/SkSLConstructor.h b/src/sksl/ir/SkSLConstructor.h index 8f963e68eb..51af1c1132 100644 --- a/src/sksl/ir/SkSLConstructor.h +++ b/src/sksl/ir/SkSLConstructor.h @@ -50,6 +50,17 @@ struct Constructor : public Expression { &fType)); } } + if (fArguments.size() == 1 && fArguments[0]->fKind == Expression::kFloatLiteral_Kind) { + if (fType == *irGenerator.fContext.fFloat_Type || + fType == *irGenerator.fContext.fHalf_Type) { + // convert float(1.0) to 1.0 + double floatValue = ((FloatLiteral&) *fArguments[0]).fValue; + return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, + fPosition, + floatValue, + &fType)); + } + } return nullptr; } diff --git a/src/sksl/ir/SkSLSwizzle.h b/src/sksl/ir/SkSLSwizzle.h index cb1343c4f9..1c7c04d2b9 100644 --- a/src/sksl/ir/SkSLSwizzle.h +++ b/src/sksl/ir/SkSLSwizzle.h @@ -94,13 +94,15 @@ struct Swizzle : public Expression { if (fBase->fKind == Expression::kConstructor_Kind && fBase->isConstant()) { // we're swizzling a constant vector, e.g. float4(1).x. Simplify it. ASSERT(fBase->fKind == Expression::kConstructor_Kind); - if (fType == *irGenerator.fContext.fInt_Type) { + if (fType == *irGenerator.fContext.fInt_Type || + fType == *irGenerator.fContext.fShort_Type) { ASSERT(fComponents.size() == 1); int64_t value = ((Constructor&) *fBase).getIVecComponent(fComponents[0]); return std::unique_ptr<Expression>(new IntLiteral(irGenerator.fContext, Position(), value)); - } else if (fType == *irGenerator.fContext.fFloat_Type) { + } else if (fType == *irGenerator.fContext.fFloat_Type || + fType == *irGenerator.fContext.fHalf_Type) { ASSERT(fComponents.size() == 1); double value = ((Constructor&) *fBase).getFVecComponent(fComponents[0]); return std::unique_ptr<Expression>(new FloatLiteral(irGenerator.fContext, diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 73c6dccbde..e4088ceee7 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -1573,4 +1573,17 @@ DEF_TEST(SkSLNumberConversions, r) { "float f2f = f;\n"); } +DEF_TEST(SkSLConstantSwizzleComparison, r) { + test(r, + "void main() { if (half4(1.0).x == half4(1.0).y) { sk_FragColor = half4(1.0); } }", + *SkSL::ShaderCapsFactory::Default(), + "#version 400\n" + "out vec4 sk_FragColor;\n" + "void main() {\n" + " {\n" + " sk_FragColor = vec4(1.0);\n" + " }\n" + "}\n"); +} + #endif |