diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index a98ab53e0d..f9aa2d7bd4 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -398,6 +398,7 @@ sksl_folding_tests = [ sksl_inliner_tests = [ "$_tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl", "$_tests/sksl/inliner/DoWhileTestCannotBeInlined.sksl", + "$_tests/sksl/inliner/EnumsCanBeInlinedSafely.sksl", "$_tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl", "$_tests/sksl/inliner/ForInitializerExpressionsCanBeInlined.sksl", "$_tests/sksl/inliner/ForWithReturnInsideCannotBeInlined.sksl", @@ -423,6 +424,7 @@ sksl_inliner_tests = [ "$_tests/sksl/inliner/InlinerWrapsEarlyReturnsWithForLoop.sksl", "$_tests/sksl/inliner/InlinerWrapsSwitchWithReturnInsideWithForLoop.sksl", "$_tests/sksl/inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl", + "$_tests/sksl/inliner/StructsCanBeInlinedSafely.sksl", "$_tests/sksl/inliner/SwitchWithCastCanBeInlined.sksl", "$_tests/sksl/inliner/SwitchWithoutReturnInsideCanBeInlined.sksl", "$_tests/sksl/inliner/SwizzleCanBeInlinedDirectly.sksl", diff --git a/src/sksl/ir/SkSLType.cpp b/src/sksl/ir/SkSLType.cpp index 41dcaee507..2824e2a586 100644 --- a/src/sksl/ir/SkSLType.cpp +++ b/src/sksl/ir/SkSLType.cpp @@ -229,8 +229,12 @@ const Type* Type::clone(SymbolTable* symbolTable) const { this->columns())); case TypeKind::kStruct: + return symbolTable->add(Type::MakeStructType(this->fOffset, this->name(), + this->fields())); + case TypeKind::kEnum: - // TODO: implement Type cloning for structs and enums. + return symbolTable->add(Type::MakeEnumType(this->name())); + default: SkDEBUGFAILF("don't know how to clone type '%s'", this->description().c_str()); return nullptr; diff --git a/tests/sksl/inliner/EnumsCanBeInlinedSafely.sksl b/tests/sksl/inliner/EnumsCanBeInlinedSafely.sksl new file mode 100644 index 0000000000..b53c82eef4 --- /dev/null +++ b/tests/sksl/inliner/EnumsCanBeInlinedSafely.sksl @@ -0,0 +1,21 @@ +half4 helper(); + +void main() { + sk_FragColor = helper(); +} + +enum class E { + kBlack = 0, + kGray = 1, + kWhite = 2 +}; + +half4 helper() { + E temp = E::kGray; + switch (temp) { + case E::kBlack: return half4(0, 0, 0, 1); + case E::kGray: return half4(0.5, 0.5, 0.5, 1); + case E::kWhite: return half4(1); + default: return half4(1, 0, 0, 1); + } +} diff --git a/tests/sksl/inliner/StructsCanBeInlinedSafely.sksl b/tests/sksl/inliner/StructsCanBeInlinedSafely.sksl new file mode 100644 index 0000000000..a550ebfaba --- /dev/null +++ b/tests/sksl/inliner/StructsCanBeInlinedSafely.sksl @@ -0,0 +1,21 @@ +half4 helper(); + +void main() { + sk_FragColor = helper(); +} + +struct Color { + half red; + half green; + half blue; + half alpha; +}; + +half4 helper() { + Color c; + c.red = 0.25; + c.green = 0.5; + c.blue = 0.75; + c.alpha = 1.0; + return half4(c.red, c.green, c.blue, c.alpha); +} diff --git a/tests/sksl/inliner/golden/EnumsCanBeInlinedSafely.glsl b/tests/sksl/inliner/golden/EnumsCanBeInlinedSafely.glsl new file mode 100644 index 0000000000..cc423dce45 --- /dev/null +++ b/tests/sksl/inliner/golden/EnumsCanBeInlinedSafely.glsl @@ -0,0 +1,14 @@ + +out vec4 sk_FragColor; +vec4 helper(); +void main() { + for (int _1_loop = 0;_1_loop < 1; _1_loop++) { + { + { + continue; + } + } + } + sk_FragColor = vec4(0.5, 0.5, 0.5, 1.0); + +} diff --git a/tests/sksl/inliner/golden/StructsCanBeInlinedSafely.glsl b/tests/sksl/inliner/golden/StructsCanBeInlinedSafely.glsl new file mode 100644 index 0000000000..215f38a5b2 --- /dev/null +++ b/tests/sksl/inliner/golden/StructsCanBeInlinedSafely.glsl @@ -0,0 +1,17 @@ + +out vec4 sk_FragColor; +vec4 helper(); +void main() { + struct Color { + float red; + float green; + float blue; + float alpha; + } _1_c; + _1_c.red = 0.25; + _1_c.green = 0.5; + _1_c.blue = 0.75; + _1_c.alpha = 1.0; + sk_FragColor = vec4(_1_c.red, _1_c.green, _1_c.blue, _1_c.alpha); + +}