From 34de5cb57bfd5ef1721e8fda338dcc73cc279e3d Mon Sep 17 00:00:00 2001 From: John Stiles Date: Fri, 13 Nov 2020 18:14:11 -0500 Subject: [PATCH] Convert remaining Metal tests to golden outputs. Metal-specific tests are pretty thin on the ground here, and some of the remaining tests no longer added value as they were already covered pretty well by existing tests in Shared. The majority of remaining tests were specific to Metal's lack of flexible matrix casting (and SkSL's ability to paper over this with helper functions). Change-Id: I7b3c445268b95320e7f46ec88d793c315d43ee8a Bug: skia:10694 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334956 Auto-Submit: John Stiles Reviewed-by: Brian Osman Commit-Queue: John Stiles --- gn/sksl_tests.gni | 13 +- gn/tests.gni | 2 +- tests/SkSLGLSLTestbed.cpp | 7 - tests/SkSLMetalTest.cpp | 366 ------------------ tests/SkSLMetalTestbed.cpp | 40 ++ tests/sksl/metal/CastHalf4ToMat2x2.sksl | 4 + tests/sksl/metal/CastMat2x2ToMat3x3.sksl | 5 + tests/sksl/metal/CastMat2x3ToMat4x4.sksl | 5 + tests/sksl/metal/CastMat4x4ToMat3x4.sksl | 5 + tests/sksl/metal/CastMat4x4ToMat4x3.sksl | 5 + tests/sksl/metal/NumericGlobals.sksl | 8 + tests/sksl/metal/SamplerGlobals.sksl | 6 + .../sksl/metal/golden/CastHalf4ToMat2x2.metal | 17 + .../metal/golden/CastMat2x2ToMat3x3.metal | 17 + .../metal/golden/CastMat2x3ToMat4x4.metal | 17 + .../metal/golden/CastMat4x4ToMat3x4.metal | 17 + .../metal/golden/CastMat4x4ToMat4x3.metal | 17 + tests/sksl/metal/golden/NumericGlobals.metal | 26 ++ tests/sksl/metal/golden/SamplerGlobals.metal | 24 ++ tests/sksl/shared/Matrices.sksl | 14 + tests/sksl/shared/golden/Matrices.glsl | 2 + tests/sksl/shared/golden/Matrices.metal | 11 + 22 files changed, 253 insertions(+), 375 deletions(-) delete mode 100644 tests/SkSLMetalTest.cpp create mode 100644 tests/SkSLMetalTestbed.cpp create mode 100644 tests/sksl/metal/CastHalf4ToMat2x2.sksl create mode 100644 tests/sksl/metal/CastMat2x2ToMat3x3.sksl create mode 100644 tests/sksl/metal/CastMat2x3ToMat4x4.sksl create mode 100644 tests/sksl/metal/CastMat4x4ToMat3x4.sksl create mode 100644 tests/sksl/metal/CastMat4x4ToMat4x3.sksl create mode 100644 tests/sksl/metal/NumericGlobals.sksl create mode 100644 tests/sksl/metal/SamplerGlobals.sksl create mode 100644 tests/sksl/metal/golden/CastHalf4ToMat2x2.metal create mode 100644 tests/sksl/metal/golden/CastMat2x2ToMat3x3.metal create mode 100644 tests/sksl/metal/golden/CastMat2x3ToMat4x4.metal create mode 100644 tests/sksl/metal/golden/CastMat4x4ToMat3x4.metal create mode 100644 tests/sksl/metal/golden/CastMat4x4ToMat4x3.metal create mode 100644 tests/sksl/metal/golden/NumericGlobals.metal create mode 100644 tests/sksl/metal/golden/SamplerGlobals.metal diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index d0176c0ef5..343d962886 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -159,6 +159,16 @@ sksl_glsl_tests = [ "$_tests/sksl/glsl/Version450Core.sksl", ] +sksl_metal_tests = [ + "$_tests/sksl/metal/CastHalf4ToMat2x2.sksl", + "$_tests/sksl/metal/CastMat2x2ToMat3x3.sksl", + "$_tests/sksl/metal/CastMat2x3ToMat4x4.sksl", + "$_tests/sksl/metal/CastMat4x4ToMat3x4.sksl", + "$_tests/sksl/metal/CastMat4x4ToMat4x3.sksl", + "$_tests/sksl/metal/NumericGlobals.sksl", + "$_tests/sksl/metal/SamplerGlobals.sksl", +] + sksl_shared_tests = [ "$_tests/sksl/shared/ArrayConstructors.sksl", "$_tests/sksl/shared/ArrayIndexTypes.sksl", @@ -356,4 +366,5 @@ sksl_glsl_settings_tests_sources = sksl_blend_tests + sksl_settings_tests # Tests in sksl_metal_tests_sources will be compiled with --settings on, and are expected to # generate a .metal output file. -sksl_metal_tests_sources = sksl_blend_tests + sksl_shared_tests +sksl_metal_tests_sources = + sksl_metal_tests + sksl_blend_tests + sksl_shared_tests diff --git a/gn/tests.gni b/gn/tests.gni index 38a4ca5958..55c8a27cf2 100644 --- a/gn/tests.gni +++ b/gn/tests.gni @@ -268,7 +268,7 @@ tests_sources = [ "$_tests/SkSLGLSLTestbed.cpp", "$_tests/SkSLInterpreterTest.cpp", "$_tests/SkSLMemoryLayoutTest.cpp", - "$_tests/SkSLMetalTest.cpp", + "$_tests/SkSLMetalTestbed.cpp", "$_tests/SkSLNodeArrayWrapperTest.cpp", "$_tests/SkSLSPIRVTest.cpp", "$_tests/SkScalerCacheTest.cpp", diff --git a/tests/SkSLGLSLTestbed.cpp b/tests/SkSLGLSLTestbed.cpp index 298fb94e6a..60e21aa267 100644 --- a/tests/SkSLGLSLTestbed.cpp +++ b/tests/SkSLGLSLTestbed.cpp @@ -9,13 +9,6 @@ #include "tests/Test.h" -// Note that the optimizer will aggressively kill dead code and substitute constants in place of -// variables, so we have to jump through a few hoops to ensure that the code in these tests has the -// necessary side-effects to remain live. In some cases we rely on the optimizer not (yet) being -// smart enough to optimize around certain constructs; as the optimizer gets smarter it will -// undoubtedly end up breaking some of these tests. That is a good thing, as long as the new code is -// equivalent! - static void test(skiatest::Reporter* r, const GrShaderCaps& caps, const char* src, diff --git a/tests/SkSLMetalTest.cpp b/tests/SkSLMetalTest.cpp deleted file mode 100644 index 98769918d8..0000000000 --- a/tests/SkSLMetalTest.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright 2019 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "src/sksl/SkSLCompiler.h" - -#include "tests/Test.h" - -static void test(skiatest::Reporter* r, const GrShaderCaps& caps, const char* src, - const char* expected, SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) { - SkSL::Compiler compiler(&caps); - SkSL::Program::Settings settings; - SkSL::String output; - std::unique_ptr program = compiler.convertProgram(kind, SkSL::String(src), - settings); - if (!program) { - SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); - } - REPORTER_ASSERT(r, program); - REPORTER_ASSERT(r, compiler.toMetal(*program, &output)); - if (program) { - SkSL::String skExpected(expected); - if (output != skExpected) { - SkDebugf("MSL MISMATCH:\nsource:\n%s\n\nexpected:\n'%s'\n\nreceived:\n'%s'", src, - expected, output.c_str()); - } - REPORTER_ASSERT(r, output == skExpected); - } -} - -DEF_TEST(SkSLMetalHelloWorld, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), - "void main() { sk_FragColor = half4(0.75); }", - "#include \n" - "#include \n" - "using namespace metal;\n" - "struct Inputs {\n" - "};\n" - "struct Outputs {\n" - " float4 sk_FragColor [[color(0)]];\n" - "};\n" - "fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {\n" - " Outputs _outputStruct;\n" - " thread Outputs* _out = &_outputStruct;\n" - " _out->sk_FragColor = float4(0.75);\n" - " return *_out;\n" - "}\n"); -} - -DEF_TEST(SkSLMetal2x2MatrixCopyFromFloat2x2, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { - float2x2 m1 = float2x2(float2(1, 2), float2(3, 4)); - float2x2 m2 = m1; - float2x2 m3 = float2x2(m1); - sk_FragColor = half4(half(m1[0][0] + m2[0][0] + m3[0][0])); -})__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor = float4((float2x2(float2(1.0, 2.0), float2(3.0, 4.0))[0][0] + float2x2(float2(1.0, 2.0), float2(3.0, 4.0))[0][0]) + float2x2(float2(1.0, 2.0), float2(3.0, 4.0))[0][0]); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetal2x2MatrixCopyFromConstantPropagatedFloat4, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { - float2x2 m1 = float2x2(float4(1, 2, 3, 4)); - float2x2 m2 = m1; - float2x2 m3 = float2x2(m1); - sk_FragColor = half4(half(m1[0][0] + m2[0][0] + m3[0][0])); -})__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float2x2 float2x2_from_float4(float4 x0) { - return float2x2(float2(x0[0], x0[1]), float2(x0[2], x0[3])); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor = float4((float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0] + float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]) + float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalCastMat2x2ToMat3x3, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { -float3x3 a = float3x3(1); -float3x3 b = float3x3(float2x2(1)); -sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float3x3 float3x3_from_float2x2(float2x2 x0) { - return float3x3(float3(x0[0].xy, 0.0), float3(x0[1].xy, 0.0), float3(0.0, 0.0, 1.0)); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor.x = float(all(float3x3(1.0)[0] == float3x3_from_float2x2(float2x2(1.0))[0]) ? 0 : 1); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalCastMat2x3ToMat4x4, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { -float4x4 a = float4x4(6); -float4x4 b = float4x4(float2x3(7)); -sk_FragColor.x = (a[1] == b[1]) ? 0 : 1; -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float4x4 float4x4_from_float2x3(float2x3 x0) { - return float4x4(float4(x0[0].xyz, 0.0), float4(x0[1].xyz, 0.0), float4(0.0, 0.0, 1.0, 0.0), float4(0.0, 0.0, 0.0, 1.0)); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor.x = float(all(float4x4(6.0)[1] == float4x4_from_float2x3(float2x3(7.0))[1]) ? 0 : 1); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalCastMat4x4ToMat3x4, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { -float3x4 a = float3x4(1); -float3x4 b = float3x4(float4x4(1)); -sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float3x4 float3x4_from_float4x4(float4x4 x0) { - return float3x4(float4(x0[0].xyzw), float4(x0[1].xyzw), float4(x0[2].xyzw)); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor.x = float(all(float3x4(1.0)[0] == float3x4_from_float4x4(float4x4(1.0))[0]) ? 0 : 1); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalCastMat4x4ToMat4x3, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { -float4x3 a = float4x3(1); -float4x3 b = float4x3(float4x4(1)); -sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float4x3 float4x3_from_float4x4(float4x4 x0) { - return float4x3(float3(x0[0].xyz), float3(x0[1].xyz), float3(x0[2].xyz), float3(x0[3].xyz)); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor.x = float(all(float4x3(1.0)[0] == float4x3_from_float4x4(float4x4(1.0))[0]) ? 0 : 1); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalMatrices, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -void main() { - float2x2 m1 = float2x2(float4(1, 2, 3, 4)); - float2x2 m2 = float2x2(float4(0)); - float2x2 m3 = float2x2(m1); - float2x2 m4 = float2x2(1); - float2x2 m5 = float2x2(m1[0][0]); - float2x2 m6 = float2x2(1, 2, 3, 4); - float2x2 m7 = float2x2(5, float3(6, 7, 8)); - float3x2 m8 = float3x2(float2(1, 2), 3, float3(4, 5, 6)); - float3x3 m9 = float3x3(1); - float4x4 m10 = float4x4(1); - float4x4 m11 = float4x4(2); - sk_FragColor = half4(half(m1[0][0] + m2[0][0] + m3[0][0] + m4[0][0] + m5[0][0] + - m6[0][0] + m7[0][0] + m8[0][0] + m9[0][0] + m10[0][0] + m11[0][0])); -})__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -float2x2 float2x2_from_float4(float4 x0) { - return float2x2(float2(x0[0], x0[1]), float2(x0[2], x0[3])); -} -float2x2 float2x2_from_float_float3(float x0, float3 x1) { - return float2x2(float2(x0, x1[0]), float2(x1[1], x1[2])); -} -float3x2 float3x2_from_float2_float_float3(float2 x0, float x1, float3 x2) { - return float3x2(float2(x0[0], x0[1]), float2(x1, x2[0]), float2(x2[1], x2[2])); -} -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - float2x2 m5 = float2x2(float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]); - _out->sk_FragColor = float4((((((((((float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0] + float2x2_from_float4(float4(0.0))[0][0]) + float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]) + float2x2(1.0)[0][0]) + m5[0][0]) + float2x2(float2(1.0, 2.0), float2(3.0, 4.0))[0][0]) + float2x2_from_float_float3(5.0, float3(6.0, 7.0, 8.0))[0][0]) + float3x2_from_float2_float_float3(float2(1.0, 2.0), 3.0, float3(4.0, 5.0, 6.0))[0][0]) + float3x3(1.0)[0][0]) + float4x4(1.0)[0][0]) + float4x4(2.0)[0][0]); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalConstantSwizzle, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), - "void main() {" - "sk_FragColor = half4(0.5).rgb1;" - "}", - "#include \n" - "#include \n" - "using namespace metal;\n" - "struct Inputs {\n" - "};\n" - "struct Outputs {\n" - " float4 sk_FragColor [[color(0)]];\n" - "};\n" - "fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {\n" - " Outputs _outputStruct;\n" - " thread Outputs* _out = &_outputStruct;\n" - " _out->sk_FragColor = float4(float4(0.5).xyz, 1.0);\n" - " return *_out;\n" - "}\n"); -} - -DEF_TEST(SkSLMetalNumericGlobals, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -half attr1; -int attr2 = 123; -float attr3; -half4 attr4 = half4(4, 5, 6, 7); -void main() -{ - sk_FragColor = half4(attr1, attr2, half(attr3), attr4.x); -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -struct Globals { - float attr1; - int attr2; - float attr3; - float4 attr4; -}; - - - -fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Globals globalStruct{{}, 123, {}, float4(4.0, 5.0, 6.0, 7.0)}; - thread Globals* _globals = &globalStruct; - (void)_globals; - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor = float4(_globals->attr1, float(_globals->attr2), _globals->attr3, _globals->attr4.x); - return *_out; -} -)__MSL__"); -} - -DEF_TEST(SkSLMetalSamplerGlobals, r) { - test(r, *SkSL::ShaderCapsFactory::Default(), -R"__SkSL__( -layout(binding=1) uniform sampler2D texA; -layout(binding=0) uniform sampler2D texB; -void main() -{ - sk_FragColor = sample(texA, half2(0)) * sample(texB, half2(0)); -} -)__SkSL__", -R"__MSL__(#include -#include -using namespace metal; -struct Inputs { -}; -struct Outputs { - float4 sk_FragColor [[color(0)]]; -}; -struct Globals { - texture2d texA; - sampler texASmplr; - texture2d texB; - sampler texBSmplr; -}; - -fragment Outputs fragmentMain(Inputs _in [[stage_in]], texture2d texA[[texture(1)]], sampler texASmplr[[sampler(1)]], texture2d texB[[texture(0)]], sampler texBSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { - Globals globalStruct{texA, texASmplr, texB, texBSmplr}; - thread Globals* _globals = &globalStruct; - (void)_globals; - Outputs _outputStruct; - thread Outputs* _out = &_outputStruct; - _out->sk_FragColor = _globals->texA.sample(_globals->texASmplr, float2(0.0)) * _globals->texB.sample(_globals->texBSmplr, float2(0.0)); - return *_out; -} -)__MSL__"); -} diff --git a/tests/SkSLMetalTestbed.cpp b/tests/SkSLMetalTestbed.cpp new file mode 100644 index 0000000000..bde8212334 --- /dev/null +++ b/tests/SkSLMetalTestbed.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2020 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "src/sksl/SkSLCompiler.h" + +#include "tests/Test.h" + +static void test(skiatest::Reporter* r, + const GrShaderCaps& caps, + const char* src, + SkSL::Program::Kind kind = SkSL::Program::kFragment_Kind) { + SkSL::Compiler compiler(&caps); + SkSL::Program::Settings settings; + SkSL::String output; + std::unique_ptr program = compiler.convertProgram(kind, SkSL::String(src), + settings); + if (!program) { + SkDebugf("Unexpected error compiling %s\n%s", src, compiler.errorText().c_str()); + REPORTER_ASSERT(r, program); + } else { + REPORTER_ASSERT(r, compiler.toMetal(*program, &output)); + REPORTER_ASSERT(r, output != ""); + //SkDebugf("Metal output:\n\n%s", output.c_str()); + } +} + +DEF_TEST(SkSLMetalTestbed, r) { + // Add in your SkSL here. + test(r, + *SkSL::ShaderCapsFactory::Default(), + R"__SkSL__( + void main() { + sk_FragColor = half4(0); + } + )__SkSL__"); +} diff --git a/tests/sksl/metal/CastHalf4ToMat2x2.sksl b/tests/sksl/metal/CastHalf4ToMat2x2.sksl new file mode 100644 index 0000000000..f9b61a7f03 --- /dev/null +++ b/tests/sksl/metal/CastHalf4ToMat2x2.sksl @@ -0,0 +1,4 @@ +void main() { + half2x2 m1 = half2x2(half4(1, 2, 3, 4)); + sk_FragColor = m1[0].xyxy; +} diff --git a/tests/sksl/metal/CastMat2x2ToMat3x3.sksl b/tests/sksl/metal/CastMat2x2ToMat3x3.sksl new file mode 100644 index 0000000000..f7001df751 --- /dev/null +++ b/tests/sksl/metal/CastMat2x2ToMat3x3.sksl @@ -0,0 +1,5 @@ +void main() { + float3x3 a = float3x3(1); + float3x3 b = float3x3(float2x2(1)); + sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; +} diff --git a/tests/sksl/metal/CastMat2x3ToMat4x4.sksl b/tests/sksl/metal/CastMat2x3ToMat4x4.sksl new file mode 100644 index 0000000000..2093f530b2 --- /dev/null +++ b/tests/sksl/metal/CastMat2x3ToMat4x4.sksl @@ -0,0 +1,5 @@ +void main() { + float4x4 a = float4x4(6); + float4x4 b = float4x4(float2x3(7)); + sk_FragColor.x = (a[1] == b[1]) ? 0 : 1; +} diff --git a/tests/sksl/metal/CastMat4x4ToMat3x4.sksl b/tests/sksl/metal/CastMat4x4ToMat3x4.sksl new file mode 100644 index 0000000000..30428748bf --- /dev/null +++ b/tests/sksl/metal/CastMat4x4ToMat3x4.sksl @@ -0,0 +1,5 @@ +void main() { + float3x4 a = float3x4(1); + float3x4 b = float3x4(float4x4(1)); + sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; +} diff --git a/tests/sksl/metal/CastMat4x4ToMat4x3.sksl b/tests/sksl/metal/CastMat4x4ToMat4x3.sksl new file mode 100644 index 0000000000..87111a1030 --- /dev/null +++ b/tests/sksl/metal/CastMat4x4ToMat4x3.sksl @@ -0,0 +1,5 @@ +void main() { + float4x3 a = float4x3(1); + float4x3 b = float4x3(float4x4(1)); + sk_FragColor.x = (a[0] == b[0]) ? 0 : 1; +} diff --git a/tests/sksl/metal/NumericGlobals.sksl b/tests/sksl/metal/NumericGlobals.sksl new file mode 100644 index 0000000000..72e5f91c4a --- /dev/null +++ b/tests/sksl/metal/NumericGlobals.sksl @@ -0,0 +1,8 @@ +half attr1; +int attr2 = 123; +float attr3; +half4 attr4 = half4(4, 5, 6, 7); +void main() +{ + sk_FragColor = half4(attr1, attr2, half(attr3), attr4.x); +} diff --git a/tests/sksl/metal/SamplerGlobals.sksl b/tests/sksl/metal/SamplerGlobals.sksl new file mode 100644 index 0000000000..560efc1061 --- /dev/null +++ b/tests/sksl/metal/SamplerGlobals.sksl @@ -0,0 +1,6 @@ +layout(binding=1) uniform sampler2D texA; +layout(binding=0) uniform sampler2D texB; +void main() +{ + sk_FragColor = sample(texA, half2(0)) * sample(texB, half2(0)); +} diff --git a/tests/sksl/metal/golden/CastHalf4ToMat2x2.metal b/tests/sksl/metal/golden/CastHalf4ToMat2x2.metal new file mode 100644 index 0000000000..50abe48d0d --- /dev/null +++ b/tests/sksl/metal/golden/CastHalf4ToMat2x2.metal @@ -0,0 +1,17 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +float2x2 float2x2_from_half4(half4 x0) { + return float2x2(float2(x0[0], x0[1]), float2(x0[2], x0[3])); +} +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor = float2x2_from_half4(float4(1.0, 2.0, 3.0, 4.0))[0].xyxy; + return *_out; +} diff --git a/tests/sksl/metal/golden/CastMat2x2ToMat3x3.metal b/tests/sksl/metal/golden/CastMat2x2ToMat3x3.metal new file mode 100644 index 0000000000..1f170334b8 --- /dev/null +++ b/tests/sksl/metal/golden/CastMat2x2ToMat3x3.metal @@ -0,0 +1,17 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +float3x3 float3x3_from_float2x2(float2x2 x0) { + return float3x3(float3(x0[0].xy, 0.0), float3(x0[1].xy, 0.0), float3(0.0, 0.0, 1.0)); +} +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor.x = float(all(float3x3(1.0)[0] == float3x3_from_float2x2(float2x2(1.0))[0]) ? 0 : 1); + return *_out; +} diff --git a/tests/sksl/metal/golden/CastMat2x3ToMat4x4.metal b/tests/sksl/metal/golden/CastMat2x3ToMat4x4.metal new file mode 100644 index 0000000000..878e4b8ec6 --- /dev/null +++ b/tests/sksl/metal/golden/CastMat2x3ToMat4x4.metal @@ -0,0 +1,17 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +float4x4 float4x4_from_float2x3(float2x3 x0) { + return float4x4(float4(x0[0].xyz, 0.0), float4(x0[1].xyz, 0.0), float4(0.0, 0.0, 1.0, 0.0), float4(0.0, 0.0, 0.0, 1.0)); +} +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor.x = float(all(float4x4(6.0)[1] == float4x4_from_float2x3(float2x3(7.0))[1]) ? 0 : 1); + return *_out; +} diff --git a/tests/sksl/metal/golden/CastMat4x4ToMat3x4.metal b/tests/sksl/metal/golden/CastMat4x4ToMat3x4.metal new file mode 100644 index 0000000000..c92b6773c2 --- /dev/null +++ b/tests/sksl/metal/golden/CastMat4x4ToMat3x4.metal @@ -0,0 +1,17 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +float3x4 float3x4_from_float4x4(float4x4 x0) { + return float3x4(float4(x0[0].xyzw), float4(x0[1].xyzw), float4(x0[2].xyzw)); +} +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor.x = float(all(float3x4(1.0)[0] == float3x4_from_float4x4(float4x4(1.0))[0]) ? 0 : 1); + return *_out; +} diff --git a/tests/sksl/metal/golden/CastMat4x4ToMat4x3.metal b/tests/sksl/metal/golden/CastMat4x4ToMat4x3.metal new file mode 100644 index 0000000000..2c6808b3e9 --- /dev/null +++ b/tests/sksl/metal/golden/CastMat4x4ToMat4x3.metal @@ -0,0 +1,17 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +float4x3 float4x3_from_float4x4(float4x4 x0) { + return float4x3(float3(x0[0].xyz), float3(x0[1].xyz), float3(x0[2].xyz), float3(x0[3].xyz)); +} +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor.x = float(all(float4x3(1.0)[0] == float4x3_from_float4x4(float4x4(1.0))[0]) ? 0 : 1); + return *_out; +} diff --git a/tests/sksl/metal/golden/NumericGlobals.metal b/tests/sksl/metal/golden/NumericGlobals.metal new file mode 100644 index 0000000000..792f25adb0 --- /dev/null +++ b/tests/sksl/metal/golden/NumericGlobals.metal @@ -0,0 +1,26 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +struct Globals { + float attr1; + int attr2; + float attr3; + float4 attr4; +}; + + + +fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Globals globalStruct{{}, 123, {}, float4(4.0, 5.0, 6.0, 7.0)}; + thread Globals* _globals = &globalStruct; + (void)_globals; + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor = float4(_globals->attr1, float(_globals->attr2), _globals->attr3, _globals->attr4.x); + return *_out; +} diff --git a/tests/sksl/metal/golden/SamplerGlobals.metal b/tests/sksl/metal/golden/SamplerGlobals.metal new file mode 100644 index 0000000000..6d405efa0f --- /dev/null +++ b/tests/sksl/metal/golden/SamplerGlobals.metal @@ -0,0 +1,24 @@ +#include +#include +using namespace metal; +struct Inputs { +}; +struct Outputs { + float4 sk_FragColor [[color(0)]]; +}; +struct Globals { + texture2d texA; + sampler texASmplr; + texture2d texB; + sampler texBSmplr; +}; + +fragment Outputs fragmentMain(Inputs _in [[stage_in]], texture2d texA[[texture(1)]], sampler texASmplr[[sampler(1)]], texture2d texB[[texture(0)]], sampler texBSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { + Globals globalStruct{texA, texASmplr, texB, texBSmplr}; + thread Globals* _globals = &globalStruct; + (void)_globals; + Outputs _outputStruct; + thread Outputs* _out = &_outputStruct; + _out->sk_FragColor = _globals->texA.sample(_globals->texASmplr, float2(0.0)) * _globals->texB.sample(_globals->texBSmplr, float2(0.0)); + return *_out; +} diff --git a/tests/sksl/shared/Matrices.sksl b/tests/sksl/shared/Matrices.sksl index b8287f1345..40587d0cef 100644 --- a/tests/sksl/shared/Matrices.sksl +++ b/tests/sksl/shared/Matrices.sksl @@ -5,4 +5,18 @@ void main() { float3 v1 = float3x3(1) * float3(2); float3 v2 = float3(2) * float3x3(1); sk_FragColor = half4(half(z[0].x), half3(v1 + v2)); + + float2x2 m1 = float2x2(float4(1, 2, 3, 4)); + float2x2 m2 = float2x2(float4(0)); + float2x2 m3 = float2x2(m1); + float2x2 m4 = float2x2(1); + float2x2 m5 = float2x2(m1[0][0]); + float2x2 m6 = float2x2(1, 2, 3, 4); + float2x2 m7 = float2x2(5, float3(6, 7, 8)); + float3x2 m8 = float3x2(float2(1, 2), 3, float3(4, 5, 6)); + float3x3 m9 = float3x3(1); + float4x4 m10 = float4x4(1); + float4x4 m11 = float4x4(2); + sk_FragColor = half4(half(m1[0][0] + m2[0][0] + m3[0][0] + m4[0][0] + m5[0][0] + + m6[0][0] + m7[0][0] + m8[0][0] + m9[0][0] + m10[0][0] + m11[0][0])); } diff --git a/tests/sksl/shared/golden/Matrices.glsl b/tests/sksl/shared/golden/Matrices.glsl index aa45821f7d..bc86bb5688 100644 --- a/tests/sksl/shared/golden/Matrices.glsl +++ b/tests/sksl/shared/golden/Matrices.glsl @@ -5,4 +5,6 @@ void main() { vec3 v1 = mat3(1.0) * vec3(2.0); vec3 v2 = vec3(2.0) * mat3(1.0); sk_FragColor = vec4(z[0].x, v1 + v2); + mat2 m5 = mat2(mat2(vec4(1.0, 2.0, 3.0, 4.0))[0][0]); + sk_FragColor = vec4((((((((((mat2(vec4(1.0, 2.0, 3.0, 4.0))[0][0] + mat2(vec4(0.0))[0][0]) + mat2(vec4(1.0, 2.0, 3.0, 4.0))[0][0]) + mat2(1.0)[0][0]) + m5[0][0]) + mat2(1.0, 2.0, 3.0, 4.0)[0][0]) + mat2(5.0, vec3(6.0, 7.0, 8.0))[0][0]) + mat3x2(vec2(1.0, 2.0), 3.0, vec3(4.0, 5.0, 6.0))[0][0]) + mat3(1.0)[0][0]) + mat4(1.0)[0][0]) + mat4(2.0)[0][0]); } diff --git a/tests/sksl/shared/golden/Matrices.metal b/tests/sksl/shared/golden/Matrices.metal index 0a7eae0da6..f3455573b3 100644 --- a/tests/sksl/shared/golden/Matrices.metal +++ b/tests/sksl/shared/golden/Matrices.metal @@ -6,6 +6,15 @@ struct Inputs { struct Outputs { float4 sk_FragColor [[color(0)]]; }; +float2x2 float2x2_from_float4(float4 x0) { + return float2x2(float2(x0[0], x0[1]), float2(x0[2], x0[3])); +} +float2x2 float2x2_from_float_float3(float x0, float3 x1) { + return float2x2(float2(x0, x1[0]), float2(x1[1], x1[2])); +} +float3x2 float3x2_from_float2_float_float3(float2 x0, float x1, float3 x2) { + return float3x2(float2(x0[0], x0[1]), float2(x1, x2[0]), float2(x2[1], x2[2])); +} fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Outputs _outputStruct; thread Outputs* _out = &_outputStruct; @@ -13,5 +22,7 @@ fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front float3 v1 = float3x3(1.0) * float3(2.0); float3 v2 = float3(2.0) * float3x3(1.0); _out->sk_FragColor = float4(z[0].x, v1 + v2); + float2x2 m5 = float2x2(float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]); + _out->sk_FragColor = float4((((((((((float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0] + float2x2_from_float4(float4(0.0))[0][0]) + float2x2_from_float4(float4(1.0, 2.0, 3.0, 4.0))[0][0]) + float2x2(1.0)[0][0]) + m5[0][0]) + float2x2(float2(1.0, 2.0), float2(3.0, 4.0))[0][0]) + float2x2_from_float_float3(5.0, float3(6.0, 7.0, 8.0))[0][0]) + float3x2_from_float2_float_float3(float2(1.0, 2.0), 3.0, float3(4.0, 5.0, 6.0))[0][0]) + float3x3(1.0)[0][0]) + float4x4(1.0)[0][0]) + float4x4(2.0)[0][0]); return *_out; }