SkSL now supports constant 1/0 in all swizzle channels, as well as "LTRB" as an alias for "xyzw" / "rgba".
Bug: skia:9181
Change-Id: Iedefbb94bbb05ce37fcf66ca0b40c97f2adf7698
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241276
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 7342e20..b7ffd1c 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1923,25 +1923,25 @@
this->writeWord(this->getType(swizzle.fType), out);
this->writeWord(result, out);
this->writeWord(base, out);
- SpvId other;
- int last = swizzle.fComponents.back();
- if (last < 0) {
- if (!fConstantZeroOneVector) {
- FloatLiteral zero(fContext, -1, 0);
- SpvId zeroId = this->writeFloatLiteral(zero);
- FloatLiteral one(fContext, -1, 1);
- SpvId oneId = this->writeFloatLiteral(one);
- SpvId type = this->getType(*fContext.fFloat2_Type);
- fConstantZeroOneVector = this->nextId();
- this->writeOpCode(SpvOpConstantComposite, 5, fConstantBuffer);
- this->writeWord(type, fConstantBuffer);
- this->writeWord(fConstantZeroOneVector, fConstantBuffer);
- this->writeWord(zeroId, fConstantBuffer);
- this->writeWord(oneId, fConstantBuffer);
+ SpvId other = base;
+ for (int c : swizzle.fComponents) {
+ if (c < 0) {
+ if (!fConstantZeroOneVector) {
+ FloatLiteral zero(fContext, -1, 0);
+ SpvId zeroId = this->writeFloatLiteral(zero);
+ FloatLiteral one(fContext, -1, 1);
+ SpvId oneId = this->writeFloatLiteral(one);
+ SpvId type = this->getType(*fContext.fFloat2_Type);
+ fConstantZeroOneVector = this->nextId();
+ this->writeOpCode(SpvOpConstantComposite, 5, fConstantBuffer);
+ this->writeWord(type, fConstantBuffer);
+ this->writeWord(fConstantZeroOneVector, fConstantBuffer);
+ this->writeWord(zeroId, fConstantBuffer);
+ this->writeWord(oneId, fConstantBuffer);
+ }
+ other = fConstantZeroOneVector;
+ break;
}
- other = fConstantZeroOneVector;
- } else {
- other = base;
}
this->writeWord(other, out);
for (int component : swizzle.fComponents) {