diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-08-16 22:01:21 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-17 02:23:35 +0000 |
commit | 8ac36a577f14158c820bbc673f477a7ce20702e5 (patch) | |
tree | 19fd50c4b6b91a01677fe8a5c2c8e990f0568505 /src/sksl | |
parent | 88d99c63878c2d3d340120f0321676f72afcb4f0 (diff) |
fixed constant vector swizzling
Bug: skia:
Change-Id: I2d205bf7242d2223c4939c3e7897db9aba02c705
Reviewed-on: https://skia-review.googlesource.com/35640
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/ir/SkSLConstructor.h | 11 | ||||
-rw-r--r-- | src/sksl/ir/SkSLSwizzle.h | 6 |
2 files changed, 15 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, |