aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir/SkSLType.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl/ir/SkSLType.h')
-rw-r--r--src/sksl/ir/SkSLType.h66
1 files changed, 53 insertions, 13 deletions
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h
index ec91a1c52b..6ea4c5694c 100644
--- a/src/sksl/ir/SkSLType.h
+++ b/src/sksl/ir/SkSLType.h
@@ -52,37 +52,47 @@ public:
kOther_Kind
};
+ enum NumberKind {
+ kFloat_NumberKind,
+ kSigned_NumberKind,
+ kUnsigned_NumberKind,
+ kNonnumeric_NumberKind
+ };
+
// Create an "other" (special) type with the given name. These types cannot be directly
// referenced from user code.
Type(String name)
: INHERITED(Position(), kType_Kind, std::move(name))
- , fTypeKind(kOther_Kind) {}
+ , fTypeKind(kOther_Kind)
+ , fNumberKind(kNonnumeric_NumberKind) {}
// Create a generic type which maps to the listed types.
Type(String name, std::vector<const Type*> types)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kGeneric_Kind)
+ , fNumberKind(kNonnumeric_NumberKind)
, fCoercibleTypes(std::move(types)) {}
// Create a struct type with the given fields.
Type(Position position, String name, std::vector<Field> fields)
: INHERITED(position, kType_Kind, std::move(name))
, fTypeKind(kStruct_Kind)
+ , fNumberKind(kNonnumeric_NumberKind)
, fFields(std::move(fields)) {}
// Create a scalar type.
- Type(String name, bool isNumber)
+ Type(String name, NumberKind numberKind)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
- , fIsNumber(isNumber)
+ , fNumberKind(numberKind)
, fColumns(1)
, fRows(1) {}
// Create a scalar type which can be coerced to the listed types.
- Type(String name, bool isNumber, std::vector<const Type*> coercibleTypes)
+ Type(String name, NumberKind numberKind, std::vector<const Type*> coercibleTypes)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kScalar_Kind)
- , fIsNumber(isNumber)
+ , fNumberKind(numberKind)
, fCoercibleTypes(std::move(coercibleTypes))
, fColumns(1)
, fRows(1) {}
@@ -95,6 +105,7 @@ public:
Type(String name, Kind kind, const Type& componentType, int columns)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kind)
+ , fNumberKind(kNonnumeric_NumberKind)
, fComponentType(&componentType)
, fColumns(columns)
, fRows(1)
@@ -104,6 +115,7 @@ public:
Type(String name, const Type& componentType, int columns, int rows)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kMatrix_Kind)
+ , fNumberKind(kNonnumeric_NumberKind)
, fComponentType(&componentType)
, fColumns(columns)
, fRows(rows)
@@ -114,13 +126,14 @@ public:
bool isSampled)
: INHERITED(Position(), kType_Kind, std::move(name))
, fTypeKind(kSampler_Kind)
+ , fNumberKind(kNonnumeric_NumberKind)
, fDimensions(dimensions)
, fIsDepth(isDepth)
, fIsArrayed(isArrayed)
, fIsMultisampled(isMultisampled)
, fIsSampled(isSampled) {}
- String name() const {
+ const String& name() const {
return fName;
}
@@ -147,7 +160,35 @@ public:
* Returns true if this is a numeric scalar type.
*/
bool isNumber() const {
- return fIsNumber;
+ return fNumberKind != kNonnumeric_NumberKind;
+ }
+
+ /**
+ * Returns true if this is a floating-point scalar type (float, half, or double).
+ */
+ bool isFloat() const {
+ return fNumberKind == kFloat_NumberKind;
+ }
+
+ /**
+ * Returns true if this is a signed scalar type (int or short).
+ */
+ bool isSigned() const {
+ return fNumberKind == kSigned_NumberKind;
+ }
+
+ /**
+ * Returns true if this is an unsigned scalar type (uint or ushort).
+ */
+ bool isUnsigned() const {
+ return fNumberKind == kUnsigned_NumberKind;
+ }
+
+ /**
+ * Returns true if this is a signed or unsigned integer.
+ */
+ bool isInteger() const {
+ return isSigned() || isUnsigned();
}
/**
@@ -155,17 +196,15 @@ public:
* another type.
*/
bool canCoerceTo(const Type& other) const {
- int cost;
- return determineCoercionCost(other, &cost);
+ return coercionCost(other) != INT_MAX;
}
/**
* Determines the "cost" of coercing (implicitly converting) this type to another type. The cost
* is a number with no particular meaning other than that lower costs are preferable to higher
- * costs. Returns true if a conversion is possible, false otherwise. The value of the out
- * parameter is undefined if false is returned.
+ * costs. Returns INT_MAX if the coercion is not possible.
*/
- bool determineCoercionCost(const Type& other, int* outCost) const;
+ int coercionCost(const Type& other) const;
/**
* For matrices and vectors, returns the type of individual cells (e.g. mat2 has a component
@@ -245,7 +284,8 @@ private:
typedef Symbol INHERITED;
const Kind fTypeKind;
- const bool fIsNumber = false;
+ // always kNonnumeric_NumberKind for non-scalar values
+ const NumberKind fNumberKind;
const Type* fComponentType = nullptr;
const std::vector<const Type*> fCoercibleTypes;
const int fColumns = -1;