| Flutter Impeller |

Classes | Functions | Variables
impeller::compiler::testing Namespace Reference

## Classes
class | CompilerTest

## 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)
| 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 (CompilerTest, UniformsHaveBindingAndSet)
| TEST_P (CompilerTest, SkSLTextureLookUpOrderOfOperations)
| TEST_P (CompilerTest, CanCompileStructs)
| INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P (CompilerSuite)
| 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)

## 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 }

Referenced by TEST().

## ◆ GetIntermediatesPath()

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

Definition at line 16 of file compiler_test.cc.

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

## ◆ INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P()

impeller::compiler::testing::INSTANTIATE_TARGET_PLATFORM_TEST_SUITE_P | ( | CompilerSuite |  | ) |

## ◆ MakeSwitchesDesktopGL()

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

Definition at line 18 of file switches_unittests.cc.

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

Referenced by TEST().

## ◆ ReflectionCCName()

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

Definition at line 46 of file compiler_test.cc.

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

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

## ◆ ReflectionHeaderName()

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

Definition at line 40 of file compiler_test.cc.

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

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

## ◆ ReflectionJSONName()

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

Definition at line 52 of file compiler_test.cc.

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

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

## ◆ SLFileName()

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

Definition at line 64 of file compiler_test.cc.

65 {
66 std::stringstream stream;
67 stream << fixture_name << "." << TargetPlatformSLExtension(platform);
68 return stream.str();
69 }

References impeller::compiler::TargetPlatformSLExtension().

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

## ◆ SPIRVFileName()

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

Definition at line 58 of file compiler_test.cc.

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

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

## ◆ TEST() [1/16]

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

Definition at line 18 of file compiler_unittests.cc.

18 {
19 ASSERT_EQ(SourceTypeFromFileName("hello.vert"), SourceType::kVertexShader);
20 ASSERT_EQ(SourceTypeFromFileName("hello.frag"), SourceType::kFragmentShader);
21 ASSERT_EQ(SourceTypeFromFileName("hello.comp"), SourceType::kComputeShader);
22 ASSERT_EQ(SourceTypeFromFileName("hello.msl"), SourceType::kUnknown);
23 ASSERT_EQ(SourceTypeFromFileName("hello.glsl"), SourceType::kUnknown);
24 }

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

