Fix SPIRV bug constructing a constant vector from another vector
This fix is overly conservative in some situations (identity conversions
among vectors with the same component type), but fixes errors in two
existing unit test cases.
Bug: skia:11116
Change-Id: If852f8591fb26817528fdc37191c49129e17d6b3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347053
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index f39b23b..b8e50d9 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1437,7 +1437,10 @@
SpvId SPIRVCodeGenerator::writeVectorConstructor(const Constructor& c, OutputStream& out) {
const Type& type = c.type();
SkASSERT(type.isVector());
- if (c.isCompileTimeConstant()) {
+ // Constructing a vector from another vector (even if it's constant) requires our general
+ // case code, to deal with (possible) per-element type conversion.
+ bool vectorToVector = c.arguments().size() == 1 && c.arguments()[0]->type().isVector();
+ if (c.isCompileTimeConstant() && !vectorToVector) {
return this->writeConstantVector(c);
}
// go ahead and write the arguments so we don't try to write new instructions in the middle of