fixed a bug with SPIR-V ternaries

When both the true and false values are constants, we use OpSelect to
choose between them instead of branching. However, it turns out that
this fails when the values are vectors, because then OpSelect does
componentwise selection and expects the input condition to be a vector
as well.

Bug: skia:
Change-Id: Ia30aadc590ac1d1760c7df933595c2c867c472cd
Reviewed-on: https://skia-review.googlesource.com/142885
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2018-07-23 09:25:40 -04:00 committed by Skia Commit-Bot
parent 0067369061
commit 0f21c2327e

View File

@ -2278,7 +2278,7 @@ SpvId SPIRVCodeGenerator::writeLogicalOr(const BinaryExpression& o, OutputStream
SpvId SPIRVCodeGenerator::writeTernaryExpression(const TernaryExpression& t, OutputStream& out) {
SpvId test = this->writeExpression(*t.fTest, out);
if (t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) {
if (t.fIfTrue->fType.columns() == 1 && t.fIfTrue->isConstant() && t.fIfFalse->isConstant()) {
// both true and false are constants, can just use OpSelect
SpvId result = this->nextId();
SpvId trueId = this->writeExpression(*t.fIfTrue, out);