## ◆ TEST() [2/16]

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 const auto* vertex = FindByName(shaders, "UnlitVertex");
150 const auto* fragment = FindByName(shaders, "UnlitFragment");
151 ASSERT_NE(vertex, nullptr);
152 ASSERT_NE(fragment, nullptr);
153
154 // --------------------------------------------------------------------------
155 /// Verify vertex shader.
156 ///
157
158 EXPECT_STREQ(vertex->metal_desktop->entrypoint.c_str(),
159 "flutter_gpu_unlit_vertex_main");
160 EXPECT_EQ(vertex->metal_desktop->stage,
161 fb::shaderbundle::ShaderStage::kVertex);
162
163 // Inputs.
164 ASSERT_EQ(vertex->metal_desktop->inputs.size(), 1u);
165 const auto& v_in_position = vertex->metal_desktop->inputs[0];
166 EXPECT_STREQ(v_in_position->name.c_str(), "position");
167 EXPECT_EQ(v_in_position->location, 0u);
168 EXPECT_EQ(v_in_position->set, 0u);
169 EXPECT_EQ(v_in_position->binding, 0u);
170 EXPECT_EQ(v_in_position->type, fb::shaderbundle::InputDataType::kFloat);
171 EXPECT_EQ(v_in_position->bit_width, 32u);
172 EXPECT_EQ(v_in_position->vec_size, 2u);
173 EXPECT_EQ(v_in_position->columns, 1u);
174 EXPECT_EQ(v_in_position->offset, 0u);
175
176 // Uniforms.
177 ASSERT_EQ(vertex->metal_desktop->uniform_structs.size(), 1u);
178 const auto* vert_info =
179 FindByName(vertex->metal_desktop->uniform_structs, "VertInfo");
180 ASSERT_NE(vert_info, nullptr);
181 EXPECT_EQ(vert_info->ext_res_0, 0u);
182 EXPECT_EQ(vert_info->set, 0u);
183 EXPECT_EQ(vert_info->binding, 0u);
184 ASSERT_EQ(vert_info->fields.size(), 2u);
185 const auto& mvp = vert_info->fields[0];
186 EXPECT_STREQ(mvp->name.c_str(), "mvp");
187 EXPECT_EQ(mvp->type, fb::shaderbundle::UniformDataType::kFloat);
188 EXPECT_EQ(mvp->offset_in_bytes, 0u);
189 EXPECT_EQ(mvp->element_size_in_bytes, 64u);
190 EXPECT_EQ(mvp->total_size_in_bytes, 64u);
191 EXPECT_EQ(mvp->array_elements, 0u);
192 const auto& color = vert_info->fields[1];
193 EXPECT_STREQ(color->name.c_str(), "color");
194 EXPECT_EQ(color->type, fb::shaderbundle::UniformDataType::kFloat);
195 EXPECT_EQ(color->offset_in_bytes, 64u);
196 EXPECT_EQ(color->element_size_in_bytes, 16u);
197 EXPECT_EQ(color->total_size_in_bytes, 16u);
198 EXPECT_EQ(color->array_elements, 0u);
199
200 // --------------------------------------------------------------------------
201 /// Verify fragment shader.
202 ///
203
204 EXPECT_STREQ(fragment->metal_desktop->entrypoint.c_str(),
205 "flutter_gpu_unlit_fragment_main");
206 EXPECT_EQ(fragment->metal_desktop->stage,
207 fb::shaderbundle::ShaderStage::kFragment);
208
209 // Inputs (not recorded for fragment shaders).
210 ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
211
212 // Uniforms.
213 ASSERT_EQ(fragment->metal_desktop->inputs.size(), 0u);
214 }

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

## ◆ TEST() [3/16]

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 }

References impeller::compiler::ParseShaderBundleConfig().

## ◆ TEST() [4/16]

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() [5/16]

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() [6/16]

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() [7/16]

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() [8/16]

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() [9/16]

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

Definition at line 88 of file shader_bundle_unittests.cc.

88 {
89 std::string bundle =
90 "{" + kUnlitVertexBundleConfig + ", " + kUnlitFragmentBundleConfig + "}";
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 }

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

## ◆ TEST() [10/16]

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

Definition at line 72 of file switches_unittests.cc.

72 {
73 ASSERT_EQ(ConvertToEntrypointName("mandelbrot_unrolled"),
74 "mandelbrot_unrolled");
75 ASSERT_EQ(ConvertToEntrypointName("mandelbrot-unrolled"),
76 "mandelbrotunrolled");
77 ASSERT_EQ(ConvertToEntrypointName("7_"), "i_7_");
78 ASSERT_EQ(ConvertToEntrypointName("415"), "i_415");
79 ASSERT_EQ(ConvertToEntrypointName("#$%"), "i_");
80 ASSERT_EQ(ConvertToEntrypointName(""), "");
81 }

References impeller::compiler::ConvertToEntrypointName().

## ◆ TEST() [11/16]

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

Definition at line 60 of file switches_unittests.cc.

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

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

## ◆ TEST() [12/16]

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

Definition at line 31 of file switches_unittests.cc.

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

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

## ◆ TEST() [13/16]

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

Definition at line 66 of file switches_unittests.cc.

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

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

## ◆ TEST() [14/16]

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

Definition at line 83 of file switches_unittests.cc.

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

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

## ◆ TEST() [15/16]

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

Definition at line 54 of file switches_unittests.cc.

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

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

## ◆ TEST() [16/16]

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

Definition at line 48 of file switches_unittests.cc.

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

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

## ◆ TEST_P() [1/10]

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

Definition at line 81 of file compiler_unittests.cc.

