Interpreter: Fix scalar -> vector constructors

We were never replicating scalar values when constructing vector types
from a single argument.

Change-Id: I5bdeeb91f5a10c151b18561de6c275f2db2898fe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215526
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-05-22 15:16:16 -07:00 committed by Skia Commit-Bot
parent acd66b4946
commit c51d791ab9
2 changed files with 17 additions and 12 deletions

View File

@ -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);
}
}
}
}

View File

@ -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) {