Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Unified Diff: src/sksl/ir/SkSLType.cpp

Issue 2131223002: SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: minor fixes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/sksl/ir/SkSLType.cpp
diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp
index 27cbd39e44f4b1c0bb7b0fd254d3564490278969..429cae58c98daedcd6a8bf69efad560673a8496a 100644
--- a/src/sksl/ir/SkSLType.cpp
+++ b/src/sksl/ir/SkSLType.cpp
@@ -9,26 +9,26 @@
namespace SkSL {
-bool Type::determineCoercionCost(std::shared_ptr<Type> other, int* outCost) const {
- if (this == other.get()) {
+bool Type::determineCoercionCost(const Type& other, int* outCost) const {
+ if (*this == other) {
*outCost = 0;
return true;
}
- if (this->kind() == kVector_Kind && other->kind() == kVector_Kind) {
- if (this->columns() == other->columns()) {
- return this->componentType()->determineCoercionCost(other->componentType(), outCost);
+ if (this->kind() == kVector_Kind && other.kind() == kVector_Kind) {
+ if (this->columns() == other.columns()) {
+ return this->componentType().determineCoercionCost(other.componentType(), outCost);
}
return false;
}
if (this->kind() == kMatrix_Kind) {
- if (this->columns() == other->columns() &&
- this->rows() == other->rows()) {
- return this->componentType()->determineCoercionCost(other->componentType(), outCost);
+ if (this->columns() == other.columns() &&
+ this->rows() == other.rows()) {
+ return this->componentType().determineCoercionCost(other.componentType(), outCost);
}
return false;
}
for (size_t i = 0; i < fCoercibleTypes.size(); i++) {
- if (fCoercibleTypes[i] == other) {
+ if (*fCoercibleTypes[i] == other) {
*outCost = (int) i + 1;
return true;
}
@@ -36,12 +36,12 @@ bool Type::determineCoercionCost(std::shared_ptr<Type> other, int* outCost) cons
return false;
}
-std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
+const Type& Type::toCompound(int columns, int rows) const {
ASSERT(this->kind() == Type::kScalar_Kind);
if (columns == 1 && rows == 1) {
- return std::shared_ptr<Type>(this);
+ return *this;
}
- if (*this == *kFloat_Type) {
+ if (*this == kFloat_Type) {
switch (rows) {
case 1:
switch (columns) {
@@ -73,7 +73,7 @@ std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
}
default: ABORT("unsupported row count (%d)", rows);
}
- } else if (*this == *kDouble_Type) {
+ } else if (*this == kDouble_Type) {
switch (rows) {
case 1:
switch (columns) {
@@ -105,7 +105,7 @@ std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
}
default: ABORT("unsupported row count (%d)", rows);
}
- } else if (*this == *kInt_Type) {
+ } else if (*this == kInt_Type) {
switch (rows) {
case 1:
switch (columns) {
@@ -116,7 +116,7 @@ std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
}
default: ABORT("unsupported row count (%d)", rows);
}
- } else if (*this == *kUInt_Type) {
+ } else if (*this == kUInt_Type) {
switch (rows) {
case 1:
switch (columns) {
@@ -131,128 +131,112 @@ std::shared_ptr<Type> Type::toCompound(int columns, int rows) {
ABORT("unsupported scalar_to_compound type %s", this->description().c_str());
}
-const std::shared_ptr<Type> kVoid_Type(new Type("void"));
-
-const std::shared_ptr<Type> kDouble_Type(new Type("double", true));
-const std::shared_ptr<Type> kDVec2_Type(new Type("dvec2", kDouble_Type, 2));
-const std::shared_ptr<Type> kDVec3_Type(new Type("dvec3", kDouble_Type, 3));
-const std::shared_ptr<Type> kDVec4_Type(new Type("dvec4", kDouble_Type, 4));
-
-const std::shared_ptr<Type> kFloat_Type(new Type("float", true, { kDouble_Type }));
-const std::shared_ptr<Type> kVec2_Type(new Type("vec2", kFloat_Type, 2));
-const std::shared_ptr<Type> kVec3_Type(new Type("vec3", kFloat_Type, 3));
-const std::shared_ptr<Type> kVec4_Type(new Type("vec4", kFloat_Type, 4));
-
-const std::shared_ptr<Type> kUInt_Type(new Type("uint", true, { kFloat_Type, kDouble_Type }));
-const std::shared_ptr<Type> kUVec2_Type(new Type("uvec2", kUInt_Type, 2));
-const std::shared_ptr<Type> kUVec3_Type(new Type("uvec3", kUInt_Type, 3));
-const std::shared_ptr<Type> kUVec4_Type(new Type("uvec4", kUInt_Type, 4));
-
-const std::shared_ptr<Type> kInt_Type(new Type("int", true, { kUInt_Type, kFloat_Type,
- kDouble_Type }));
-const std::shared_ptr<Type> kIVec2_Type(new Type("ivec2", kInt_Type, 2));
-const std::shared_ptr<Type> kIVec3_Type(new Type("ivec3", kInt_Type, 3));
-const std::shared_ptr<Type> kIVec4_Type(new Type("ivec4", kInt_Type, 4));
-
-const std::shared_ptr<Type> kBool_Type(new Type("bool", false));
-const std::shared_ptr<Type> kBVec2_Type(new Type("bvec2", kBool_Type, 2));
-const std::shared_ptr<Type> kBVec3_Type(new Type("bvec3", kBool_Type, 3));
-const std::shared_ptr<Type> kBVec4_Type(new Type("bvec4", kBool_Type, 4));
-
-const std::shared_ptr<Type> kMat2x2_Type(new Type("mat2", kFloat_Type, 2, 2));
-const std::shared_ptr<Type> kMat2x3_Type(new Type("mat2x3", kFloat_Type, 2, 3));
-const std::shared_ptr<Type> kMat2x4_Type(new Type("mat2x4", kFloat_Type, 2, 4));
-const std::shared_ptr<Type> kMat3x2_Type(new Type("mat3x2", kFloat_Type, 3, 2));
-const std::shared_ptr<Type> kMat3x3_Type(new Type("mat3", kFloat_Type, 3, 3));
-const std::shared_ptr<Type> kMat3x4_Type(new Type("mat3x4", kFloat_Type, 3, 4));
-const std::shared_ptr<Type> kMat4x2_Type(new Type("mat4x2", kFloat_Type, 4, 2));
-const std::shared_ptr<Type> kMat4x3_Type(new Type("mat4x3", kFloat_Type, 4, 3));
-const std::shared_ptr<Type> kMat4x4_Type(new Type("mat4", kFloat_Type, 4, 4));
-
-const std::shared_ptr<Type> kDMat2x2_Type(new Type("dmat2", kFloat_Type, 2, 2));
-const std::shared_ptr<Type> kDMat2x3_Type(new Type("dmat2x3", kFloat_Type, 2, 3));
-const std::shared_ptr<Type> kDMat2x4_Type(new Type("dmat2x4", kFloat_Type, 2, 4));
-const std::shared_ptr<Type> kDMat3x2_Type(new Type("dmat3x2", kFloat_Type, 3, 2));
-const std::shared_ptr<Type> kDMat3x3_Type(new Type("dmat3", kFloat_Type, 3, 3));
-const std::shared_ptr<Type> kDMat3x4_Type(new Type("dmat3x4", kFloat_Type, 3, 4));
-const std::shared_ptr<Type> kDMat4x2_Type(new Type("dmat4x2", kFloat_Type, 4, 2));
-const std::shared_ptr<Type> kDMat4x3_Type(new Type("dmat4x3", kFloat_Type, 4, 3));
-const std::shared_ptr<Type> kDMat4x4_Type(new Type("dmat4", kFloat_Type, 4, 4));
-
-const std::shared_ptr<Type> kSampler1D_Type(new Type("sampler1D", SpvDim1D, false, false, false, true));
-const std::shared_ptr<Type> kSampler2D_Type(new Type("sampler2D", SpvDim2D, false, false, false, true));
-const std::shared_ptr<Type> kSampler3D_Type(new Type("sampler3D", SpvDim3D, false, false, false, true));
-const std::shared_ptr<Type> kSamplerCube_Type(new Type("samplerCube"));
-const std::shared_ptr<Type> kSampler2DRect_Type(new Type("sampler2DRect"));
-const std::shared_ptr<Type> kSampler1DArray_Type(new Type("sampler1DArray"));
-const std::shared_ptr<Type> kSampler2DArray_Type(new Type("sampler2DArray"));
-const std::shared_ptr<Type> kSamplerCubeArray_Type(new Type("samplerCubeArray"));
-const std::shared_ptr<Type> kSamplerBuffer_Type(new Type("samplerBuffer"));
-const std::shared_ptr<Type> kSampler2DMS_Type(new Type("sampler2DMS"));
-const std::shared_ptr<Type> kSampler2DMSArray_Type(new Type("sampler2DMSArray"));
-const std::shared_ptr<Type> kSampler1DShadow_Type(new Type("sampler1DShadow"));
-const std::shared_ptr<Type> kSampler2DShadow_Type(new Type("sampler2DShadow"));
-const std::shared_ptr<Type> kSamplerCubeShadow_Type(new Type("samplerCubeShadow"));
-const std::shared_ptr<Type> kSampler2DRectShadow_Type(new Type("sampler2DRectShadow"));
-const std::shared_ptr<Type> kSampler1DArrayShadow_Type(new Type("sampler1DArrayShadow"));
-const std::shared_ptr<Type> kSampler2DArrayShadow_Type(new Type("sampler2DArrayShadow"));
-const std::shared_ptr<Type> kSamplerCubeArrayShadow_Type(new Type("samplerCubeArrayShadow"));
-
-static std::vector<std::shared_ptr<Type>> type(std::shared_ptr<Type> t) {
- return { t, t, t, t };
+const Type kVoid_Type("void");
+
+const Type kDouble_Type("double", true);
+const Type kDVec2_Type("dvec2", kDouble_Type, 2);
+const Type kDVec3_Type("dvec3", kDouble_Type, 3);
+const Type kDVec4_Type("dvec4", kDouble_Type, 4);
+
+const Type kFloat_Type("float", true, { &kDouble_Type });
+const Type kVec2_Type("vec2", kFloat_Type, 2);
+const Type kVec3_Type("vec3", kFloat_Type, 3);
+const Type kVec4_Type("vec4", kFloat_Type, 4);
+
+const Type kUInt_Type("uint", true, { &kFloat_Type, &kDouble_Type });
+const Type kUVec2_Type("uvec2", kUInt_Type, 2);
+const Type kUVec3_Type("uvec3", kUInt_Type, 3);
+const Type kUVec4_Type("uvec4", kUInt_Type, 4);
+
+const Type kInt_Type("int", true, { &kUInt_Type, &kFloat_Type, &kDouble_Type });
+const Type kIVec2_Type("ivec2", kInt_Type, 2);
+const Type kIVec3_Type("ivec3", kInt_Type, 3);
+const Type kIVec4_Type("ivec4", kInt_Type, 4);
+
+const Type kBool_Type("bool", false);
+const Type kBVec2_Type("bvec2", kBool_Type, 2);
+const Type kBVec3_Type("bvec3", kBool_Type, 3);
+const Type kBVec4_Type("bvec4", kBool_Type, 4);
+
+const Type kMat2x2_Type("mat2", kFloat_Type, 2, 2);
+const Type kMat2x3_Type("mat2x3", kFloat_Type, 2, 3);
+const Type kMat2x4_Type("mat2x4", kFloat_Type, 2, 4);
+const Type kMat3x2_Type("mat3x2", kFloat_Type, 3, 2);
+const Type kMat3x3_Type("mat3", kFloat_Type, 3, 3);
+const Type kMat3x4_Type("mat3x4", kFloat_Type, 3, 4);
+const Type kMat4x2_Type("mat4x2", kFloat_Type, 4, 2);
+const Type kMat4x3_Type("mat4x3", kFloat_Type, 4, 3);
+const Type kMat4x4_Type("mat4", kFloat_Type, 4, 4);
+
+const Type kDMat2x2_Type("dmat2", kFloat_Type, 2, 2);
+const Type kDMat2x3_Type("dmat2x3", kFloat_Type, 2, 3);
+const Type kDMat2x4_Type("dmat2x4", kFloat_Type, 2, 4);
+const Type kDMat3x2_Type("dmat3x2", kFloat_Type, 3, 2);
+const Type kDMat3x3_Type("dmat3", kFloat_Type, 3, 3);
+const Type kDMat3x4_Type("dmat3x4", kFloat_Type, 3, 4);
+const Type kDMat4x2_Type("dmat4x2", kFloat_Type, 4, 2);
+const Type kDMat4x3_Type("dmat4x3", kFloat_Type, 4, 3);
+const Type kDMat4x4_Type("dmat4", kFloat_Type, 4, 4);
+
+const Type kSampler1D_Type("sampler1D", SpvDim1D, false, false, false, true);
+const Type kSampler2D_Type("sampler2D", SpvDim2D, false, false, false, true);
+const Type kSampler3D_Type("sampler3D", SpvDim3D, false, false, false, true);
+const Type kSamplerCube_Type("samplerCube");
+const Type kSampler2DRect_Type("sampler2DRect");
+const Type kSampler1DArray_Type("sampler1DArray");
+const Type kSampler2DArray_Type("sampler2DArray");
+const Type kSamplerCubeArray_Type("samplerCubeArray");
+const Type kSamplerBuffer_Type("samplerBuffer");
+const Type kSampler2DMS_Type("sampler2DMS");
+const Type kSampler2DMSArray_Type("sampler2DMSArray");
+const Type kSampler1DShadow_Type("sampler1DShadow");
+const Type kSampler2DShadow_Type("sampler2DShadow");
+const Type kSamplerCubeShadow_Type("samplerCubeShadow");
+const Type kSampler2DRectShadow_Type("sampler2DRectShadow");
+const Type kSampler1DArrayShadow_Type("sampler1DArrayShadow");
+const Type kSampler2DArrayShadow_Type("sampler2DArrayShadow");
+const Type kSamplerCubeArrayShadow_Type("samplerCubeArrayShadow");
+
+static std::vector<const Type*> type(const Type& t) {
+ return { &t, &t, &t, &t };
}
// FIXME figure out what we're supposed to do with the gsampler et al. types
-const std::shared_ptr<Type> kGSampler1D_Type(new Type("$gsampler1D", type(kSampler1D_Type)));
-const std::shared_ptr<Type> kGSampler2D_Type(new Type("$gsampler2D", type(kSampler2D_Type)));
-const std::shared_ptr<Type> kGSampler3D_Type(new Type("$gsampler3D", type(kSampler3D_Type)));
-const std::shared_ptr<Type> kGSamplerCube_Type(new Type("$gsamplerCube", type(kSamplerCube_Type)));
-const std::shared_ptr<Type> kGSampler2DRect_Type(new Type("$gsampler2DRect",
- type(kSampler2DRect_Type)));
-const std::shared_ptr<Type> kGSampler1DArray_Type(new Type("$gsampler1DArray",
- type(kSampler1DArray_Type)));
-const std::shared_ptr<Type> kGSampler2DArray_Type(new Type("$gsampler2DArray",
- type(kSampler2DArray_Type)));
-const std::shared_ptr<Type> kGSamplerCubeArray_Type(new Type("$gsamplerCubeArray",
- type(kSamplerCubeArray_Type)));
-const std::shared_ptr<Type> kGSamplerBuffer_Type(new Type("$gsamplerBuffer",
- type(kSamplerBuffer_Type)));
-const std::shared_ptr<Type> kGSampler2DMS_Type(new Type("$gsampler2DMS",
- type(kSampler2DMS_Type)));
-const std::shared_ptr<Type> kGSampler2DMSArray_Type(new Type("$gsampler2DMSArray",
- type(kSampler2DMSArray_Type)));
-const std::shared_ptr<Type> kGSampler2DArrayShadow_Type(new Type("$gsampler2DArrayShadow",
- type(kSampler2DArrayShadow_Type)));
-const std::shared_ptr<Type> kGSamplerCubeArrayShadow_Type(new Type("$gsamplerCubeArrayShadow",
- type(kSamplerCubeArrayShadow_Type)));
-
-const std::shared_ptr<Type> kGenType_Type(new Type("$genType", { kFloat_Type, kVec2_Type,
- kVec3_Type, kVec4_Type }));
-const std::shared_ptr<Type> kGenDType_Type(new Type("$genDType", { kDouble_Type, kDVec2_Type,
- kDVec3_Type, kDVec4_Type }));
-const std::shared_ptr<Type> kGenIType_Type(new Type("$genIType", { kInt_Type, kIVec2_Type,
- kIVec3_Type, kIVec4_Type }));
-const std::shared_ptr<Type> kGenUType_Type(new Type("$genUType", { kUInt_Type, kUVec2_Type,
- kUVec3_Type, kUVec4_Type }));
-const std::shared_ptr<Type> kGenBType_Type(new Type("$genBType", { kBool_Type, kBVec2_Type,
- kBVec3_Type, kBVec4_Type }));
-
-const std::shared_ptr<Type> kMat_Type(new Type("$mat"));
-
-const std::shared_ptr<Type> kVec_Type(new Type("$vec", { kVec2_Type, kVec2_Type, kVec3_Type,
- kVec4_Type }));
-
-const std::shared_ptr<Type> kGVec_Type(new Type("$gvec"));
-const std::shared_ptr<Type> kGVec2_Type(new Type("$gvec2"));
-const std::shared_ptr<Type> kGVec3_Type(new Type("$gvec3"));
-const std::shared_ptr<Type> kGVec4_Type(new Type("$gvec4", type(kVec4_Type)));
-const std::shared_ptr<Type> kDVec_Type(new Type("$dvec"));
-const std::shared_ptr<Type> kIVec_Type(new Type("$ivec"));
-const std::shared_ptr<Type> kUVec_Type(new Type("$uvec"));
-
-const std::shared_ptr<Type> kBVec_Type(new Type("$bvec", { kBVec2_Type, kBVec2_Type,
- kBVec3_Type, kBVec4_Type }));
-
-const std::shared_ptr<Type> kInvalid_Type(new Type("<INVALID>"));
+const Type kGSampler1D_Type("$gsampler1D", type(kSampler1D_Type));
+const Type kGSampler2D_Type("$gsampler2D", type(kSampler2D_Type));
+const Type kGSampler3D_Type("$gsampler3D", type(kSampler3D_Type));
+const Type kGSamplerCube_Type("$gsamplerCube", type(kSamplerCube_Type));
+const Type kGSampler2DRect_Type("$gsampler2DRect", type(kSampler2DRect_Type));
+const Type kGSampler1DArray_Type("$gsampler1DArray", type(kSampler1DArray_Type));
+const Type kGSampler2DArray_Type("$gsampler2DArray", type(kSampler2DArray_Type));
+const Type kGSamplerCubeArray_Type("$gsamplerCubeArray", type(kSamplerCubeArray_Type));
+const Type kGSamplerBuffer_Type("$gsamplerBuffer", type(kSamplerBuffer_Type));
+const Type kGSampler2DMS_Type("$gsampler2DMS", type(kSampler2DMS_Type));
+const Type kGSampler2DMSArray_Type("$gsampler2DMSArray", type(kSampler2DMSArray_Type));
+const Type kGSampler2DArrayShadow_Type("$gsampler2DArrayShadow", type(kSampler2DArrayShadow_Type));
+const Type kGSamplerCubeArrayShadow_Type("$gsamplerCubeArrayShadow",
+ type(kSamplerCubeArrayShadow_Type));
+
+const Type kGenType_Type("$genType", { &kFloat_Type, &kVec2_Type, &kVec3_Type, &kVec4_Type });
+const Type kGenDType_Type("$genDType", { &kDouble_Type, &kDVec2_Type, &kDVec3_Type, &kDVec4_Type });
+const Type kGenIType_Type("$genIType", { &kInt_Type, &kIVec2_Type, &kIVec3_Type, &kIVec4_Type });
+const Type kGenUType_Type("$genUType", { &kUInt_Type, &kUVec2_Type, &kUVec3_Type, &kUVec4_Type });
+const Type kGenBType_Type("$genBType", { &kBool_Type, &kBVec2_Type, &kBVec3_Type, &kBVec4_Type });
+
+const Type kMat_Type("$mat");
+
+const Type kVec_Type("$vec", { &kVec2_Type, &kVec2_Type, &kVec3_Type, &kVec4_Type });
+
+const Type kGVec_Type("$gvec");
+const Type kGVec2_Type("$gvec2");
+const Type kGVec3_Type("$gvec3");
+const Type kGVec4_Type("$gvec4", type(kVec4_Type));
+const Type kDVec_Type("$dvec");
+const Type kIVec_Type("$ivec");
+const Type kUVec_Type("$uvec");
+
+const Type kBVec_Type("$bvec", { &kBVec2_Type, &kBVec2_Type, &kBVec3_Type, &kBVec4_Type });
+
+const Type kInvalid_Type("<INVALID>");
} // namespace

Powered by Google App Engine
This is Rietveld 408576698