Flutter Impeller
impeller::compiler::testing Namespace Reference

Classes

class  CompilerTestBase
 
class  CompilerTest
 
class  CompilerTestRuntime
 
class  CompilerTestSkSL
 
class  CompilerTestUnknownPlatform
 

Functions

static std::string GetIntermediatesPath ()
 
static std::string ReflectionHeaderName (const char *fixture_name)
 
static std::string ReflectionCCName (const char *fixture_name)
 
static std::string ReflectionJSONName (const char *fixture_name)
 
static std::string SPIRVFileName (const char *fixture_name)
 
static std::string SLFileName (const char *fixture_name, TargetPlatform platform)
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTest, ::testing::Values(TargetPlatform::kOpenGLES, TargetPlatform::kOpenGLDesktop, TargetPlatform::kMetalDesktop, TargetPlatform::kMetalIOS, TargetPlatform::kVulkan), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestRuntime, ::testing::Values(TargetPlatform::kRuntimeStageMetal, TargetPlatform::kRuntimeStageGLES, TargetPlatform::kRuntimeStageGLES3, TargetPlatform::kRuntimeStageVulkan, TargetPlatform::kSkSL), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestSkSL, ::testing::Values(TargetPlatform::kSkSL), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 INSTANTIATE_TEST_SUITE_P (CompilerSuite, CompilerTestUnknownPlatform, ::testing::Values(TargetPlatform::kUnknown), [](const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);})
 
 TEST (CompilerTest, Defines)
 
 TEST (CompilerTest, ShaderKindMatchingIsSuccessful)
 
 TEST_P (CompilerTest, CanCompile)
 
 TEST_P (CompilerTest, CanCompileHLSL)
 
 TEST_P (CompilerTest, CanCompileHLSLWithMultipleStages)
 
 TEST_P (CompilerTest, CanCompileComputeShader)
 
 TEST_P (CompilerTest, MustFailDueToExceedingResourcesLimit)
 
 TEST_P (CompilerTest, MustFailDueToMultipleLocationPerStructMember)
 
 TEST_P (CompilerTest, BindingBaseForFragShader)
 
 TEST_P (CompilerTestRuntime, UniformsAppearInJson)
 
 TEST_P (CompilerTestRuntime, PositionedUniformsAppearInJson)
 
 TEST_P (CompilerTest, UniformsHaveBindingAndSet)
 
 TEST_P (CompilerTestSkSL, SkSLTextureLookUpOrderOfOperations)
 
 TEST_P (CompilerTestSkSL, CanCompileStructs)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayInitializerWithConstants)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayInitializerWithVariables)
 
 TEST_P (CompilerTestSkSL, FailsToCompileDueToArrayAssignment)
 
 TEST_P (CompilerTestSkSL, CompilesWithValidArrayInitialization)
 
 TEST_P (CompilerTestRuntime, Mat2Reflection)
 
 TEST_P (CompilerTestUnknownPlatform, MustFailDueToUnknownPlatform)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidJSON)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenEntryNotObject)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingFile)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsWhenMissingType)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidType)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigFailsForInvalidLanguage)
 
 TEST (ShaderBundleTest, ParseShaderBundleConfigReturnsExpectedConfig)
 
