diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp index aa2428c097..56c34d066e 100644 --- a/src/sksl/ir/SkSLType.cpp +++ b/src/sksl/ir/SkSLType.cpp @@ -63,6 +63,11 @@ public: return fComponentType.isAllowedInES2(); } + size_t slotCount() const override { + SkASSERT(fCount > 0); + return fCount * fComponentType.slotCount(); + } + private: using INHERITED = Type; @@ -129,6 +134,10 @@ public: return true; } + size_t slotCount() const override { + return 1; + } + private: using INHERITED = Type; @@ -176,6 +185,10 @@ public: return fNumberKind != NumberKind::kUnsigned; } + size_t slotCount() const override { + return 1; + } + private: using INHERITED = Type; @@ -222,6 +235,10 @@ public: return fColumns == fRows; } + size_t slotCount() const override { + return fColumns * fRows; + } + private: using INHERITED = Type; @@ -339,6 +356,14 @@ public: }); } + size_t slotCount() const override { + size_t slots = 0; + for (const Field& field : fFields) { + slots += field.fType->slotCount(); + } + return slots; + } + private: using INHERITED = Type; @@ -381,6 +406,10 @@ public: return fComponentType.isAllowedInES2(); } + size_t slotCount() const override { + return fColumns; + } + private: using INHERITED = Type; diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index f8fee9b958..db75066332 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -387,41 +387,8 @@ public: /** * Returns the number of scalars needed to hold this type. */ - size_t slotCount() const { - switch (this->typeKind()) { - case Type::TypeKind::kBlender: - case Type::TypeKind::kColorFilter: - case Type::TypeKind::kGeneric: - case Type::TypeKind::kOther: - case Type::TypeKind::kSampler: - case Type::TypeKind::kSeparateSampler: - case Type::TypeKind::kShader: - case Type::TypeKind::kTexture: - case Type::TypeKind::kVoid: - return 0; - - case Type::TypeKind::kLiteral: - case Type::TypeKind::kScalar: - return 1; - - case Type::TypeKind::kVector: - return this->columns(); - - case Type::TypeKind::kMatrix: - return this->columns() * this->rows(); - - case Type::TypeKind::kStruct: { - size_t slots = 0; - for (const Field& field : this->fields()) { - slots += field.fType->slotCount(); - } - return slots; - } - case Type::TypeKind::kArray: - SkASSERT(this->columns() > 0); - return this->columns() * this->componentType().slotCount(); - } - SkUNREACHABLE; + virtual size_t slotCount() const { + return 0; } virtual const std::vector& fields() const {