22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ #include < cstring>
56#include " flutter/testing/testing.h"
7+ #include " gtest/gtest.h"
68#include " impeller/base/validation.h"
79#include " impeller/compiler/compiler.h"
810#include " impeller/compiler/compiler_test.h"
@@ -26,18 +28,27 @@ TEST(CompilerTest, ShaderKindMatchingIsSuccessful) {
2628}
2729
2830TEST_P (CompilerTest, CanCompile) {
31+ if (GetParam () == TargetPlatform::kSkSL ) {
32+ GTEST_SKIP () << " Not supported with SkSL" ;
33+ }
2934 ASSERT_TRUE (CanCompileAndReflect (" sample.vert" ));
3035 ASSERT_TRUE (CanCompileAndReflect (" sample.vert" , SourceType::kVertexShader ));
3136 ASSERT_TRUE (CanCompileAndReflect (" sample.vert" , SourceType::kVertexShader ,
3237 SourceLanguage::kGLSL ));
3338}
3439
3540TEST_P (CompilerTest, CanCompileHLSL) {
41+ if (GetParam () == TargetPlatform::kSkSL ) {
42+ GTEST_SKIP () << " Not supported with SkSL" ;
43+ }
3644 ASSERT_TRUE (CanCompileAndReflect (
3745 " simple.vert.hlsl" , SourceType::kVertexShader , SourceLanguage::kHLSL ));
3846}
3947
4048TEST_P (CompilerTest, CanCompileHLSLWithMultipleStages) {
49+ if (GetParam () == TargetPlatform::kSkSL ) {
50+ GTEST_SKIP () << " Not supported with SkSL" ;
51+ }
4152 ASSERT_TRUE (CanCompileAndReflect (" multiple_stages.hlsl" ,
4253 SourceType::kVertexShader ,
4354 SourceLanguage::kHLSL , " VertexShader" ));
@@ -47,12 +58,18 @@ TEST_P(CompilerTest, CanCompileHLSLWithMultipleStages) {
4758}
4859
4960TEST_P (CompilerTest, CanCompileTessellationControlShader) {
61+ if (GetParam () == TargetPlatform::kSkSL ) {
62+ GTEST_SKIP () << " Not supported with SkSL" ;
63+ }
5064 ASSERT_TRUE (CanCompileAndReflect (" sample.tesc" ));
5165 ASSERT_TRUE (CanCompileAndReflect (" sample.tesc" ,
5266 SourceType::kTessellationControlShader ));
5367}
5468
5569TEST_P (CompilerTest, CanCompileTessellationEvaluationShader) {
70+ if (GetParam () == TargetPlatform::kSkSL ) {
71+ GTEST_SKIP () << " Not supported with SkSL" ;
72+ }
5673 ASSERT_TRUE (CanCompileAndReflect (" sample.tese" ));
5774 ASSERT_TRUE (CanCompileAndReflect (" sample.tese" ,
5875 SourceType::kTessellationEvaluationShader ));
@@ -67,12 +84,18 @@ TEST_P(CompilerTest, CanCompileComputeShader) {
6784}
6885
6986TEST_P (CompilerTest, MustFailDueToExceedingResourcesLimit) {
87+ if (GetParam () == TargetPlatform::kSkSL ) {
88+ GTEST_SKIP () << " Not supported with SkSL" ;
89+ }
7090 ScopedValidationDisable disable_validation;
7191 ASSERT_FALSE (
7292 CanCompileAndReflect (" resources_limit.vert" , SourceType::kVertexShader ));
7393}
7494
7595TEST_P (CompilerTest, MustFailDueToMultipleLocationPerStructMember) {
96+ if (GetParam () == TargetPlatform::kSkSL ) {
97+ GTEST_SKIP () << " Not supported with SkSL" ;
98+ }
7699 ScopedValidationDisable disable_validation;
77100 ASSERT_FALSE (CanCompileAndReflect (" struct_def_bug.vert" ));
78101}
@@ -98,6 +121,9 @@ TEST_P(CompilerTest, BindingBaseForFragShader) {
98121}
99122
100123TEST_P (CompilerTest, UniformsHaveBindingAndSet) {
124+ if (GetParam () == TargetPlatform::kSkSL ) {
125+ GTEST_SKIP () << " Not supported with SkSL" ;
126+ }
101127 ASSERT_TRUE (CanCompileAndReflect (" sample_with_binding.vert" ,
102128 SourceType::kVertexShader ));
103129 ASSERT_TRUE (CanCompileAndReflect (" sample.frag" , SourceType::kFragmentShader ));
@@ -123,14 +149,30 @@ TEST_P(CompilerTest, UniformsHaveBindingAndSet) {
123149 ASSERT_EQ (vert_uniform_binding.binding , 17u );
124150}
125151
126- #define INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (suite_name ) \
127- INSTANTIATE_TEST_SUITE_P ( \
128- suite_name, CompilerTest, \
129- ::testing::Values ( \
130- TargetPlatform::kOpenGLES , TargetPlatform::kOpenGLDesktop , \
131- TargetPlatform::kMetalDesktop , TargetPlatform::kMetalIOS ), \
132- [](const ::testing::TestParamInfo<CompilerTest::ParamType>& info) { \
133- return TargetPlatformToString (info.param ); \
152+ TEST_P (CompilerTest, SkSLTextureLookUpOrderOfOperations) {
153+ if (GetParam () != TargetPlatform::kSkSL ) {
154+ GTEST_SKIP () << " Only supported on SkSL" ;
155+ }
156+ ASSERT_TRUE (
157+ CanCompileAndReflect (" texture_lookup.frag" , SourceType::kFragmentShader ));
158+
159+ auto shader = GetShaderFile (" texture_lookup.frag" , GetParam ());
160+ auto string_mapping = reinterpret_cast <const char *>(shader->GetMapping ());
161+
162+ EXPECT_TRUE (strcmp (string_mapping,
163+ " textureA.eval(textureA_size * ( vec2(1.0) + "
164+ " flutter_FragCoord.xy));" ) != -1 );
165+ }
166+
167+ #define INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (suite_name ) \
168+ INSTANTIATE_TEST_SUITE_P ( \
169+ suite_name, CompilerTest, \
170+ ::testing::Values (TargetPlatform::kOpenGLES , \
171+ TargetPlatform::kOpenGLDesktop , \
172+ TargetPlatform::kMetalDesktop , \
173+ TargetPlatform::kMetalIOS , TargetPlatform::kSkSL ), \
174+ [](const ::testing::TestParamInfo<CompilerTest::ParamType>& info) { \
175+ return TargetPlatformToString (info.param ); \
134176 });
135177
136178INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite);
0 commit comments