template<typename T >
const T * FindByName (const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
 
 TEST (ShaderBundleTest, GenerateShaderBundleFlatbufferProducesCorrectResult)
 
Switches MakeSwitchesDesktopGL (std::initializer_list< const char * > additional_options={})
 
 TEST (SwitchesTest, DoesntMangleUnicodeIncludes)
 
 TEST (SwitchesTest, SourceLanguageDefaultsToGLSL)
 
 TEST (SwitchesTest, SourceLanguageCanBeSetToHLSL)
 
 TEST (SwitchesTest, DefaultEntryPointIsMain)
 
 TEST (SwitchesTest, EntryPointCanBeSetForHLSL)
 
 TEST (SwitchesTEst, ConvertToEntrypointName)
 
 TEST (SwitchesTest, ShaderBundleModeValid)
 
 TEST (SwitchesTest, EntryPointPrefixIsApplied)
 
 TEST (SwitchesTest, CommandLinePathUtf8)
 

Variables

const std::string kUnlitFragmentBundleConfig
 
const std::string kUnlitVertexBundleConfig
 

Function Documentation

◆ FindByName()

template<typename T >
const T* impeller::compiler::testing::FindByName ( const std::vector< std::unique_ptr< T >> &  collection,
const std::string &  name 
)

Definition at line 119 of file shader_bundle_unittests.cc.

120  {
121  const auto maybe = std::find_if(
122  collection.begin(), collection.end(),
123  [&name](const std::unique_ptr<T>& value) { return value->name == name; });
124  if (maybe == collection.end()) {
125  return nullptr;
126  }
127  return maybe->get();
128 }
int32_t value

References value.

Referenced by TEST().

◆ GetIntermediatesPath()

static std::string impeller::compiler::testing::GetIntermediatesPath ( )
static

Definition at line 17 of file compiler_test.cc.

17  {
18  auto test_name = flutter::testing::GetCurrentTestName();
19  std::replace(test_name.begin(), test_name.end(), '/', '_');
20  std::replace(test_name.begin(), test_name.end(), '.', '_');
21  std::stringstream dir_name;
22  dir_name << test_name << "_" << std::to_string(fml::GetCurrentProcId());
23  return fml::paths::JoinPaths(
24  {flutter::testing::GetFixturesPath(), dir_name.str()});
25 }

◆ INSTANTIATE_TEST_SUITE_P() [1/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTest  ,
::testing::Values(TargetPlatform::kOpenGLES, TargetPlatform::kOpenGLDesktop, TargetPlatform::kMetalDesktop, TargetPlatform::kMetalIOS, TargetPlatform::kVulkan ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [2/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestRuntime  ,
::testing::Values(TargetPlatform::kRuntimeStageMetal, TargetPlatform::kRuntimeStageGLES, TargetPlatform::kRuntimeStageGLES3, TargetPlatform::kRuntimeStageVulkan, TargetPlatform::kSkSL ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [3/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestSkSL  ,
::testing::Values(TargetPlatform::kSkSL ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ INSTANTIATE_TEST_SUITE_P() [4/4]

impeller::compiler::testing::INSTANTIATE_TEST_SUITE_P ( CompilerSuite  ,
CompilerTestUnknownPlatform  ,
::testing::Values(TargetPlatform::kUnknown ,
[] (const ::testing::TestParamInfo< CompilerTest::ParamType > &info) { return TargetPlatformToString(info.param);}   
)

◆ MakeSwitchesDesktopGL()

Switches impeller::compiler::testing::MakeSwitchesDesktopGL ( std::initializer_list< const char * >  additional_options = {})

Definition at line 20 of file switches_unittests.cc.

21  {}) {
22  std::vector<const char*> options = {"--opengl-desktop", "--input=input.vert",
23  "--sl=output.vert",
24  "--spirv=output.spirv"};
25  options.insert(options.end(), additional_options.begin(),
26  additional_options.end());
27 
28  auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
29  options.end());
30  return Switches(cl);
31 }

Referenced by TEST().

◆ ReflectionCCName()

static std::string impeller::compiler::testing::ReflectionCCName ( const char *  fixture_name)
static

Definition at line 48 of file compiler_test.cc.

48  {
49  std::stringstream stream;
50  stream << fixture_name << ".cc";
51  return stream.str();
52 }

Referenced by impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect().

◆ ReflectionHeaderName()

static std::string impeller::compiler::testing::ReflectionHeaderName ( const char *  fixture_name)
static

Definition at line 42 of file compiler_test.cc.

42  {
43  std::stringstream stream;
44  stream << fixture_name << ".h";
45  return stream.str();
46 }

Referenced by impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect().

◆ ReflectionJSONName()

static std::string impeller::compiler::testing::ReflectionJSONName ( const char *  fixture_name)
static

Definition at line 54 of file compiler_test.cc.

54  {
55  std::stringstream stream;
56  stream << fixture_name << ".json";
57  return stream.str();
58 }

Referenced by impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect(), and impeller::compiler::testing::CompilerTestBase::GetReflectionJson().

◆ SLFileName()

static std::string impeller::compiler::testing::SLFileName ( const char *  fixture_name,
TargetPlatform  platform 
)
static

Definition at line 66 of file compiler_test.cc.

67  {
68  std::stringstream stream;
69  stream << fixture_name << "." << TargetPlatformSLExtension(platform);
70  return stream.str();
71 }
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:218

References impeller::compiler::TargetPlatformSLExtension().

Referenced by impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect(), and impeller::compiler::testing::CompilerTestBase::GetShaderFile().

◆ SPIRVFileName()

static std::string impeller::compiler::testing::SPIRVFileName ( const char *  fixture_name)
static

Definition at line 60 of file compiler_test.cc.

60  {
61  std::stringstream stream;
62  stream << fixture_name << ".spv";
63  return stream.str();
64 }

Referenced by impeller::compiler::testing::CompilerTestBase::CanCompileAndReflect().

◆ TEST() [1/19]

impeller::compiler::testing::TEST ( CompilerTest  ,
Defines   
)

Definition at line 58 of file compiler_unittests.cc.

58  {
59  std::shared_ptr<const fml::Mapping> fixture =
60  flutter::testing::OpenFixtureAsMapping("check_gles_definition.frag");
61 
62  SourceOptions options;
63  options.source_language = SourceLanguage::kGLSL;
64  options.target_platform = TargetPlatform::kRuntimeStageGLES;
65  options.entry_point_name = "main";
66  options.type = SourceType::kFragmentShader;
67 
68  Reflector::Options reflector_options;
69  reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES;
70  Compiler compiler = Compiler(fixture, options, reflector_options);
71 
72  // Should fail as the shader has a compilation error in it.
73  EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr);
74 
75  // Should succeed as the compilation error is ifdef'd out.
76  options.target_platform = TargetPlatform::kRuntimeStageVulkan;
77  reflector_options.target_platform = TargetPlatform::kRuntimeStageVulkan;
78  Compiler compiler_2 = Compiler(fixture, options, reflector_options);
79  EXPECT_NE(compiler_2.GetSPIRVAssembly(), nullptr);
80 }

References impeller::compiler::SourceOptions::entry_point_name, impeller::compiler::Compiler::GetSPIRVAssembly(), impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageGLES, impeller::compiler::kRuntimeStageVulkan, impeller::compiler::SourceOptions::source_language, impeller::compiler::Reflector::Options::target_platform, impeller::compiler::SourceOptions::target_platform, and impeller::compiler::SourceOptions::type.

◆ TEST() [2/19]

impeller::compiler::testing::TEST ( CompilerTest  ,
ShaderKindMatchingIsSuccessful   
)

Definition at line 82 of file compiler_unittests.cc.

82  {
83  ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
84  ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
85  ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
86  ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
87  ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
88 }
SourceType SourceTypeFromFileName(const std::filesystem::path &file_name)
Definition: types.cc:17

References impeller::compiler::kComputeShader, impeller::compiler::kFragmentShader, impeller::compiler::kUnknown, impeller::compiler::kVertexShader, and impeller::compiler::SourceTypeFromFileName().

◆ TEST() [3/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
GenerateShaderBundleFlatbufferProducesCorrectResult   
)

Verify vertex shader.

Verify fragment shader.

Definition at line 130 of file shader_bundle_unittests.cc.

130  {
131  std::string fixtures_path = flutter::testing::GetFixturesPath();
132  std::string config =
133  "{\"UnlitFragment\": {\"type\": \"fragment\", \"file\": \"" +
134  fixtures_path +
135  "/flutter_gpu_unlit.frag\"}, \"UnlitVertex\": {\"type\": "
136  "\"vertex\", \"file\": \"" +
137  fixtures_path + "/flutter_gpu_unlit.vert\"}}";
138 
139  SourceOptions options;
140  options.target_platform = TargetPlatform::kRuntimeStageMetal;
141  options.source_language = SourceLanguage::kGLSL;
142 
143  std::optional<fb::shaderbundle::ShaderBundleT> bundle =
144  GenerateShaderBundleFlatbuffer(config, options);
145  ASSERT_TRUE(bundle.has_value());
146 
147  // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
148  const auto& shaders = bundle->shaders;
149 
150  const auto* vertex = FindByName(shaders, "UnlitVertex");
151  const auto* fragment = FindByName(shaders, "UnlitFragment");
152  ASSERT_NE(vertex, nullptr);
153  ASSERT_NE(fragment, nullptr);
154 
155  // --------------------------------------------------------------------------
156  /// Verify vertex shader.
157  ///
158 
159  EXPECT_STREQ(vertex->metal_desktop->entrypoint.c_str(),
160  "flutter_gpu_unlit_vertex_main");
161  EXPECT_EQ(vertex->metal_desktop->stage,
162  fb::shaderbundle::ShaderStage::kVertex);
163 
164  // Inputs.
165  ASSERT_EQ(vertex->metal_desktop->inputs.size(), 1u);
166  const auto& v_in_position = vertex->metal_desktop->inputs[0];
167  EXPECT_STREQ(v_in_position->name.c_str(), "position");
168  EXPECT_EQ(v_in_position->location, 0u);
169  EXPECT_EQ(v_in_position->set, 0u);
170  EXPECT_EQ(v_in_position->binding, 0u);
171  EXPECT_EQ(v_in_position->type, fb::shaderbundle::InputDataType::kFloat);
172  EXPECT_EQ(v_in_position->bit_width, 32u);
173  EXPECT_EQ(v_in_position->vec_size, 2u);
174  EXPECT_EQ(v_in_position->columns, 1u);
175  EXPECT_EQ(v_in_position->offset, 0u);
176 
177  // Uniforms.
178  ASSERT_EQ(vertex->metal_desktop->uniform_structs.size(), 1u);
179  const auto* vert_info =
180  FindByName(vertex->metal_desktop->uniform_structs, "VertInfo");
181  ASSERT_NE(vert_info, nullptr);
182  EXPECT_EQ(vert_info->ext_res_0, 0u);
183  EXPECT_EQ(vert_info->set, 0u);
184  EXPECT_EQ(vert_info->binding, 0u);
185  ASSERT_EQ(vert_info->fields.size(), 2u);
186  const auto& mvp = vert_info->fields[0];
187  EXPECT_STREQ(mvp->name.c_str(), "mvp");
188  EXPECT_EQ(mvp->type, fb::shaderbundle::UniformDataType::kFloat);
189  EXPECT_EQ(mvp->offset_in_bytes, 0u);
190  EXPECT_EQ(mvp->element_size_in_bytes, 64u);
191  EXPECT_EQ(mvp->total_size_in_bytes, 64u);
192  EXPECT_EQ(mvp->array_elements, 0u);
193  const auto& color = vert_info->fields[1];
194  EXPECT_STREQ(color->name.c_str(), "color");
195  EXPECT_EQ(color->type, fb::shaderbundle::UniformDataType::kFloat);
196  EXPECT_EQ(color->offset_in_bytes, 64u);
197  EXPECT_EQ(color->element_size_in_bytes, 16u);
198  EXPECT_EQ(color->total_size_in_bytes, 16u);
199  EXPECT_EQ(color->array_elements, 0u);
200 
201  // --------------------------------------------------------------------------
202  /// Verify fragment shader.
203  ///
204 
205  EXPECT_STREQ(fragment->metal_desktop->entrypoint.c_str(),
206  "flutter_gpu_unlit_fragment_main");
207  EXPECT_EQ(fragment->metal_desktop->stage,
208  fb::shaderbundle::ShaderStage::kFragment);
209 
210  // Inputs (not recorded for fragment shaders).
211  ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
212 
213  // Uniforms.
214  ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
215 }
const T * FindByName(const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
std::optional< fb::shaderbundle::ShaderBundleT > GenerateShaderBundleFlatbuffer(const std::string &bundle_config_json, const SourceOptions &options)
Parses the JSON shader bundle configuration and invokes the compiler multiple times to produce a shad...

References FindByName(), impeller::compiler::GenerateShaderBundleFlatbuffer(), impeller::kFloat, impeller::compiler::kGLSL, impeller::compiler::kRuntimeStageMetal, impeller::compiler::SourceOptions::source_language, and impeller::compiler::SourceOptions::target_platform.

◆ TEST() [4/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsForInvalidJSON   
)

Definition at line 24 of file shader_bundle_unittests.cc.

24  {
25  std::string bundle = "";
26  std::stringstream error;
27  auto result = ParseShaderBundleConfig(bundle, error);
28  ASSERT_FALSE(result.has_value());
29  ASSERT_STREQ(error.str().c_str(),
30  "The shader bundle is not a valid JSON object.\n");
31 }
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [5/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsForInvalidLanguage   
)

Definition at line 76 of file shader_bundle_unittests.cc.

76  {
77  std::string bundle =
78  "{\"UnlitVertex\": {\"type\": \"vertex\", \"language\": \"invalid\", "
79  "\"file\": \"shaders/flutter_gpu_unlit.vert\"}}";
80  std::stringstream error;
81  auto result = ParseShaderBundleConfig(bundle, error);
82  ASSERT_FALSE(result.has_value());
83  ASSERT_STREQ(error.str().c_str(),
84  "Invalid shader entry \"UnlitVertex\": Unknown language type "
85  "\"invalid\".\n");
86 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [6/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsForInvalidType   
)

Definition at line 64 of file shader_bundle_unittests.cc.

64  {
65  std::string bundle =
66  "{\"UnlitVertex\": {\"type\": \"invalid\", \"file\": "
67  "\"shaders/flutter_gpu_unlit.vert\"}}";
68  std::stringstream error;
69  auto result = ParseShaderBundleConfig(bundle, error);
70  ASSERT_FALSE(result.has_value());
71  ASSERT_STREQ(error.str().c_str(),
72  "Invalid shader entry \"UnlitVertex\": Shader type "
73  "\"invalid\" is unknown.\n");
74 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [7/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsWhenEntryNotObject   
)

Definition at line 33 of file shader_bundle_unittests.cc.

33  {
34  std::string bundle = "{\"UnlitVertex\": []}";
35  std::stringstream error;
36  auto result = ParseShaderBundleConfig(bundle, error);
37  ASSERT_FALSE(result.has_value());
38  ASSERT_STREQ(
39  error.str().c_str(),
40  "Invalid shader entry \"UnlitVertex\": Entry is not a JSON object.\n");
41 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [8/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsWhenMissingFile   
)

Definition at line 43 of file shader_bundle_unittests.cc.

43  {
44  std::string bundle = "{\"UnlitVertex\": {\"type\": \"vertex\"}}";
45  std::stringstream error;
46  auto result = ParseShaderBundleConfig(bundle, error);
47  ASSERT_FALSE(result.has_value());
48  ASSERT_STREQ(error.str().c_str(),
49  "Invalid shader entry \"UnlitVertex\": Missing required "
50  "\"file\" field.\n");
51 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [9/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigFailsWhenMissingType   
)

Definition at line 53 of file shader_bundle_unittests.cc.

53  {
54  std::string bundle =
55  "{\"UnlitVertex\": {\"file\": \"shaders/flutter_gpu_unlit.vert\"}}";
56  std::stringstream error;
57  auto result = ParseShaderBundleConfig(bundle, error);
58  ASSERT_FALSE(result.has_value());
59  ASSERT_STREQ(error.str().c_str(),
60  "Invalid shader entry \"UnlitVertex\": Missing required "
61  "\"type\" field.\n");
62 }

References impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [10/19]

impeller::compiler::testing::TEST ( ShaderBundleTest  ,
ParseShaderBundleConfigReturnsExpectedConfig   
)

Definition at line 88 of file shader_bundle_unittests.cc.

88  {
89  std::string bundle =
91  std::stringstream error;
92  auto result = ParseShaderBundleConfig(bundle, error);
93  ASSERT_TRUE(result.has_value());
94  ASSERT_STREQ(error.str().c_str(), "");
95 
96  // NOLINTBEGIN(bugprone-unchecked-optional-access)
97  auto maybe_vertex = result->find("UnlitVertex");
98  auto maybe_fragment = result->find("UnlitFragment");
99  ASSERT_TRUE(maybe_vertex != result->end());
100  ASSERT_TRUE(maybe_fragment != result->end());
101  auto vertex = maybe_vertex->second;
102  auto fragment = maybe_fragment->second;
103  // NOLINTEND(bugprone-unchecked-optional-access)
104 
105  EXPECT_EQ(vertex.type, SourceType::kVertexShader);
106  EXPECT_EQ(vertex.language, SourceLanguage::kGLSL);
107  EXPECT_STREQ(vertex.entry_point.c_str(), "main");
108  EXPECT_STREQ(vertex.source_file_name.c_str(),
109  "shaders/flutter_gpu_unlit.vert");
110 
111  EXPECT_EQ(fragment.type, SourceType::kFragmentShader);
112  EXPECT_EQ(fragment.language, SourceLanguage::kGLSL);
113  EXPECT_STREQ(fragment.entry_point.c_str(), "main");
114  EXPECT_STREQ(fragment.source_file_name.c_str(),
115  "shaders/flutter_gpu_unlit.frag");
116 }
const std::string kUnlitFragmentBundleConfig

References impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, kUnlitFragmentBundleConfig, kUnlitVertexBundleConfig, impeller::compiler::kVertexShader, and impeller::compiler::ParseShaderBundleConfig().

◆ TEST() [11/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
CommandLinePathUtf8   
)

Definition at line 109 of file switches_unittests.cc.

109  {
110  std::u16string filename = u"test\u1234";
111  std::string input_flag = "--input=" + fml::Utf16ToUtf8(filename);
112  Switches switches = MakeSwitchesDesktopGL({input_flag.c_str()});
113  ASSERT_TRUE(switches.AreValid(std::cout));
114  ASSERT_EQ(switches.source_file_name, filename);
115 }
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})

References impeller::compiler::Switches::AreValid(), MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_file_name.

◆ TEST() [12/19]

impeller::compiler::testing::TEST ( SwitchesTEst  ,
ConvertToEntrypointName   
)

Definition at line 74 of file switches_unittests.cc.

74  {
75  ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
76  "mandelbrot_unrolled");
77  ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
78  "mandelbrotunrolled");
79  ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
80  ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
81  ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
82  ASSERT_EQ(ConvertToEntrypointName(""), "");
83 }
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition: utilities.cc:68

References impeller::compiler::ConvertToEntrypointName().

◆ TEST() [13/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
DefaultEntryPointIsMain   
)

Definition at line 62 of file switches_unittests.cc.

62  {
63  Switches switches = MakeSwitchesDesktopGL({});
64  ASSERT_TRUE(switches.AreValid(std::cout));
65  ASSERT_EQ(switches.entry_point, "main");
66 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::entry_point, and MakeSwitchesDesktopGL().

◆ TEST() [14/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
DoesntMangleUnicodeIncludes   
)

Definition at line 33 of file switches_unittests.cc.

33  {
34  const char* directory_name = "test_shader_include_�";
35  fml::CreateDirectory(flutter::testing::OpenFixturesDirectory(),
36  {directory_name}, fml::FilePermission::kRead);
37 
38  auto include_path =
39  std::string(flutter::testing::GetFixturesPath()) + "/" + directory_name;
40  auto include_option = "--include=" + include_path;
41 
42  Switches switches = MakeSwitchesDesktopGL({include_option.c_str()});
43 
44  ASSERT_TRUE(switches.AreValid(std::cout));
45  ASSERT_EQ(switches.include_directories.size(), 1u);
46  ASSERT_NE(switches.include_directories[0].dir, nullptr);
47  ASSERT_EQ(switches.include_directories[0].name, include_path);
48 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::include_directories, and MakeSwitchesDesktopGL().

◆ TEST() [15/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
EntryPointCanBeSetForHLSL   
)

Definition at line 68 of file switches_unittests.cc.

68  {
69  Switches switches = MakeSwitchesDesktopGL({"--entry-point=CustomEntryPoint"});
70  ASSERT_TRUE(switches.AreValid(std::cout));
71  ASSERT_EQ(switches.entry_point, "CustomEntryPoint");
72 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::entry_point, and MakeSwitchesDesktopGL().

◆ TEST() [16/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
EntryPointPrefixIsApplied   
)

Definition at line 98 of file switches_unittests.cc.

98  {
99  Switches switches =
100  MakeSwitchesDesktopGL({"--entry-point-prefix=my_prefix_"});
101  ASSERT_TRUE(switches.AreValid(std::cout));
102  EXPECT_EQ(switches.entry_point_prefix, "my_prefix_");
103 
104  switches.source_file_name = "test.frag";
105  auto options = switches.CreateSourceOptions();
106  EXPECT_EQ(options.entry_point_name, "my_prefix_test_fragment_main");
107 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::Switches::CreateSourceOptions(), impeller::compiler::Switches::entry_point_prefix, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_file_name.

◆ TEST() [17/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
ShaderBundleModeValid   
)

Definition at line 85 of file switches_unittests.cc.

85  {
86  // Shader bundles process multiple shaders, and so the single-file input/spirv
87  // flags are not required.
88  std::vector<const char*> options = {
89  "--shader-bundle={}", "--sl=test.shaderbundle", "--runtime-stage-metal"};
90 
91  auto cl = fml::CommandLineFromIteratorsWithArgv0("impellerc", options.begin(),
92  options.end());
93  Switches switches(cl);
94  ASSERT_TRUE(switches.AreValid(std::cout));
95  ASSERT_EQ(switches.shader_bundle, "{}");
96 }

References impeller::compiler::Switches::AreValid(), and impeller::compiler::Switches::shader_bundle.

◆ TEST() [18/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
SourceLanguageCanBeSetToHLSL   
)

Definition at line 56 of file switches_unittests.cc.

56  {
57  Switches switches = MakeSwitchesDesktopGL({"--source-language=hLsL"});
58  ASSERT_TRUE(switches.AreValid(std::cout));
59  ASSERT_EQ(switches.source_language, SourceLanguage::kHLSL);
60 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::kHLSL, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_language.

◆ TEST() [19/19]

impeller::compiler::testing::TEST ( SwitchesTest  ,
SourceLanguageDefaultsToGLSL   
)

Definition at line 50 of file switches_unittests.cc.

50  {
51  Switches switches = MakeSwitchesDesktopGL();
52  ASSERT_TRUE(switches.AreValid(std::cout));
53  ASSERT_EQ(switches.source_language, SourceLanguage::kGLSL);
54 }

References impeller::compiler::Switches::AreValid(), impeller::compiler::kGLSL, MakeSwitchesDesktopGL(), and impeller::compiler::Switches::source_language.

◆ TEST_P() [1/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
BindingBaseForFragShader   
)

Definition at line 131 of file compiler_unittests.cc.

131  {
132  if (!TargetPlatformIsVulkan(GetParam())) {
133  GTEST_SKIP();
134  }
135 
136  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
137  ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
138 
139  auto get_binding = [&](const char* fixture) -> uint32_t {
140  auto json_fd = GetReflectionJson(fixture);
141  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
142  return shader_json["buffers"][0]["binding"].get<uint32_t>();
143  };
144 
145  auto vert_uniform_binding = get_binding("sample.vert");
146  auto frag_uniform_binding = get_binding("sample.frag");
147 
148  ASSERT_GT(frag_uniform_binding, vert_uniform_binding);
149 }
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:277

References impeller::compiler::kFragmentShader, impeller::compiler::kVertexShader, and impeller::compiler::TargetPlatformIsVulkan().

◆ TEST_P() [2/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
CanCompile   
)

Definition at line 90 of file compiler_unittests.cc.

90  {
91  ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
92  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
93  ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
94  SourceLanguage::kGLSL));
95 }

References impeller::compiler::kGLSL, and impeller::compiler::kVertexShader.

◆ TEST_P() [3/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
CanCompileComputeShader   
)

Definition at line 111 of file compiler_unittests.cc.

111  {
112  if (!TargetPlatformIsMetal(GetParam())) {
113  GTEST_SKIP()
114  << "Only enabled on Metal backends till ES 3.2 support is added.";
115  }
116  ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
117  ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
118 }
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:258

References impeller::compiler::kComputeShader, and impeller::compiler::TargetPlatformIsMetal().

◆ TEST_P() [4/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
CanCompileHLSL   
)

Definition at line 97 of file compiler_unittests.cc.

97  {
98  ASSERT_TRUE(CanCompileAndReflect(
99  "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
100 }

References impeller::compiler::kHLSL, and impeller::compiler::kVertexShader.

◆ TEST_P() [5/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
CanCompileHLSLWithMultipleStages   
)

Definition at line 102 of file compiler_unittests.cc.

102  {
103  ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
104  SourceType::kVertexShader,
105  SourceLanguage::kHLSL, "VertexShader"));
106  ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
107  SourceType::kFragmentShader,
108  SourceLanguage::kHLSL, "FragmentShader"));
109 }

References impeller::compiler::kFragmentShader, impeller::compiler::kHLSL, and impeller::compiler::kVertexShader.

◆ TEST_P() [6/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
MustFailDueToExceedingResourcesLimit   
)

Definition at line 120 of file compiler_unittests.cc.

120  {
121  ScopedValidationDisable disable_validation;
122  ASSERT_FALSE(
123  CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
124 }

References impeller::compiler::kVertexShader.

◆ TEST_P() [7/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
MustFailDueToMultipleLocationPerStructMember   
)

Definition at line 126 of file compiler_unittests.cc.

126  {
127  ScopedValidationDisable disable_validation;
128  ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
129 }

◆ TEST_P() [8/18]

impeller::compiler::testing::TEST_P ( CompilerTest  ,
UniformsHaveBindingAndSet   
)

Definition at line 335 of file compiler_unittests.cc.

335  {
336  if (GetParam() == TargetPlatform::kSkSL) {
337  GTEST_SKIP() << "Not supported with SkSL";
338  }
339  ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
340  SourceType::kVertexShader));
341  ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
342 
343  struct binding_and_set {
344  uint32_t binding;
345  uint32_t set;
346  };
347 
348  auto get_binding = [&](const char* fixture) -> binding_and_set {
349  auto json_fd = GetReflectionJson(fixture);
350  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
351  uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
352  uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
353  return {binding, set};
354  };
355 
356  auto vert_uniform_binding = get_binding("sample_with_binding.vert");
357  auto frag_uniform_binding = get_binding("sample.frag");
358 
359  ASSERT_EQ(frag_uniform_binding.set, 0u);
360  ASSERT_EQ(vert_uniform_binding.set, 3u);
361  ASSERT_EQ(vert_uniform_binding.binding, 17u);
362 }

References impeller::compiler::kFragmentShader, impeller::compiler::kSkSL, and impeller::compiler::kVertexShader.

◆ TEST_P() [9/18]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
Mat2Reflection   
)

Definition at line 471 of file compiler_unittests.cc.

471  {
472  if (GetParam() == TargetPlatform::kSkSL) {
473  GTEST_SKIP() << "Not supported with SkSL";
474  }
475 
476  ASSERT_TRUE(CanCompileAndReflect(
477  "mat2_test.frag", SourceType::kFragmentShader, SourceLanguage::kGLSL));
478 
479  std::unique_ptr<fml::FileMapping> json_fd =
480  GetReflectionJson("mat2_test.frag");
481  ASSERT_TRUE(json_fd);
482  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
483  nlohmann::json::value_type buffers = shader_json["buffers"];
484 
485  // uParams should be in buffers.
486  ASSERT_GE(buffers.size(), 1u);
487  nlohmann::json::value_type uParams = buffers[0];
488  EXPECT_EQ(uParams["name"], "Params");
489 
490  nlohmann::json::value_type members = uParams["type"]["members"];
491  // We expect 1 member (for the mat2) which is a Point (vec2) with array
492  // size 2.
493  ASSERT_EQ(members.size(), 1u);
494 
495  nlohmann::json::value_type mat2Member = members[0];
496 
497  // Should be Mat2 (vec2)
498  EXPECT_EQ(mat2Member["type"], "Mat2");
499 
500  // Size 8 bytes (vec2)
501  EXPECT_EQ(mat2Member["size"], 8u);
502 
503  // Byte length should be total array size (stride * count)
504  // Stride 16 * 2 = 32.
505  EXPECT_EQ(mat2Member["byte_length"], 32u);
506 
507  // Array elements should be 2 (columns).
508  EXPECT_EQ(mat2Member["array_elements"], 2u);
509 
510  // Offset 0
511  EXPECT_EQ(mat2Member["offset"], 0u);
512 }

References impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, and impeller::compiler::kSkSL.

◆ TEST_P() [10/18]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
PositionedUniformsAppearInJson   
)

Definition at line 281 of file compiler_unittests.cc.

281  {
282  if (GetParam() == TargetPlatform::kRuntimeStageVulkan) {
283  // TODO(https://github.com/flutter/flutter/issues/182578): Investigate why
284  // this does not pass.
285  GTEST_SKIP() << "Not supported with Vulkan";
286  }
287 
288  ASSERT_TRUE(CanCompileAndReflect("sample_with_positioned_uniforms.frag",
289  SourceType::kFragmentShader,
290  SourceLanguage::kGLSL));
291 
292  auto json_fd = GetReflectionJson("sample_with_positioned_uniforms.frag");
293  ASSERT_TRUE(json_fd);
294  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
295  auto sampler_list = shader_json["sampled_images"];
296  auto float_list = shader_json["uniforms"];
297  ASSERT_EQ(sampler_list.size(), 3u);
298  ASSERT_EQ(float_list.size(), 7u);
299 
300  {
301  // clang-format off
302  std::array expected_infos = {
303  UniformInfo::Sampler("uSamplerNotPositioned1", 1u),
304  UniformInfo::Sampler("uSampler", 0u),
305  UniformInfo::Sampler("uSamplerNotPositioned2", 3u),
306  };
307  // clang-format on
308  ASSERT_EQ(sampler_list.size(), expected_infos.size());
309  for (size_t i = 0; i < expected_infos.size(); i++) {
310  EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
311  << "index: " << i;
312  }
313  }
314 
315  {
316  // clang-format off
317  std::array expected_infos = {
318  UniformInfo::Float("uFloatNotPositioned1", 0u),
319  UniformInfo::Float("uFloat", 6u),
320  UniformInfo::Vec2("uVec2", 5u),
321  UniformInfo::Vec3("uVec3", 3u),
322  UniformInfo::Vec4("uVec4", 2u),
323  UniformInfo::Mat4("uMat4", 1u),
324  UniformInfo::Float("uFloatNotPositioned2", 2u),
325  };
326  // clang-format on
327  ASSERT_EQ(float_list.size(), expected_infos.size());
328  for (size_t i = 0; i < expected_infos.size(); i++) {
329  EXPECT_EQ(UniformInfo::fromJson(float_list[i]), expected_infos[i])
330  << "index: " << i;
331  }
332  }
333 }

References impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, and impeller::compiler::kRuntimeStageVulkan.

◆ TEST_P() [11/18]

impeller::compiler::testing::TEST_P ( CompilerTestRuntime  ,
UniformsAppearInJson   
)

Definition at line 229 of file compiler_unittests.cc.

229  {
230  if (GetParam() == TargetPlatform::kRuntimeStageVulkan) {
231  // TODO(https://github.com/flutter/flutter/issues/182578): Investigate why
232  // this does not pass.
233  GTEST_SKIP() << "Not supported with Vulkan";
234  }
235 
236  ASSERT_TRUE(CanCompileAndReflect("sample_with_uniforms.frag",
237  SourceType::kFragmentShader,
238  SourceLanguage::kGLSL));
239 
240  auto json_fd = GetReflectionJson("sample_with_uniforms.frag");
241  ASSERT_TRUE(json_fd);
242  nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
243  auto sampler_list = shader_json["sampled_images"];
244  auto float_list = shader_json["uniforms"];
245  ASSERT_EQ(sampler_list.size(), 2u);
246  ASSERT_EQ(float_list.size(), 6u);
247 
248  {
249  // clang-format off
250  std::array expected_infos = {
251  UniformInfo::Sampler("uFirstSampler", 1u),
252  UniformInfo::Sampler("uSampler", 7u),
253  };
254  // clang-format on
255  ASSERT_EQ(sampler_list.size(), expected_infos.size());
256  for (size_t i = 0; i < expected_infos.size(); i++) {
257  EXPECT_EQ(UniformInfo::fromJson(sampler_list[i]), expected_infos[i])
258  << "index: " << i;
259  }
260  }
261 
262  {
263  // clang-format off
264  std::array expected_infos = {
265  UniformInfo::Float("uFirstFloat", 0u),
266  UniformInfo::Float("uFloat", 2u),
267  UniformInfo::Vec2("uVec2", 3u),
268  UniformInfo::Vec3("uVec3", 4u),
269  UniformInfo::Vec4("uVec4", 5u),
270  UniformInfo::Mat4("uMat4", 6u),
271  };
272  // clang-format on
273  ASSERT_EQ(float_list.size(), expected_infos.size());
274  for (size_t i = 0; i < expected_infos.size(); i++) {
275  EXPECT_EQ(UniformInfo::fromJson(float_list[i]), expected_infos[i])
276  << "index: " << i;
277  }
278  }
279 }

References impeller::compiler::kFragmentShader, impeller::compiler::kGLSL, and impeller::compiler::kRuntimeStageVulkan.

◆ TEST_P() [12/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
CanCompileStructs   
)

Definition at line 378 of file compiler_unittests.cc.

378  {
379  ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
380  SourceType::kFragmentShader));
381 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [13/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
CompilesWithValidArrayInitialization   
)

Definition at line 465 of file compiler_unittests.cc.

465  {
466  ASSERT_TRUE(
467  CanCompileAndReflect("array_initialization_without_initializer.frag",
468  SourceType::kFragmentShader));
469 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [14/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayAssignment   
)

Definition at line 403 of file compiler_unittests.cc.

403  {
404  // Does not EXIT because the backend SkSL compiler doesn't detect the invalid
405  // SkSL. Returns false because the Impeller Compiler's post-compile validation
406  // fails.
407  ASSERT_FALSE(CanCompileAndReflect("array_assignment.frag",
408  SourceType::kFragmentShader));
409 
410  const Compiler* compiler = GetCompiler();
411  ASSERT_TRUE(compiler);
412  // Truncated error message.
413  ASSERT_STREQ(
414  compiler->GetErrorMessages().c_str(),
415  "\"array_assignment.frag\": \n"
416  "Compiled to invalid SkSL:\n"
417  " // This SkSL shader is autogenerated by spirv-cross.\n"
418  " \n"
419  " float4 flutter_FragCoord;\n"
420  " \n"
421  " vec4 frag_color;\n"
422  " \n"
423  "... (truncated 16 lines)\n"
424  "SkSL Error:\n"
425  " error: 12: initializers are not permitted on arrays (or structs "
426  "containing arrays)\n"
427  " float more_nums[2] = nums;\n"
428  " ^^^^\n"
429  " 1 error\n");
430  // Full error message.
431  ASSERT_STREQ(compiler->GetVerboseErrorMessages().c_str(),
432  "\"array_assignment.frag\": \n"
433  "Compiled to invalid SkSL:\n"
434  "// This SkSL shader is autogenerated by spirv-cross.\n"
435  "\n"
436  "float4 flutter_FragCoord;\n"
437  "\n"
438  "vec4 frag_color;\n"
439  "\n"
440  "void FLT_main()\n"
441  "{\n"
442  " float nums[2];\n"
443  " nums[0] = 1.0;\n"
444  " nums[1] = 0.5;\n"
445  " float more_nums[2] = nums;\n"
446  " frag_color = vec4(nums[0], nums[1], 1.0, 1.0);\n"
447  "}\n"
448  "\n"
449  "half4 main(float2 iFragCoord)\n"
450  "{\n"
451  " flutter_FragCoord = float4(iFragCoord, 0, 0);\n"
452  " FLT_main();\n"
453  " return frag_color;\n"
454  "}\n"
455  "\n"
456  "SkSL Error:\n"
457  "error: 12: initializers are not permitted on arrays (or "
458  "structs containing arrays)\n"
459  " float more_nums[2] = nums;\n"
460  " ^^^^\n"
461  "1 error\n"
462  "\n");
463 }

References impeller::compiler::Compiler::GetErrorMessages(), impeller::compiler::Compiler::GetVerboseErrorMessages(), and impeller::compiler::kFragmentShader.

◆ TEST_P() [15/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayInitializerWithConstants   
)

Definition at line 383 of file compiler_unittests.cc.

383  {
384  auto expected_err =
385  "There was a compiler error: SkSL does not support array initializers: "
386  "array_initializer_with_constants.frag:6";
387 
388  EXPECT_EXIT(CanCompileAndReflect("array_initializer_with_constants.frag",
389  SourceType::kFragmentShader),
390  ::testing::ExitedWithCode(1), expected_err);
391 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [16/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
FailsToCompileDueToArrayInitializerWithVariables   
)

Definition at line 393 of file compiler_unittests.cc.

393  {
394  auto expected_err =
395  "There was a compiler error: SkSL does not support array initializers: "
396  "array_initializer_with_variables.frag:12";
397 
398  EXPECT_EXIT(CanCompileAndReflect("array_initializer_with_variables.frag",
399  SourceType::kFragmentShader),
400  ::testing::ExitedWithCode(1), expected_err);
401 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [17/18]

impeller::compiler::testing::TEST_P ( CompilerTestSkSL  ,
SkSLTextureLookUpOrderOfOperations   
)

Definition at line 364 of file compiler_unittests.cc.

364  {
365  ASSERT_TRUE(
366  CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
367 
368  auto shader = GetShaderFile("texture_lookup.frag", GetParam());
369  std::string_view shader_mapping(
370  reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
371 
372  constexpr std::string_view expected =
373  "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
374 
375  EXPECT_NE(shader_mapping.find(expected), std::string::npos);
376 }

References impeller::compiler::kFragmentShader.

◆ TEST_P() [18/18]

impeller::compiler::testing::TEST_P ( CompilerTestUnknownPlatform  ,
MustFailDueToUnknownPlatform   
)

Definition at line 514 of file compiler_unittests.cc.

514  {
515  ASSERT_FALSE(
516  CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
517 }

References impeller::compiler::kFragmentShader.

Variable Documentation

◆ kUnlitFragmentBundleConfig

const std::string impeller::compiler::testing::kUnlitFragmentBundleConfig
Initial value:
=
"\"UnlitFragment\": {\"type\": \"fragment\", \"file\": "
"\"shaders/flutter_gpu_unlit.frag\"}"

Definition at line 17 of file shader_bundle_unittests.cc.

Referenced by TEST().

◆ kUnlitVertexBundleConfig

const std::string impeller::compiler::testing::kUnlitVertexBundleConfig
Initial value:
=
"\"UnlitVertex\": {\"type\": \"vertex\", \"file\": "
"\"shaders/flutter_gpu_unlit.vert\"}"

Definition at line 20 of file shader_bundle_unittests.cc.

Referenced by TEST().