diff --git a/src/sksl/SkSLByteCodeGenerator.cpp b/src/sksl/SkSLByteCodeGenerator.cpp index b53fe47774..bc3aaea56f 100644 --- a/src/sksl/SkSLByteCodeGenerator.cpp +++ b/src/sksl/SkSLByteCodeGenerator.cpp @@ -326,37 +326,37 @@ void ByteCodeGenerator::writeBoolLiteral(const BoolLiteral& b) { } void ByteCodeGenerator::writeConstructor(const Constructor& c) { - if (c.fArguments.size() == 1 && - type_category(c.fType) == type_category(c.fArguments[0]->fType)) { - // cast from float to half or similar no-op - this->writeExpression(*c.fArguments[0]); - return; - } for (const auto& arg : c.fArguments) { this->writeExpression(*arg); } if (c.fArguments.size() == 1) { TypeCategory inCategory = type_category(c.fArguments[0]->fType); TypeCategory outCategory = type_category(c.fType); + int inCount = c.fArguments[0]->fType.columns(); + int outCount = c.fType.columns(); if (inCategory != outCategory) { + SkASSERT(inCount == outCount); if (inCategory == TypeCategory::kFloat) { SkASSERT(outCategory == TypeCategory::kSigned || outCategory == TypeCategory::kUnsigned); - this->write(vector_instruction(ByteCodeInstruction::kConvertFtoI, - c.fType.columns())); + this->write(vector_instruction(ByteCodeInstruction::kConvertFtoI, outCount)); } else if (outCategory == TypeCategory::kFloat) { if (inCategory == TypeCategory::kSigned) { - this->write(vector_instruction(ByteCodeInstruction::kConvertStoF, - c.fType.columns())); + this->write(vector_instruction(ByteCodeInstruction::kConvertStoF, outCount)); } else { SkASSERT(inCategory == TypeCategory::kUnsigned); - this->write(vector_instruction(ByteCodeInstruction::kConvertUtoF, - c.fType.columns())); + this->write(vector_instruction(ByteCodeInstruction::kConvertUtoF, outCount)); } } else { SkASSERT(false); } } + if (inCount != outCount) { + SkASSERT(inCount == 1); + for (; inCount != outCount; ++inCount) { + this->write(ByteCodeInstruction::kDup); + } + } } } diff --git a/tests/SkSLInterpreterTest.cpp b/tests/SkSLInterpreterTest.cpp index 6bcff4328d..2bcd82946e 100644 --- a/tests/SkSLInterpreterTest.cpp +++ b/tests/SkSLInterpreterTest.cpp @@ -179,6 +179,11 @@ DEF_TEST(SkSLInterpreterCast, r) { expected[1].fSigned = -5; test(r, "int main(float x) { return int (x); }", input, 1, expected); test(r, "int2 main(float2 x) { return int2(x); }", input, 2, expected); + + input[0].fSigned = 3; + expected[0].fFloat = 3.0f; + expected[1].fFloat = 3.0f; + test(r, "float2 main(int x) { return float2(x); }", input, 2, expected); } DEF_TEST(SkSLInterpreterIf, r) {