From 9080540b93ef65957e63ef157d92ae141f469f81 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Wed, 16 Sep 2020 15:32:21 -0400 Subject: [PATCH] Convert additional GLSL tests to use golden files. A handful of simplifications were made, but these hew very close to the original tests and are intended to cover the exact same ground. The remaining unconverted tests depend on non-default caps bits and will be updated once caps handling in skslc is fully landed. Change-Id: I3f3c29bf87f73e501561d7bfcdaabe8acc14b89f Bug: skia:10694 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317390 Commit-Queue: John Stiles Commit-Queue: Ethan Nicholas Auto-Submit: John Stiles Reviewed-by: Ethan Nicholas --- gn/sksl_tests.gni | 15 + tests/SkSLGLSLTest.cpp | 394 ------------------ tests/sksl/glsl/Caps.sksl | 9 + tests/sksl/glsl/CastsRoundTowardZero.sksl | 11 + tests/sksl/glsl/Discard.sksl | 8 + tests/sksl/glsl/FrExp.sksl | 5 + tests/sksl/glsl/Height.sksl | 3 + tests/sksl/glsl/ModifiersDeclaration.sksl | 18 + tests/sksl/glsl/NegatedVectorLiteral.sksl | 6 + tests/sksl/glsl/NumberConversions.sksl | 43 ++ tests/sksl/glsl/RectangleTexture.sksl | 8 + tests/sksl/glsl/StackingVectorCasts.sksl | 6 + tests/sksl/glsl/SwizzleLTRB.sksl | 3 + .../glsl/TernaryAsLValueEntirelyFoldable.sksl | 6 + .../glsl/TernaryAsLValueFoldableTest.sksl | 6 + .../sksl/glsl/TernaryAsLValueUnfoldable.sksl | 6 + tests/sksl/glsl/Width.sksl | 3 + tests/sksl/glsl/golden/Caps.glsl | 5 + .../glsl/golden/CastsRoundTowardZero.glsl | 6 + tests/sksl/glsl/golden/Discard.glsl | 6 + tests/sksl/glsl/golden/FrExp.glsl | 7 + tests/sksl/glsl/golden/Height.glsl | 6 + .../glsl/golden/ModifiersDeclaration.glsl | 20 + .../glsl/golden/NegatedVectorLiteral.glsl | 5 + tests/sksl/glsl/golden/NumberConversions.glsl | 42 ++ tests/sksl/glsl/golden/RectangleTexture.glsl | 9 + .../sksl/glsl/golden/StackingVectorCasts.glsl | 5 + tests/sksl/glsl/golden/SwizzleLTRB.glsl | 5 + .../TernaryAsLValueEntirelyFoldable.glsl | 5 + .../golden/TernaryAsLValueFoldableTest.glsl | 8 + .../golden/TernaryAsLValueUnfoldable.glsl | 8 + tests/sksl/glsl/golden/Width.glsl | 6 + 32 files changed, 299 insertions(+), 394 deletions(-) create mode 100644 tests/sksl/glsl/Caps.sksl create mode 100644 tests/sksl/glsl/CastsRoundTowardZero.sksl create mode 100644 tests/sksl/glsl/Discard.sksl create mode 100644 tests/sksl/glsl/FrExp.sksl create mode 100644 tests/sksl/glsl/Height.sksl create mode 100644 tests/sksl/glsl/ModifiersDeclaration.sksl create mode 100644 tests/sksl/glsl/NegatedVectorLiteral.sksl create mode 100644 tests/sksl/glsl/NumberConversions.sksl create mode 100644 tests/sksl/glsl/RectangleTexture.sksl create mode 100644 tests/sksl/glsl/StackingVectorCasts.sksl create mode 100644 tests/sksl/glsl/SwizzleLTRB.sksl create mode 100644 tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl create mode 100644 tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl create mode 100644 tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl create mode 100644 tests/sksl/glsl/Width.sksl create mode 100644 tests/sksl/glsl/golden/Caps.glsl create mode 100644 tests/sksl/glsl/golden/CastsRoundTowardZero.glsl create mode 100644 tests/sksl/glsl/golden/Discard.glsl create mode 100644 tests/sksl/glsl/golden/FrExp.glsl create mode 100644 tests/sksl/glsl/golden/Height.glsl create mode 100644 tests/sksl/glsl/golden/ModifiersDeclaration.glsl create mode 100644 tests/sksl/glsl/golden/NegatedVectorLiteral.glsl create mode 100644 tests/sksl/glsl/golden/NumberConversions.glsl create mode 100644 tests/sksl/glsl/golden/RectangleTexture.glsl create mode 100644 tests/sksl/glsl/golden/StackingVectorCasts.glsl create mode 100644 tests/sksl/glsl/golden/SwizzleLTRB.glsl create mode 100644 tests/sksl/glsl/golden/TernaryAsLValueEntirelyFoldable.glsl create mode 100644 tests/sksl/glsl/golden/TernaryAsLValueFoldableTest.glsl create mode 100644 tests/sksl/glsl/golden/TernaryAsLValueUnfoldable.glsl create mode 100644 tests/sksl/glsl/golden/Width.glsl diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index c42e86ca6a..d822dc33c7 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -18,6 +18,8 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/ArrayIndexTypes.sksl", "$_tests/sksl/glsl/ArrayTypes.sksl", "$_tests/sksl/glsl/BoolFolding.sksl", + "$_tests/sksl/glsl/Caps.sksl", + "$_tests/sksl/glsl/CastsRoundTowardZero.sksl", "$_tests/sksl/glsl/ClipDistanceFragment.sksl", "$_tests/sksl/glsl/ClipDistanceVertex.vert", "$_tests/sksl/glsl/Clockwise.sksl", @@ -27,8 +29,11 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/Control.sksl", "$_tests/sksl/glsl/DeadLoopVariable.sksl", "$_tests/sksl/glsl/DependentInitializers.sksl", + "$_tests/sksl/glsl/Discard.sksl", "$_tests/sksl/glsl/FloatFolding.sksl", + "$_tests/sksl/glsl/FrExp.sksl", "$_tests/sksl/glsl/Functions.sksl", + "$_tests/sksl/glsl/Height.sksl", "$_tests/sksl/glsl/HelloWorld.sksl", "$_tests/sksl/glsl/Hex.sksl", "$_tests/sksl/glsl/InstanceID.vert", @@ -38,11 +43,16 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/InterfaceBlockNamed.sksl", "$_tests/sksl/glsl/Matrices.sksl", "$_tests/sksl/glsl/MatrixFolding.sksl", + "$_tests/sksl/glsl/ModifiersDeclaration.sksl", "$_tests/sksl/glsl/MultipleAssignments.sksl", + "$_tests/sksl/glsl/NegatedVectorLiteral.sksl", + "$_tests/sksl/glsl/NumberConversions.sksl", "$_tests/sksl/glsl/Offset.sksl", "$_tests/sksl/glsl/Operators.sksl", + "$_tests/sksl/glsl/RectangleTexture.sksl", "$_tests/sksl/glsl/SampleMask.sksl", "$_tests/sksl/glsl/ShortCircuitBoolFolding.sksl", + "$_tests/sksl/glsl/StackingVectorCasts.sksl", "$_tests/sksl/glsl/StaticSwitchWithBreak.sksl", "$_tests/sksl/glsl/StaticSwitchWithBreakInsideBlock.sksl", "$_tests/sksl/glsl/StaticSwitchWithConditionalBreak.sksl", @@ -56,12 +66,17 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/SwitchContainingDeadCode.sksl", "$_tests/sksl/glsl/SwitchWithFallthrough.sksl", "$_tests/sksl/glsl/SwizzleConstants.sksl", + "$_tests/sksl/glsl/SwizzleLTRB.sksl", "$_tests/sksl/glsl/SwizzleOpt.sksl", "$_tests/sksl/glsl/SwizzleScalar.sksl", + "$_tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl", + "$_tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl", + "$_tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl", "$_tests/sksl/glsl/UnusedVariables.sksl", "$_tests/sksl/glsl/VectorConstructors.sksl", "$_tests/sksl/glsl/VectorFolding.sksl", "$_tests/sksl/glsl/VertexID.vert", + "$_tests/sksl/glsl/Width.sksl", "$_tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl", "$_tests/sksl/inliner/DoWhileTestCannotBeInlined.sksl", "$_tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl", diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index d66322bedd..2a4548d704 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -173,49 +173,6 @@ DEF_TEST(SkSLNegatedAtan, r) { "}\n"); } -DEF_TEST(SkSLModifiersDeclaration, r) { - test(r, - "layout(blend_support_all_equations) out;" - "layout(blend_support_all_equations) out;" - "layout(blend_support_multiply) out;" - "layout(blend_support_screen) out;" - "layout(blend_support_overlay) out;" - "layout(blend_support_darken) out;" - "layout(blend_support_lighten) out;" - "layout(blend_support_colordodge) out;" - "layout(blend_support_colorburn) out;" - "layout(blend_support_hardlight) out;" - "layout(blend_support_softlight) out;" - "layout(blend_support_difference) out;" - "layout(blend_support_exclusion) out;" - "layout(blend_support_hsl_hue) out;" - "layout(blend_support_hsl_saturation) out;" - "layout(blend_support_hsl_color) out;" - "layout(blend_support_hsl_luminosity) out;" - "void main() { }", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "layout (blend_support_all_equations) out ;\n" - "layout (blend_support_all_equations) out ;\n" - "layout (blend_support_multiply) out ;\n" - "layout (blend_support_screen) out ;\n" - "layout (blend_support_overlay) out ;\n" - "layout (blend_support_darken) out ;\n" - "layout (blend_support_lighten) out ;\n" - "layout (blend_support_colordodge) out ;\n" - "layout (blend_support_colorburn) out ;\n" - "layout (blend_support_hardlight) out ;\n" - "layout (blend_support_softlight) out ;\n" - "layout (blend_support_difference) out ;\n" - "layout (blend_support_exclusion) out ;\n" - "layout (blend_support_hsl_hue) out ;\n" - "layout (blend_support_hsl_saturation) out ;\n" - "layout (blend_support_hsl_color) out ;\n" - "layout (blend_support_hsl_luminosity) out ;\n" - "void main() {\n" - "}\n"); -} - DEF_TEST(SkSLDerivatives, r) { test(r, "void main() { sk_FragColor.r = half(dFdx(1)); }", @@ -273,25 +230,6 @@ DEF_TEST(SkSLDerivatives, r) { &inputs); } -DEF_TEST(SkSLCaps, r) { - test(r, - "void main() {" - "int x = 0;" - "int y = 0;" - "int z = 0;" - "if (sk_Caps.externalTextureSupport) x = 1;" - "if (sk_Caps.fbFetchSupport) y = 1;" - "if (sk_Caps.canUseAnyFunctionInShader) z = 1;" - "sk_FragColor = half4(x, y, z, 0.0);" - "}", - *SkSL::ShaderCapsFactory::VariousCaps(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(1.0, 0.0, 0.0, 0.0);\n" - "}\n"); -} - DEF_TEST(SkSLTexture, r) { test(r, "uniform sampler1D one;" @@ -494,38 +432,6 @@ DEF_TEST(SkSLFragCoord, r) { "}\n"); } -DEF_TEST(SkSLWidthAndHeight, r) { - SkSL::Program::Settings settings; - sk_sp caps = SkSL::ShaderCapsFactory::Default(); - settings.fCaps = caps.get(); - SkSL::Program::Inputs inputs; - test(r, - "void main() { sk_FragColor.r = half(sk_FragCoord.x / sk_Width); }", - settings, - "#version 400\n" - "uniform float u_skRTWidth;\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor.x = gl_FragCoord.x / u_skRTWidth;\n" - "}\n", - &inputs); - REPORTER_ASSERT(r, inputs.fRTWidth); - REPORTER_ASSERT(r, !inputs.fRTHeight); - - test(r, - "void main() { sk_FragColor.r = half(sk_FragCoord.y / sk_Height); }", - settings, - "#version 400\n" - "uniform float u_skRTHeight;\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor.x = gl_FragCoord.y / u_skRTHeight;\n" - "}\n", - &inputs); - REPORTER_ASSERT(r, !inputs.fRTWidth); - REPORTER_ASSERT(r, inputs.fRTHeight); -} - DEF_TEST(SkSLGeometry, r) { test(r, "layout(points) in;" @@ -553,45 +459,6 @@ DEF_TEST(SkSLGeometry, r) { SkSL::Program::kGeometry_Kind); } -DEF_TEST(SkSLRectangleTexture, r) { - test(r, - "uniform sampler2D test;" - "void main() {" - " sk_FragColor = sample(test, float2(0.5));" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "uniform sampler2D test;\n" - "void main() {\n" - " sk_FragColor = texture(test, vec2(0.5));\n" - "}\n"); - test(r, - "uniform sampler2DRect test;" - "void main() {" - " sk_FragColor = sample(test, float2(0.5));" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "uniform sampler2DRect test;\n" - "void main() {\n" - " sk_FragColor = texture(test, vec2(0.5));\n" - "}\n"); - test(r, - "uniform sampler2DRect test;" - "void main() {" - " sk_FragColor = sample(test, float3(0.5));" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "uniform sampler2DRect test;\n" - "void main() {\n" - " sk_FragColor = texture(test, vec3(0.5));\n" - "}\n"); -} - DEF_TEST(SkSLGeometryShaders, r) { test(r, "layout(points) in;" @@ -730,101 +597,6 @@ DEF_TEST(SkSLTypePrecision, r) { "}\n"); } -DEF_TEST(SkSLNumberConversions, r) { - test(r, - "short s = short(sqrt(1));" - "int i = int(sqrt(1));" - "ushort us = ushort(sqrt(1));" - "uint ui = uint(sqrt(1));" - "half h = half(sqrt(1));" - "float f = sqrt(1);" - "short s2s = s;" - "short i2s = short(i);" - "short us2s = short(us);" - "short ui2s = short(ui);" - "short h2s = short(h);" - "short f2s = short(f);" - "int s2i = s;" - "int i2i = i;" - "int us2i = int(us);" - "int ui2i = int(ui);" - "int h2i = int(h);" - "int f2i = int(f);" - "ushort s2us = ushort(s);" - "ushort i2us = ushort(i);" - "ushort us2us = us;" - "ushort ui2us = ushort(ui);" - "ushort h2us = ushort(h);" - "ushort f2us = ushort(f);" - "uint s2ui = uint(s);" - "uint i2ui = uint(i);" - "uint us2ui = us;" - "uint ui2ui = ui;" - "uint h2ui = uint(h);" - "uint f2ui = uint(f);" - "float s2f = s;" - "float i2f = i;" - "float us2f = us;" - "float ui2f = ui;" - "float h2f = h;" - "float f2f = f;" - "void main() {" - "sk_FragColor.r = half(s + i + us + half(ui) + h + f + s2s + i2s + us2s + ui2s + h2s + " - "f2s + s2i + i2i + us2i + ui2i + h2i + f2i + s2us + i2us + us2us);" - "sk_FragColor.r += half(ui2us + h2us + f2us + half(s2ui) + half(i2ui) + half(us2ui) + " - "half(ui2ui) + half(h2ui) + half(f2ui) + s2f + i2f + us2f + ui2f + " - "h2f + f2f);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "int s = int(sqrt(1.0));\n" - "int i = int(sqrt(1.0));\n" - "uint us = uint(sqrt(1.0));\n" - "uint ui = uint(sqrt(1.0));\n" - "float h = sqrt(1.0);\n" - "float f = sqrt(1.0);\n" - "int s2s = s;\n" - "int i2s = i;\n" - "int us2s = int(us);\n" - "int ui2s = int(ui);\n" - "int h2s = int(h);\n" - "int f2s = int(f);\n" - "int s2i = s;\n" - "int i2i = i;\n" - "int us2i = int(us);\n" - "int ui2i = int(ui);\n" - "int h2i = int(h);\n" - "int f2i = int(f);\n" - "uint s2us = uint(s);\n" - "uint i2us = uint(i);\n" - "uint us2us = us;\n" - "uint ui2us = ui;\n" - "uint h2us = uint(h);\n" - "uint f2us = uint(f);\n" - "uint s2ui = uint(s);\n" - "uint i2ui = uint(i);\n" - "uint us2ui = us;\n" - "uint ui2ui = ui;\n" - "uint h2ui = uint(h);\n" - "uint f2ui = uint(f);\n" - "float s2f = float(s);\n" - "float i2f = float(i);\n" - "float us2f = float(us);\n" - "float ui2f = float(ui);\n" - "float h2f = h;\n" - "float f2f = f;\n" - "void main() {\n" - " sk_FragColor.x = (((((((((((((((((float((s + i) + int(us)) + float(ui)) + h) + f) + " - "float(s2s)) + float(i2s)) + float(us2s)) + float(ui2s)) + float(h2s)) + float(f2s)) + " - "float(s2i)) + float(i2i)) + float(us2i)) + float(ui2i)) + float(h2i)) + float(f2i)) + " - "float(s2us)) + float(i2us)) + float(us2us);\n" - " sk_FragColor.x += (((((((((((float((ui2us + h2us) + f2us) + float(s2ui)) + " - "float(i2ui)) + float(us2ui)) + float(ui2ui)) + float(h2ui)) + float(f2ui)) + s2f) + " - "i2f) + us2f) + ui2f) + h2f) + f2f;\n" - "}\n"); -} - DEF_TEST(SkSLForceHighPrecision, r) { test(r, "void main() {\n half x = half(sqrt(1));\n half4 y = half4(x);\n sk_FragColor = y;\n }", @@ -906,46 +678,6 @@ DEF_TEST(SkSLNormalization, r) { SkSL::Program::kGeometry_Kind); } -DEF_TEST(SkSLTernaryLValue, r) { - test(r, - "void main() { int r, g; (true ? r : g) = 1; (false ? r : g) = 0; " - "sk_FragColor = half4(r, g, 1, 1); }", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(1.0, 0.0, 1.0, 1.0);\n" - "}\n"); - test(r, - "void main() { half r, g; (true ? r : g) = half(sqrt(1)); (false ? r : g) = half(sqrt(0));" - "sk_FragColor = half4(r, g, 1, 1); }", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " float r, g;\n" - " r = sqrt(1.0);\n" - " g = sqrt(0.0);\n" - " sk_FragColor = vec4(r, g, 1.0, 1.0);\n" - "}\n"); - test(r, - "void main() {" - "half r, g;" - "(sqrt(1) > 0 ? r : g) = half(sqrt(1));" - "(sqrt(0) > 0 ? r : g) = half(sqrt(0));" - "sk_FragColor = half4(r, g, 1, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " float r, g;\n" - " sqrt(1.0) > 0.0 ? r : g = sqrt(1.0);\n" - " sqrt(0.0) > 0.0 ? r : g = sqrt(0.0);\n" - " sk_FragColor = vec4(r, g, 1.0, 1.0);\n" - "}\n"); -} - DEF_TEST(SkSLIncompleteShortIntPrecision, r) { test(r, "uniform sampler2D tex;" @@ -991,23 +723,6 @@ DEF_TEST(SkSLIncompleteShortIntPrecision, r) { SkSL::Program::kFragment_Kind); } -DEF_TEST(SkSLFrExp, r) { - test(r, - "void main() {" - " int exp;" - " float foo = frexp(0.5, exp);" - " sk_FragColor = half4(exp);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " int exp;\n" - " float foo = frexp(0.5, exp);\n" - " sk_FragColor = vec4(float(exp));\n" - "}\n"); -} - DEF_TEST(SkSLWorkaroundAddAndTrueToLoopCondition, r) { test(r, "void main() {" @@ -1156,112 +871,3 @@ DEF_TEST(SkSLWorkaroundRemovePowWithConstantExponent, r) { SkSL::Program::kFragment_Kind ); } - -DEF_TEST(SkSLSwizzleLTRB, r) { - test(r, - "void main() {" - " sk_FragColor = sk_FragColor.BRTL;" - "}", - *SkSL::ShaderCapsFactory::RemovePowWithConstantExponent(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = sk_FragColor.wzyx;\n" - "}\n", - SkSL::Program::kFragment_Kind - ); -} - -DEF_TEST(SkSLStackingVectorCasts, r) { - test(r, - "void main() {" - " if (half4(0, 0, 1, 1) == half4(int4(0, 0, 1, 1)))" - " sk_FragColor = half4(0, 1, 0, 1);" - " else" - " sk_FragColor = half4(1, 0, 0, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - "}\n"); - test(r, - "void main() {" - " if (half4(int4(0, 0, 1, 1)) == half4(int4(half4(0, 0, 1, 1))))" - " sk_FragColor = half4(0, 1, 0, 1);" - " else" - " sk_FragColor = half4(1, 0, 0, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - "}\n"); -} - -DEF_TEST(SkSLCastsRoundTowardZero, r) { - test(r, - "void main() {" - " if (half4(int4(0, 0, 1, 2)) == half4(int4(half4(0.01, 0.99, 1.49, 2.75))))" - " sk_FragColor = half4(0, 1, 0, 1);" - " else" - " sk_FragColor = half4(1, 0, 0, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - "}\n"); - test(r, - "void main() {" - " if (half4(int4(0, 0, -1, -2)) == half4(int4(half4(-0.01, -0.99, -1.49, -2.75))))" - " sk_FragColor = half4(0, 1, 0, 1);" - " else" - " sk_FragColor = half4(1, 0, 0, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - "}\n"); -} - -DEF_TEST(SkSLNegatedVectorLiteral, r) { - test(r, - "void main() {" - " if (half4(1) == half4(-half2(-1), half2(1)))" - " sk_FragColor = half4(0, 1, 0, 1);" - " else" - " sk_FragColor = half4(1, 0, 0, 1);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " sk_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n" - "}\n"); -} - -DEF_TEST(SkSLDiscard, r) { - test(r, - "void main() {" - "half x;" - " @switch (1) {" - " case 0: x = 0; break;" - " default: x = 1; discard;" - " }" - " sk_FragColor = half4(x);" - "}", - *SkSL::ShaderCapsFactory::Default(), - R"__GLSL__(#version 400 -void main() { - { - discard; - } -} -)__GLSL__"); -} diff --git a/tests/sksl/glsl/Caps.sksl b/tests/sksl/glsl/Caps.sksl new file mode 100644 index 0000000000..10c9a13871 --- /dev/null +++ b/tests/sksl/glsl/Caps.sksl @@ -0,0 +1,9 @@ +void main() { + int x = 0; + int y = 0; + int z = 0; + if (sk_Caps.externalTextureSupport) x = 1; + if (sk_Caps.fbFetchSupport) y = 1; + if (sk_Caps.canUseAnyFunctionInShader) z = 1; + sk_FragColor.rgb = half3(x, y, z); +} diff --git a/tests/sksl/glsl/CastsRoundTowardZero.sksl b/tests/sksl/glsl/CastsRoundTowardZero.sksl new file mode 100644 index 0000000000..ac90eb6655 --- /dev/null +++ b/tests/sksl/glsl/CastsRoundTowardZero.sksl @@ -0,0 +1,11 @@ +void main() { + if (half4(int4(0, 0, 1, 2)) == half4(int4(half4(0.01, 0.99, 1.49, 2.75)))) + sk_FragColor = half4(1); + else + sk_FragColor = half4(-1); + + if (half4(int4(0, 0, -1, -2)) == half4(int4(half4(-0.01, -0.99, -1.49, -2.75)))) + sk_FragColor = half4(2); + else + sk_FragColor = half4(-2); +} diff --git a/tests/sksl/glsl/Discard.sksl b/tests/sksl/glsl/Discard.sksl new file mode 100644 index 0000000000..331c36c6be --- /dev/null +++ b/tests/sksl/glsl/Discard.sksl @@ -0,0 +1,8 @@ +void main() { +half x; + @switch (1) { + case 0: x = 0; break; + default: x = 1; discard; + } + sk_FragColor = half4(x); +} diff --git a/tests/sksl/glsl/FrExp.sksl b/tests/sksl/glsl/FrExp.sksl new file mode 100644 index 0000000000..5310b5e672 --- /dev/null +++ b/tests/sksl/glsl/FrExp.sksl @@ -0,0 +1,5 @@ +void main() { + int exp; + float foo = frexp(0.5, exp); + sk_FragColor = half4(exp); +} diff --git a/tests/sksl/glsl/Height.sksl b/tests/sksl/glsl/Height.sksl new file mode 100644 index 0000000000..45507c923f --- /dev/null +++ b/tests/sksl/glsl/Height.sksl @@ -0,0 +1,3 @@ +void main() { + sk_FragColor.r = half(sk_FragCoord.y / sk_Height); +} diff --git a/tests/sksl/glsl/ModifiersDeclaration.sksl b/tests/sksl/glsl/ModifiersDeclaration.sksl new file mode 100644 index 0000000000..13173e355e --- /dev/null +++ b/tests/sksl/glsl/ModifiersDeclaration.sksl @@ -0,0 +1,18 @@ +layout(blend_support_all_equations) out; +layout(blend_support_all_equations) out; +layout(blend_support_multiply) out; +layout(blend_support_screen) out; +layout(blend_support_overlay) out; +layout(blend_support_darken) out; +layout(blend_support_lighten) out; +layout(blend_support_colordodge) out; +layout(blend_support_colorburn) out; +layout(blend_support_hardlight) out; +layout(blend_support_softlight) out; +layout(blend_support_difference) out; +layout(blend_support_exclusion) out; +layout(blend_support_hsl_hue) out; +layout(blend_support_hsl_saturation) out; +layout(blend_support_hsl_color) out; +layout(blend_support_hsl_luminosity) out; +void main() {} diff --git a/tests/sksl/glsl/NegatedVectorLiteral.sksl b/tests/sksl/glsl/NegatedVectorLiteral.sksl new file mode 100644 index 0000000000..e9ddd8fec0 --- /dev/null +++ b/tests/sksl/glsl/NegatedVectorLiteral.sksl @@ -0,0 +1,6 @@ +void main() { + if (half4(1) == half4(-half2(-1), half2(1))) + sk_FragColor = half4(1); + else + sk_FragColor = half4(-1); +} diff --git a/tests/sksl/glsl/NumberConversions.sksl b/tests/sksl/glsl/NumberConversions.sksl new file mode 100644 index 0000000000..1021b06e20 --- /dev/null +++ b/tests/sksl/glsl/NumberConversions.sksl @@ -0,0 +1,43 @@ +short s = short(sqrt(1)); +int i = int(sqrt(1)); +ushort us = ushort(sqrt(1)); +uint ui = uint(sqrt(1)); +half h = half(sqrt(1)); +float f = sqrt(1); +short s2s = s; +short i2s = short(i); +short us2s = short(us); +short ui2s = short(ui); +short h2s = short(h); +short f2s = short(f); +int s2i = s; +int i2i = i; +int us2i = int(us); +int ui2i = int(ui); +int h2i = int(h); +int f2i = int(f); +ushort s2us = ushort(s); +ushort i2us = ushort(i); +ushort us2us = us; +ushort ui2us = ushort(ui); +ushort h2us = ushort(h); +ushort f2us = ushort(f); +uint s2ui = uint(s); +uint i2ui = uint(i); +uint us2ui = us; +uint ui2ui = ui; +uint h2ui = uint(h); +uint f2ui = uint(f); +float s2f = s; +float i2f = i; +float us2f = us; +float ui2f = ui; +float h2f = h; +float f2f = f; + +void main() { + sk_FragColor.r = half(s + i + us + half(ui) + h + f + s2s + i2s + us2s + ui2s + h2s + f2s + + s2i + i2i + us2i + ui2i + h2i + f2i + s2us + i2us + us2us); + sk_FragColor.r += half(ui2us + h2us + f2us + half(s2ui) + half(i2ui) + half(us2ui) + half(ui2ui) + + half(h2ui) + half(f2ui) + s2f + i2f + us2f + ui2f + h2f + f2f); +} diff --git a/tests/sksl/glsl/RectangleTexture.sksl b/tests/sksl/glsl/RectangleTexture.sksl new file mode 100644 index 0000000000..1f844627f1 --- /dev/null +++ b/tests/sksl/glsl/RectangleTexture.sksl @@ -0,0 +1,8 @@ +uniform sampler2D test2D; +uniform sampler2D test2DRect; + +void main() { + sk_FragColor = sample(test2D, float2(0.5)); + sk_FragColor = sample(test2DRect, float2(0.5)); + sk_FragColor = sample(test2DRect, float3(0.5)); +} diff --git a/tests/sksl/glsl/StackingVectorCasts.sksl b/tests/sksl/glsl/StackingVectorCasts.sksl new file mode 100644 index 0000000000..65c16560ed --- /dev/null +++ b/tests/sksl/glsl/StackingVectorCasts.sksl @@ -0,0 +1,6 @@ +void main() { + if (half4(0, 0, 1, 1) == half4(int4(0, 0, 1, 1))) + sk_FragColor = half4(1); + else + sk_FragColor = half4(-1); +} diff --git a/tests/sksl/glsl/SwizzleLTRB.sksl b/tests/sksl/glsl/SwizzleLTRB.sksl new file mode 100644 index 0000000000..10ab355123 --- /dev/null +++ b/tests/sksl/glsl/SwizzleLTRB.sksl @@ -0,0 +1,3 @@ +void main() { + sk_FragColor = sk_FragColor.BRTL; +} diff --git a/tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl b/tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl new file mode 100644 index 0000000000..1b538dfe79 --- /dev/null +++ b/tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl @@ -0,0 +1,6 @@ +void main() { + int r, g; + (true ? r : g) = 1; + (false ? r : g) = 0; + sk_FragColor = half4(r, g, 1, 1); +} diff --git a/tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl b/tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl new file mode 100644 index 0000000000..c659543c1c --- /dev/null +++ b/tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl @@ -0,0 +1,6 @@ +void main() { + half r, g; + (true ? r : g) = half(sqrt(1)); + (false ? r : g) = half(sqrt(0)); + sk_FragColor = half4(r, g, 1, 1); +} diff --git a/tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl b/tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl new file mode 100644 index 0000000000..45df8a674c --- /dev/null +++ b/tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl @@ -0,0 +1,6 @@ +void main() { + half r, g; + (sqrt(1) > 0 ? r : g) = half(sqrt(1)); + (sqrt(0) > 0 ? r : g) = half(sqrt(0)); + sk_FragColor = half4(r, g, 1, 1); +} diff --git a/tests/sksl/glsl/Width.sksl b/tests/sksl/glsl/Width.sksl new file mode 100644 index 0000000000..1082b8d865 --- /dev/null +++ b/tests/sksl/glsl/Width.sksl @@ -0,0 +1,3 @@ +void main() { + sk_FragColor.r = half(sk_FragCoord.x / sk_Width); +} diff --git a/tests/sksl/glsl/golden/Caps.glsl b/tests/sksl/glsl/golden/Caps.glsl new file mode 100644 index 0000000000..c6ab68121c --- /dev/null +++ b/tests/sksl/glsl/golden/Caps.glsl @@ -0,0 +1,5 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor.xyz = vec3(1.0, 1.0, 0.0); +} diff --git a/tests/sksl/glsl/golden/CastsRoundTowardZero.glsl b/tests/sksl/glsl/golden/CastsRoundTowardZero.glsl new file mode 100644 index 0000000000..bc296825fe --- /dev/null +++ b/tests/sksl/glsl/golden/CastsRoundTowardZero.glsl @@ -0,0 +1,6 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor = vec4(1.0); + sk_FragColor = vec4(2.0); +} diff --git a/tests/sksl/glsl/golden/Discard.glsl b/tests/sksl/glsl/golden/Discard.glsl new file mode 100644 index 0000000000..45fac188d8 --- /dev/null +++ b/tests/sksl/glsl/golden/Discard.glsl @@ -0,0 +1,6 @@ + +void main() { + { + discard; + } +} diff --git a/tests/sksl/glsl/golden/FrExp.glsl b/tests/sksl/glsl/golden/FrExp.glsl new file mode 100644 index 0000000000..0a85428546 --- /dev/null +++ b/tests/sksl/glsl/golden/FrExp.glsl @@ -0,0 +1,7 @@ + +out vec4 sk_FragColor; +void main() { + int exp; + float foo = frexp(0.5, exp); + sk_FragColor = vec4(float(exp)); +} diff --git a/tests/sksl/glsl/golden/Height.glsl b/tests/sksl/glsl/golden/Height.glsl new file mode 100644 index 0000000000..462dd962ac --- /dev/null +++ b/tests/sksl/glsl/golden/Height.glsl @@ -0,0 +1,6 @@ + +uniform float u_skRTHeight; +out vec4 sk_FragColor; +void main() { + sk_FragColor.x = gl_FragCoord.y / u_skRTHeight; +} diff --git a/tests/sksl/glsl/golden/ModifiersDeclaration.glsl b/tests/sksl/glsl/golden/ModifiersDeclaration.glsl new file mode 100644 index 0000000000..a7547ae775 --- /dev/null +++ b/tests/sksl/glsl/golden/ModifiersDeclaration.glsl @@ -0,0 +1,20 @@ + +layout (blend_support_all_equations) out ; +layout (blend_support_all_equations) out ; +layout (blend_support_multiply) out ; +layout (blend_support_screen) out ; +layout (blend_support_overlay) out ; +layout (blend_support_darken) out ; +layout (blend_support_lighten) out ; +layout (blend_support_colordodge) out ; +layout (blend_support_colorburn) out ; +layout (blend_support_hardlight) out ; +layout (blend_support_softlight) out ; +layout (blend_support_difference) out ; +layout (blend_support_exclusion) out ; +layout (blend_support_hsl_hue) out ; +layout (blend_support_hsl_saturation) out ; +layout (blend_support_hsl_color) out ; +layout (blend_support_hsl_luminosity) out ; +void main() { +} diff --git a/tests/sksl/glsl/golden/NegatedVectorLiteral.glsl b/tests/sksl/glsl/golden/NegatedVectorLiteral.glsl new file mode 100644 index 0000000000..61ae41839a --- /dev/null +++ b/tests/sksl/glsl/golden/NegatedVectorLiteral.glsl @@ -0,0 +1,5 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor = vec4(1.0); +} diff --git a/tests/sksl/glsl/golden/NumberConversions.glsl b/tests/sksl/glsl/golden/NumberConversions.glsl new file mode 100644 index 0000000000..c38b42a248 --- /dev/null +++ b/tests/sksl/glsl/golden/NumberConversions.glsl @@ -0,0 +1,42 @@ + +out vec4 sk_FragColor; +int s = int(sqrt(1.0)); +int i = int(sqrt(1.0)); +uint us = uint(sqrt(1.0)); +uint ui = uint(sqrt(1.0)); +float h = sqrt(1.0); +float f = sqrt(1.0); +int s2s = s; +int i2s = i; +int us2s = int(us); +int ui2s = int(ui); +int h2s = int(h); +int f2s = int(f); +int s2i = s; +int i2i = i; +int us2i = int(us); +int ui2i = int(ui); +int h2i = int(h); +int f2i = int(f); +uint s2us = uint(s); +uint i2us = uint(i); +uint us2us = us; +uint ui2us = ui; +uint h2us = uint(h); +uint f2us = uint(f); +uint s2ui = uint(s); +uint i2ui = uint(i); +uint us2ui = us; +uint ui2ui = ui; +uint h2ui = uint(h); +uint f2ui = uint(f); +float s2f = float(s); +float i2f = float(i); +float us2f = float(us); +float ui2f = float(ui); +float h2f = h; +float f2f = f; +void main() { + sk_FragColor.x = (((((((((((((((((float((s + i) + int(us)) + float(ui)) + h) + f) + float(s2s)) + float(i2s)) + float(us2s)) + float(ui2s)) + float(h2s)) + float(f2s)) + float(s2i)) + float(i2i)) + float(us2i)) + float(ui2i)) + float(h2i)) + float(f2i)) + float(s2us)) + float(i2us)) + float(us2us); + sk_FragColor.x += (((((((((((float((ui2us + h2us) + f2us) + float(s2ui)) + float(i2ui)) + float(us2ui)) + float(ui2ui)) + float(h2ui)) + float(f2ui)) + s2f) + i2f) + us2f) + ui2f) + h2f) + f2f; +} diff --git a/tests/sksl/glsl/golden/RectangleTexture.glsl b/tests/sksl/glsl/golden/RectangleTexture.glsl new file mode 100644 index 0000000000..ab64a502d9 --- /dev/null +++ b/tests/sksl/glsl/golden/RectangleTexture.glsl @@ -0,0 +1,9 @@ + +out vec4 sk_FragColor; +uniform sampler2D test2D; +uniform sampler2D test2DRect; +void main() { + sk_FragColor = texture(test2D, vec2(0.5)); + sk_FragColor = texture(test2DRect, vec2(0.5)); + sk_FragColor = textureProj(test2DRect, vec3(0.5)); +} diff --git a/tests/sksl/glsl/golden/StackingVectorCasts.glsl b/tests/sksl/glsl/golden/StackingVectorCasts.glsl new file mode 100644 index 0000000000..61ae41839a --- /dev/null +++ b/tests/sksl/glsl/golden/StackingVectorCasts.glsl @@ -0,0 +1,5 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor = vec4(1.0); +} diff --git a/tests/sksl/glsl/golden/SwizzleLTRB.glsl b/tests/sksl/glsl/golden/SwizzleLTRB.glsl new file mode 100644 index 0000000000..9d474eed84 --- /dev/null +++ b/tests/sksl/glsl/golden/SwizzleLTRB.glsl @@ -0,0 +1,5 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor = sk_FragColor.wzyx; +} diff --git a/tests/sksl/glsl/golden/TernaryAsLValueEntirelyFoldable.glsl b/tests/sksl/glsl/golden/TernaryAsLValueEntirelyFoldable.glsl new file mode 100644 index 0000000000..98d26b0def --- /dev/null +++ b/tests/sksl/glsl/golden/TernaryAsLValueEntirelyFoldable.glsl @@ -0,0 +1,5 @@ + +out vec4 sk_FragColor; +void main() { + sk_FragColor = vec4(1.0, 0.0, 1.0, 1.0); +} diff --git a/tests/sksl/glsl/golden/TernaryAsLValueFoldableTest.glsl b/tests/sksl/glsl/golden/TernaryAsLValueFoldableTest.glsl new file mode 100644 index 0000000000..2870c24acb --- /dev/null +++ b/tests/sksl/glsl/golden/TernaryAsLValueFoldableTest.glsl @@ -0,0 +1,8 @@ + +out vec4 sk_FragColor; +void main() { + float r, g; + r = sqrt(1.0); + g = sqrt(0.0); + sk_FragColor = vec4(r, g, 1.0, 1.0); +} diff --git a/tests/sksl/glsl/golden/TernaryAsLValueUnfoldable.glsl b/tests/sksl/glsl/golden/TernaryAsLValueUnfoldable.glsl new file mode 100644 index 0000000000..42deabaf16 --- /dev/null +++ b/tests/sksl/glsl/golden/TernaryAsLValueUnfoldable.glsl @@ -0,0 +1,8 @@ + +out vec4 sk_FragColor; +void main() { + float r, g; + sqrt(1.0) > 0.0 ? r : g = sqrt(1.0); + sqrt(0.0) > 0.0 ? r : g = sqrt(0.0); + sk_FragColor = vec4(r, g, 1.0, 1.0); +} diff --git a/tests/sksl/glsl/golden/Width.glsl b/tests/sksl/glsl/golden/Width.glsl new file mode 100644 index 0000000000..617bbbd079 --- /dev/null +++ b/tests/sksl/glsl/golden/Width.glsl @@ -0,0 +1,6 @@ + +uniform float u_skRTWidth; +out vec4 sk_FragColor; +void main() { + sk_FragColor.x = gl_FragCoord.x / u_skRTWidth; +}