Allow type-fluid GLSL-style vec2(int, bool) ctors in SkSL.
Note that GLSL accepts these sorts of constructors natively, but Metal
and SPIR-V do not. In the generated IR we actually add a cast for
subexpressions where the type does not match. These casts can be seen in
the final output for both GLSL (where they are no-ops) and Metal/SPIR-V
(where they are essential).
This change exposed some missing SPIR-V functionality (vector casts do
not support bool types). This can be fixed up in a followup CL; these
casts were previously disallowed by SkSL entirely, so there won't be any
of them in existing code.
Change-Id: I54ae922e91b38bed032537496428747a081dc774
Bug: skia:11164, skia:11171
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353576
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp
index 52c99a5..fc2c759 100644
--- a/src/sksl/SkSLSPIRVCodeGenerator.cpp
+++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp
@@ -1506,9 +1506,9 @@
if (argType.isVector()) {
// SPIR-V doesn't support vector(vector-of-different-type) directly, so we need to
// extract the components and convert them in that case manually. On top of that,
- // as of this writing there's a bug in the Intel Vulkan driver where OpCreateComposite
- // doesn't handle vector arguments at all, so we always extract vector components and
- // pass them into OpCreateComposite individually.
+ // as of this writing there's a bug in the Intel Vulkan driver where
+ // OpCompositeConstruct doesn't handle vector arguments at all, so we always extract
+ // vector components and pass them into OpCompositeConstruct individually.
SpvId vec = this->writeExpression(*c.arguments()[i], out);
SpvOp_ op = SpvOpUndef;
const Type& src = argType.componentType();
@@ -1527,7 +1527,9 @@
src == *fContext.fTypes.fUByte) {
op = SpvOpConvertUToF;
} else {
- SkASSERT(false);
+ fErrors.error(c.arguments()[i]->fOffset, "unsupported cast in SPIR-V: vector " +
+ src.description() + " to " +
+ dst.description());
}
} else if (dst == *fContext.fTypes.fInt ||
dst == *fContext.fTypes.fShort ||
@@ -1545,7 +1547,9 @@
src == *fContext.fTypes.fUByte) {
op = SpvOpBitcast;
} else {
- SkASSERT(false);
+ fErrors.error(c.arguments()[i]->fOffset, "unsupported cast in SPIR-V: vector " +
+ src.description() + " to " +
+ dst.description());
}
} else if (dst == *fContext.fTypes.fUInt ||
dst == *fContext.fTypes.fUShort ||
@@ -1563,7 +1567,9 @@
return vec;
}
} else {
- SkASSERT(false);
+ fErrors.error(c.arguments()[i]->fOffset, "unsupported cast in SPIR-V: vector " +
+ src.description() + " to " +
+ dst.description());
}
}
for (int j = 0; j < argType.columns(); j++) {