diff options
author | ethannicholas <ethannicholas@google.com> | 2016-07-12 09:07:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-12 09:07:21 -0700 |
commit | 9fd67a1f53809f5eff1210dd107241b450c48acc (patch) | |
tree | da60b78933d92f796cf1f5dc3ff3dffa6febf78f /src/sksl/ir/SkSLType.h | |
parent | 5dba301e916448bbb17bfe8e70dc367f32eb7159 (diff) |
SkSL performance improvements (plus a couple of minor warning fixes)
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2131223002
Review-Url: https://codereview.chromium.org/2131223002
Diffstat (limited to 'src/sksl/ir/SkSLType.h')
-rw-r--r-- | src/sksl/ir/SkSLType.h | 234 |
1 files changed, 117 insertions, 117 deletions
diff --git a/src/sksl/ir/SkSLType.h b/src/sksl/ir/SkSLType.h index e17bae68db..8a73b139ba 100644 --- a/src/sksl/ir/SkSLType.h +++ b/src/sksl/ir/SkSLType.h @@ -24,18 +24,18 @@ namespace SkSL { class Type : public Symbol { public: struct Field { - Field(Modifiers modifiers, std::string name, std::shared_ptr<Type> type) + Field(Modifiers modifiers, std::string name, const Type& type) : fModifiers(modifiers) , fName(std::move(name)) , fType(std::move(type)) {} - const std::string description() { - return fType->description() + " " + fName + ";"; + const std::string description() const { + return fType.description() + " " + fName + ";"; } const Modifiers fModifiers; const std::string fName; - const std::shared_ptr<Type> fType; + const Type& fType; }; enum Kind { @@ -56,7 +56,7 @@ public: , fTypeKind(kOther_Kind) {} // Create a generic type which maps to the listed types. - Type(std::string name, std::vector<std::shared_ptr<Type>> types) + Type(std::string name, std::vector<const Type*> types) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kGeneric_Kind) , fCoercibleTypes(std::move(types)) { @@ -78,7 +78,7 @@ public: , fRows(1) {} // Create a scalar type which can be coerced to the listed types. - Type(std::string name, bool isNumber, std::vector<std::shared_ptr<Type>> coercibleTypes) + Type(std::string name, bool isNumber, std::vector<const Type*> coercibleTypes) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kScalar_Kind) , fIsNumber(isNumber) @@ -87,23 +87,23 @@ public: , fRows(1) {} // Create a vector type. - Type(std::string name, std::shared_ptr<Type> componentType, int columns) + Type(std::string name, const Type& componentType, int columns) : Type(name, kVector_Kind, componentType, columns) {} // Create a vector or array type. - Type(std::string name, Kind kind, std::shared_ptr<Type> componentType, int columns) + Type(std::string name, Kind kind, const Type& componentType, int columns) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kind) - , fComponentType(std::move(componentType)) + , fComponentType(&componentType) , fColumns(columns) , fRows(1) , fDimensions(SpvDim1D) {} // Create a matrix type. - Type(std::string name, std::shared_ptr<Type> componentType, int columns, int rows) + Type(std::string name, const Type& componentType, int columns, int rows) : INHERITED(Position(), kType_Kind, std::move(name)) , fTypeKind(kMatrix_Kind) - , fComponentType(std::move(componentType)) + , fComponentType(&componentType) , fColumns(columns) , fRows(rows) , fDimensions(SpvDim1D) {} @@ -153,7 +153,7 @@ public: * Returns true if an instance of this type can be freely coerced (implicitly converted) to * another type. */ - bool canCoerceTo(std::shared_ptr<Type> other) const { + bool canCoerceTo(const Type& other) const { int cost; return determineCoercionCost(other, &cost); } @@ -164,15 +164,15 @@ public: * costs. Returns true if a conversion is possible, false otherwise. The value of the out * parameter is undefined if false is returned. */ - bool determineCoercionCost(std::shared_ptr<Type> other, int* outCost) const; + bool determineCoercionCost(const Type& other, int* outCost) const; /** * For matrices and vectors, returns the type of individual cells (e.g. mat2 has a component * type of kFloat_Type). For all other types, causes an assertion failure. */ - std::shared_ptr<Type> componentType() const { + const Type& componentType() const { ASSERT(fComponentType); - return fComponentType; + return *fComponentType; } /** @@ -195,7 +195,7 @@ public: return fRows; } - std::vector<Field> fields() const { + const std::vector<Field>& fields() const { ASSERT(fTypeKind == kStruct_Kind); return fFields; } @@ -204,7 +204,7 @@ public: * For generic types, returns the types that this generic type can substitute for. For other * types, returns a list of other types that this type can be coerced into. */ - std::vector<std::shared_ptr<Type>> coercibleTypes() const { + const std::vector<const Type*>& coercibleTypes() const { ASSERT(fCoercibleTypes.size() > 0); return fCoercibleTypes; } @@ -257,7 +257,7 @@ public: case kStruct_Kind: { size_t result = 16; for (size_t i = 0; i < fFields.size(); i++) { - size_t alignment = fFields[i].fType->alignment(); + size_t alignment = fFields[i].fType.alignment(); if (alignment > result) { result = alignment; } @@ -300,13 +300,13 @@ public: case kStruct_Kind: { size_t total = 0; for (size_t i = 0; i < fFields.size(); i++) { - size_t alignment = fFields[i].fType->alignment(); + size_t alignment = fFields[i].fType.alignment(); if (total % alignment != 0) { total += alignment - total % alignment; } ASSERT(false); ASSERT(total % alignment == 0); - total += fFields[i].fType->size(); + total += fFields[i].fType.size(); } return total; } @@ -319,15 +319,15 @@ public: * Returns the corresponding vector or matrix type with the specified number of columns and * rows. */ - std::shared_ptr<Type> toCompound(int columns, int rows); + const Type& toCompound(int columns, int rows) const; private: typedef Symbol INHERITED; const Kind fTypeKind; const bool fIsNumber = false; - const std::shared_ptr<Type> fComponentType = nullptr; - const std::vector<std::shared_ptr<Type>> fCoercibleTypes = { }; + const Type* fComponentType = nullptr; + const std::vector<const Type*> fCoercibleTypes = { }; const int fColumns = -1; const int fRows = -1; const std::vector<Field> fFields = { }; @@ -338,100 +338,100 @@ private: const bool fIsSampled = false; }; -extern const std::shared_ptr<Type> kVoid_Type; - -extern const std::shared_ptr<Type> kFloat_Type; -extern const std::shared_ptr<Type> kVec2_Type; -extern const std::shared_ptr<Type> kVec3_Type; -extern const std::shared_ptr<Type> kVec4_Type; -extern const std::shared_ptr<Type> kDouble_Type; -extern const std::shared_ptr<Type> kDVec2_Type; -extern const std::shared_ptr<Type> kDVec3_Type; -extern const std::shared_ptr<Type> kDVec4_Type; -extern const std::shared_ptr<Type> kInt_Type; -extern const std::shared_ptr<Type> kIVec2_Type; -extern const std::shared_ptr<Type> kIVec3_Type; -extern const std::shared_ptr<Type> kIVec4_Type; -extern const std::shared_ptr<Type> kUInt_Type; -extern const std::shared_ptr<Type> kUVec2_Type; -extern const std::shared_ptr<Type> kUVec3_Type; -extern const std::shared_ptr<Type> kUVec4_Type; -extern const std::shared_ptr<Type> kBool_Type; -extern const std::shared_ptr<Type> kBVec2_Type; -extern const std::shared_ptr<Type> kBVec3_Type; -extern const std::shared_ptr<Type> kBVec4_Type; - -extern const std::shared_ptr<Type> kMat2x2_Type; -extern const std::shared_ptr<Type> kMat2x3_Type; -extern const std::shared_ptr<Type> kMat2x4_Type; -extern const std::shared_ptr<Type> kMat3x2_Type; -extern const std::shared_ptr<Type> kMat3x3_Type; -extern const std::shared_ptr<Type> kMat3x4_Type; -extern const std::shared_ptr<Type> kMat4x2_Type; -extern const std::shared_ptr<Type> kMat4x3_Type; -extern const std::shared_ptr<Type> kMat4x4_Type; - -extern const std::shared_ptr<Type> kDMat2x2_Type; -extern const std::shared_ptr<Type> kDMat2x3_Type; -extern const std::shared_ptr<Type> kDMat2x4_Type; -extern const std::shared_ptr<Type> kDMat3x2_Type; -extern const std::shared_ptr<Type> kDMat3x3_Type; -extern const std::shared_ptr<Type> kDMat3x4_Type; -extern const std::shared_ptr<Type> kDMat4x2_Type; -extern const std::shared_ptr<Type> kDMat4x3_Type; -extern const std::shared_ptr<Type> kDMat4x4_Type; - -extern const std::shared_ptr<Type> kSampler1D_Type; -extern const std::shared_ptr<Type> kSampler2D_Type; -extern const std::shared_ptr<Type> kSampler3D_Type; -extern const std::shared_ptr<Type> kSamplerCube_Type; -extern const std::shared_ptr<Type> kSampler2DRect_Type; -extern const std::shared_ptr<Type> kSampler1DArray_Type; -extern const std::shared_ptr<Type> kSampler2DArray_Type; -extern const std::shared_ptr<Type> kSamplerCubeArray_Type; -extern const std::shared_ptr<Type> kSamplerBuffer_Type; -extern const std::shared_ptr<Type> kSampler2DMS_Type; -extern const std::shared_ptr<Type> kSampler2DMSArray_Type; - -extern const std::shared_ptr<Type> kGSampler1D_Type; -extern const std::shared_ptr<Type> kGSampler2D_Type; -extern const std::shared_ptr<Type> kGSampler3D_Type; -extern const std::shared_ptr<Type> kGSamplerCube_Type; -extern const std::shared_ptr<Type> kGSampler2DRect_Type; -extern const std::shared_ptr<Type> kGSampler1DArray_Type; -extern const std::shared_ptr<Type> kGSampler2DArray_Type; -extern const std::shared_ptr<Type> kGSamplerCubeArray_Type; -extern const std::shared_ptr<Type> kGSamplerBuffer_Type; -extern const std::shared_ptr<Type> kGSampler2DMS_Type; -extern const std::shared_ptr<Type> kGSampler2DMSArray_Type; - -extern const std::shared_ptr<Type> kSampler1DShadow_Type; -extern const std::shared_ptr<Type> kSampler2DShadow_Type; -extern const std::shared_ptr<Type> kSamplerCubeShadow_Type; -extern const std::shared_ptr<Type> kSampler2DRectShadow_Type; -extern const std::shared_ptr<Type> kSampler1DArrayShadow_Type; -extern const std::shared_ptr<Type> kSampler2DArrayShadow_Type; -extern const std::shared_ptr<Type> kSamplerCubeArrayShadow_Type; -extern const std::shared_ptr<Type> kGSampler2DArrayShadow_Type; -extern const std::shared_ptr<Type> kGSamplerCubeArrayShadow_Type; - -extern const std::shared_ptr<Type> kGenType_Type; -extern const std::shared_ptr<Type> kGenDType_Type; -extern const std::shared_ptr<Type> kGenIType_Type; -extern const std::shared_ptr<Type> kGenUType_Type; -extern const std::shared_ptr<Type> kGenBType_Type; -extern const std::shared_ptr<Type> kMat_Type; -extern const std::shared_ptr<Type> kVec_Type; -extern const std::shared_ptr<Type> kGVec_Type; -extern const std::shared_ptr<Type> kGVec2_Type; -extern const std::shared_ptr<Type> kGVec3_Type; -extern const std::shared_ptr<Type> kGVec4_Type; -extern const std::shared_ptr<Type> kDVec_Type; -extern const std::shared_ptr<Type> kIVec_Type; -extern const std::shared_ptr<Type> kUVec_Type; -extern const std::shared_ptr<Type> kBVec_Type; - -extern const std::shared_ptr<Type> kInvalid_Type; +extern const Type* kVoid_Type; + +extern const Type* kFloat_Type; +extern const Type* kVec2_Type; +extern const Type* kVec3_Type; +extern const Type* kVec4_Type; +extern const Type* kDouble_Type; +extern const Type* kDVec2_Type; +extern const Type* kDVec3_Type; +extern const Type* kDVec4_Type; +extern const Type* kInt_Type; +extern const Type* kIVec2_Type; +extern const Type* kIVec3_Type; +extern const Type* kIVec4_Type; +extern const Type* kUInt_Type; +extern const Type* kUVec2_Type; +extern const Type* kUVec3_Type; +extern const Type* kUVec4_Type; +extern const Type* kBool_Type; +extern const Type* kBVec2_Type; +extern const Type* kBVec3_Type; +extern const Type* kBVec4_Type; + +extern const Type* kMat2x2_Type; +extern const Type* kMat2x3_Type; +extern const Type* kMat2x4_Type; +extern const Type* kMat3x2_Type; +extern const Type* kMat3x3_Type; +extern const Type* kMat3x4_Type; +extern const Type* kMat4x2_Type; +extern const Type* kMat4x3_Type; +extern const Type* kMat4x4_Type; + +extern const Type* kDMat2x2_Type; +extern const Type* kDMat2x3_Type; +extern const Type* kDMat2x4_Type; +extern const Type* kDMat3x2_Type; +extern const Type* kDMat3x3_Type; +extern const Type* kDMat3x4_Type; +extern const Type* kDMat4x2_Type; +extern const Type* kDMat4x3_Type; +extern const Type* kDMat4x4_Type; + +extern const Type* kSampler1D_Type; +extern const Type* kSampler2D_Type; +extern const Type* kSampler3D_Type; +extern const Type* kSamplerCube_Type; +extern const Type* kSampler2DRect_Type; +extern const Type* kSampler1DArray_Type; +extern const Type* kSampler2DArray_Type; +extern const Type* kSamplerCubeArray_Type; +extern const Type* kSamplerBuffer_Type; +extern const Type* kSampler2DMS_Type; +extern const Type* kSampler2DMSArray_Type; + +extern const Type* kGSampler1D_Type; +extern const Type* kGSampler2D_Type; +extern const Type* kGSampler3D_Type; +extern const Type* kGSamplerCube_Type; +extern const Type* kGSampler2DRect_Type; +extern const Type* kGSampler1DArray_Type; +extern const Type* kGSampler2DArray_Type; +extern const Type* kGSamplerCubeArray_Type; +extern const Type* kGSamplerBuffer_Type; +extern const Type* kGSampler2DMS_Type; +extern const Type* kGSampler2DMSArray_Type; + +extern const Type* kSampler1DShadow_Type; +extern const Type* kSampler2DShadow_Type; +extern const Type* kSamplerCubeShadow_Type; +extern const Type* kSampler2DRectShadow_Type; +extern const Type* kSampler1DArrayShadow_Type; +extern const Type* kSampler2DArrayShadow_Type; +extern const Type* kSamplerCubeArrayShadow_Type; +extern const Type* kGSampler2DArrayShadow_Type; +extern const Type* kGSamplerCubeArrayShadow_Type; + +extern const Type* kGenType_Type; +extern const Type* kGenDType_Type; +extern const Type* kGenIType_Type; +extern const Type* kGenUType_Type; +extern const Type* kGenBType_Type; +extern const Type* kMat_Type; +extern const Type* kVec_Type; +extern const Type* kGVec_Type; +extern const Type* kGVec2_Type; +extern const Type* kGVec3_Type; +extern const Type* kGVec4_Type; +extern const Type* kDVec_Type; +extern const Type* kIVec_Type; +extern const Type* kUVec_Type; +extern const Type* kBVec_Type; + +extern const Type* kInvalid_Type; } // namespace |