81 {
82 if (!TargetPlatformIsVulkan(GetParam())) {
83 GTEST_SKIP();
84 }
85
86 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
87 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
88
89 auto get_binding = [&](const char* fixture) -> uint32_t {
90 auto json_fd = GetReflectionJson(fixture);
91 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
92 return shader_json["buffers"][0]["binding"].get<uint32_t>();
93 };
94
95 auto vert_uniform_binding = get_binding("sample.vert");
96 auto frag_uniform_binding = get_binding("sample.frag");
97
98 ASSERT_GT(frag_uniform_binding, vert_uniform_binding);
99 }

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

## ◆ TEST_P() [2/10]

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

Definition at line 26 of file compiler_unittests.cc.

26 {
27 if (GetParam() == TargetPlatform::kSkSL) {
28 GTEST_SKIP() << "Not supported with SkSL";
29 }
30 ASSERT_TRUE(CanCompileAndReflect("sample.vert"));
31 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader));
32 ASSERT_TRUE(CanCompileAndReflect("sample.vert", SourceType::kVertexShader,
33 SourceLanguage::kGLSL));
34 }

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

## ◆ TEST_P() [3/10]

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

Definition at line 56 of file compiler_unittests.cc.

56 {
57 if (!TargetPlatformIsMetal(GetParam())) {
58 GTEST_SKIP_("Only enabled on Metal backends till ES 3.2 support is added.");
59 }
60 ASSERT_TRUE(CanCompileAndReflect("sample.comp"));
61 ASSERT_TRUE(CanCompileAndReflect("sample.comp", SourceType::kComputeShader));
62 }

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

## ◆ TEST_P() [4/10]

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

Definition at line 36 of file compiler_unittests.cc.

36 {
37 if (GetParam() == TargetPlatform::kSkSL) {
38 GTEST_SKIP() << "Not supported with SkSL";
39 }
40 ASSERT_TRUE(CanCompileAndReflect(
41 "simple.vert.hlsl", SourceType::kVertexShader, SourceLanguage::kHLSL));
42 }

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

## ◆ TEST_P() [5/10]

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

Definition at line 44 of file compiler_unittests.cc.

44 {
45 if (GetParam() == TargetPlatform::kSkSL) {
46 GTEST_SKIP() << "Not supported with SkSL";
47 }
48 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
49 SourceType::kVertexShader,
50 SourceLanguage::kHLSL, "VertexShader"));
51 ASSERT_TRUE(CanCompileAndReflect("multiple_stages.hlsl",
52 SourceType::kFragmentShader,
53 SourceLanguage::kHLSL, "FragmentShader"));
54 }

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

## ◆ TEST_P() [6/10]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | CanCompileStructs |
| ) |  |

Definition at line 147 of file compiler_unittests.cc.

147 {
148 if (GetParam() != TargetPlatform::kSkSL) {
149 GTEST_SKIP() << "Only supported on SkSL";
150 }
151 ASSERT_TRUE(CanCompileAndReflect("struct_internal.frag",
152 SourceType::kFragmentShader));
153 }

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

## ◆ TEST_P() [7/10]

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

Definition at line 64 of file compiler_unittests.cc.

64 {
65 if (GetParam() == TargetPlatform::kSkSL) {
66 GTEST_SKIP() << "Not supported with SkSL";
67 }
68 ScopedValidationDisable disable_validation;
69 ASSERT_FALSE(
70 CanCompileAndReflect("resources_limit.vert", SourceType::kVertexShader));
71 }

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

## ◆ TEST_P() [8/10]

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

Definition at line 73 of file compiler_unittests.cc.

73 {
74 if (GetParam() == TargetPlatform::kSkSL) {
75 GTEST_SKIP() << "Not supported with SkSL";
76 }
77 ScopedValidationDisable disable_validation;
78 ASSERT_FALSE(CanCompileAndReflect("struct_def_bug.vert"));
79 }

References impeller::compiler::kSkSL.

## ◆ TEST_P() [9/10]

impeller::compiler::testing::TEST_P | ( | CompilerTest | ,
|  | SkSLTextureLookUpOrderOfOperations |
| ) |  |

Definition at line 130 of file compiler_unittests.cc.

