Add support for enum types in SPIR-V code.

- is_float: Calling `type.columns()` on an arbitrary type isn't safe; it
will assert if the passed-in type is not a scalar/vector/matrix/array.
This was asserting when being passed an enum type. Additionally, this
code would have returned true for arrays of float but that does not
appear to be the intent.

- is_signed: This now returns true for enum types, as these boil down to
int for our purposes.

- is_unsigned/is_bool: Updated structurally to match is_float and
is_signed, but behaviorally unchanged.

- getActualType: now treats enum types as int. This prevents us from
declaring the "OpTypeInt, 32, 1" type twice, which triggers a validator
error: "Duplicate non-aggregate type declarations are not allowed."

These changes are necessary to properly compile Enum.sksl in SPIR-V with
optimizations disabled.

Change-Id: Ib7ae00239c9f87c1a9463e0c8745622743e62cf6
Bug: skia:11304
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368576
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-02-09 18:31:34 -05:00 committed by Skia Commit-Bot
parent a028936b52
commit 4c15170960

View File

@ -167,31 +167,21 @@ void SPIRVCodeGenerator::writeWord(int32_t word, OutputStream& out) {
}
static bool is_float(const Context& context, const Type& type) {
if (type.columns() > 1) {
return is_float(context, type.componentType());
}
return type.isFloat();
return (type.isScalar() || type.isVector() || type.isMatrix()) &&
type.componentType().isFloat();
}
static bool is_signed(const Context& context, const Type& type) {
if (type.isVector()) {
return is_signed(context, type.componentType());
}
return type.isSigned();
return type.isEnum() ||
((type.isScalar() || type.isVector()) && type.componentType().isSigned());
}
static bool is_unsigned(const Context& context, const Type& type) {
if (type.isVector()) {
return is_unsigned(context, type.componentType());
}
return type.isUnsigned();
return (type.isScalar() || type.isVector()) && type.componentType().isUnsigned();
}
static bool is_bool(const Context& context, const Type& type) {
if (type.isVector()) {
return is_bool(context, type.componentType());
}
return type.isBoolean();
return (type.isScalar() || type.isVector()) && type.componentType().isBoolean();
}
static bool is_out(const Variable& var) {
@ -467,7 +457,7 @@ const Type& SPIRVCodeGenerator::getActualType(const Type& type) {
if (type.isFloat()) {
return *fContext.fTypes.fFloat;
}
if (type.isSigned()) {
if (type.isSigned() || type.isEnum()) {
return *fContext.fTypes.fInt;
}
if (type.isUnsigned()) {