diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2018-03-14 13:51:39 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-14 18:18:51 +0000 |
commit | 48e240573319f0e0496bf7e7a4bc1053cfed0b98 (patch) | |
tree | ba21a4df7ceb20ca60bcdee9609d0298f70d0262 /src | |
parent | efbf00c8191e480c04bf5f5d431c34701d444850 (diff) |
fixed SkSL SPIR-V vector comparisons
Bug: skia:
Change-Id: I57788fe427f62e20c6e073fd96279910febef22e
Reviewed-on: https://skia-review.googlesource.com/114367
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.cpp | 53 | ||||
-rw-r--r-- | src/sksl/SkSLSPIRVCodeGenerator.h | 2 |
2 files changed, 37 insertions, 18 deletions
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index fbe8bf02a0..02bd336b55 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -1802,10 +1802,11 @@ bool is_assignment(Token::Kind op) { } } -SpvId SPIRVCodeGenerator::foldToBool(SpvId id, const Type& operandType, OutputStream& out) { +SpvId SPIRVCodeGenerator::foldToBool(SpvId id, const Type& operandType, SpvOp op, + OutputStream& out) { if (operandType.kind() == Type::kVector_Kind) { SpvId result = this->nextId(); - this->writeInstruction(SpvOpAll, this->getType(*fContext.fBool_Type), result, id, out); + this->writeInstruction(op, this->getType(*fContext.fBool_Type), result, id, out); return result; } return id; @@ -1877,36 +1878,38 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, Outpu return rhs; } Type tmp("<invalid>"); - // component type we are operating on: float, int, uint + // overall type we are operating on: float2, int, uint4... const Type* operandType; - // IR allows mismatched types in expressions (e.g. float2* float), but they need special handling - // in SPIR-V + // IR allows mismatched types in expressions (e.g. float2 * float), but they need special + // handling in SPIR-V if (this->getActualType(b.fLeft->fType) != this->getActualType(b.fRight->fType)) { if (b.fLeft->fType.kind() == Type::kVector_Kind && b.fRight->fType.isNumber()) { // promote number to vector SpvId vec = this->nextId(); - this->writeOpCode(SpvOpCompositeConstruct, 3 + b.fType.columns(), out); - this->writeWord(this->getType(resultType), out); + const Type& vecType = b.fLeft->fType; + this->writeOpCode(SpvOpCompositeConstruct, 3 + vecType.columns(), out); + this->writeWord(this->getType(vecType), out); this->writeWord(vec, out); - for (int i = 0; i < resultType.columns(); i++) { + for (int i = 0; i < vecType.columns(); i++) { this->writeWord(rhs, out); } rhs = vec; - operandType = &b.fRight->fType; + operandType = &b.fLeft->fType; } else if (b.fRight->fType.kind() == Type::kVector_Kind && b.fLeft->fType.isNumber()) { // promote number to vector SpvId vec = this->nextId(); - this->writeOpCode(SpvOpCompositeConstruct, 3 + b.fType.columns(), out); - this->writeWord(this->getType(resultType), out); + const Type& vecType = b.fRight->fType; + this->writeOpCode(SpvOpCompositeConstruct, 3 + vecType.columns(), out); + this->writeWord(this->getType(vecType), out); this->writeWord(vec, out); - for (int i = 0; i < resultType.columns(); i++) { + for (int i = 0; i < vecType.columns(); i++) { this->writeWord(lhs, out); } lhs = vec; ASSERT(!lvalue); - operandType = &b.fLeft->fType; + operandType = &b.fRight->fType; } else if (b.fLeft->fType.kind() == Type::kMatrix_Kind) { SpvOp_ op; if (b.fRight->fType.kind() == Type::kMatrix_Kind) { @@ -1956,10 +1959,18 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, Outpu SpvOpIEqual, out); } ASSERT(resultType == *fContext.fBool_Type); - return this->foldToBool(this->writeBinaryOperation(resultType, *operandType, lhs, rhs, + const Type* tmpType; + if (operandType->kind() == Type::kVector_Kind) { + tmpType = &fContext.fBool_Type->toCompound(fContext, + operandType->columns(), + operandType->rows()); + } else { + tmpType = &resultType; + } + return this->foldToBool(this->writeBinaryOperation(*tmpType, *operandType, lhs, rhs, SpvOpFOrdEqual, SpvOpIEqual, SpvOpIEqual, SpvOpLogicalEqual, out), - *operandType, out); + *operandType, SpvOpAll, out); } case Token::NEQ: if (operandType->kind() == Type::kMatrix_Kind) { @@ -1967,11 +1978,19 @@ SpvId SPIRVCodeGenerator::writeBinaryExpression(const BinaryExpression& b, Outpu SpvOpINotEqual, out); } ASSERT(resultType == *fContext.fBool_Type); - return this->foldToBool(this->writeBinaryOperation(resultType, *operandType, lhs, rhs, + const Type* tmpType; + if (operandType->kind() == Type::kVector_Kind) { + tmpType = &fContext.fBool_Type->toCompound(fContext, + operandType->columns(), + operandType->rows()); + } else { + tmpType = &resultType; + } + return this->foldToBool(this->writeBinaryOperation(*tmpType, *operandType, lhs, rhs, SpvOpFOrdNotEqual, SpvOpINotEqual, SpvOpINotEqual, SpvOpLogicalNotEqual, out), - *operandType, out); + *operandType, SpvOpAny, out); case Token::GT: ASSERT(resultType == *fContext.fBool_Type); return this->writeBinaryOperation(resultType, *operandType, lhs, rhs, diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index 4bd8d86dd8..8f6dcd95c0 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -209,7 +209,7 @@ private: * same dimensions, and applys all() to it to fold it down to a single bool value. Otherwise, * returns the original id value. */ - SpvId foldToBool(SpvId id, const Type& operandType, OutputStream& out); + SpvId foldToBool(SpvId id, const Type& operandType, SpvOp op, OutputStream& out); SpvId writeMatrixComparison(const Type& operandType, SpvId lhs, SpvId rhs, SpvOp_ floatOperator, SpvOp_ intOperator, OutputStream& out); |