130 {
131 if (GetParam() != TargetPlatform::kSkSL) {
132 GTEST_SKIP() << "Only supported on SkSL";
133 }
134 ASSERT_TRUE(
135 CanCompileAndReflect("texture_lookup.frag", SourceType::kFragmentShader));
136
137 auto shader = GetShaderFile("texture_lookup.frag", GetParam());
138 std::string_view shader_mapping(
139 reinterpret_cast<const char*>(shader->GetMapping()), shader->GetSize());
140
141 constexpr std::string_view expected =
142 "textureA.eval(textureA_size * ( vec2(1.0) + flutter_FragCoord.xy));";
143
144 EXPECT_NE(shader_mapping.find(expected), std::string::npos);
145 }

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

## ◆ TEST_P() [10/10]

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

Definition at line 101 of file compiler_unittests.cc.

101 {
102 if (GetParam() == TargetPlatform::kSkSL) {
103 GTEST_SKIP() << "Not supported with SkSL";
104 }
105 ASSERT_TRUE(CanCompileAndReflect("sample_with_binding.vert",
106 SourceType::kVertexShader));
107 ASSERT_TRUE(CanCompileAndReflect("sample.frag", SourceType::kFragmentShader));
108
109 struct binding_and_set {
110 uint32_t binding;
111 uint32_t set;
112 };
113
114 auto get_binding = [&](const char* fixture) -> binding_and_set {
115 auto json_fd = GetReflectionJson(fixture);
116 nlohmann::json shader_json = nlohmann::json::parse(json_fd->GetMapping());
117 uint32_t binding = shader_json["buffers"][0]["binding"].get<uint32_t>();
118 uint32_t set = shader_json["buffers"][0]["set"].get<uint32_t>();
119 return {binding, set};
120 };
121
122 auto vert_uniform_binding = get_binding("sample_with_binding.vert");
123 auto frag_uniform_binding = get_binding("sample.frag");
124
125 ASSERT_EQ(frag_uniform_binding.set, 0u);
126 ASSERT_EQ(vert_uniform_binding.set, 3u);
127 ASSERT_EQ(vert_uniform_binding.binding, 17u);
128 }

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

## 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().

impeller::kFloat
@ kFloat
Definition: runtime_types.h:23
impeller::compiler::ConvertToEntrypointName
std::string ConvertToEntrypointName(std::string_view string)
Ensure that the entrypoint name is a valid identifier in the target language.
Definition: utilities.cc:69
impeller::compiler::TargetPlatformSLExtension
std::string TargetPlatformSLExtension(TargetPlatform platform)
Definition: types.cc:246
impeller::compiler::testing::kUnlitVertexBundleConfig
const std::string kUnlitVertexBundleConfig
Definition: shader_bundle_unittests.cc:20
impeller::compiler::ParseShaderBundleConfig
std::optional< ShaderBundleConfig > ParseShaderBundleConfig(const std::string &bundle_config_json, std::ostream &error_stream)
Parse a shader bundle configuration from a given JSON string.
Definition: shader_bundle.cc:19
impeller::compiler::testing::FindByName
const T * FindByName(const std::vector< std::unique_ptr< T >> &collection, const std::string &name)
Definition: shader_bundle_unittests.cc:119
impeller::compiler::testing::kUnlitFragmentBundleConfig
const std::string kUnlitFragmentBundleConfig
Definition: shader_bundle_unittests.cc:17
impeller::compiler::GenerateShaderBundleFlatbuffer
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...
Definition: shader_bundle.cc:179
impeller::compiler::TargetPlatformIsMetal
bool TargetPlatformIsMetal(TargetPlatform platform)
Definition: types.cc:284
impeller::compiler::TargetPlatformIsVulkan
bool TargetPlatformIsVulkan(TargetPlatform platform)
Definition: types.cc:302
impeller::compiler::SourceTypeFromFileName
SourceType SourceTypeFromFileName(const std::string &file_name)
Definition: types.cc:30
impeller::compiler::testing::MakeSwitchesDesktopGL
Switches MakeSwitchesDesktopGL(std::initializer_list< const char * > additional_options={})
Definition: switches_unittests.cc:18
color
DlColor color
Definition: dl_golden_blur_unittests.cc:23